Beispiel #1
0
        private static void SelectReferencesByType(string assetType)
        {
            HashSet <string> references = new HashSet <string>();
            var  objects = Selection.objects;
            bool Cancel  = false;

            for (int i = 0; i < objects.Length; i++)
            {
                var    path          = AssetDatabase.GetAssetPath(objects[i]);
                string message       = "Find references of " + path;
                float  startProgress = i * 1f / objects.Length;
                float  endProgress   = (i + 1) * 1f / objects.Length;

                List <string> referencesAssets = new List <string>();
                switch (assetType)
                {
                case AssetType.MODELS:
                    referencesAssets = APCache.GetReferencesByType <APModel>(path, APAssetType.Model, message, startProgress, endProgress, ref Cancel);
                    break;

                case AssetType.MATERIALS:
                    referencesAssets = APCache.GetReferencesByType <APMaterial>(path, APAssetType.Material, message, startProgress, endProgress, ref Cancel);
                    break;

                case AssetType.PREFABS:
                    referencesAssets = APCache.GetReferencesByType <APPrefab>(path, APAssetType.Prefab, message, startProgress, endProgress, ref Cancel);
                    break;

                case AssetType.SCENE:
                    referencesAssets = APCache.GetReferencesInScene(path, ref Cancel, true, message, startProgress, endProgress);
                    break;

                default:
                    break;
                }

                foreach (var item in referencesAssets)
                {
                    if (!item.Equals(path, StringComparison.CurrentCultureIgnoreCase))
                    {
                        references.Add(item);
                    }
                }

                if (Cancel)
                {
                    break;
                }
            }

            if (!Cancel)
            {
                SelectReferences(references.ToList());
            }
            else
            {
                EditorUtility.ClearProgressBar();
            }
        }