Browse Source

up

master
chenbin 4 years ago
parent
commit
ab64739382
1 changed files with 34 additions and 11 deletions
  1. 34
    11
      Assets/CoolapeFrame/Scripts/ui/form/CLUIFormRoot.cs

+ 34
- 11
Assets/CoolapeFrame/Scripts/ui/form/CLUIFormRoot.cs View File

@@ -43,6 +43,20 @@ public class CLUIFormRoot : MonoBehaviour
43 43
 		return ret == null ? "" : ret;
44 44
 	}
45 45
 
46
+	bool containKey(object map, object key)
47
+    {
48
+		bool ret = false;
49
+		if (map is LuaTable)
50
+		{
51
+			ret = ((LuaTable)map).ContainsKey(key);
52
+		}
53
+		else if (map is Hashtable)
54
+		{
55
+			ret = ((Hashtable)map).ContainsKey(key);
56
+		}
57
+		return ret;
58
+	}
59
+
46 60
 	public object getValue (bool isLuatable = false)
47 61
 	{
48 62
 		return getValue (null, isLuatable);
@@ -87,16 +101,16 @@ public class CLUIFormRoot : MonoBehaviour
87 101
 		return map;
88 102
 	}
89 103
 
90
-	public void setValue (object map)
104
+	public void setValue (object map, bool onlySetWhenContainKey = false)
91 105
 	{
92 106
 		if (map is LuaTable) {
93
-			setValue (transform, map, true);
107
+			setValue (transform, map, true, onlySetWhenContainKey);
94 108
 		} else {
95
-			setValue (transform, map);
109
+			setValue (transform, map, false, onlySetWhenContainKey);
96 110
 		}
97 111
 	}
98 112
 
99
-	public void setValue (Transform tr, object map, bool isLuatable = false)
113
+	public void setValue (Transform tr, object map, bool isLuatable = false, bool onlySetWhenContainKey = false)
100 114
 	{
101 115
 		if (map == null) {
102 116
 			map = new Hashtable ();
@@ -110,18 +124,27 @@ public class CLUIFormRoot : MonoBehaviour
110 124
 			cellTr = tr.GetChild (i);
111 125
 			cell = cellTr.GetComponent<CLUIElement> ();
112 126
 			if (cell != null && !string.IsNullOrEmpty (cell.jsonKey)) {
113
-				if (cell.valueIsNumber) {
114
-					cell.value = getVal (map, cell.jsonKey).ToString ();
115
-//					cell.value = MapEx.getInt(map, cell.jsonKey).ToString();
116
-				} else {
117
-					cell.value = getVal (map, cell.jsonKey).ToString ();
127
+				if (!onlySetWhenContainKey || (onlySetWhenContainKey && containKey(map, cell.jsonKey)))
128
+				{
129
+					if (cell.valueIsNumber)
130
+					{
131
+						cell.value = getVal(map, cell.jsonKey).ToString();
132
+					}
133
+					else
134
+					{
135
+						cell.value = getVal(map, cell.jsonKey).ToString();
136
+					}
118 137
 				}
119 138
 			}
120 139
 			
121 140
 			root = cellTr.GetComponent<CLUIFormRoot> ();
122 141
 			if (root != null) {
123
-				if (!string.IsNullOrEmpty (root.jsonKey)) {
124
-					setValue (root.transform, getVal (map, root.jsonKey), isLuatable);
142
+				if (!string.IsNullOrEmpty (root.jsonKey))
143
+				{
144
+					if (!onlySetWhenContainKey || (onlySetWhenContainKey && containKey(map, root.jsonKey)))
145
+					{
146
+						setValue(root.transform, getVal(map, root.jsonKey), isLuatable);
147
+					}
125 148
 				} else {
126 149
 					setValue (root.transform, map, isLuatable);
127 150
 				}

Loading…
Cancel
Save