Beispiel #1
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Modify Assets Directly: Modify assets.", MessageType.Info);
            editor.UpdateNodeName(node);

            GUILayout.Space(10f);

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

                var modifier = m_instance.Get <IModifier>(editor.CurrentEditingGroup);

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

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

                Dictionary <string, string> map = null;

                if (incomingType != null)
                {
                    map = ModifierUtility.GetAttributeAssemblyQualifiedNameMap(incomingType);
                }

                if (map != null && map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("Modifier");
                        var guiName = ModifierUtility.GetModifierGUIName(m_instance.ClassName);
                        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)) {
                                        modifier = ModifierUtility.CreateModifier(selectedGUIName, incomingType);
                                        m_instance.Set(editor.CurrentEditingGroup, modifier);
                                        onValueChanged();
                                    }
                                }
                                                          );
                            }
                        }

                        MonoScript s = TypeUtility.LoadMonoScript(m_instance.ClassName);

                        using (new EditorGUI.DisabledScope(s == null)) {
                            if (GUILayout.Button("Edit", GUILayout.Width(50)))
                            {
                                AssetDatabase.OpenAsset(s, 0);
                            }
                        }
                    }
                }
                else
                {
                    string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_MODIFIER.Split('/');

                    if (incomingType == null)
                    {
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "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]
                                ), MessageType.Info);
                    }
                    else
                    {
                        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);

                editor.DrawPlatformSelector(node);
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = editor.DrawOverrideTargetToggle(node, m_instance.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            m_instance.CopyDefaultValueTo(editor.CurrentEditingGroup);
                        }
                        else
                        {
                            m_instance.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    });

                    using (disabledScope) {
                        if (modifier != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change Modifier Setting", node)) {
                                    m_instance.Set(editor.CurrentEditingGroup, modifier);
                                    onValueChanged();
                                }
                            };

                            modifier.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Split By Filter: Split incoming assets by filter conditions.", MessageType.Info);
            editor.UpdateNodeName(node);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                GUILayout.Label("Filter Settings:");
                FilterEntry removing = null;
                for (int i = 0; i < m_filter.Count; ++i)
                {
                    var cond = m_filter[i];

                    Action messageAction = null;

                    using (new GUILayout.HorizontalScope()) {
                        if (GUILayout.Button("-", GUILayout.Width(30)))
                        {
                            removing = cond;
                        }
                        else
                        {
                            IFilter filter = cond.Instance.Object;
                            if (filter == null)
                            {
                                using (new GUILayout.VerticalScope()) {
                                    EditorGUILayout.HelpBox(string.Format("Failed to deserialize assigned filter({0}). Please select valid class.", cond.Instance.ClassName), MessageType.Error);
                                    if (GUILayout.Button(cond.Instance.ClassName, "Popup", GUILayout.MinWidth(150f)))
                                    {
                                        var map = FilterUtility.GetAttributeAssemblyQualifiedNameMap();
                                        NodeGUI.ShowTypeNamesMenu(cond.Instance.ClassName, map.Keys.ToList(), (string selectedGUIName) =>
                                        {
                                            using (new RecordUndoScope("Change Filter Setting", node)) {
                                                var newFilter = FilterUtility.CreateFilter(selectedGUIName);
                                                cond.Instance = new FilterInstance(newFilter);
                                                onValueChanged();
                                            }
                                        }
                                                                  );
                                    }
                                }
                            }
                            else
                            {
                                cond.Instance.Object.OnInspectorGUI(() => {
                                    using (new RecordUndoScope("Change Filter Setting", node)) {
                                        cond.Instance.Save();
                                        UpdateFilterEntry(node.Data, cond);
                                        // event must raise to propagate change to connection associated with point
                                        NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_CONNECTIONPOINT_LABELCHANGED, node, Vector2.zero, GetConnectionPoint(node.Data, cond)));
                                        onValueChanged();
                                    }
                                });
                            }
                        }
                    }

                    if (messageAction != null)
                    {
                        using (new GUILayout.HorizontalScope()) {
                            messageAction.Invoke();
                        }
                    }
                }

                // add contains keyword interface.
                if (GUILayout.Button("+"))
                {
                    var map = FilterUtility.GetAttributeAssemblyQualifiedNameMap();
                    if (map.Keys.Count > 1)
                    {
                        GenericMenu menu = new GenericMenu();
                        foreach (var name in map.Keys)
                        {
                            var guiName = name;
                            menu.AddItem(new GUIContent(guiName), false, () => {
                                using (new RecordUndoScope("Add Filter Condition", node)){
                                    var filter = FilterUtility.CreateFilter(guiName);
                                    AddFilterCondition(node.Data, filter);
                                    onValueChanged();
                                }
                            });
                        }
                        menu.ShowAsContext();
                    }
                    else
                    {
                        using (new RecordUndoScope("Add Filter Condition", node)){
                            AddFilterCondition(node.Data, new FilterByNameAndType());
                            onValueChanged();
                        }
                    }
                }

                if (removing != null)
                {
                    using (new RecordUndoScope("Remove Filter Condition", node, true)){
                        // event must raise to remove connection associated with point
                        NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_CONNECTIONPOINT_DELETED, node, Vector2.zero, GetConnectionPoint(node.Data, removing)));
                        RemoveFilterCondition(node.Data, removing);
                        onValueChanged();
                    }
                }
            }
        }
