Exemplo n.º 1
0
        void initializeSearch()
        {
            addIgnorableResources();
            AnimationMode.StopAnimationMode(); // If recording is on, it will hose the animation.
            search.OnSearchBegin();
            resultSet        = new SearchResultSet(search);
            resultSet.status = SearchStatus.InProgress;

            currentItem = 1;
        }
Exemplo n.º 2
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);
            }
        }