void OnGUI() { bool isCompiling = EditorApplication.isCompiling; if (isCompiling || mScriptItems.Count <= 0) { mToUpdate = true; } if (!isCompiling && mToUpdate) { mToUpdate = false; UpdateDataTypes(); } EditorGUI.BeginDisabledGroup(isCompiling); EditorGUILayout.BeginHorizontal(); mSearch = GUILayout.TextField(mSearch, "SearchTextField"); if (GUILayout.Button("", "SearchCancelButton")) { mSearch = null; } EditorGUILayout.EndHorizontal(); float width = (position.width - 224f) * 0.5f; mScroll = EditorGUILayout.BeginScrollView(mScroll, false, false, GUILayout.ExpandHeight(true)); int n = mScriptItems.Count; int count = -1; for (int i = 0; i < n; i++) { ScriptItem si = mScriptItems[i]; bool flag = true; if (!string.IsNullOrEmpty(mSearch)) { while (true) { if (si.Name.IndexOf(mSearch, StringComparison.OrdinalIgnoreCase) >= 0) { break; } bool ok = false; for (int j = 0, jmax = si.TypeCount; j < jmax; j++) { if (si.GetTypeItem(j).TypeName.IndexOf(mSearch, StringComparison.OrdinalIgnoreCase) >= 0) { ok = true; break; } } if (ok) { break; } flag = false; break; } } if (!flag) { continue; } count++; Color cachedColor = GUI.color; Color zebra = (count & 1) == 0 ? GUI.backgroundColor : new Color(0.8f, 0.8f, 0.8f); GUI.backgroundColor = zebra; EditorGUILayout.BeginVertical("CN Box", GUILayout.MinHeight(10f)); GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f); EditorGUILayout.BeginHorizontal("CN Box", GUILayout.MinHeight(10f)); GUI.backgroundColor = cachedColor; if (GUILayout.Button(si.Unfold.target ? "\u25BC" : "\u25BA", "WhiteMiniLabel", GUILayout.Width(16f))) { si.Unfold.target = !si.Unfold.target; SaveUnfoldState(); } cachedColor = GUI.backgroundColor; GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f); EditorGUILayout.ObjectField(si.Script, typeof(MonoScript), false); GUI.backgroundColor = cachedColor; GUILayout.FlexibleSpace(); EditorGUI.BeginDisabledGroup(!si.Dirty); if (GUILayout.Button("Update", GUILayout.Width(64f))) { string error = si.UpdateCode(); if (string.IsNullOrEmpty(error)) { AssetDatabase.Refresh(); mToUpdate = true; } else { EditorUtility.DisplayDialog("Rts Data Types", "Failed when generating code !\n" + error, "OK"); } } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); if (EditorGUILayout.BeginFadeGroup(si.Unfold.faded)) { EditorGUILayout.BeginHorizontal(); GUILayout.Label("NameSpace", GUILayout.Width(80f)); cachedColor = GUI.backgroundColor; if (!si.IsNameSpaceValid) { GUI.backgroundColor = Color.red; } si.NameSpace = EditorGUILayout.DelayedTextField(si.NameSpace); GUI.backgroundColor = cachedColor; EditorGUILayout.EndHorizontal(); int m = si.TypeCount; int toInsertType = -1; int toRemoveType = -1; for (int j = 0; j < m; j++) { cachedColor = GUI.backgroundColor; GUI.backgroundColor = zebra; EditorGUILayout.BeginVertical("CN Box", GUILayout.MinHeight(10f)); GUI.backgroundColor = cachedColor; TypeItem ti = si.GetTypeItem(j); EditorGUILayout.BeginHorizontal(); cachedColor = GUI.color; if (!ti.IsTypeNameValid) { GUI.color = Color.red; } ti.Name = EditorGUILayout.DelayedTextField(ti.Name, (GUIStyle)"BoldLabel", GUILayout.ExpandWidth(false), GUILayout.MinWidth(10f)); GUI.color = cachedColor; GUILayout.FlexibleSpace(); if (GUILayout.Button("+", "minibutton", GUILayout.Width(18f))) { toInsertType = j; } if (GUILayout.Button("x", "minibutton", GUILayout.Width(18f))) { toRemoveType = j; } EditorGUILayout.EndHorizontal(); GUILayout.Space(6f); int p = ti.FieldCount; int toInsertField = -1; int toRemoveField = -1; for (int k = 0; k < p; k++) { EditorGUILayout.BeginHorizontal(); FieldItem fi = ti.GetFieldItem(k); GUILayout.Label("Field Type:", GUILayout.Width(72f)); cachedColor = GUI.backgroundColor; if (!fi.IsTypeValid) { GUI.backgroundColor = Color.red; } fi.Type = EditorGUILayout.DelayedTextField(fi.Type, GUILayout.Width(width)); GUI.backgroundColor = cachedColor; GUILayout.FlexibleSpace(); GUILayout.Label("Field Name:", GUILayout.Width(72f)); cachedColor = GUI.backgroundColor; if (!fi.IsNameValid) { GUI.backgroundColor = Color.red; } fi.Name = EditorGUILayout.DelayedTextField(fi.Name, GUILayout.Width(width)); GUI.backgroundColor = cachedColor; if (GUILayout.Button("+", "minibutton", GUILayout.Width(18f))) { toInsertField = k; } if (GUILayout.Button("x", "minibutton", GUILayout.Width(18f))) { toRemoveField = k; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Create New Field", "minibutton", GUILayout.Width(100f))) { toInsertField = p; } EditorGUILayout.EndHorizontal(); if (toInsertField >= 0) { ti.InsertField(toInsertField); } if (toRemoveField >= 0) { ti.RemoveField(toRemoveField); } EditorGUILayout.EndVertical(); } cachedColor = GUI.backgroundColor; GUI.backgroundColor = zebra; EditorGUILayout.BeginHorizontal("CN Box", GUILayout.MinHeight(10f)); GUI.backgroundColor = cachedColor; if (GUILayout.Button("New Data Type", "minibutton", GUILayout.Width(100f))) { toInsertType = m; } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (toInsertType >= 0) { si.InsertType(toInsertType); } if (toRemoveType >= 0) { si.RemoveType(toRemoveType); } GUILayout.Space(2f); } EditorGUILayout.EndFadeGroup(); EditorGUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); if (GUILayout.Button("Create New Data Script")) { string path = EditorUtility.SaveFilePanelInProject("New RTS Data File", "NewRTSData", "cs", ""); if (!string.IsNullOrEmpty(path)) { string error = CreateNewDataFileAtPath(path); if (!string.IsNullOrEmpty(error)) { EditorUtility.DisplayDialog("New RTS Data File", string.Format("Failed in creating RTS Data file at '{0}' !\n{1}", path, error), "OK"); } else { AssetDatabase.Refresh(); } } } EditorGUI.EndDisabledGroup(); }