From ab647393822c224c6d1f2ad4b7ccbc3ebf3a3525 Mon Sep 17 00:00:00 2001 From: chenbin Date: Sat, 11 Jul 2020 20:27:12 +0800 Subject: [PATCH] up --- .../Scripts/ui/form/CLUIFormRoot.cs | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/Assets/CoolapeFrame/Scripts/ui/form/CLUIFormRoot.cs b/Assets/CoolapeFrame/Scripts/ui/form/CLUIFormRoot.cs index c09be78..386d8e3 100644 --- a/Assets/CoolapeFrame/Scripts/ui/form/CLUIFormRoot.cs +++ b/Assets/CoolapeFrame/Scripts/ui/form/CLUIFormRoot.cs @@ -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 (); 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 (); 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); }