protected virtual void OnFocus() { if (this.componentWindow != null) { this.lastEditingComponent = this.componentWindow.component; this.componentWindow.Close(); this.componentWindow = null; this.skipComponentEditorOpening = true; } }
private void DrawComponent(Rect rect, int i, bool isActive, bool isFocused) { if (this.hub.components[i].hasEditorGUI == true) { Rect rect2 = rect; rect2.width = 40F; rect.xMin += rect2.width; if (Event.current.type == EventType.MouseDown && rect2.Contains(Event.current.mousePosition) == true) { // This condition is required to prevent closing and opening in the same frame when toggling the same component. if (this.skipComponentEditorOpening == true && this.lastEditingComponent == this.hub.components[i]) { this.skipComponentEditorOpening = false; return; } HubComponentWindow[] windows = Resources.FindObjectsOfTypeAll <HubComponentWindow>(); if (windows.Length > 0) { for (int j = 0; j < windows.Length; j++) { windows[j].Close(); } } else { this.componentWindow = EditorWindow.CreateInstance <HubComponentWindow>(); this.componentWindow.titleContent.text = this.hub.components[i].name; this.componentWindow.position = new Rect(this.position.x + rect.x, this.position.y + rect.y + rect.height + this.headerRect.yMax - this.scrollPosition.y, Mathf.Max(HubComponentWindow.MinWidth, this.position.width - rect2.xMax), this.componentWindow.position.height); this.componentWindow.Init(this, this.hub.components[i]); this.componentWindow.ShowPopup(); this.componentWindow.Focus(); } } GUI.Button(rect2, "Edit"); } this.hub.components[i].OnPreviewGUI(rect); }
private void OnCreateComponent(Type type) { if (this.CheckMaxHubComponents(this.components.Count) == false) { return; } HubComponent component = Activator.CreateInstance(type) as HubComponent; component.Init(this); HubComponentWindow[] editors = Resources.FindObjectsOfTypeAll <HubComponentWindow>(); for (int i = 0; i < editors.Length; i++) { editors[i].Close(); } if (component.hasEditorGUI == true) { HubComponentWindow editor = EditorWindow.CreateInstance <HubComponentWindow>(); editor.titleContent.text = component.name; editor.position = new Rect(this.position.x, this.position.y + this.height, Mathf.Max(HubComponentWindow.MinWidth, editor.position.width), editor.position.height); editor.Init(this, component); editor.ShowPopup(); } this.components.Add(component); this.SaveComponents(); this.Repaint(); NGHubEditorWindow[] windows = Resources.FindObjectsOfTypeAll <NGHubEditorWindow>(); for (int i = 0; i < windows.Length; i++) { windows[i].Repaint(); } }