public override void OnFlowWindowScreenMenuGUI(FD.FlowWindow windowSource, GenericMenu menu) { menu.AddItem(new GUIContent("Components Editor..."), on: false, func: (object win) => { var window = win as FD.FlowWindow; var screen = window.GetScreen() as LayoutWindowType; if (screen != null) { this.flowEditor.SetDisabled(); //this.window = window; this.screen = screen; this.editor = Editor.CreateEditor(window.GetScreen()) as IPreviewEditor; this.component = null; this.hovered = null; this.element = null; this.listScrollPosition = Vector2.zero; var serializedObject = new SerializedObject(this.screen); var layout = serializedObject.FindProperty("layout"); var components = layout.FindPropertyRelative("components"); this.props.Clear(); for (int i = 0; i < components.arraySize; ++i) { var component = components.GetArrayElementAtIndex(i); this.props.Add(component); var componentParametersEditor = this.screen.layout.components[i].OnComponentChanged(this.screen, this.screen.layout.components[i].component); if (componentParametersEditor != null) { var e = Editor.CreateEditor(componentParametersEditor) as IParametersEditor; this.screen.layout.components[i].componentParametersEditor = e; } } this.settingsScrollPosition = Vector2.zero; this.opened = true; } }, userData: windowSource); }
private void DrawLayoutItem(WindowBase screen, WindowLayout layout, UnityEngine.UI.Windows.Types.Layout.Component component, float width) { if (layout == null) { return; } var tempComponent = layout.elements.FirstOrDefault((e) => e != null && e.tag == component.tag); var selected = (Selection.activeGameObject == tempComponent.gameObject); var oldColor = GUI.color; var boxStyle = new GUIStyle(EditorStyles.toolbar); boxStyle.fixedHeight = 0f; boxStyle.stretchHeight = true; boxStyle.padding.right = -20; boxStyle.margin.right = -20; var titleStyle = EditorStyles.whiteMiniLabel; EditorGUILayout.Separator(); GUI.color = selected == true ? new Color(0.7f, 1f, 0.7f, 1f) : Color.white; EditorGUILayout.BeginVertical(boxStyle, GUILayout.Width(width)); if (GUILayout.Button(component.tag.ToString() + " (" + component.description + ")", titleStyle, GUILayout.Width(width)) == true) { Selection.activeGameObject = tempComponent.gameObject; } EditorGUILayout.BeginHorizontal(); GUILayout.Label("Order:", GUILayout.Width(50f)); var newOrder = EditorGUILayout.IntField(component.sortingOrder, EditorStyles.miniTextField, GUILayout.Width(50f)); if (newOrder != component.sortingOrder) { component.sortingOrder = newOrder; this.isScreenDirty = true; } if (component.sortingOrder == 0) { GUILayout.Label("(Auto)", EditorStyles.miniLabel); } else { if (GUILayout.Button("Set Auto", EditorStyles.miniButton) == true) { component.sortingOrder = 0; this.isScreenDirty = true; } } EditorGUILayout.EndHorizontal(); var newComponent = EditorGUILayout.ObjectField(component.component, typeof(WindowComponent), false, GUILayout.Width(width)) as WindowComponent; if (newComponent != component.component) { component.component = newComponent; this.isScreenDirty = true; } tempComponent.tempEditorComponent = component.component; EditorGUILayout.EndVertical(); var rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition) == true) { Selection.activeGameObject = tempComponent.gameObject; } GUI.color = oldColor; }
public override void OnGUI() { if (Layout.styles == null) { Layout.styles = new Styles(); } if (this.opened == true) { const float settingsWidth = 320f; const float listHeight = 200f; const float padding = 5f; const float closeSize = 30f; const float scrollWidth = 16f; var rect = new Rect(0f, -OFFSET, Screen.width, Screen.height - OFFSET).PixelPerfect(); var rectContent = new Rect(rect.x + MARGIN + settingsWidth + padding, rect.y + MARGIN, rect.width - MARGIN * 2f - padding - settingsWidth, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT).PixelPerfect(); var rectList = new Rect(MARGIN, rect.y + MARGIN, settingsWidth, listHeight - padding).PixelPerfect(); var rectSettings = new Rect(MARGIN, rect.y + MARGIN + listHeight, settingsWidth, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT - listHeight).PixelPerfect(); var rectCloseButton = new Rect(rectContent.x + rectContent.width, rectContent.y - closeSize * 0.5f, closeSize, closeSize).PixelPerfect(); GUI.Box(new Rect(rect.x + MARGIN, rect.y + MARGIN, rect.width - MARGIN * 2f, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT).PixelPerfect(), string.Empty, Layout.styles.layoutBack); GUI.Box(rect, string.Empty, Layout.styles.backLock); GUI.Box(new Rect(0f, 0f, Screen.width, Screen.height).PixelPerfect(), string.Empty, Layout.styles.dropShadow); GUI.Box(rectList, string.Empty, Layout.styles.content); GUI.Box(rectSettings, string.Empty, Layout.styles.content); GUI.Box(rectContent, string.Empty, Layout.styles.contentScreen); GUI.BeginGroup(rectSettings); { if (this.component != null) { const float offsetTop = 50f; var viewRect = new Rect(0f, 0f, rectSettings.width, 0f).PixelPerfect(); var scrollView = new Rect(0f, 0f + offsetTop, rectSettings.width, rectSettings.height - offsetTop).PixelPerfect(); System.Action <WindowComponent> onChange = (WindowComponent component) => { //Debug.Log(component + "!=" + this.component.component); if (component != this.component.component) { this.component.componentParametersEditor = null; this.component.componentParameters = this.component.OnComponentChanged(this.screen, component); if (this.component.componentParameters != null) { var e = Editor.CreateEditor(this.component.componentParameters) as IParametersEditor; this.component.componentParametersEditor = e; } UnityEditor.EditorUtility.SetDirty(this.screen); } }; var c = EditorGUI.ObjectField(new Rect(5f, 5f, viewRect.width - 40f - 5f * 2f, 16f).PixelPerfect(), this.component.component, typeof(WindowComponent), allowSceneObjects: false) as WindowComponent; if (c != this.component.component) { onChange(c); } var nRect = new Rect(viewRect.width - 40f, 5f, 40f - 5f, 16f).PixelPerfect(); GUILayoutExt.DrawComponentChooser(nRect, this.screen.gameObject, this.component.component, (component) => { onChange(component); }); if (this.component.component != null) { var editor = this.component.componentParametersEditor; nRect.x = 5f; nRect.width = viewRect.width - 5f * 2f; nRect.y += nRect.height + 5f; this.component.sortingOrder = EditorGUI.IntField(nRect, new GUIContent("Sorting Order"), this.component.sortingOrder); if (editor != null) { var h = Mathf.Max(scrollView.height, (editor == null) ? 0f : editor.GetHeight()); viewRect = new Rect(scrollView.x, scrollView.y, viewRect.width - scrollWidth, h).PixelPerfect(); var oldSkin = GUI.skin; GUI.skin = FlowSystemEditorWindow.defaultSkin; this.settingsScrollPosition = GUI.BeginScrollView(scrollView, this.settingsScrollPosition, viewRect, false, true); GUI.skin = oldSkin; { if (editor != null) { EditorGUIUtility.labelWidth = 100f; //++EditorGUI.indentLevel; editor.OnParametersGUI(viewRect); //--EditorGUI.indentLevel; EditorGUIUtilityExt.LookLikeControls(); } } GUI.EndScrollView(); } else { GUI.Label(new Rect(0f, 0f, rectSettings.width - scrollWidth, rectSettings.height).PixelPerfect(), "Selected component have no parameters", EditorStyles.centeredGreyMiniLabel); } } } else { GUI.Label(new Rect(0f, 0f, rectSettings.width - scrollWidth, rectSettings.height).PixelPerfect(), "Select an Element", EditorStyles.centeredGreyMiniLabel); } } GUI.EndGroup(); GUI.BeginGroup(rectList); { const float itemHeight = 30f; this.highlighted.Clear(); var viewRect = new Rect(0f, 0f, rectList.width - scrollWidth, 0f).PixelPerfect(); this.allListHeight = 0f; for (int i = 0; i < this.props.Count; ++i) { var root = this.screen.layout.layout.GetRootByTag(this.screen.layout.components[i].tag); if (root.showInComponentsList == false) { continue; } if (this.screen.layout.components[i].component == null) { this.highlighted.Add(root); } this.allListHeight += itemHeight; } viewRect.height = Mathf.Max(rectList.height, this.allListHeight); var oldSkin = GUI.skin; GUI.skin = FlowSystemEditorWindow.defaultSkin; this.listScrollPosition = GUI.BeginScrollView(new Rect(0f, 0f, rectList.width, rectList.height).PixelPerfect(), this.listScrollPosition, viewRect, false, true); GUI.skin = oldSkin; { GUI.BeginGroup(viewRect); { var h = 0f; this.hovered = null; for (int i = 0; i < this.props.Count; ++i) { var root = this.screen.layout.layout.GetRootByTag(this.screen.layout.components[i].tag); if (root.showInComponentsList == false) { continue; } var r = new Rect(0f, h, viewRect.width, itemHeight).PixelPerfect(); h += r.height; var isSelected = (this.element == root); if (isSelected == true) { GUI.Label(r, this.screen.layout.components[i].description, Layout.styles.listButtonSelected); } else { //r.width -= scrollWidth; if (GUI.Button(r, this.screen.layout.components[i].description, Layout.styles.listButton) == true) { this.component = this.screen.layout.components.FirstOrDefault(c => c.tag == root.tag); this.element = root; } var inRect = rectList.Contains(Event.current.mousePosition - this.listScrollPosition + Vector2.up * 40f); if (GUI.enabled == true) { EditorGUIUtility.AddCursorRect(r, MouseCursor.Link); } if (r.Contains(Event.current.mousePosition) == true && inRect == true) { this.hovered = this.screen.layout.components[i]; } //r.width += scrollWidth; } //r.width -= scrollWidth; GUI.Label(r, this.screen.layout.components[i].tag.ToString(), Layout.styles.listTag); } } GUI.EndGroup(); } GUI.EndScrollView(); } GUI.EndGroup(); var selected = (this.hovered != null) ? this.screen.layout.layout.GetRootByTag(this.hovered.tag) : this.element; this.editor.OnPreviewGUI(Color.white, rectContent, Layout.styles.content, selected: selected, onSelection: (element) => { this.component = this.screen.layout.components.FirstOrDefault(c => c.tag == element.tag); this.element = element; }, highlighted: this.highlighted); if (GUI.Button(rectCloseButton, string.Empty, Layout.styles.closeButton) == true) { this.flowEditor.SetEnabled(); this.opened = false; } } }
public override void OnGUI() { if (this.opened == true) { GUI.Box(new Rect(0f, 0f, Screen.width, Screen.height), string.Empty, Layout.styles.dropShadow); const float settingsWidth = 320f; const float listHeight = 200f; const float padding = 5f; const float closeSize = 30f; const float scrollWidth = 16f; var rect = new Rect(0f, -OFFSET, Screen.width, Screen.height - OFFSET); var rectContent = new Rect(rect.x + MARGIN + settingsWidth + padding, rect.y + MARGIN, rect.width - MARGIN * 2f - padding - settingsWidth, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT); var rectList = new Rect(MARGIN, rect.y + MARGIN, settingsWidth, listHeight - padding); var rectSettings = new Rect(MARGIN, rect.y + MARGIN + listHeight, settingsWidth, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT - listHeight); var rectCloseButton = new Rect(rect.x + rect.width - closeSize, rect.y, closeSize, closeSize); GUI.Box(new Rect(rect.x + MARGIN, rect.y + MARGIN, rect.width - MARGIN * 2f, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT), string.Empty, Layout.styles.layoutBack); GUI.Box(rect, string.Empty, Layout.styles.backLock); GUI.Box(rectList, string.Empty, Layout.styles.content); GUI.Box(rectSettings, string.Empty, Layout.styles.content); GUI.Box(rectContent, string.Empty, Layout.styles.contentScreen); GUI.BeginGroup(rectSettings); { if (this.component != null) { const float offsetTop = 50f; var viewRect = new Rect(0f, 0f, rectSettings.width, 0f); var scrollView = new Rect(0f, 0f + offsetTop, rectSettings.width, rectSettings.height - offsetTop); System.Action<WindowComponent> onChange = (WindowComponent component) => { //Debug.Log(component + "!=" + this.component.component); if (component != this.component.component) { this.component.component = component; this.component.componentParametersEditor = null; this.component.componentParameters = this.component.OnComponentChanged(this.screen, component); } }; var c = EditorGUI.ObjectField(new Rect(5f, 5f, viewRect.width - 40f - 5f * 2f, 16f), this.component.component, typeof(WindowComponent), allowSceneObjects: false) as WindowComponent; if (c != this.component.component) { onChange(c); } var nRect = new Rect(viewRect.width - 40f, 5f, 40f - 5f, 16f); GUILayoutExt.DrawComponentChooser(nRect, this.screen.gameObject, this.component.component, (component) => { onChange(component); }); if (this.component.component != null) { nRect.x = 5f; nRect.width = viewRect.width - 5f * 2f; nRect.y += nRect.height + 5f; this.component.sortingOrder = EditorGUI.IntField(nRect, new GUIContent("Sorting Order"), this.component.sortingOrder); var editor = this.component.componentParametersEditor; if (editor == null && this.component.componentParameters != null) { var e = Editor.CreateEditor(this.component.componentParameters) as IParametersEditor; this.component.componentParametersEditor = e; } if (editor != null) { var h = Mathf.Max(scrollView.height, (editor == null) ? 0f : editor.GetHeight()); viewRect = new Rect(scrollView.x, scrollView.y, viewRect.width - scrollWidth, h); var oldSkin = GUI.skin; GUI.skin = FlowSystemEditorWindow.defaultSkin; this.settingsScrollPosition = GUI.BeginScrollView(scrollView, this.settingsScrollPosition, viewRect, false, true); GUI.skin = oldSkin; { if (editor != null) { EditorGUIUtility.labelWidth = 100f; //++EditorGUI.indentLevel; editor.OnParametersGUI(viewRect); //--EditorGUI.indentLevel; EditorGUIUtility.LookLikeControls(); } } GUI.EndScrollView(); } else { GUI.Label(new Rect(0f, 0f, rectSettings.width - scrollWidth, rectSettings.height), "Selected component have no parameters", EditorStyles.centeredGreyMiniLabel); } } } else { GUI.Label(new Rect(0f, 0f, rectSettings.width - scrollWidth, rectSettings.height), "Select an Element", EditorStyles.centeredGreyMiniLabel); } } GUI.EndGroup(); GUI.BeginGroup(rectList); { const float itemHeight = 30f; this.highlighted.Clear(); var viewRect = new Rect(0f, 0f, rectList.width - scrollWidth, 0f); this.allListHeight = 0f; for (int i = 0; i < this.props.Count; ++i) { var root = this.screen.layout.layout.GetRootByTag(this.screen.layout.components[i].tag); if (root.showInComponentsList == false) continue; if (this.screen.layout.components[i].component == null) { this.highlighted.Add(root); } this.allListHeight += itemHeight; } viewRect.height = Mathf.Max(rectList.height, this.allListHeight); var oldSkin = GUI.skin; GUI.skin = FlowSystemEditorWindow.defaultSkin; this.listScrollPosition = GUI.BeginScrollView(new Rect(0f, 0f, rectList.width, rectList.height), this.listScrollPosition, viewRect, false, true); GUI.skin = oldSkin; { GUI.BeginGroup(viewRect); { var h = 0f; this.hovered = null; for (int i = 0; i < this.props.Count; ++i) { var root = this.screen.layout.layout.GetRootByTag(this.screen.layout.components[i].tag); if (root.showInComponentsList == false) continue; var r = new Rect(0f, h, viewRect.width, itemHeight); h += r.height; var isSelected = (this.element == root); if (isSelected == true) { GUI.Label(r, this.screen.layout.components[i].description, Layout.styles.listButtonSelected); } else { //r.width -= scrollWidth; if (GUI.Button(r, this.screen.layout.components[i].description, Layout.styles.listButton) == true) { this.component = this.screen.layout.components.FirstOrDefault(c => c.tag == root.tag); this.element = root; } var inRect = rectList.Contains(Event.current.mousePosition - this.listScrollPosition + Vector2.up * 40f); if (GUI.enabled == true) EditorGUIUtility.AddCursorRect(r, MouseCursor.Link); if (r.Contains(Event.current.mousePosition) == true && inRect == true) { this.hovered = this.screen.layout.components[i]; } //r.width += scrollWidth; } //r.width -= scrollWidth; GUI.Label(r, this.screen.layout.components[i].tag.ToString(), Layout.styles.listTag); } } GUI.EndGroup(); } GUI.EndScrollView(); } GUI.EndGroup(); var selected = (this.hovered != null) ? this.screen.layout.layout.GetRootByTag(this.hovered.tag) : this.element; this.editor.OnPreviewGUI(Color.white, rectContent, Layout.styles.content, selected: selected, onSelection: (element) => { this.component = this.screen.layout.components.FirstOrDefault(c => c.tag == element.tag); this.element = element; }, highlighted: this.highlighted); if (GUI.Button(rectCloseButton, string.Empty, Layout.styles.closeButton) == true) { FlowSystemEditorWindow.GetWindow<FlowSystemEditorWindow>().SetEnabled(); this.opened = false; } } }
public override void OnFlowWindowScreenMenuGUI(FD.FlowWindow windowSource, GenericMenu menu) { menu.AddItem(new GUIContent("Components Editor..."), on: false, func: (object win) => { var window = win as FD.FlowWindow; var screen = window.GetScreen() as LayoutWindowType; if (screen != null) { FlowSystemEditorWindow.GetWindow<FlowSystemEditorWindow>().SetDisabled(); //this.window = window; this.screen = screen; this.editor = Editor.CreateEditor(window.GetScreen()) as IPreviewEditor; this.component = null; this.hovered = null; this.element = null; this.listScrollPosition = Vector2.zero; var serializedObject = new SerializedObject(this.screen); var layout = serializedObject.FindProperty("layout"); var components = layout.FindPropertyRelative("components"); this.props.Clear(); for (int i = 0; i < components.arraySize; ++i) { var component = components.GetArrayElementAtIndex(i); this.props.Add(component); this.screen.layout.components[i].OnComponentChanged(this.screen, this.screen.layout.components[i].component); } this.settingsScrollPosition = Vector2.zero; this.opened = true; } }, userData: windowSource); }