public override void OnGUI(Rect rect) { scrollViewPos = EditorGUILayout.BeginScrollView(scrollViewPos); jsonStr = EditorGUILayout.TextArea(jsonStr); GUILayout.FlexibleSpace(); if (GUILayout.Button("OK")) { try { rp.Value = JsonConvert.DeserializeObject <T> (jsonStr); this.editorWindow.Close(); } catch { if (EditorUtility.DisplayDialog("警告!", "输入的 Json 编码有误,重置到最初?", "重置", "取消")) { rp.Value = JsonConvert.DeserializeObject <T> (jsonStr_ori); } } parent.VMCopyToJson(); } if (GUILayout.Button("Set Null")) { rp.Value = default(T); this.editorWindow.Close(); parent.VMCopyToJson(); GUI.changed = true; } if (GUILayout.Button("Close")) { this.editorWindow.Close(); } EditorGUILayout.EndScrollView(); }
public override void OnGUI(Rect rect) { scrollViewPos = EditorGUILayout.BeginScrollView(scrollViewPos); for (int i = 0; i < rc.Count; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(i.ToString(), GUILayout.MaxWidth(30)); T e = rc [i]; string tempJson = JsonConvert.SerializeObject(e); string tempJson2 = EditorGUILayout.DelayedTextField(tempJson); if (tempJson != tempJson2) { rc [i] = JsonConvert.DeserializeObject <T> (tempJson2); parent.VMCopyToJson(); } if (GUILayout.Button("-", GUILayout.MaxWidth(20))) { rc.RemoveAt(i); parent.VMCopyToJson(); break; } if (GUILayout.Button("+", GUILayout.MaxWidth(20))) { rc.Insert(i, PE); parent.VMCopyToJson(); break; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("NEW", GUILayout.MaxWidth(30)); string PEJson = JsonConvert.SerializeObject(PE); PEJson = EditorGUILayout.DelayedTextField(PEJson); PE = JsonConvert.DeserializeObject <T> (PEJson); if (GUILayout.Button("+", GUILayout.MaxWidth(40))) { rc.Add(PE); (parent as IElementEditor).VMCopyToJson(); } EditorGUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Json")) { PRDebug.TagLog("ReactiveDictionary", new Color(.2f, .2f, 1f), JsonConvert.SerializeObject(rc, Formatting.Indented)); } if (GUILayout.Button("Clear")) { rc.Clear(); this.editorWindow.Close(); parent.VMCopyToJson(); GUI.changed = true; } if (GUILayout.Button("Close")) { this.editorWindow.Close(); } EditorGUILayout.EndScrollView(); }
public override void OnGUI(Rect rect) { scrollViewPos = EditorGUILayout.BeginScrollView(scrollViewPos); foreach (T key in rd.Keys) { U value = rd [key]; EditorGUILayout.BeginHorizontal(); string tempkJson = JsonConvert.SerializeObject(key); string tempkJson2 = EditorGUILayout.DelayedTextField(tempkJson); if (tempkJson != tempkJson2) { T newKey = JsonConvert.DeserializeObject <T> (tempkJson2); rd [newKey] = value; rd.Remove(key); parent.VMCopyToJson(); } string tempvJson = JsonConvert.SerializeObject(value); string tempvJson2 = EditorGUILayout.DelayedTextField(tempvJson); if (tempvJson != tempvJson2) { U newValue = JsonConvert.DeserializeObject <U> (tempvJson2); rd [key] = newValue; parent.VMCopyToJson(); } if (GUILayout.Button("-", GUILayout.MaxWidth(20))) { rd.Remove(key); parent.VMCopyToJson(); break; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); string PKJson = JsonConvert.SerializeObject(PK); PKJson = EditorGUILayout.DelayedTextField(PKJson); PK = JsonConvert.DeserializeObject <T> (PKJson); string PVJson = JsonConvert.SerializeObject(PV); PVJson = EditorGUILayout.DelayedTextField(PVJson); PV = JsonConvert.DeserializeObject <U> (PVJson); if (GUILayout.Button("+", GUILayout.MaxWidth(20))) { rd.Add(PK, PV); parent.VMCopyToJson(); } EditorGUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Json")) { PRDebug.TagLog("ReactiveDictionary", new Color(.2f, .2f, 1f), JsonConvert.SerializeObject(rd, Formatting.Indented)); } if (GUILayout.Button("Clear")) { rd.Clear(); this.editorWindow.Close(); parent.VMCopyToJson(); GUI.changed = true; } if (GUILayout.Button("Close")) { this.editorWindow.Close(); } EditorGUILayout.EndScrollView(); }