Пример #1
0
        public IEnumerator ExecuteAsync()
        {
            initializeSearch();
            if (searchIncludesScenes)
            {
                bool shouldContinue = SceneUtil.SaveDirtyScenes();
                if (!shouldContinue)
                {
                    userAbortedSearch();
                    yield break;
                }
            }


            foreach (SearchAssetData searchAssetData in searchAssets)
            {
                if (cancelled)
                {
                    break;
                }
                searchAsset(searchAssetData);
                yield return(searchDependencies(searchAssetData.Roots));

                searchAssetData.Unload();

                if (resultSet.resultsCount > maxItemsAllowed && !shownMaxItemsWarning)
                {
                    shownMaxItemsWarning = true;
                    bool userContinues = EditorUtility.DisplayDialog("Too Many Results", "The search and replace plugin has found " + resultSet.resultsCount + " results so far. Do you want to continue searching?", "Continue", "Cancel");
                    if (!userContinues)
                    {
                        cancelled = true;
                    }
                }
                currentItem++;
                yield return(null);
            }

            EditorUtility.ClearProgressBar();
            search.OnSearchEnd(this);

            if (cancelled)
            {
                userAbortedSearch();
            }

            calculateSearchedItems();

            string log = logBuilder.ToString();

            if (log.Length > 0)
            {
                Debug.Log("[Search & Replace] Log:\n" + log);
            }
            SRWindow.Instance.Repaint();
        }
Пример #2
0
        public Object GetSelection(bool openInProject)
        {
            string extension = Path.GetExtension(pathInfo.assetPath);

            switch (extension)
            {
            case ".unity":
                if (openInProject)
                {
                    // it is not possible to open a scene object in the project.
                    return(null);
                }
                Scene currentScene = EditorSceneManager.GetActiveScene();
                if (currentScene.path != pathInfo.assetPath)
                {
                    bool shouldContinue = SceneUtil.SaveDirtyScenes();
                    if (!shouldContinue)
                    {
                        return(null);
                    }
                    currentScene = EditorSceneManager.OpenScene(pathInfo.assetPath, OpenSceneMode.Single);
                }
#if UNITY_2018_3_OR_NEWER
                PrefabStage currentPrefabStage = PrefabStageUtility.GetCurrentPrefabStage();
                if (currentPrefabStage != null)
                {
                    StageUtility.GoToMainStage();
                }
#endif
                return(pathInfo.objID.searchForObjectInScene(currentScene));

            case ".prefab":
#if UNITY_2018_3_OR_NEWER
                if (openInProject)
                {
                    GameObject root = AssetDatabase.LoadAssetAtPath <GameObject>(pathInfo.assetPath);
                    return(pathInfo.objID.localPath.GetObject(root));
                }
                else
                {
                    // is the prefab open in the stage?
                    PrefabStage stage = PrefabStageUtility.GetCurrentPrefabStage();
                    GameObject  root  = null;
                    if (stage == null || stage.assetPath != pathInfo.assetPath)
                    {
                        // this is not the currently open path. open the latest.
                        root = AssetDatabase.LoadAssetAtPath <GameObject>(pathInfo.assetPath);
                        AssetDatabase.OpenAsset(root);
                    }
                    else
                    {
                        root = stage.prefabContentsRoot;
                    }
                    return(pathInfo.objID.searchForObjectInScene());
                }
#else
                // This case is pretty straightforward. Just select the object.
                return(EditorUtility.InstanceIDToObject(pathInfo.gameObjectID));
#endif
            case ".controller":
                EditorApplication.ExecuteMenuItem("Window/Animator");
                // now get the animator to display it.
                string             assetPath = AssetDatabase.GetAssetPath(pathInfo.gameObjectID);
                UnityEngine.Object assetObj  = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
                //set it as the selection.
                Selection.activeObject = assetObj;
                //wait until inspectors are updated and now we can set the
                // selection to the internal object.
                EditorApplication.delayCall += () => {
                    Selection.activeInstanceID = pathInfo.gameObjectID;
                };
                return(assetObj);

            default:
                return(EditorUtility.InstanceIDToObject(pathInfo.gameObjectID));
            }
        }
