Exemplo n.º 1
0
        private void OnPreprocessAsset()
        {
            if (!assetImporter.importSettingsMissing)
            {
                return;
            }

            if (!IsPresetAsset(assetImporter.assetPath))
            {
                return;
            }

            string path = Path.GetDirectoryName(assetPath);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (!PresetManagerStorage.IsInstanceAvailable())
            {
                return;
            }

            PresetManagerUtils.ApplySettingsToAsset(path, assetImporter);
        }
        private bool HasFolderSelected()
        {
            if (newSetupFolder == null)
            {
                return(false);
            }

            string path = AssetDatabase.GetAssetPath(newSetupFolder);

            return(Directory.Exists(PresetManagerUtils.RelativeToAbsolutePath(path)));
        }
Exemplo n.º 3
0
        private void OnEnable()
        {
            relativeFolderPath = AssetDatabase.GetAssetPath(target);
            absoluteFolderPath = PresetManagerUtils.RelativeToAbsolutePath(relativeFolderPath);
            isFolder           = Directory.Exists(absoluteFolderPath);

            if (!isFolder)
            {
                return;
            }

            ReadFolder();
        }
Exemplo n.º 4
0
        private void SearchForAllFiles(string directoryAbsolutePath, ref List <string> filesPath)
        {
            filesPath.AddRange(Directory.GetFiles(directoryAbsolutePath));

            string[] folderPaths = Directory.GetDirectories(directoryAbsolutePath);
            for (int i = 0; i < folderPaths.Length; i++)
            {
                string folderPath = folderPaths[i];
                if (!PresetManagerUtils.HasAnyPresetForFolder(PresetManagerUtils.AbsoluteToRelativePath(folderPath)))
                {
                    SearchForAllFiles(folderPath, ref filesPath);
                }
            }
        }
Exemplo n.º 5
0
        private void ShowOptionsForImporter(AssetImporter assetImporter)
        {
            Preset[] presets      = PresetManagerUtils.GetAvailablePresetsForAssetImporter(assetImporter);
            string[] presetsNames = GetNamesFromList(presets, true);

            if (selectedIndex == -1)
            {
                if (PresetManagerUtils.TryGetAssetPresetFromFolder(relativeFolderPath, assetImporter, out PresetData appliedPreset))
                {
                    selectedIndex = Array.IndexOf(presets, appliedPreset.Preset) + 1;
                }
                else
                {
                    selectedIndex = 0;
                }
            }

            if (selectedIndex == 0)
            {
                if (PresetManagerUtils.TryToGetParentPresetSettings(relativeFolderPath, assetImporter,
                                                                    out string parentRelativePath))
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.ObjectField("Inheriting settings from:",
                                                AssetDatabase.LoadAssetAtPath <DefaultAsset>(parentRelativePath), typeof(DefaultAsset), false);
                    EditorGUI.EndDisabledGroup();
                }
            }

            EditorGUI.BeginChangeCheck();

            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(20);
                selectedIndex = GUILayout.SelectionGrid(selectedIndex, presetsNames, 1, EditorStyles.radioButton);
            }


            if (EditorGUI.EndChangeCheck())
            {
                if (selectedIndex > 0)
                {
                    PresetManagerUtils.SetPresetForFolder(relativeFolderPath, presets[selectedIndex - 1]);
                }
                else
                {
                    PresetManagerUtils.ClearPresetForFolder(relativeFolderPath);
                }
            }
        }
Exemplo n.º 6
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
                                           string[] movedFromAssetPaths)
        {
            if (!PresetManagerStorage.IsInstanceAvailable())
            {
                return;
            }

            if (IsPresetAsset(importedAssets) || IsPresetAsset(deletedAssets))
            {
                PresetManagerUtils.ProjectPresetsChanged();
                return;
            }
        }
Exemplo n.º 7
0
        private void ReadFolder()
        {
            string[] files = GetAllFiles(absoluteFolderPath);

            HashSet <AssetImporter> assetImporters      = new HashSet <AssetImporter>();
            HashSet <Type>          assetImportersTypes = new HashSet <Type>();

            for (var i = 0; i < files.Length; i++)
            {
                string absoluteFilePath = files[i];
                if (absoluteFilePath.EndsWith(".meta"))
                {
                    continue;
                }
                string relativeFilePath = PresetManagerUtils.AbsoluteToRelativePath(absoluteFilePath);

                AssetImporter assetImporter = AssetImporter.GetAtPath(relativeFilePath);

                if (assetImporter == null)
                {
                    continue;
                }

                if (!PresetManagerUtils.HasPresetFor(assetImporter))
                {
                    continue;
                }

                if (assetImportersTypes.Contains(assetImporter.GetType()))
                {
                    continue;
                }

                assetImporters.Add(assetImporter);
                assetImportersTypes.Add(assetImporter.GetType());
            }

            assetImportersType = assetImporters.ToArray();
            if (assetImportersTypeFoldout == null || assetImportersTypeFoldout.Length != assetImportersType.Length)
            {
                assetImportersTypeFoldout = new bool[assetImportersType.Length];
            }
        }
Exemplo n.º 8
0
        private void DrawOptions()
        {
            EditorGUILayout.BeginHorizontal("Box");
            bool hasAnyPresetForFolder = PresetManagerUtils.HasAnyPresetForFolder(relativeFolderPath);

            EditorGUI.BeginDisabledGroup(!hasAnyPresetForFolder);
            if (GUILayout.Button("Apply on current", EditorStyles.toolbarButton))
            {
                PresetManagerUtils.ApplyPresetsToFolder(relativeFolderPath);
            }

            if (GUILayout.Button("Delete Folder Settings", EditorStyles.toolbarButton))
            {
                PresetManagerUtils.ClearAllPresetsForFolder(relativeFolderPath);
                selectedIndex = 0;
            }
            EditorGUI.EndDisabledGroup();


            EditorGUILayout.EndHorizontal();
        }
Exemplo n.º 9
0
        private void OnPreprocessAsset()
        {
            if (!assetImporter.importSettingsMissing)
            {
                return;
            }

            if (IsPresetAsset(assetImporter.assetPath))
            {
                PresetManagerUtils.ProjectPresetsChanged();
                return;
            }

            string path = Path.GetDirectoryName(assetPath);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            PresetManagerUtils.ApplySettingsToAsset(path, assetImporter);
        }
Exemplo n.º 10
0
        private void SearchForAllFiles(string directoryAbsolutePath, ref List <string> filesPath, ref int level)
        {
            filesPath.AddRange(Directory.GetFiles(directoryAbsolutePath));

            string[] folderPaths = Directory.GetDirectories(directoryAbsolutePath);
            for (int i = 0; i < folderPaths.Length; i++)
            {
                string folderPath             = folderPaths[i];
                string absoluteToRelativePath = PresetManagerUtils.AbsoluteToRelativePath(folderPath);

                if (level > PresetManagerSettings.MaximumDirectorySearch)
                {
                    continue;
                }

                if (!PresetManagerUtils.HasAnyPresetForFolder(absoluteToRelativePath))
                {
                    level++;
                    SearchForAllFiles(folderPath, ref filesPath, ref level);
                }
            }
        }
Exemplo n.º 11
0
        private void OnEnable()
        {
            if (!PresetManagerSettings.DisplayFolderInspector)
            {
                return;
            }

            relativeFolderPath = AssetDatabase.GetAssetPath(target);
            if (!relativeFolderPath.StartsWith("Assets"))
            {
                return;
            }

            absoluteFolderPath = PresetManagerUtils.RelativeToAbsolutePath(relativeFolderPath);
            isFolder           = Directory.Exists(absoluteFolderPath);

            if (!isFolder)
            {
                return;
            }

            ReadFolder();
        }