コード例 #1
0
ファイル: DebugStuff.cs プロジェクト: sswelm/DebugStuff
        private void DrawObjects(GameObject go)
        {
            Profiler.BeginSample("DrawColliders");

            if (transforms)
            {
                Profiler.BeginSample("transforms");
                DrawTools.DrawTransform(go.transform, 0.3f);
                Profiler.EndSample();
            }

            if (colliders)
            {
                Profiler.BeginSample("colliders");
                Collider[] comp = go.GetComponents <Collider>();
                for (int i = 0; i < comp.Length; i++)
                {
                    Collider baseCol = comp[i];

                    if (baseCol is BoxCollider)
                    {
                        Profiler.BeginSample("BoxCollider");
                        BoxCollider box = baseCol as BoxCollider;
                        DrawTools.DrawLocalCube(box.transform, box.size, Color.yellow, box.center);
                        Profiler.EndSample();
                    }

                    if (baseCol is SphereCollider)
                    {
                        Profiler.BeginSample("SphereCollider");
                        SphereCollider sphere = baseCol as SphereCollider;
                        DrawTools.DrawSphere(sphere.transform.TransformPoint(sphere.center), Color.red, sphere.radius);
                        Profiler.EndSample();
                    }

                    if (baseCol is CapsuleCollider)
                    {
                        Profiler.BeginSample("CapsuleCollider");
                        CapsuleCollider caps   = baseCol as CapsuleCollider;
                        Vector3         dir    = new Vector3(caps.direction == 0 ? 1 : 0, caps.direction == 1 ? 1 : 0, caps.direction == 2 ? 1 : 0);
                        Vector3         top    = caps.transform.TransformPoint(caps.center + caps.height * 0.5f * dir);
                        Vector3         bottom = caps.transform.TransformPoint(caps.center - caps.height * 0.5f * dir);
                        DrawTools.DrawCapsule(top, bottom, Color.green, caps.radius);
                        Profiler.EndSample();
                    }

                    if (baseCol is MeshCollider)
                    {
                        Profiler.BeginSample("MeshCollider");
                        MeshCollider mesh = baseCol as MeshCollider;
                        DrawTools.DrawLocalMesh(mesh.transform, mesh.sharedMesh, XKCDColors.ElectricBlue);
                        Profiler.EndSample();
                    }
                }
                Profiler.EndSample();
            }

            if (bounds && mode != Mode.UI)
            {
                Profiler.BeginSample("bounds");

                //DrawTools.DrawBounds(go.GetRendererBounds(), XKCDColors.Pink);

                //Renderer[] renderers = go.GetComponents<Renderer>();
                //for (int i = 0; i < renderers.Length; i++)
                //{
                //    Bounds bound = renderers[i].bounds;
                //    DrawTools.DrawLocalCube(renderers[i].transform, bound.size, XKCDColors.Pink, bound.center);
                //}

                MeshFilter[] mesh = go.GetComponents <MeshFilter>();
                for (int i = 0; i < mesh.Length; i++)
                {
                    DrawTools.DrawLocalCube(mesh[i].transform, mesh[i].mesh.bounds.size, XKCDColors.Pink, mesh[i].mesh.bounds.center);
                }
                Profiler.EndSample();
            }

            if (bounds && mode == Mode.UI)
            {
                Profiler.BeginSample("bounds");

                RectTransform[] rt = go.GetComponents <RectTransform>();
                for (int i = 0; i < rt.Length; i++)
                {
                    // TODO : search for the actual Canvas ?
                    DrawTools.DrawRectTransform(rt[i], UIMasterController.Instance.appCanvas, XKCDColors.GreenApple);
                }
                Profiler.EndSample();
            }

            if (meshes)
            {
                Profiler.BeginSample("meshes");
                MeshFilter[] mesh = go.GetComponents <MeshFilter>();

                for (int i = 0; i < mesh.Length; i++)
                {
                    Profiler.BeginSample("LocalMesh");
                    DrawTools.DrawLocalMesh(mesh[i].transform, mesh[i].sharedMesh, XKCDColors.Orange);
                    Profiler.EndSample();
                }
                Profiler.EndSample();
            }

            int count = go.transform.childCount;

            for (int i = 0; i < count; i++)
            {
                GameObject child = go.transform.GetChild(i).gameObject;

                if (!child.GetComponent <Part>() && child.name != "main camera pivot")
                {
                    DrawObjects(child);
                }
            }
            Profiler.EndSample();
        }