Пример #3
0
        public void Execute()
        {
            addIgnorableResources();
            string[] assetPaths = AssetDatabase.GetAllAssetPaths();
            AnimationMode.StopAnimationMode(); // If recording is on, it will hose the animation.

            subjobs.Add(new SearchSubJob(this, AssetScope.Prefabs, assetPaths, new string[] { ".prefab" }, false));

            //scenes are oh so 'special'.
            sceneSubJob = new SceneSubJob(this, AssetScope.Scenes, assetPaths, new string[] { ".unity" });
            subjobs.Add(sceneSubJob);
            subjobs.Add(new SearchSubJob(this, AssetScope.Materials, assetPaths, new string[] { ".mat" }, false));
            subjobs.Add(new SearchSubJob(this, AssetScope.ScriptableObjects, assetPaths, new string[] { ".asset" }, false));
            subjobs.Add(new SearchSubJob(this, AssetScope.Animations, assetPaths, new string[] { ".anim" }, false));
            subjobs.Add(new SearchSubJob(this, AssetScope.Animators, assetPaths, new string[] { ".controller" }, false));
            subjobs.Add(new SearchSubJob(this, AssetScope.AudioClips, assetPaths, new string[] { ".wav", ".mp3" }, true));
            subjobs.Add(new SearchSubJob(this, AssetScope.Textures, assetPaths, new string[] { ".png", ".psd", ".tiff", ".tif", ".tga", ".gif", ".bmp", ".jpg", ".jpeg", ".iff", ".pict" }, true));
            subjobs.Add(new SceneObjectSubJob(this, AssetScope.None, assetPaths, new string[] { "" }));

            foreach (SearchSubJob subjob in subjobs)
            {
                totalItems += subjob.assetPaths.Count;
            }
            search.OnSearchBegin();
            result        = new SearchResultSet(search);
            result.status = SearchStatus.InProgress;

            currentItem = 1;

            if (sceneSubJob.assetPaths.Count > 0 && scope.projectScope != ProjectScope.CurrentScene)
            {
                bool shouldContinue = SceneUtil.SaveDirtyScenes();
                if (!shouldContinue)
                {
                    userAbortedSearch();
                    return;
                }
            }
            bool cancelled = false;

            try{
                foreach (SearchSubJob subjob in subjobs)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        if (!cancelled)
                        {
                            cancelled = progress();
                        }
                        while (!cancelled && subjob.SearchNextAsset())
                        {
                            if (result.resultsCount > maxItemsAllowed && !shownMaxItemsWarning)
                            {
                                shownMaxItemsWarning = true;
                                bool userContinues = EditorUtility.DisplayDialog("Too Many Results", "The search and replace plugin has found " + result.resultsCount + " results so far. Do you want to continue searching?", "Continue", "Cancel");
                                if (!userContinues)
                                {
                                    cancelled = true;
                                }
                            }
                            currentItem++;
                        }
                    }
                }
            }catch (System.Exception ex) {
                Debug.LogException(ex);
                result.status    = SearchStatus.InProgress;
                result.statusMsg = "An exception occurred: " + ex.ToString();
                EditorUtility.ClearProgressBar();
            }

            EditorUtility.ClearProgressBar();

            foreach (SearchSubJob subjob in subjobs)
            {
                subjob.JobDone();
            }

            search.OnSearchEnd(this);

            if (cancelled)
            {
                userAbortedSearch();
            }

            //calculate searchedItems
            int searchedItems = 0;

            foreach (var kvp in searchAssetsData)
            {
                SearchAssetData data = kvp.Value;
                if (data.searchExecuted)
                {
                    searchedItems++;
                }
            }
            if (result.status == SearchStatus.InProgress)
            {
                //standard termination.
                result.searchedItems = searchedItems;
                result.status        = SearchStatus.Complete;
            }
            result.OnSearchComplete();

            string log = logBuilder.ToString();

            if (log.Length > 0)
            {
                Debug.Log("[Search & Replace] Log:\n" + log);
            }
        }