コード例 #1
0
        void FindLayers()
        {
            var allObjects = SceneObjectUtility.GetAllObjectsInScene(false);

            layerWithObjectList.Clear();

            int defaultLayer = LayerMask.NameToLayer("Default");

            foreach (var obj in allObjects)
            {
                if (obj.layer == defaultLayer)
                {
                    continue;
                }

                var layerWithObj = layerWithObjectList.Find((item) => item.layer == obj.layer);

                if (layerWithObj == null)
                {
                    layerWithObj = new LayerWithObject()
                    {
                        layer = obj.layer
                    };
                    layerWithObjectList.Add(layerWithObj);
                }

                layerWithObj.objectList.Add(obj);
            }
        }
コード例 #2
0
        void FindTags()
        {
            var allObjects = SceneObjectUtility.GetAllObjectsInScene(false);

            tagWithObjectList.Clear();

            foreach (var obj in allObjects)
            {
                if (obj.CompareTag("Untagged"))
                {
                    continue;
                }

                var tagWithObj = tagWithObjectList.Find((item) => item.tag == obj.tag);

                if (tagWithObj == null)
                {
                    tagWithObj = new TagWithObjects()
                    {
                        tag = obj.tag
                    };
                    tagWithObjectList.Add(tagWithObj);
                }

                tagWithObj.objectList.Add(obj);
            }
        }
コード例 #3
0
        void DisappearUnreferenceObjects()
        {
            isHiding = true;

            var refObjectList = new List <ReferenceObject>();
            var allObject     = SceneObjectUtility.GetAllObjectsInScene(false);

            foreach (var obj in allObject)
            {
                obj.hideFlags = HideFlags.HideInHierarchy;
                SceneObjectUtility.GetReferenceObject(obj, refObjectList);
            }
            refObjectList.Sort((x, y) => { return(x.referenceComponent.GetInstanceID() - y.referenceComponent.GetInstanceID()); });

            foreach (var item in refObjectList)
            {
                ParentShow(item.referenceComponent.transform);
                if (item.value == null)
                {
                    continue;
                }

                var obj = SceneObjectUtility.GetGameObject(item.value);

                if (obj != null)
                {
                    ParentShow(obj.transform);
                }
            }
        }
コード例 #4
0
        void SelectTargetComponent(MonoScript target)
        {
            var allObject = SceneObjectUtility.GetAllObjectsInScene(false);

            var haveComponentObjects = allObject.FindAll(item => item.GetComponent(target.name) != null);

            Selection.objects = haveComponentObjects.ToArray();
        }
コード例 #5
0
        void AppearUnreferenceObjects()
        {
            isHiding = false;
            var allObject = SceneObjectUtility.GetAllObjectsInScene(false);

            foreach (var obj in allObject)
            {
                obj.hideFlags = HideFlags.None;
            }
        }
コード例 #6
0
        void UpdateAllObject()
        {
            allObject = SceneObjectUtility.GetAllObjectsInScene(false);
            allObject.Sort((x, y) => {
                return(System.String.Compare(x.name, y.name));
            });

            if (SceneObjectUtility.SceneReferenceObjects.Length == 0)
            {
                SceneObjectUtility.UpdateReferenceList();
            }
        }
コード例 #7
0
        void UpdateCameras()
        {
            allCameras.Clear();
            var allObject = SceneObjectUtility.GetAllObjectsInScene(false);

            foreach (var obj in allObject)
            {
                var camera = obj.GetComponent <Camera>();
                if (camera != null)
                {
                    allCameras.Add(camera);
                }
            }

            SortCamera();
        }
