public static void FoldOut(ref bool state, string content, System.Action onContent, GUIStyle style = null) { if (style == null) { style = new GUIStyle(EditorStyles.foldoutHeader); style.fixedWidth = 0f; style.stretchWidth = true; if (GUILayoutExt.foldOutLevel == 0) { style.fixedHeight = 24f; style.richText = true; content = "<b>" + content + "</b>"; } else { style.fixedHeight = 16f; style.richText = true; } } ++GUILayoutExt.foldOutLevel; state = GUILayoutExt.BeginFoldoutHeaderGroup(state, new GUIContent(content), style); if (state == true) { onContent.Invoke(); } EditorGUILayout.EndFoldoutHeaderGroup(); --GUILayoutExt.foldOutLevel; }
public static bool BeginFoldoutHeaderGroup( bool foldout, GUIContent content, GUIStyle style = null, System.Action <Rect> menuAction = null, GUIStyle menuIcon = null) { return(GUILayoutExt.BeginFoldoutHeaderGroup(GUILayoutUtility.GetRect(content, style), foldout, content, style, menuAction, menuIcon)); }
private void OnDrawListItem(Rect rect, int index, bool isActive, bool isFocused) { var featureData = (FeaturesList.FeatureData) this.list.list[index]; rect.height = InitializerEditor.ONE_LINE_HEIGHT; var rectCheckBox = new Rect(rect); rectCheckBox.width = 20f; var isDirty = false; { rect.y += 1f; rect.height -= 2f; var rectObjectField = new Rect(rect); rectObjectField.x += rectCheckBox.width; rectObjectField.width -= rectCheckBox.width; var oldColor = GUI.color; if (featureData.enabled == false) { GUI.color = new Color(oldColor.r, oldColor.g, oldColor.b, 0.5f); } var obj = (FeatureBase)EditorGUI.ObjectField(rectObjectField, featureData.feature, typeof(FeatureBase), allowSceneObjects: false); if (obj != featureData.feature) { featureData.feature = obj; var count = 0; for (int i = 0; i < this.list.count; ++i) { var data = (FeaturesList.FeatureData) this.list.list[i]; if (data.feature != null && featureData.feature != null && featureData.feature == data.feature) { ++count; } } if (count > 1) { featureData.feature = null; } isDirty = true; } GUI.color = oldColor; if (featureData.feature == null) { featureData.enabled = false; } EditorGUI.BeginDisabledGroup(featureData.feature == null); var flag = GUI.Toggle(rectCheckBox, featureData.enabled, string.Empty); if (flag != featureData.enabled) { featureData.enabled = flag; isDirty = true; } EditorGUI.EndDisabledGroup(); } if (featureData.feature != null) // Draw feature { rect.x += rectCheckBox.width + 14f; var editorComment = featureData.feature.editorComment; if (string.IsNullOrEmpty(editorComment) == false) { var style = EditorStyles.label; var content = new GUIContent(editorComment); var newRect = new Rect(rect); newRect.height = style.CalcHeight(content, rect.width); newRect.width = rect.width; newRect.y += InitializerEditor.ONE_LINE_HEIGHT; GUI.Label(newRect, content, style); rect.y += newRect.height; } var count = this.GetSystemsCount(featureData.feature); if (count > 0) { rect.y += InitializerEditor.ONE_LINE_HEIGHT; var isOpen = GUILayoutExt.BeginFoldoutHeaderGroup(rect, this.IsSystemFoldout(featureData.feature), new GUIContent(string.Format("Systems ({0})", count))); this.SetSystemFoldout(featureData.feature, isOpen); if (isOpen == true) { var systems = this.GetSystems(featureData.feature); foreach (var system in systems) { rect.y += InitializerEditor.ONE_LINE_HEIGHT; GUI.Label(rect, system, EditorStyles.label); } } } count = this.GetModulesCount(featureData.feature); if (count > 0) { rect.y += InitializerEditor.ONE_LINE_HEIGHT; var isOpen = GUILayoutExt.BeginFoldoutHeaderGroup(rect, this.IsModuleFoldout(featureData.feature), new GUIContent(string.Format("Modules ({0})", count))); this.SetModuleFoldout(featureData.feature, isOpen); if (isOpen == true) { var systems = this.GetModules(featureData.feature); foreach (var system in systems) { rect.y += InitializerEditor.ONE_LINE_HEIGHT; GUI.Label(rect, system, EditorStyles.label); } } } } if (isDirty == true) { EditorUtility.SetDirty(this.target); } }
public override void OnInspectorGUI() { ((Component)this.target).transform.hideFlags = HideFlags.HideInInspector; GUILayoutExt.CollectEditors <IDebugViewGUIEditor <InitializerBase>, ViewProviderCustomEditorAttribute>(ref this.viewsDebugEditors); GUILayoutExt.CollectEditors <IJobsViewGUIEditor <InitializerBase>, ViewProviderCustomEditorAttribute>(ref this.viewsJobsEditors); var target = this.target as InitializerBase; if (target.featuresList == null) { target.featuresList = new FeaturesList(); } if (target.featuresList.features == null) { target.featuresList.features = new System.Collections.Generic.List <FeaturesList.FeatureData>(); } if (this.list == null) { this.list = new UnityEditorInternal.ReorderableList(target.featuresList.features, typeof(FeaturesList.FeatureData), true, true, true, true); this.list.drawElementCallback = this.OnDrawListItem; this.list.drawHeaderCallback = this.OnDrawHeader; this.list.onChangedCallback = this.OnChanged; this.list.elementHeightCallback = this.GetElementHeight; } GUILayoutExt.Box(15f, 0f, () => { var isDirty = false; this.definesFoldOut = GUILayoutExt.BeginFoldoutHeaderGroup(this.definesFoldOut, new GUIContent("Defines"), EditorStyles.foldoutHeader); if (this.definesFoldOut == true) { GUILayout.Space(10f); EditorGUI.BeginDisabledGroup(EditorApplication.isCompiling == true || EditorApplication.isPlaying == true || EditorApplication.isPaused == true /* || InitializerEditor.isCompilingManual == true*/); foreach (var defineInfo in InitializerEditor.defines) { if (defineInfo.showInList == false) { continue; } var value = defineInfo.isActive.Invoke(); if (GUILayoutExt.ToggleLeft( ref value, ref isDirty, defineInfo.define, defineInfo.description) == true) { //InitializerEditor.isCompilingManual = true; if (value == true) { this.CompileWithDefine(defineInfo.define); } else { this.CompileWithoutDefine(defineInfo.define); } } } EditorGUI.EndDisabledGroup(); } this.settingsFoldOut = GUILayoutExt.BeginFoldoutHeaderGroup(this.settingsFoldOut, new GUIContent("Settings"), EditorStyles.foldoutHeader); if (this.settingsFoldOut == true) { GUILayout.Space(10f); GUILayoutExt.ToggleLeft( ref target.worldSettings.turnOffViews, ref isDirty, "Turn off views module", "If you want to run ME.ECS on server, you don't need to use Views at all. Turn off views module to avoid updating view instances overhead."); GUILayoutExt.ToggleLeft( ref target.worldSettings.useJobsForSystems, ref isDirty, "Use jobs for Systems", "Each system with filter has `jobs` flag which determine AdvanceTick behavior. If checked, jobs will be enabled and AdvanceTick will run asynchronously."); GUILayoutExt.ToggleLeft( ref target.worldSettings.useJobsForViews, ref isDirty, "Use jobs for Views", "Some view providers have jobs implementation. Turn it on to enable them update views inside jobs. Please note that some providers could lose some method calls."); if (this.viewsJobsEditors != null) { GUILayout.BeginHorizontal(); GUILayout.Space(10f); { GUILayout.BeginVertical(); foreach (var editor in this.viewsJobsEditors) { GUILayoutExt.Separator(); editor.Value.target = this.target as InitializerBase; if (editor.Value.OnDrawGUI() == true) { isDirty = true; } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } } this.settingsDebugFoldOut = GUILayoutExt.BeginFoldoutHeaderGroup(this.settingsDebugFoldOut, new GUIContent("Debug Settings"), EditorStyles.foldoutHeader); if (this.settingsDebugFoldOut == true) { GUILayout.Space(10f); GUILayoutExt.ToggleLeft( ref target.worldDebugSettings.createGameObjectsRepresentation, ref isDirty, "Create GameObject representation", "Editor-only feature. If checked, all entities will be represented by GameObject with debug information."); GUILayoutExt.ToggleLeft( ref target.worldDebugSettings.showViewsOnScene, ref isDirty, "Show Views in Hierarchy", "Editor-only feature. If checked, views module always show views on scene."); if (this.viewsDebugEditors != null) { GUILayout.BeginHorizontal(); GUILayout.Space(10f); { GUILayout.BeginVertical(); foreach (var editor in this.viewsDebugEditors) { GUILayoutExt.Separator(); editor.Value.target = this.target as InitializerBase; if (editor.Value.OnDrawGUI() == true) { isDirty = true; } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } } { var editor = Editor.CreateEditor(target); var field = editor.serializedObject.GetIterator(); editor.serializedObject.Update(); var baseClassEnd = false; while (field.NextVisible(true) == true) { if (baseClassEnd == true) { EditorGUILayout.PropertyField(field); } if (field.type == "EndOfBaseClass") { baseClassEnd = true; } } editor.serializedObject.ApplyModifiedProperties(); } if (isDirty == true) { EditorUtility.SetDirty(this.target); } }); EditorGUILayout.Space(); EditorGUI.BeginDisabledGroup(EditorApplication.isPlaying == true || EditorApplication.isPaused == true); this.drawWidth = GUILayoutUtility.GetLastRect().width; this.list.DoLayoutList(); EditorGUI.EndDisabledGroup(); }