예제 #1
0
        private void DoInspectorModifierGUI(NodeGUI node)
        {
            EditorGUILayout.HelpBox("Modifier: Modify asset settings.", MessageType.Info);
            UpdateNodeName(node);

            GUILayout.Space(10f);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                Type incomingType = FindFirstIncomingAssetType(node.Data.InputPoints[0]);

                if (incomingType == null)
                {
                    // if there is no asset input to determine incomingType,
                    // retrieve from assigned Modifier.
                    incomingType = ModifierUtility.GetModifierTargetType(node.Data.ScriptClassName);

                    if (incomingType == null)
                    {
                        EditorGUILayout.HelpBox("Modifier needs a single type of incoming assets.", MessageType.Info);
                        return;
                    }
                }

                var map = ModifierUtility.GetAttributeClassNameMap(incomingType);
                if (map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("Modifier");
                        var guiName = ModifierUtility.GetModifierGUIName(node.Data.ScriptClassName);
                        if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f)))
                        {
                            var builders = map.Keys.ToList();

                            if (builders.Count > 0)
                            {
                                NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) =>
                                {
                                    using (new RecordUndoScope("Change Modifier class", node, true)) {
                                        m_modifier = ModifierUtility.CreateModifier(selectedGUIName, incomingType);
                                        if (m_modifier != null)
                                        {
                                            node.Data.ScriptClassName = ModifierUtility.GUINameToClassName(selectedGUIName, incomingType);
                                            node.Data.InstanceData[currentEditingGroup] = m_modifier.Serialize();
                                        }
                                    }
                                }
                                                          );
                            }
                        }

                        MonoScript s = TypeUtility.LoadMonoScript(node.Data.ScriptClassName);

                        using (new EditorGUI.DisabledScope(s == null)) {
                            if (GUILayout.Button("Edit", GUILayout.Width(50)))
                            {
                                AssetDatabase.OpenAsset(s, 0);
                            }
                        }
                    }
                }
                else
                {
                    string[] menuNames = AssetBundleGraphSettings.GUI_TEXT_MENU_GENERATE_MODIFIER.Split('/');
                    EditorGUILayout.HelpBox(
                        string.Format(
                            "No CustomModifier found for {3} type. \n" +
                            "You need to create at least one Modifier script to select script for Modifier. " +
                            "To start, select {0}>{1}>{2} menu and create a new script.",
                            menuNames[1], menuNames[2], menuNames[3], incomingType.FullName
                            ), MessageType.Info);
                }

                GUILayout.Space(10f);

                if (DrawPlatformSelector(node))
                {
                    // if platform tab is changed, renew modifierModifierInstance for that tab.
                    m_modifier = null;
                }
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = DrawOverrideTargetToggle(node, node.Data.InstanceData.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            node.Data.InstanceData[currentEditingGroup] = node.Data.InstanceData.DefaultValue;
                        }
                        else
                        {
                            node.Data.InstanceData.Remove(currentEditingGroup);
                        }
                        m_modifier = null;
                    });

                    using (disabledScope) {
                        //reload modifierModifier instance from saved modifierModifier data.
                        if (m_modifier == null)
                        {
                            m_modifier = ModifierUtility.CreateModifier(node.Data, currentEditingGroup);
                            if (m_modifier != null)
                            {
                                node.Data.ScriptClassName = m_modifier.GetType().FullName;
                                if (node.Data.InstanceData.ContainsValueOf(currentEditingGroup))
                                {
                                    node.Data.InstanceData[currentEditingGroup] = m_modifier.Serialize();
                                }
                            }
                        }

                        if (m_modifier != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change Modifier Setting", node)) {
                                    node.Data.ScriptClassName = m_modifier.GetType().FullName;
                                    if (node.Data.InstanceData.ContainsValueOf(currentEditingGroup))
                                    {
                                        node.Data.InstanceData[currentEditingGroup] = m_modifier.Serialize();
                                    }
                                }
                            };

                            m_modifier.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }
