コード例 #1
0
        public void RefreshReference(EventReference er)
        {
            if (er != null)
            {
                er.ReferenceNames = new List <string>();
                er.Events         = new List <CustomEvent>();
                er.Fields         = new List <FieldInfo>();
                {
                    FieldInfo[] fields = er.Reference.GetType().GetFields();

                    foreach (var field in fields)
                    {
                        KAIEvent attrib = Attribute.GetCustomAttribute(field, typeof(KAIEvent)) as KAIEvent;

                        if (attrib != null)
                        {
                            er.Events.Add(field.GetValue(er.Reference) as CustomEvent);
                            er.ReferenceNames.Add(field.Name);
                            er.Fields.Add(field);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void FindAllReferences(List <string> scenes)
        {
            References = new List <EventReference>();

            if (scenes.Count > 0)
            {
                var activeScene = EditorSceneManager.GetActiveScene();
                for (int i = 0; i < EditorSceneManager.sceneCount; i++)
                {
                    if (EditorSceneManager.GetSceneAt(i) != activeScene && EditorSceneManager.GetSceneAt(i).isLoaded)
                    {
                        if (EditorSceneManager.GetSceneAt(i).isLoaded)
                        {
                            EditorSceneManager.SaveScene(EditorSceneManager.GetSceneAt(i));
                        }
                        else
                        {
                            EditorSceneManager.LoadScene(EditorSceneManager.GetSceneAt(i).path, LoadSceneMode.Additive);
                        }

                        EditorSceneManager.SetActiveScene(activeScene);
                    }
                }

                for (int i = 0; i < scenes.Count; i++)
                {
                    for (int j = 0; j < _Scenes.Count; j++)
                    {
                        {
                            var guid1 = AssetDatabase.AssetPathToGUID(scenes[i]);
                            var guid2 = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(_Scenes[j]));

                            if (guid1.Equals(guid2))
                            {
                                var scene = EditorSceneManager.OpenScene(scenes[i], OpenSceneMode.Additive);

                                {
                                    if (scene.IsValid() && scene.isLoaded)
                                    {
                                        var allObjects = scene.GetRootGameObjects();

                                        for (int k = 0; k < allObjects.Length; k++)
                                        {
                                            var obj = allObjects[k];

                                            var comps = obj.GetComponentsInChildren <MonoBehaviour>(true);

                                            foreach (var comp in comps)
                                            {
                                                FieldInfo[] fields = comp.GetType().GetFields();

                                                var eventReference = new EventReference();
                                                eventReference.Reference = comp;
                                                bool add = false;
                                                foreach (var field in fields)
                                                {
                                                    KAIEvent attrib = Attribute.GetCustomAttribute(field, typeof(KAIEvent)) as KAIEvent;

                                                    if (attrib != null)
                                                    {
                                                        eventReference.Events.Add(field.GetValue(comp) as CustomEvent);
                                                        eventReference.ReferenceNames.Add(field.Name);
                                                        eventReference.Fields.Add(field);
                                                        add = true;
                                                    }
                                                }

                                                if (add)
                                                {
                                                    References.Add(eventReference);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }