Ejemplo n.º 1
0
        /**
         * Before we can do the search, we must determine the list of potential
         * assets that can be searched.
         */
        protected virtual void filterAssetPaths(string[] allAssets)
        {
            assetPaths = new List <string>(); //default to nothing.

            if (job.scope.projectScope == ProjectScope.EntireProject)
            {
                //If the asset scope is set and has this value OR the scope is not set at all (everything)
                if ((job.scope.assetScope & assetScope) == assetScope || job.scope.assetScope == AssetScope.None)
                {
                    IEnumerable <string> filteredPaths = allAssets.Where(asset => suffixes.Any(suffix => asset.EndsWith(suffix, System.StringComparison.OrdinalIgnoreCase)));
                    addItems(filteredPaths);
                }
                else
                {
                    // Debug.Log("[SearchSubJob] Ignoring, not in scope.");
                }
            }
            else if (job.scope.projectScope == ProjectScope.SpecificLocation)
            {
                addObjectsInLocation(job.scope.scopeObj, allAssets, job.scope.assetScope);
            }
            else if (job.scope.projectScope == ProjectScope.CurrentSelection)
            {
                foreach (UnityEngine.Object obj in Selection.objects)
                {
                    ObjectID objID = new ObjectID(obj);
                    objID.Clear();
                    if (objID.isSceneObject)
                    {
                        //scene objects handled in scenesubjob.
                    }
                    else
                    {
                        //Ignore asset scope for current selection.
                        addObjectsInLocation(objID, allAssets, SearchScope.allAssets);
                    }
                }
            }
            else if (job.scope.projectScope == ProjectScope.CurrentScene)
            {
                //this is handled in the SceneSubJob.
            }
        }
        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);
        }