Beispiel #3
0
        private void DrawGeneratorSetting(
            GeneratorEntry entry,
            NodeGUI node,
            AssetReferenceStreamManager streamManager,
            NodeGUIEditor editor,
            Action onValueChanged)
        {
            var generator = entry.m_instance.Get <IAssetGenerator>(editor.CurrentEditingGroup);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var newName = EditorGUILayout.TextField("Name", entry.m_name);
                if (newName != entry.m_name)
                {
                    using (new RecordUndoScope("Change Name", node, true)) {
                        entry.m_name = newName;
                        UpdateGeneratorEntry(node.Data, entry);
                        // event must raise to propagate change to connection associated with point
                        NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_CONNECTIONPOINT_LABELCHANGED, node, Vector2.zero, GetConnectionPoint(node.Data, entry)));
                        onValueChanged();
                    }
                }

                var map = AssetGeneratorUtility.GetAttributeAssemblyQualifiedNameMap();
                if (map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("AssetGenerator");
                        var guiName = AssetGeneratorUtility.GetGUIName(entry.m_instance.ClassName);

                        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 AssetGenerator class", node, true)) {
                                        generator = AssetGeneratorUtility.CreateGenerator(selectedGUIName);
                                        entry.m_instance.Set(editor.CurrentEditingGroup, generator);
                                        onValueChanged();
                                    }
                                }
                                                          );
                            }
                        }

                        MonoScript s = TypeUtility.LoadMonoScript(entry.m_instance.ClassName);

                        using (new EditorGUI.DisabledScope(s == null)) {
                            if (GUILayout.Button("Edit", GUILayout.Width(50)))
                            {
                                AssetDatabase.OpenAsset(s, 0);
                            }
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(entry.m_instance.ClassName))
                    {
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "Your AssetGenerator script {0} is missing from assembly. Did you delete script?", entry.m_instance.ClassName), MessageType.Info);
                    }
                    else
                    {
                        string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_ASSETGENERATOR.Split('/');
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "You need to create at least one AssetGenerator script to use this 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);

                editor.DrawPlatformSelector(node);
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = editor.DrawOverrideTargetToggle(node, entry.m_instance.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            entry.m_instance.CopyDefaultValueTo(editor.CurrentEditingGroup);
                        }
                        else
                        {
                            entry.m_instance.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    });

                    using (disabledScope) {
                        if (generator != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change AssetGenerator Setting", node)) {
                                    entry.m_instance.Set(editor.CurrentEditingGroup, generator);
                                    onValueChanged();
                                }
                            };

                            generator.OnInspectorGUI(onChangedAction);
                        }
                    }
                }

                GUILayout.Space(4);

                if (GUILayout.Button("Remove Generator"))
                {
                    m_removingEntry = entry;
                }
            }
        }