This commit is contained in:
2020-07-11 20:27:12 +08:00
parent 096f0ae4a1
commit ab64739382

View File

@@ -43,6 +43,20 @@ public class CLUIFormRoot : MonoBehaviour
return ret == null ? "" : ret;
}
bool containKey(object map, object key)
{
bool ret = false;
if (map is LuaTable)
{
ret = ((LuaTable)map).ContainsKey(key);
}
else if (map is Hashtable)
{
ret = ((Hashtable)map).ContainsKey(key);
}
return ret;
}
public object getValue (bool isLuatable = false)
{
return getValue (null, isLuatable);
@@ -87,16 +101,16 @@ public class CLUIFormRoot : MonoBehaviour
return map;
}
public void setValue (object map)
public void setValue (object map, bool onlySetWhenContainKey = false)
{
if (map is LuaTable) {
setValue (transform, map, true);
setValue (transform, map, true, onlySetWhenContainKey);
} else {
setValue (transform, map);
setValue (transform, map, false, onlySetWhenContainKey);
}
}
public void setValue (Transform tr, object map, bool isLuatable = false)
public void setValue (Transform tr, object map, bool isLuatable = false, bool onlySetWhenContainKey = false)
{
if (map == null) {
map = new Hashtable ();
@@ -110,18 +124,27 @@ public class CLUIFormRoot : MonoBehaviour
cellTr = tr.GetChild (i);
cell = cellTr.GetComponent<CLUIElement> ();
if (cell != null && !string.IsNullOrEmpty (cell.jsonKey)) {
if (cell.valueIsNumber) {
cell.value = getVal (map, cell.jsonKey).ToString ();
// cell.value = MapEx.getInt(map, cell.jsonKey).ToString();
} else {
cell.value = getVal (map, cell.jsonKey).ToString ();
if (!onlySetWhenContainKey || (onlySetWhenContainKey && containKey(map, cell.jsonKey)))
{
if (cell.valueIsNumber)
{
cell.value = getVal(map, cell.jsonKey).ToString();
}
else
{
cell.value = getVal(map, cell.jsonKey).ToString();
}
}
}
root = cellTr.GetComponent<CLUIFormRoot> ();
if (root != null) {
if (!string.IsNullOrEmpty (root.jsonKey)) {
setValue (root.transform, getVal (map, root.jsonKey), isLuatable);
if (!string.IsNullOrEmpty (root.jsonKey))
{
if (!onlySetWhenContainKey || (onlySetWhenContainKey && containKey(map, root.jsonKey)))
{
setValue(root.transform, getVal(map, root.jsonKey), isLuatable);
}
} else {
setValue (root.transform, map, isLuatable);
}