Beispiel #1
0
        private string PrepareOutputDirectory(BuildTarget target, Model.NodeData node, bool autoCreate, bool throwException)
        {
            var outputOption = (OutputOption)m_outputOption [target];

            if (outputOption == OutputOption.BuildInCacheDirectory)
            {
                return(FileUtility.EnsureAssetBundleCacheDirExists(target, node));
            }

            var outputDir = m_outputDir [target];

            outputDir = outputDir.Replace("{Platform}", BuildTargetUtility.TargetToAssetBundlePlatformName(target));

            if (throwException)
            {
                if (string.IsNullOrEmpty(outputDir))
                {
                    throw new NodeException("Output directory is empty.",
                                            "Select valid output directory from inspector.", node);
                }

                if (target != BuildTargetUtility.GroupToTarget(BuildTargetGroup.Unknown) &&
                    outputOption == OutputOption.ErrorIfNoOutputDirectoryFound)
                {
                    if (!Directory.Exists(outputDir))
                    {
                        throw new NodeException("Output directory not found. \n" + outputDir,
                                                "Create output directory or select other valid directory from inspector.", node);
                    }
                }
            }

            if (autoCreate)
            {
                if (outputOption == OutputOption.DeleteAndRecreateOutputDirectory)
                {
                    if (Directory.Exists(outputDir))
                    {
                        FileUtility.DeleteDirectory(outputDir, true);
                    }
                }

                if (!Directory.Exists(outputDir))
                {
                    Directory.CreateDirectory(outputDir);
                }
            }

            return(outputDir);
        }
Beispiel #2
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Generate Asset: Generate new asset from incoming asset.", MessageType.Info);
            editor.UpdateNodeName(node);

            GUILayout.Space(8f);

            if (m_popupIcon == null)
            {
                m_popupIcon = EditorGUIUtility.Load(EditorGUIUtility.isProSkin ? "icons/d__Popup.png" : "icons/_Popup.png") as Texture2D;
            }

            editor.DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope()) {
                var disabledScope = editor.DrawOverrideTargetToggle(node, m_outputOption.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                    if (enabled)
                    {
                        m_outputOption[editor.CurrentEditingGroup] = m_outputOption.DefaultValue;
                        m_outputDir[editor.CurrentEditingGroup]    = m_outputDir.DefaultValue;
                    }
                    else
                    {
                        m_outputOption.Remove(editor.CurrentEditingGroup);
                        m_outputDir.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;
                    }
                    if (opt != OutputOption.CreateInCacheDirectory)
                    {
                        EditorGUILayout.HelpBox("When you are not creating assets under cache directory, make sure your generators are not overwriting assets each other.", MessageType.Info);
                    }

                    using (new EditorGUI.DisabledScope(opt == OutputOption.CreateInCacheDirectory)) {
                        var newDirPath = m_outputDir[editor.CurrentEditingGroup];

                        if (opt == OutputOption.CreateInSelectedDirectory)
                        {
                            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);
                            }
                                                                   );
                        }
                        else if (opt == OutputOption.RelativeToSourceAsset)
                        {
                            newDirPath = EditorGUILayout.TextField("Relative Path", m_outputDir[editor.CurrentEditingGroup]);
                        }

                        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();
                        }

                        if (opt == OutputOption.CreateInSelectedDirectory || opt == OutputOption.CreateInCacheDirectory)
                        {
                            var outputDir = PrepareOutputDirectory(BuildTargetUtility.GroupToTarget(editor.CurrentEditingGroup), node.Data, null);

                            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);

            foreach (var s in m_entries)
            {
                DrawGeneratorSetting(s, node, streamManager, editor, onValueChanged);
                GUILayout.Space(10f);
            }

            if (m_removingEntry != null)
            {
                using (new RecordUndoScope("Remove Generator", node)) {
                    RemoveGeneratorEntry(node, m_removingEntry);
                    m_removingEntry = null;
                    onValueChanged();
                }
            }

            GUILayout.Space(8);

            if (GUILayout.Button("Add Generator"))
            {
                using (new RecordUndoScope("Add Generator", node)) {
                    AddEntry(node);
                    onValueChanged();
                }
            }
        }