コード例 #8
0
        static string ComponentBaseGraph()
        {
            List <string> uniqueStrings = new List <string>();
            StringBuilder exportText    = new StringBuilder();
            Dictionary <string, List <ReferenceObject> > itemDirectry = new Dictionary <string, List <ReferenceObject> >();
            List <string> ignoreType = new List <string> {
                "GameObject", "Transform"
            };

            List <MonoBehaviour> monobehaviourList = new List <MonoBehaviour>();

            SceneObjectUtility.UpdateGlovalReferenceList();

            exportText.AppendLine("digraph sample {");
            exportText.AppendLine("graph [rankdir=\"LR\"]");
            exportText.AppendLine("node [ shape = record , style=filled, fillcolor=\"#efefef\",fontname=Helvetica, fontsize=10.5, fontcolor=\"#2b2b2b\", height=0.25, width=1, penwidth=0.1 ];");
            exportText.AppendLine("edge [arrowhead=normal,arrowsize=0.5,len=0.5, color=\"#bfbfbf\"];");


            foreach (var obj in SceneObjectUtility.GetAllObjectsInScene(false))
            {
                foreach (var comp in obj.GetComponents <MonoBehaviour>())
                {
                    monobehaviourList.Add(comp);
                }
            }

            ///-------------------


            foreach (var obj in SceneObjectUtility.SceneReferenceObjects)
            {
                var componentType = obj.referenceComponent.GetType().Name;

                if (obj.referenceComponent.gameObject.CompareTag("EditorOnly"))
                {
                    continue;
                }

                if (!itemDirectry.ContainsKey(componentType))
                {
                    itemDirectry.Add(componentType, new List <ReferenceObject>());
                }
                var list = itemDirectry[componentType];
                list.Add(obj);
            }

            foreach (var dic in itemDirectry.Keys)
            {
                if (dic == null)
                {
                    continue;
                }

                var list = itemDirectry[dic];
                list.RemoveAll(item => SceneObjectUtility.GetGameObject(item.value) == item.referenceComponent.gameObject);
                if (list.Count == 0)
                {
                    continue;
                }

                foreach (var obj in list)
                {
                    var baseObject = obj.referenceComponent.GetType();
                    var toObject   = obj.value.GetType();

                    if (toObject == null)
                    {
                        continue;
                    }

                    if (ignoreType.Contains(toObject.Name))
                    {
                        continue;
                    }


                    string text = string.Format("\"{0}\" -> \"{1}\";", baseObject.Name, toObject.Name);

                    if (uniqueStrings.Contains(text))
                    {
                        continue;
                    }

                    exportText.AppendLine(text);
                    uniqueStrings.Add(text);
                }
            }

            ///-------------------


            List <ToReferenceWindow.PerhapsReferenceObject> perhapsList = new List <ToReferenceWindow.PerhapsReferenceObject>();

            foreach (var monobehaviour in monobehaviourList)
            {
                ToReferenceWindow.UpdatePerahpsReferenceObjectList(monobehaviour, perhapsList);
            }


            foreach (var obj in perhapsList)
            {
                if (ignoreType.Contains(obj.referenceMonobehaviourName))
                {
                    continue;
                }


                string text = string.Format("\"{0}\" -> \"{1}\";", obj.compType.Name, obj.referenceMonobehaviourName);

                if (uniqueStrings.Contains(text))
                {
                    continue;
                }

                exportText.AppendLine(text);
                uniqueStrings.Add(text);
            }


            ///-------------------


            List <CallbackCallObject> callbackObjectList = new List <CallbackCallObject>();

            foreach (var monobehaviour in monobehaviourList)
            {
                foreach (var text in MonoScript.FromMonoBehaviour(monobehaviour).text.Split(';'))
                {
                    if (SceneObjectUtility.AddMatchMethod(text, monobehaviour, "SendMessage\\((?<call>.*?),.*\\)", callbackObjectList))
                    {
                        continue;
                    }
                    if (SceneObjectUtility.AddMatchMethod(text, monobehaviour, "SendMessage\\((?<call>.*?)\\)", callbackObjectList))
                    {
                        continue;
                    }
                    if (SceneObjectUtility.AddMatchMethod(text, monobehaviour, "BroadcastMessage\\((?<call>.*?)\\)", callbackObjectList))
                    {
                        continue;
                    }
                    if (SceneObjectUtility.AddMatchMethod(text, monobehaviour, "BroadcastMessage\\((?<call>.*?)\\)", callbackObjectList))
                    {
                        continue;
                    }
                }
            }

            foreach (var callback in callbackObjectList)
            {
                foreach (var item in monobehaviourList)
                {
                    var method = item.GetType().GetMethod(callback.method,
                                                          System.Reflection.BindingFlags.NonPublic |
                                                          System.Reflection.BindingFlags.Public |
                                                          System.Reflection.BindingFlags.Instance);
                    if (method != null)
                    {
                        foreach (var comp in callback.callComponent)
                        {
                            if (ignoreType.Contains(item.GetType().Name))
                            {
                                continue;
                            }

                            string text = string.Format("\"{0}\" -> \"{1}\" [style = dotted];", comp.GetType().Name, item.GetType().Name);
                            if (uniqueStrings.Contains(text))
                            {
                                continue;
                            }
                            exportText.AppendLine(text);
                            uniqueStrings.Add(text);
                        }
                    }
                }
            }

            List <ANimationCallbackObject> animCallbackObjectList = new List <ANimationCallbackObject>();

            foreach (var obj in SceneObjectUtility.GetAllObjectsInScene(false))
            {
                if (obj.GetComponent <Animator>() != null)
                {
                    SceneObjectUtility.GetAnimationEvents(obj.GetComponent <Animator>(), animCallbackObjectList);
                }
            }

            foreach (var callback in animCallbackObjectList)
            {
                foreach (var item in monobehaviourList)
                {
                    var method = item.GetType().GetMethod(callback.method,
                                                          System.Reflection.BindingFlags.NonPublic |
                                                          System.Reflection.BindingFlags.Public |
                                                          System.Reflection.BindingFlags.Instance);
                    if (method != null)
                    {
                        foreach (var comp in callback.callComponent)
                        {
                            if (ignoreType.Contains(item.GetType().Name))
                            {
                                continue;
                            }

                            string text = string.Format("\"AnimClip({0})\" -> \"{1}\" [style = dotted];", callback.clip.name, item.GetType().Name);
                            if (uniqueStrings.Contains(text))
                            {
                                continue;
                            }
                            exportText.AppendLine(text);
                            uniqueStrings.Add(text);
                        }
                    }
                }
            }



            //---------------


            List <CallbackObject> co = new List <CallbackObject>();

            if (GameObject.FindObjectOfType <Collider2D>() != null)
            {
                co.Add(new CallbackObject()
                {
                    method = "OnCollisionEnter2D", callComponenttype = typeof(Collider2D)
                });
                co.Add(new CallbackObject()
                {
                    method = "OnCollisionExit2D", callComponenttype = typeof(Collider2D)
                });
                co.Add(new CallbackObject()
                {
                    method = "OnCollisionStay2D", callComponenttype = typeof(Collider2D)
                });
                co.Add(new CallbackObject()
                {
                    method = "OnTriggerEnter2D", callComponenttype = typeof(Collider2D)
                });
                co.Add(new CallbackObject()
                {
                    method = "OnTriggerExit2D", callComponenttype = typeof(Collider2D)
                });
                co.Add(new CallbackObject()
                {
                    method = "OnTriggerStay2D", callComponenttype = typeof(Collider2D)
                });
            }

            if (GameObject.FindObjectOfType <Collider>() != null)
            {
                co.Add(new CallbackObject()
                {
                    method = "OnCollisionEnter", callComponenttype = typeof(Collider)
                });
                co.Add(new CallbackObject()
                {
                    method = "OnCollisionExit", callComponenttype = typeof(Collider)
                });
                co.Add(new CallbackObject()
                {
                    method = "OnCollisionStay", callComponenttype = typeof(Collider)
                });
                co.Add(new CallbackObject()
                {
                    method = "OnTriggerEnter", callComponenttype = typeof(Collider)
                });
                co.Add(new CallbackObject()
                {
                    method = "OnTriggerExit", callComponenttype = typeof(Collider)
                });
                co.Add(new CallbackObject()
                {
                    method = "OnTriggerStay", callComponenttype = typeof(Collider)
                });
            }

            if (GameObject.FindObjectOfType <Animator>() != null)
            {
                co.Add(new CallbackObject()
                {
                    method = "OnAnimatorMove", callComponenttype = typeof(Animator)
                });
            }

            if (GameObject.FindObjectOfType <Camera>() != null)
            {
                var type = typeof(Camera);
                co.Add(new CallbackObject()
                {
                    method = "OnPostRender", callComponenttype = type
                });
                co.Add(new CallbackObject()
                {
                    method = "OnPreCull", callComponenttype = type
                });
                co.Add(new CallbackObject()
                {
                    method = "OnPreRender", callComponenttype = type
                });
                co.Add(new CallbackObject()
                {
                    method = "OnRenderImage", callComponenttype = type
                });
                co.Add(new CallbackObject()
                {
                    method = "OnRenderObject", callComponenttype = type
                });
                co.Add(new CallbackObject()
                {
                    method = "OnWillRenderObject ", callComponenttype = type
                });
            }

            List <System.Type> uniqueMonobehaviourType = new List <System.Type>();

            foreach (var monobehaviour in monobehaviourList)
            {
                var type = monobehaviour.GetType();
                if (!uniqueMonobehaviourType.Contains(type))
                {
                    uniqueMonobehaviourType.Add(type);
                }
            }

            foreach (var callback in co)
            {
                foreach (var monobehaviourType in uniqueMonobehaviourType)
                {
                    var method = monobehaviourType.GetMethod(callback.method,
                                                             System.Reflection.BindingFlags.NonPublic |
                                                             System.Reflection.BindingFlags.Public |
                                                             System.Reflection.BindingFlags.Instance);

                    if (method != null)
                    {
                        string text = string.Format("\"{0}\" -> \"{1}\" [style = dotted];", callback.callComponenttype.Name, monobehaviourType.Name);
                        if (uniqueStrings.Contains(text))
                        {
                            continue;
                        }
                        exportText.AppendLine(text);
                        uniqueStrings.Add(text);
                    }
                }
            }


            exportText.AppendLine("}");

            return(exportText.ToString());
        }