Esempio n. 1
0
 private static void ShowGameobjectMeshStatistic(GameObject gameobject, GameobjectMeshStatisticResult statistic = null)
 {
     if (gameobject != null && gameobject.transform.childCount > 0)
     {
         bool isInludeinactive             = true;
         SceneMeshStatisticResult sceneRes = null;
         Action <bool>            reset    = (bool inludeinactive) =>
         {
             List <GameObject> gos = new List <GameObject>();
             if (gameobject.transform.childCount > 0)
             {
                 for (int i = 0; i < gameobject.transform.childCount; ++i)
                 {
                     gos.Add(gameobject.transform.GetChild(i).gameObject);
                 }
             }
             sceneRes = MeshStatisticGameObjects(gos);
             if (statistic == null)
             {
                 statistic = MeshStatisticGameObjects(new GameObject[] { gameobject }).BiggestObject;
             }
             var goDelfStatistic = GetGameObjectSelfMeshSatistic(gameobject);
             if (goDelfStatistic.IsBiggerThan(sceneRes.BiggestObject))
             {
                 sceneRes.BiggestObject = goDelfStatistic;
             }
         };
         reset(isInludeinactive);
         var wndEditor = EditorWindow.GetWindow <SceneMeshStatisticEditor>(false);
         wndEditor.titleContent = new GUIContent(string.Format("物体的面数: {0}", gameobject.name));
         wndEditor.DoOnGUI      = () =>
         {
             isInludeinactive = GUILayout.Toggle(isInludeinactive, "是否包含Inactive对象");
             if (GUILayout.Button("刷新", GUILayout.Width(50)))
             {
                 reset(isInludeinactive);
             }
             GUILayout.Space(20);
             EditorGUILayout.BeginHorizontal();
             EditorGUILayout.ObjectField(string.Format("{0}:", string.IsNullOrEmpty(gameobject.name) ? "GameObject" : gameobject.name), gameobject, typeof(GameObject), true);
             EditorGUILayout.EndHorizontal();
             if (statistic != null)
             {
                 GUILayout.Label(string.Format("mesh: {0}\ntriangle: {1}\nvertext: {2}", GetSize(statistic.MeshCount), GetSize(statistic.TriangleCount), GetSize(statistic.VertextCount)));
             }
             EditorGUILayout.BeginHorizontal();
             if (sceneRes.BiggestObject != null && sceneRes.BiggestObject.Object != null)
             {
                 EditorGUILayout.ObjectField("面数最多的物体:", sceneRes.BiggestObject.Object, typeof(GameObject), true);
                 if (GUILayout.Button("统计此物体"))
                 {
                     ShowGameobjectMeshStatistic(sceneRes.BiggestObject.Object, sceneRes.BiggestObject);
                 }
             }
             EditorGUILayout.EndHorizontal();
             GUILayout.Label(string.Format("mesh: {0}\ntriangle: {1}\nvertext: {2}", GetSize(sceneRes.BiggestObject.MeshCount), GetSize(sceneRes.BiggestObject.TriangleCount), GetSize(sceneRes.BiggestObject.VertextCount)));
             GUILayout.Space(20);
         };
     }
 }
Esempio n. 2
0
 public bool IsBiggerThan(GameobjectMeshStatisticResult other)
 {
     if (other == null)
     {
         return(true);
     }
     return(this.TriangleCount > 0 && this.TriangleCount > other.TriangleCount);
 }
Esempio n. 3
0
        private static GameobjectMeshStatisticResult GetGameObjectSelfMeshSatistic(GameObject go)
        {
            GameobjectMeshStatisticResult goRest = new GameobjectMeshStatisticResult();

            goRest.Object = go;
            {
                var filter = go.GetComponent <MeshFilter>();
                if (filter != null && filter.sharedMesh != null)
                {
                    goRest.MeshCount++;
                    goRest.VertextCount  += filter.sharedMesh.vertexCount;
                    goRest.TriangleCount += filter.sharedMesh.triangles.Length / 3;
                }
            }
            return(goRest);
        }
Esempio n. 4
0
        public static SceneMeshStatisticResult MeshStatisticGameObjects(ICollection <GameObject> gameobjects, bool includeInactive = false)
        {
            int meshCount     = 0;
            int triangleCount = 0;
            int vertCount     = 0;
            GameobjectMeshStatisticResult goMax   = null;
            GameobjectMeshStatisticResult meshMax = null;
            int transformCount = 0;

            if (gameobjects != null && gameobjects.Count > 0)
            {
                foreach (var go in gameobjects)
                {
                    {
                        var transforms = go.GetComponentsInChildren <Transform>(includeInactive);
                        if (transforms != null)
                        {
                            transformCount += transforms.Length;
                        }
                    }
                    GameobjectMeshStatisticResult goRest = new GameobjectMeshStatisticResult();
                    goRest.Object = go;
                    {
                        var meshFilters = go.GetComponentsInChildren <MeshFilter>(includeInactive);
                        if (meshFilters != null && meshFilters.Length > 0)
                        {
                            foreach (var filter in meshFilters)
                            {
                                if (filter.sharedMesh != null)
                                {
                                    GameobjectMeshStatisticResult filterObj = new GameobjectMeshStatisticResult()
                                    {
                                        VertextCount  = filter.sharedMesh.vertexCount,
                                        MeshCount     = 1,
                                        TriangleCount = filter.sharedMesh.triangles.Length / 3,
                                        Object        = filter.gameObject
                                    };
                                    goRest.MeshCount++;
                                    goRest.VertextCount  += filterObj.VertextCount;
                                    goRest.TriangleCount += filterObj.TriangleCount;
                                    if (filterObj.IsBiggerThan(meshMax))
                                    {
                                        meshMax = filterObj;
                                    }
                                }
                            }
                        }
                    }
                    meshCount     += goRest.MeshCount;
                    triangleCount += goRest.TriangleCount;
                    vertCount     += goRest.VertextCount;
                    if (goRest.IsBiggerThan(goMax))
                    {
                        goMax = goRest;
                    }
                }
            }
            return(new SceneMeshStatisticResult()
            {
                MeshCount = meshCount,
                TriangleCount = triangleCount,
                VertextCount = vertCount,
                BiggestObject = goMax,
                MostMesh = meshMax,
                TotalGameObjectCount = transformCount
            });
        }