예제 #1
0
        private static void FindReferencesIfChanged(BaseAssetBucket bucket, AssetChanges changes, HashSet <string> changedDirectories)
        {
            // Skip if bucket is null.
            if (!bucket)
            {
                return;
            }

            // Skip if bucket is updated manually.
            if (bucket.ManualUpdate)
            {
                return;
            }

            // Skip is no source paths are in the changed directories.
            string[] sourcePaths = bucket.EDITOR_Sources.Where(o => o).Select(AssetDatabase.GetAssetPath).ToArray();

            if (changedDirectories != null && !changedDirectories.Any(bucket.EDITOR_IsValidDirectory))
            {
                return;
            }

            // Skip if all imported files already exist in the bucket or can't be added to the bucket.
            if (changes.MovedFrom.Length == 0 && changes.MovedTo.Length == 0 && changes.Deleted.Length == 0 && changes.Imported.Length < 50)
            {
                if (!changes.Imported.Any(bucket.EDITOR_IsMissing))
                {
                    return;
                }
            }

            FindReferences(bucket, sourcePaths);
        }
예제 #2
0
        public static void FindReferences(BaseAssetBucket bucket, string[] sourcePaths = null)
        {
            sourcePaths = sourcePaths ?? bucket.EDITOR_Sources.Where(o => o).Select(AssetDatabase.GetAssetPath).ToArray();

            string filter = bucket.AssetSearchType.IsSubclassOf(typeof(Component)) ? "t:GameObject" : "t:" + bucket.AssetSearchType.Name;

            string[] newPaths = AssetDatabase
                                .FindAssets(filter, sourcePaths)
                                .Select(AssetDatabase.GUIDToAssetPath).Where(p => CanBeType(p, bucket.AssetSearchType))
                                .OrderBy(System.IO.Path.GetFileName)
                                .ToArray();

            HashSet <Object> newObjects = new HashSet <Object>(newPaths.Select(p => AssetDatabase.LoadAssetAtPath(p, bucket.AssetSearchType)).Where(o => o && bucket.EDITOR_CanAdd(o)).OrderBy(o => o.name));

            bucket.EDITOR_Clear();
            newObjects.ForEach(bucket.EDITOR_TryAdd);
            bucket.EDITOR_Sort(AssetGuidSorter);
            EditorUtility.SetDirty(bucket);
            SaveAssetsDelayed();
            Debug.LogFormat(bucket, "<color=#6699cc>AssetBuckets</color>: Updated {0}", bucket.name);
        }