示例#1
0
 protected virtual void  OnFocus()
 {
     if (this.componentWindow != null)
     {
         this.lastEditingComponent = this.componentWindow.component;
         this.componentWindow.Close();
         this.componentWindow            = null;
         this.skipComponentEditorOpening = true;
     }
 }
示例#2
0
        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();
            }
        }
示例#3
0
 public void     Init(EditorWindow editor, HubComponent component)
 {
     this.editor            = editor;
     this.component         = component;
     this.titleContent.text = component.name;
 }
示例#4
0
        public bool     HandleDrop()
        {
            if (DragAndDrop.objectReferences.Length > 0 &&
                1.Equals(DragAndDrop.GetGenericData(Utility.DragObjectDataName)) == false &&
                true.Equals(DragAndDrop.GetGenericData(NGHubWindow.DragFromNGHub)) == false)
            {
                MethodInfo[] droppableComponents = this.DroppableComponents;

                for (int i = 0; i < droppableComponents.Length; i++)
                {
                    if ((bool)droppableComponents[i].Invoke(null, null) == true)
                    {
                        string name = droppableComponents[i].DeclaringType.Name;

                        if (name.EndsWith("Component") == true)
                        {
                            name = name.Substring(0, name.Length - "Component".Length);
                        }

                        Utility.content.text = name;
                        Rect r = GUILayoutUtility.GetRect(GUI.skin.label.CalcSize(Utility.content).x, this.height, GUI.skin.label);

                        if (Event.current.type == EventType.Repaint)
                        {
                            Utility.DropZone(r, Utility.NicifyVariableName(name));
                            this.Repaint();
                        }
                        else if (Event.current.type == EventType.DragUpdated &&
                                 r.Contains(Event.current.mousePosition) == true)
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                        }
                        else if (Event.current.type == EventType.DragPerform &&
                                 r.Contains(Event.current.mousePosition) == true)
                        {
                            DragAndDrop.AcceptDrag();

                            if (this.CheckMaxHubComponents(this.components.Count) == true)
                            {
                                HubComponent component = Activator.CreateInstance(this.droppableComponents[i].DeclaringType) as HubComponent;

                                if (component != null)
                                {
                                    component.InitDrop(this);
                                    this.components.Insert(0, component);
                                    EditorApplication.delayCall += this.Repaint;
                                    this.SaveComponents();
                                }
                            }

                            DragAndDrop.PrepareStartDrag();
                            Event.current.Use();
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
示例#5
0
        protected virtual void  OnGUI()
        {
            if (this.hub == null || this.hub.Initialized == false)
            {
                return;
            }

            if (this.list == null)
            {
                this.list = new ReorderableList(this.hub.components, typeof(HubComponent), true, false, true, true);
                this.list.headerHeight          = 24F;
                this.list.drawHeaderCallback    = (r) => GUI.Label(r, "Components", GeneralStyles.Title1);
                this.list.showDefaultBackground = false;
                this.list.drawElementCallback   = this.DrawComponent;
                this.list.onAddCallback         = this.OpenAddComponentWizard;
                this.list.onRemoveCallback      = (l) => { l.list.RemoveAt(l.index); this.hub.SaveComponents(); };
                this.list.onReorderCallback     = (l) => this.hub.SaveComponents();
                this.list.onChangedCallback     = (l) => this.hub.Repaint();
            }

            MethodInfo[] droppableComponentsMethods = this.hub.DroppableComponents;

            if (droppableComponentsMethods.Length > 0 &&
                DragAndDrop.objectReferences.Length > 0)
            {
                for (int i = 0; i < droppableComponentsMethods.Length; i++)
                {
                    if ((bool)droppableComponentsMethods[i].Invoke(null, null) == true)
                    {
                        Rect r = GUILayoutUtility.GetRect(GUI.skin.label.CalcSize(new GUIContent(droppableComponentsMethods[i].DeclaringType.Name)).x, this.hub.height, GUI.skin.label);

                        if (Event.current.type == EventType.Repaint)
                        {
                            Utility.DropZone(r, Utility.NicifyVariableName(droppableComponentsMethods[i].DeclaringType.Name));
                            this.Repaint();
                        }
                        else if (Event.current.type == EventType.DragUpdated &&
                                 r.Contains(Event.current.mousePosition) == true)
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                        }
                        else if (Event.current.type == EventType.DragPerform &&
                                 r.Contains(Event.current.mousePosition) == true)
                        {
                            DragAndDrop.AcceptDrag();

                            HubComponent component = Activator.CreateInstance(droppableComponentsMethods[i].DeclaringType) as HubComponent;

                            if (component != null)
                            {
                                component.InitDrop(this.hub);
                                this.hub.components.Add(component);
                                this.hub.SaveComponents();
                            }

                            DragAndDrop.PrepareStartDrag();
                            Event.current.Use();
                        }
                    }
                }
            }

            Rect r2 = this.position;

            r2.x = 0F;

            if (this.hub.DockedAsMenu == false)
            {
                r2.y = 24F;

                using (LabelWidthRestorer.Get(50F))
                {
                    EditorGUI.BeginChangeCheck();
                    this.hub.height = EditorGUILayout.FloatField("Height", this.hub.height);
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        this.hub.Repaint();
                    }
                }
            }
            else
            {
                r2.y = 0F;
            }

            EditorGUI.BeginChangeCheck();
            this.hub.backgroundColor = EditorGUILayout.ColorField("Background Color", this.hub.backgroundColor);
            if (EditorGUI.EndChangeCheck() == true)
            {
                this.hub.Repaint();
            }

            this.headerRect = GUILayoutUtility.GetLastRect();

            this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition);
            {
                this.list.DoLayoutList();
            }
            EditorGUILayout.EndScrollView();
        }