예제 #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)) {
                if (string.IsNullOrEmpty(m_modifierType))
                {
                    EditorGUILayout.HelpBox("Select asset type to modify with this node.", MessageType.Info);
                    using (new EditorGUILayout.HorizontalScope()) {
                        EditorGUILayout.LabelField("Asset Type");
                        if (GUILayout.Button("", "Popup", GUILayout.MinWidth(150f)))
                        {
                            var menu = new GenericMenu();

                            var types = ModifierUtility.GetModifyableTypes().ToArray();

                            for (var i = 0; i < types.Length; i++)
                            {
                                var index = i;
                                menu.AddItem(
                                    new GUIContent(types [i].Name),
                                    false,
                                    () => {
                                    ResetConfig();
                                    m_modifierType = types[index].AssemblyQualifiedName;
                                }
                                    );
                            }
                            menu.ShowAsContext();
                        }
                    }
                    return;
                }

                var targetType = Type.GetType(m_modifierType);
                var modifier   = m_instance.Get <IModifier>(editor.CurrentEditingGroup);

                Dictionary <string, string> map = null;

                if (targetType != null)
                {
                    EditorGUILayout.LabelField("Asset Type", targetType.Name);

                    map = ModifierUtility.GetAttributeAssemblyQualifiedNameMap(targetType);
                }

                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, targetType);
                                        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 (targetType == null)
                    {
                        EditorGUILayout.HelpBox(
                            "You need to create at least one Modifier script to select script for Modifier. " +
                            $"To start, select {menuNames[1]}>{menuNames[2]}>{menuNames[3]} menu and create a new script.", 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], targetType.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);
                        }
                    }
                }

                GUILayout.Space(40f);
                using (new EditorGUILayout.HorizontalScope(GUI.skin.box)) {
                    GUILayout.Space(4f);
                    EditorGUILayout.LabelField("Reset Modifier Setting");

                    if (GUILayout.Button("Clear"))
                    {
                        if (EditorUtility.DisplayDialog("Clear Modifier Setting",
                                                        $"Do you want to reset modifier for \"{node.Name}\"?", "OK", "Cancel"))
                        {
                            using (new RecordUndoScope("Clear Modifier Setting", node)) {
                                ResetConfig();
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Create Prefab From Group: Create prefab from incoming group of assets, using assigned script.", MessageType.Info);
            editor.UpdateNodeName(node);

            var builder = m_instance.Get <IPrefabBuilder>(editor.CurrentEditingGroup);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var map = PrefabBuilderUtility.GetAttributeAssemblyQualifiedNameMap();
                if (map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("PrefabBuilder");
                        var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(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 PrefabBuilder class", node, true)) {
                                        builder = PrefabBuilderUtility.CreatePrefabBuilder(selectedGUIName);
                                        m_instance.Set(editor.CurrentEditingGroup, builder);
                                        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);
                            }
                        }
                    }
                    ReplacePrefabOptions opt = (ReplacePrefabOptions)EditorGUILayout.EnumPopup("Prefab Replace Option", m_replacePrefabOptions, GUILayout.MinWidth(150f));
                    if (m_replacePrefabOptions != opt)
                    {
                        using (new RecordUndoScope("Change Prefab Replace Option", node, true)) {
                            m_replacePrefabOptions = opt;
                            onValueChanged();
                        }
                        opt = m_replacePrefabOptions;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(m_instance.ClassName))
                    {
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "Your PrefabBuilder script {0} is missing from assembly. Did you delete script?", m_instance.ClassName), MessageType.Info);
                    }
                    else
                    {
                        string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_PREFABBUILDER.Split('/');
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "You need to create at least one PrefabBuilder 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, m_instance.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            m_instance.CopyDefaultValueTo(editor.CurrentEditingGroup);
                            m_outputDir[editor.CurrentEditingGroup]    = m_outputDir.DefaultValue;
                            m_outputOption[editor.CurrentEditingGroup] = m_outputOption.DefaultValue;
                        }
                        else
                        {
                            m_instance.Remove(editor.CurrentEditingGroup);
                            m_outputDir.Remove(editor.CurrentEditingGroup);
                            m_outputOption.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    });

                    using (disabledScope) {
                        OutputOption opt       = (OutputOption)m_outputOption[editor.CurrentEditingGroup];
                        var          newOption = (OutputOption)EditorGUILayout.EnumPopup("Output Option", opt);
                        if (newOption != opt)
                        {
                            using (new RecordUndoScope("Change Output Option", node, true)){
                                m_outputOption[editor.CurrentEditingGroup] = (int)newOption;
                                onValueChanged();
                            }
                            opt = newOption;
                        }

                        using (new EditorGUI.DisabledScope(opt == OutputOption.CreateInCacheDirectory)) {
                            var newDirPath = editor.DrawFolderSelector("Output Directory", "Select Output Folder",
                                                                       m_outputDir[editor.CurrentEditingGroup],
                                                                       Application.dataPath,
                                                                       (string folderSelected) => {
                                string basePath = Application.dataPath;

                                if (basePath == folderSelected)
                                {
                                    folderSelected = string.Empty;
                                }
                                else
                                {
                                    var index = folderSelected.IndexOf(basePath);
                                    if (index >= 0)
                                    {
                                        folderSelected = folderSelected.Substring(basePath.Length + index);
                                        if (folderSelected.IndexOf('/') == 0)
                                        {
                                            folderSelected = folderSelected.Substring(1);
                                        }
                                    }
                                }
                                return(folderSelected);
                            }
                                                                       );
                            if (newDirPath != m_outputDir[editor.CurrentEditingGroup])
                            {
                                using (new RecordUndoScope("Change Output Directory", node, true)){
                                    m_outputDir[editor.CurrentEditingGroup] = newDirPath;
                                    onValueChanged();
                                }
                            }

                            var dirPath = Path.Combine(Application.dataPath, m_outputDir [editor.CurrentEditingGroup]);

                            if (opt == OutputOption.CreateInSelectedDirectory &&
                                !string.IsNullOrEmpty(m_outputDir [editor.CurrentEditingGroup]) &&
                                !Directory.Exists(dirPath))
                            {
                                using (new EditorGUILayout.HorizontalScope()) {
                                    EditorGUILayout.LabelField(m_outputDir[editor.CurrentEditingGroup] + " does not exist.");
                                    if (GUILayout.Button("Create directory"))
                                    {
                                        Directory.CreateDirectory(dirPath);
                                        AssetDatabase.Refresh();
                                    }
                                }
                                EditorGUILayout.Space();

                                string parentDir = Path.GetDirectoryName(m_outputDir[editor.CurrentEditingGroup]);
                                if (Directory.Exists(parentDir))
                                {
                                    EditorGUILayout.LabelField("Available Directories:");
                                    string[] dirs = Directory.GetDirectories(parentDir);
                                    foreach (string s in dirs)
                                    {
                                        EditorGUILayout.LabelField(s);
                                    }
                                }
                                EditorGUILayout.Space();
                            }

                            var outputDir = PrepareOutputDirectory(BuildTargetUtility.GroupToTarget(editor.CurrentEditingGroup), node.Data);

                            using (new EditorGUI.DisabledScope(!Directory.Exists(outputDir)))
                            {
                                using (new EditorGUILayout.HorizontalScope()) {
                                    GUILayout.FlexibleSpace();
                                    if (GUILayout.Button("Highlight in Project Window", GUILayout.Width(180f)))
                                    {
                                        var folder = AssetDatabase.LoadMainAssetAtPath(outputDir);
                                        EditorGUIUtility.PingObject(folder);
                                    }
                                }
                            }
                        }

                        GUILayout.Space(8f);

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

                            builder.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }