public static void UpdateLinkedAssets(Preset preset)
        {
            var autoPresetConfigList = AssetDatabaseTools.GetAllAutoPresetConfigs();

            const string UPDATE_ASSETS_TITLE = "Updating AutoPresetConfigs";

            EditorUtility.DisplayProgressBar(UPDATE_ASSETS_TITLE, String.Empty, 0f);

            for (var i = 0; i < autoPresetConfigList.Count; i++)
            {
                var progress = Mathf.Clamp01((float)i / autoPresetConfigList.Count);
                EditorUtility.DisplayProgressBar(UPDATE_ASSETS_TITLE, String.Empty, progress);

                var autoPresetConfig = autoPresetConfigList[i];
                if (autoPresetConfig.Preset != preset)
                {
                    continue;
                }

                var msg = string.Format("Importing assets for [{0}]", autoPresetConfig.name);

                EditorUtility.DisplayProgressBar(UPDATE_ASSETS_TITLE, msg, progress);

                var assetPath  = AssetDatabase.GetAssetPath(autoPresetConfig);
                var parentPath = AssetDatabaseTools.GetAssetParentFolderPath(assetPath);

                AssetDatabaseTools.ReimportAllAssets(parentPath, autoPresetConfig);
            }

            EditorUtility.ClearProgressBar();
        }
Beispiel #2
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            GUILayout.Space(5);
            GUILayout.Label(ACTIONS_TITLE_TEXT, EditorStyles.boldLabel);

            var config = (AutoPresetConfig)target;

            if (GUILayout.Button(REIMPORT_BUTTON_TEXT))
            {
                var assetPath  = AssetDatabase.GetAssetPath(config);
                var parentPath = AssetDatabaseTools.GetAssetParentFolderPath(assetPath);

                AssetDatabaseTools.ReimportAllAssets(parentPath, config);
            }
        }
        /// <summary>
        /// Returns true if an <see cref="AutoPresetConfig"/> instance was found in the same folder as the
        /// asset that applies to it, otherwise false. If true, <paramref name="autoPreset"/> will be
        /// initialized with that value.
        /// </summary>
        /// <param name="autoPreset"></param>
        /// <returns></returns>
        private bool TryGetPresetAsset(out AutoPresetConfig autoPreset)
        {
            autoPreset = null;

            var parentFolder      = AssetDatabaseTools.GetAssetParentFolderPath(assetPath);
            var autoPresetConfigs = AssetDatabaseTools.GetAllAutoPresetConfigs(new[] { parentFolder });

            foreach (var autoPresetConfig in autoPresetConfigs)
            {
                if (!autoPresetConfig.CanBeAppliedTo(assetImporter))
                {
                    continue;
                }

                autoPreset = autoPresetConfig;
                return(true);
            }

            return(false);
        }