private void DrawScreenChooser(float width) { var screens = new string[this.screens.Count + 1]; screens[0] = "None"; for (int i = 1; i < screens.Length; ++i) { screens[i] = this.screens[i - 1].name.Replace("Screen", string.Empty); } GUILayout.Label("Use existing screen:"); var index = this.screenPrefab == null ? 0 : (System.Array.IndexOf(screens, this.screenPrefab.name.Replace("Screen", string.Empty))); index = EditorGUILayout.Popup(index, screens); if (index > 0) { this.screenPrefab = this.screens[index - 1]; } this.screenPrefab = EditorGUILayout.ObjectField(this.screenPrefab, typeof(WindowBase), false) as WindowBase; if (GUILayout.Button("Load") == true) { this.LoadScreen(this.screenPrefab); } GUILayout.Label("Or create the new one:"); if (GUILayout.Button("Create Screen...", GUILayout.Height(30f)) == true) { this.showScreenWindow = true; } if (Event.current.type == EventType.Repaint && this.showScreenWindow == true) { this.showScreenWindow = false; var commentStyle = new GUIStyle(EditorStyles.miniLabel); commentStyle.wordWrap = true; var rect = GUILayoutUtility.GetLastRect(); rect.x += this.mainRect.x + this.currentView.position.x - this.scrollPosition.x + this.lastRect.x; rect.y += this.mainRect.y + this.currentView.position.y + rect.height - this.scrollPosition.y + this.lastRect.y + 15f; FlowDropDownFilterWindow.Show <FlowLayoutWindowTypeTemplate>(rect, (screen) => { this.screenPrefab = FlowDatabase.GenerateScreen(this.window, screen); this.ReloadScreens(); this.LoadScreen(this.screenPrefab); this.isScreenDirty = true; }, (screen) => { GUILayout.Label(screen.comment, commentStyle); }, strongType: true); Event.current.Use(); } }
public static void Show <T>(Rect buttonRect, Vector2 windowSize, System.Action <T> onSelect, System.Action <T> onEveryGUI = null, bool strongType = true) where T : Component { var editor = FlowDropDownFilterWindow.CreateInstance <FlowDropDownFilterWindow>(); editor.title = "UI.Windows Flow Filter"; editor.ShowAsDropDown(new Rect(buttonRect.x, buttonRect.y, buttonRect.width, 1), windowSize); editor.onSelect = (c) => { if (onSelect != null) { onSelect(c as T); } editor.Close(); }; editor.onEveryGUI = (c) => { if (onEveryGUI != null) { onEveryGUI(c as T); } }; editor.Scan <T>(strongType); }
private void DrawModules(float width) { if (this.screenInstance != null) { var screen = this.screenInstance; if (screen != null) { var commentStyle = new GUIStyle(EditorStyles.miniLabel); commentStyle.wordWrap = true; var modules = screen.modules.GetModulesInfo(); var query = from x in modules group x.moduleSource by x.moduleSource into g let count = g.Count() orderby count descending select new { Value = g.Key, Count = count }; var warnings = new List <string>(); foreach (var element in query) { if (element.Count > 1) { warnings.Add(element.Value.name); } } if (warnings.Count > 0) { EditorGUILayout.HelpBox("Warning! You have duplicate elements in modules list. It may cause problems in the View. Modules: " + (string.Join(", ", warnings.ToArray())), MessageType.Warning); } foreach (var moduleInfo in modules) { var oldColor = GUI.color; GUILayout.BeginVertical(GUI.skin.box); { GUILayout.BeginHorizontal(); { GUILayout.Label(moduleInfo.moduleSource.name, EditorStyles.miniButtonLeft); GUI.color = Color.red; if (GUILayout.Button("X", EditorStyles.miniButtonRight, GUILayout.Width(30f)) == true) { screen.modules.RemoveModule(moduleInfo); this.isScreenDirty = true; break; } GUI.color = oldColor; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(moduleInfo.moduleSource.comment, commentStyle); } GUILayout.EndHorizontal(); GUILayout.BeginVertical(); { this.foldoutModules = EditorGUILayout.Foldout(this.foldoutModules, "Properties", EditorStyles.foldout); if (this.foldoutModules == true) { EditorGUIUtility.labelWidth = 100f; EditorGUILayout.HelpBox("Sorting Order - it's SiblibngIndex() of transform. Sorting order always must have more than zero values.", MessageType.Info); var sortingOrder = EditorGUILayout.IntField("Sorting Order:", moduleInfo.sortingOrder, GUILayout.Width(width)); if (sortingOrder < 0) { sortingOrder = 0; } if (sortingOrder != moduleInfo.sortingOrder) { this.isScreenDirty = true; moduleInfo.sortingOrder = sortingOrder; } EditorGUIUtility.labelWidth = 140f; EditorGUILayout.HelpBox("To set SiblingIndex() lower than zero use this option.", MessageType.Info); var backgroundLayer = EditorGUILayout.Toggle("Is Background Layer:", moduleInfo.backgroundLayer, GUILayout.Width(width)); if (backgroundLayer != moduleInfo.backgroundLayer) { this.isScreenDirty = true; moduleInfo.backgroundLayer = backgroundLayer; } } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } if (GUILayout.Button("Add Module...", GUILayout.Height(30f)) == true) { this.showModuleWindow = true; } if (Event.current.type == EventType.Repaint && this.showModuleWindow == true) { this.showModuleWindow = false; var rect = GUILayoutUtility.GetLastRect(); rect.x += this.mainRect.x + this.currentView.position.x - this.scrollPosition.x + this.lastRect.x; rect.y += this.mainRect.y + this.currentView.position.y + rect.height - this.scrollPosition.y + this.lastRect.y + 15f; FlowDropDownFilterWindow.Show <WindowModule>(rect, (module) => { screen.modules.AddModuleInfo(module, module.defaultSortingOrder, module.defaultBackgroundLayer); this.isScreenDirty = true; }, (module) => { GUILayout.Label(module.comment, commentStyle); }, strongType: false); Event.current.Use(); } } } }
public static void Show <T>(Rect buttonRect, System.Action <T> onSelect, System.Action <T> onEveryGUI = null, bool strongType = true) where T : Component { var size = new Vector2(buttonRect.width, 250f); FlowDropDownFilterWindow.Show(buttonRect, size, onSelect, onEveryGUI, strongType); }