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