Esempio n. 1
0
 public SearchJob(SearchItemSet s, SearchOptions o, SearchScopeData sc)
 {
     search  = s;
     options = o;
     scope   = sc;
     Execute();
 }
        static void replaceInstances(SearchJob parentJob, SearchItem item, GameObject oldValue, GameObject newValue)
        {
            SearchItemSet searchSet = new SearchItemSet();

            searchSet.OnDeserialization();
            searchSet.AddNew(Keys.Global, false);
            SearchItemGlobal searchItem = (SearchItemGlobal)searchSet.items[0];

            searchItem.SetType("Object");
            DynamicTypeObject dto = (DynamicTypeObject)searchItem.GetDTDFor(typeof(UnityEngine.Object));

            dto.SearchSubObjects = true;
            dto.SetObject(oldValue);
            ReplaceItemObject replaceItem = (ReplaceItemObject)dto.ReplaceItem;

            replaceItem.SetObject(newValue);

            SearchOptions options = new SearchOptions();

            options.searchType = SearchType.SearchAndReplace;

            // does this matter anymore since asset scope is now essentially defined by what assets are passed in?
            SearchScopeData searchScope = new SearchScopeData(ProjectScope.SpecificLocation, AssetScope.Prefabs, new ObjectID(AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(parentJob.assetData.assetPath)), false, parentJob.scope.loadPrefab);
            SearchJob       subJob      = new SearchJob(searchSet, options, searchScope);
            SearchAssetData assetData   = parentJob.assetData.Clone();

            subJob.AddAsset(assetData);
            subJob.Execute();

            // Now that we've executed the job we have to save a list of all objects from search results, because as soon as
            // we swap out the new object, the old object's position may shift in the hierarchy, making the PathInfo stale.
            SearchResultGroup         group         = subJob.resultSet.results[searchItem.sortIndex];
            List <UnityEngine.Object> resultObjects = new List <Object>();

            foreach (SearchResult result in group.results)
            {
                UnityEngine.Object resultObj = EditorUtility.InstanceIDToObject(result.pathInfo.objectID);
                resultObjects.Add(resultObj);
            }
            UnityEngine.Object.DestroyImmediate(oldValue);

            // now that we've deleted the object, let's rebuild the objects.
            for (int i = 0; i < resultObjects.Count; i++)
            {
                SearchResult result = group.results[i];
                result.pathInfo = PathInfo.GetPathInfo(resultObjects[i], assetData);
            }

            parentJob.AddResultsFromSubsearch(item, subJob.resultSet.results[searchItem.sortIndex]);
        }
Esempio n. 3
0
 public SearchJob(SearchItemSet s, SearchOptions o, SearchScopeData sc)
 {
     search  = s;
     options = o;
     scope   = sc;
     foreach (string blacklistedType in blacklistedList)
     {
         Type t = Type.GetType(blacklistedType);
         if (t != null)
         {
             blacklistedTypes.Add(t);
         }
     }
     // this.searchAssets = searchAssets;
     // foreach(SearchAssetData asset in searchAssets)
     // {
     //   searchAssetsData[asset.assetPath] = asset;
     // }
 }
        public static List <SearchAssetData> GetAssets(SearchScopeData scope)
        {
            List <SearchAssetData> retVal = new List <SearchAssetData>();

            if (scope.projectScope == ProjectScope.EntireProject)
            {
                //If the asset scope is set and has this value OR the scope is not set at all (everything)
                HashSet <string>     suffixes      = scope.GetSuffixesForScope();
                string[]             allAssets     = AssetDatabase.GetAllAssetPaths();
                IEnumerable <string> filteredPaths = allAssets.Where(asset => asset.StartsWith("Assets/")).Where(asset => suffixes.Contains(Path.GetExtension(asset).ToLowerInvariant()));

                foreach (string asset in filteredPaths)
                {
                    AddAsset(asset, retVal);
                }
            }
            else if (scope.projectScope == ProjectScope.SceneView)
            {
                SceneViewSearchAssetData sceneView = new SceneViewSearchAssetData(SceneUtil.GuidPathForActiveScene());
                retVal.Add(sceneView);
            }
            else if (scope.projectScope == ProjectScope.SpecificLocation)
            {
                string[]         allAssets = null;
                HashSet <string> suffixes  = scope.GetSuffixesForScope();
                addObjectsInLocation(scope.scopeObj, ref allAssets, suffixes, retVal);
            }
            else if (scope.projectScope == ProjectScope.CurrentSelection)
            {
                string[] allAssets = null;
                SceneObjectSearchAssetData sceneObject = null;
                foreach (UnityEngine.Object obj in Selection.objects)
                {
                    HashSet <string> suffixes = scope.GetSuffixesForScope(SearchScope.allAssets);
                    ObjectID         objID    = new ObjectID(obj);
                    objID.Clear();
                    if (objID.isSceneObject)
                    {
                        GameObject go = (GameObject)obj;
                        if (sceneObject == null)
                        {
                            sceneObject = new SceneObjectSearchAssetData(go.scene.path);
                            retVal.Add(sceneObject);
                        }
                        sceneObject.AddObject(go);
                    }
                    else if (objID.isPrefabStageObject)
                    {
                        if (sceneObject == null)
                        {
                            sceneObject = new SceneObjectSearchAssetData(SceneUtil.GuidPathForActiveScene());
                            retVal.Add(sceneObject);
                        }
                        sceneObject.AddObject((GameObject)obj);
                    }
                    else
                    {
                        //Ignore asset scope for current selection.
                        addObjectsInLocation(objID, ref allAssets, suffixes, retVal);
                    }
                }
            }
            return(retVal);
        }