Пример #1
0
        public static void FindReferences()
        {
            HashSet <string> references = new HashSet <string>();
            var objects    = Selection.objects;
            var scriptsMap = APResources.GetMonoScriptsMap();

            bool Cancel = false;

            for (int i = 0; i < objects.Length; i++)
            {
                var    path             = AssetDatabase.GetAssetPath(objects[i]);
                string message          = "Find references of " + path;
                var    referencesAssets = APCache.GetReferences(path, message, i * 1f / objects.Length, (i + 1) * 1f / objects.Length, ref Cancel);

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

                if (objects[i] is ScriptableObject || objects[i] is MonoScript)
                {
                    Type msType = null;
                    if (objects[i] is ScriptableObject)
                    {
                        msType = (objects[i] as ScriptableObject).GetType();
                    }

                    if (objects[i] is MonoScript)
                    {
                        msType = (objects[i] as MonoScript).GetClass();
                    }

                    if (msType != null)
                    {
                        msType
                        .GetFields(ReflectionUtils.BIND_FLAGS)
                        .ToList()
                        .ForEach(f =>
                        {
                            if (scriptsMap.ContainsKey(f.FieldType.ToString()))
                            {
                                references.Add(scriptsMap[f.FieldType.ToString()]);
                            }
                        });
                    }
                }

                if (Cancel)
                {
                    break;
                }
            }

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