예제 #2
0
        private void DoInspectorPrefabBuilderGUI(NodeGUI node)
        {
            EditorGUILayout.HelpBox("PrefabBuilder: Create prefab with given assets and script.", MessageType.Info);
            UpdateNodeName(node);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var map = PrefabBuilderUtility.GetAttributeClassNameMap();
                if (map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("PrefabBuilder");
                        var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(node.Data.ScriptClassName);

                        if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f)))
                        {
                            var builders = map.Keys.ToList();

                            if (builders.Count > 0)
                            {
                                NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) =>
                                {
                                    using (new RecordUndoScope("Change PrefabBuilder class", node, true)) {
                                        m_prefabBuilder = PrefabBuilderUtility.CreatePrefabBuilder(selectedGUIName);
                                        if (m_prefabBuilder != null)
                                        {
                                            node.Data.ScriptClassName           = PrefabBuilderUtility.GUINameToClassName(selectedGUIName);
                                            node.Data.InstanceData.DefaultValue = m_prefabBuilder.Serialize();
                                        }
                                    }
                                }
                                                          );
                            }
                        }

                        MonoScript s = TypeUtility.LoadMonoScript(node.Data.ScriptClassName);

                        using (new EditorGUI.DisabledScope(s == null)) {
                            if (GUILayout.Button("Edit", GUILayout.Width(50)))
                            {
                                AssetDatabase.OpenAsset(s, 0);
                            }
                        }
                    }
                    ReplacePrefabOptions opt = (ReplacePrefabOptions)EditorGUILayout.EnumPopup("Prefab Replace Option", node.Data.ReplacePrefabOptions, GUILayout.MinWidth(150f));
                    if (node.Data.ReplacePrefabOptions != opt)
                    {
                        using (new RecordUndoScope("Change Prefab Replace Option", node, true)) {
                            node.Data.ReplacePrefabOptions = opt;
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(node.Data.ScriptClassName))
                    {
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "Your PrefabBuilder script {0} is missing from assembly. Did you delete script?", node.Data.ScriptClassName), MessageType.Info);
                    }
                    else
                    {
                        string[] menuNames = AssetBundleGraphSettings.GUI_TEXT_MENU_GENERATE_PREFABBUILDER.Split('/');
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "You need to create at least one PrefabBuilder script to use PrefabBuilder node. To start, select {0}>{1}>{2} menu and create new script from template.",
                                menuNames[1], menuNames[2], menuNames[3]
                                ), MessageType.Info);
                    }
                }

                GUILayout.Space(10f);

                if (DrawPlatformSelector(node))
                {
                    // if platform tab is changed, renew prefabBuilder for that tab.
                    m_prefabBuilder = null;
                }
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = DrawOverrideTargetToggle(node, node.Data.InstanceData.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            node.Data.InstanceData[currentEditingGroup] = node.Data.InstanceData.DefaultValue;
                        }
                        else
                        {
                            node.Data.InstanceData.Remove(currentEditingGroup);
                        }
                        m_prefabBuilder = null;
                    });

                    using (disabledScope) {
                        //reload prefabBuilder instance from saved instance data.
                        if (m_prefabBuilder == null)
                        {
                            m_prefabBuilder = PrefabBuilderUtility.CreatePrefabBuilder(node.Data, currentEditingGroup);
                            if (m_prefabBuilder != null)
                            {
                                node.Data.ScriptClassName = m_prefabBuilder.GetType().FullName;
                                if (node.Data.InstanceData.ContainsValueOf(currentEditingGroup))
                                {
                                    node.Data.InstanceData[currentEditingGroup] = m_prefabBuilder.Serialize();
                                }
                            }
                        }

                        if (m_prefabBuilder != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change PrefabBuilder Setting", node)) {
                                    node.Data.ScriptClassName = m_prefabBuilder.GetType().FullName;
                                    if (node.Data.InstanceData.ContainsValueOf(currentEditingGroup))
                                    {
                                        node.Data.InstanceData[currentEditingGroup] = m_prefabBuilder.Serialize();
                                    }
                                }
                            };

                            m_prefabBuilder.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }
예제 #3
0
        /**
         *      retrieve mouse events for this node in this AssetGraoh window.
         */
        private void HandleNodeEvent()
        {
            switch (Event.current.type)
            {
            /*
             *              handling release of mouse drag from this node to another node.
             *              this node doesn't know about where the other node is. the master only knows.
             *              only emit event.
             */
            case EventType.Ignore: {
                NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_NODE_CONNECTION_OVERED, this, Event.current.mousePosition, null));
                break;
            }

            /*
             *      handling drag.
             */
            case EventType.MouseDrag: {
                NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_NODE_MOVING, this, Event.current.mousePosition, null));
                break;
            }

            /*
             *      check if the mouse-down point is over one of the connectionPoint in this node.
             *      then emit event.
             */
            case EventType.MouseDown: {
                ConnectionPointData result = IsOverConnectionPoint(Event.current.mousePosition);

                if (result != null)
                {
                    if (scaleFactor == SCALE_MAX)
                    {
                        NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_NODE_CONNECT_STARTED, this, Event.current.mousePosition, result));
                    }
                    break;
                }
                break;
            }
            }

            /*
             *      retrieve mouse events for this node in|out of this AssetGraoh window.
             */
            switch (Event.current.rawType)
            {
            case EventType.MouseUp: {
                bool eventRaised = false;
                // if mouse position is on the connection point, emit mouse raised event.
                Action <ConnectionPointData> raiseEventIfHit = (ConnectionPointData point) => {
                    // Only one connectionPoint raise event at one mouseup event
                    if (eventRaised)
                    {
                        return;
                    }

                    if (!IsValidInputConnectionPoint(point))
                    {
                        return;
                    }

                    if (point.Region.Contains(Event.current.mousePosition))
                    {
                        NodeGUIUtility.NodeEventHandler(
                            new NodeEvent(NodeEvent.EventType.EVENT_NODE_CONNECTION_RAISED,
                                          this, Event.current.mousePosition, point));
                        eventRaised = true;
                        return;
                    }
                };
                m_data.InputPoints.ForEach(raiseEventIfHit);
                m_data.OutputPoints.ForEach(raiseEventIfHit);
                if (!eventRaised)
                {
                    NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_NODE_TOUCHED,
                                                                  this, Event.current.mousePosition, null));
                }
                break;
            }
            }

            /*
             *      right click to open Context menu
             */
            if (scaleFactor == SCALE_MAX)
            {
                if (Event.current.type == EventType.ContextClick || (Event.current.type == EventType.MouseUp && Event.current.button == 1))
                {
                    var menu = new GenericMenu();

                    MonoScript s = TypeUtility.LoadMonoScript(Data.ScriptClassName);
                    if (s != null)
                    {
                        menu.AddItem(
                            new GUIContent("Edit Script"),
                            false,
                            () => {
                            AssetDatabase.OpenAsset(s, 0);
                        }
                            );
                    }

                    menu.AddItem(
                        new GUIContent("Delete"),
                        false,
                        () => {
                        NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_CLOSE_TAPPED, this, Vector2.zero, null));
                    }
                        );
                    menu.ShowAsContext();
                    Event.current.Use();
                }
            }
        }