Beispiel #3
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            if (m_enabledBundleOptions == null)
            {
                return;
            }

            EditorGUILayout.HelpBox("Build Asset Bundles: Build asset bundles with given asset bundle settings.", MessageType.Info);
            editor.UpdateNodeName(node);

            bool newOverwrite = EditorGUILayout.ToggleLeft("Keep AssetImporter settings for variants", m_overwriteImporterSetting);

            if (newOverwrite != m_overwriteImporterSetting)
            {
                using (new RecordUndoScope("Remove Target Bundle Options", node, true)){
                    m_overwriteImporterSetting = newOverwrite;
                    onValueChanged();
                }
            }

            GUILayout.Space(10f);

            //Show target configuration tab
            editor.DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var disabledScope = editor.DrawOverrideTargetToggle(node, m_enabledBundleOptions.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                    using (new RecordUndoScope("Remove Target Bundle Options", node, true)){
                        if (enabled)
                        {
                            m_enabledBundleOptions[editor.CurrentEditingGroup] = m_enabledBundleOptions.DefaultValue;
                            m_outputDir[editor.CurrentEditingGroup]            = m_outputDir.DefaultValue;
                            m_outputOption[editor.CurrentEditingGroup]         = m_outputOption.DefaultValue;
                            m_manifestName[editor.CurrentEditingGroup]         = m_manifestName.DefaultValue;
                        }
                        else
                        {
                            m_enabledBundleOptions.Remove(editor.CurrentEditingGroup);
                            m_outputDir.Remove(editor.CurrentEditingGroup);
                            m_outputOption.Remove(editor.CurrentEditingGroup);
                            m_manifestName.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();
                        }
                    }

                    using (new EditorGUI.DisabledScope(opt == OutputOption.BuildInCacheDirectory)) {
                        var newDirPath = editor.DrawFolderSelector("Output Directory", "Select Output Folder",
                                                                   m_outputDir[editor.CurrentEditingGroup],
                                                                   Application.dataPath + "/../",
                                                                   (string folderSelected) => {
                            var projectPath = Directory.GetParent(Application.dataPath).ToString();

                            if (projectPath == folderSelected)
                            {
                                folderSelected = string.Empty;
                            }
                            else
                            {
                                var index = folderSelected.IndexOf(projectPath);
                                if (index >= 0)
                                {
                                    folderSelected = folderSelected.Substring(projectPath.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 outputDir = PrepareOutputDirectory(BuildTargetUtility.GroupToTarget(editor.CurrentEditingGroup), node.Data, false, false);

                        if (opt == OutputOption.ErrorIfNoOutputDirectoryFound &&
                            editor.CurrentEditingGroup != BuildTargetGroup.Unknown &&
                            !string.IsNullOrEmpty(m_outputDir [editor.CurrentEditingGroup]) &&
                            !Directory.Exists(outputDir))
                        {
                            using (new EditorGUILayout.HorizontalScope()) {
                                Debug.LogWarning("BundleBuilder" + outputDir + " does not exist.");
                                EditorGUILayout.LabelField(outputDir + " does not exist.");
                                if (GUILayout.Button("Create directory"))
                                {
                                    Directory.CreateDirectory(outputDir);
                                }
                            }
                            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();
                        }

                        using (new EditorGUI.DisabledScope(!Directory.Exists(outputDir)))
                        {
                            using (new EditorGUILayout.HorizontalScope()) {
                                GUILayout.FlexibleSpace();
                                #if UNITY_EDITOR_OSX
                                string buttonName = "Reveal in Finder";
                                #else
                                string buttonName = "Show in Explorer";
                                #endif
                                if (GUILayout.Button(buttonName))
                                {
                                    EditorUtility.RevealInFinder(outputDir);
                                }
                            }
                        }

                        EditorGUILayout.HelpBox("You can use '{Platform}' variable for Output Directory path to include platform name.", MessageType.Info);
                    }

                    GUILayout.Space(8f);

                    var manifestName    = m_manifestName[editor.CurrentEditingGroup];
                    var newManifestName = EditorGUILayout.TextField("Manifest Name", manifestName);
                    if (newManifestName != manifestName)
                    {
                        using (new RecordUndoScope("Change Manifest Name", node, true)){
                            m_manifestName[editor.CurrentEditingGroup] = newManifestName;
                            onValueChanged();
                        }
                    }

                    GUILayout.Space(8f);

                    int bundleOptions = m_enabledBundleOptions[editor.CurrentEditingGroup];

                    bool isDisableWriteTypeTreeEnabled  = 0 < (bundleOptions & (int)BuildAssetBundleOptions.DisableWriteTypeTree);
                    bool isIgnoreTypeTreeChangesEnabled = 0 < (bundleOptions & (int)BuildAssetBundleOptions.IgnoreTypeTreeChanges);

                    // buildOptions are validated during loading. Two flags should not be true at the same time.
                    UnityEngine.Assertions.Assert.IsFalse(isDisableWriteTypeTreeEnabled && isIgnoreTypeTreeChangesEnabled);

                    bool isSomethingDisabled = isDisableWriteTypeTreeEnabled || isIgnoreTypeTreeChangesEnabled;

                    foreach (var option in Model.Settings.BundleOptionSettings)
                    {
                        // contains keyword == enabled. if not, disabled.
                        bool isEnabled = (bundleOptions & (int)option.option) != 0;

                        bool isToggleDisabled =
                            (option.option == BuildAssetBundleOptions.DisableWriteTypeTree && isIgnoreTypeTreeChangesEnabled) ||
                            (option.option == BuildAssetBundleOptions.IgnoreTypeTreeChanges && isDisableWriteTypeTreeEnabled);

                        using (new EditorGUI.DisabledScope(isToggleDisabled)) {
                            var result = EditorGUILayout.ToggleLeft(option.description, isEnabled);
                            if (result != isEnabled)
                            {
                                using (new RecordUndoScope("Change Bundle Options", node, true)){
                                    bundleOptions = (result) ?
                                                    ((int)option.option | bundleOptions) :
                                                    (((~(int)option.option)) & bundleOptions);
                                    m_enabledBundleOptions[editor.CurrentEditingGroup] = bundleOptions;
                                    onValueChanged();
                                }
                            }
                        }
                    }
                    if (isSomethingDisabled)
                    {
                        EditorGUILayout.HelpBox("'Disable Write Type Tree' and 'Ignore Type Tree Changes' can not be used together.", MessageType.Info);
                    }
                }
            }
        }
Beispiel #4
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);
                        }
                    }
                }
            }
        }