示例#1
0
        static void reserializeAllAssets()
        {
            if (!EditorUtility.DisplayDialog("Slow operation", "Do you really want to reserialize all ASSETS?", "Yes", "No"))
            {
                return;
            }
            using (var editorProgress = new EditorProgress("Reserializing All Assets")) {
                var assetsPaths = editorProgress.execute("Loading all assets", AssetDatabase.GetAllAssetPaths);

                editorProgress.execute("Setting assets dirty", () => {
                    for (var i = 0; i < assetsPaths.Length; i++)
                    {
                        var asset      = AssetDatabase.LoadMainAssetAtPath(assetsPaths[i]);
                        var isCanceled = editorProgress.progressCancellable(i, assetsPaths.Length);
                        if (isCanceled)
                        {
                            break;
                        }
                        if (asset != null)
                        {
                            EditorUtility.SetDirty(asset);
                        }
                    }
                });

                editorProgress.execute("Saving reserialized assets", AssetDatabase.SaveAssets);
            }
        }
示例#2
0
        static GameObject[] findObjects(Type type, bool includeDerived)
        {
            using (var progress = new EditorProgress(nameof(AssetSelector))) {
                var prefabs = progress.execute("Finding all prefabs", () => AssetDatabase.FindAssets("t:prefab"));

                progress.start($"Searching for {type}");
                var objects =
                    prefabs
                    .Select((a, idx) => {
                    progress.progress(idx, prefabs.Length);
                    return(a);
                })
                    .Select(AssetDatabase.GUIDToAssetPath)
                    .Select(path => AssetDatabase.LoadAssetAtPath(path, type))
                    .Where(c => c && (includeDerived || c.GetType() == type))
                    .Select(
                        c => {
                    foreach (var _ in F.opt(c as Component))
                    {
                        return(_.gameObject);
                    }
                    foreach (var _ in F.opt(c as MonoBehaviour))
                    {
                        return(_.gameObject);
                    }
                    throw new Exception($"Unrecognized type {c.GetType()} on component {c}");
                })
                    .ToArray();

                progress.execute("Printing found objects to log.", () => {
                    Log.d.info($"Total objects found: {objects.Length}");
                    foreach (var obj in objects)
                    {
                        Log.d.info(AssetDatabase.GetAssetPath(obj), obj);
                    }
                });

                return(objects);
            }
        }