コード例 #1
0
        protected static void MenuItemDoBreak()
        {
            if (Selection.objects.Length != 1)
            {
                EditorUtility.DisplayDialog("Error", "Exactly one combined mesh must be selected in the hierarchy.", "Ok");
                return;
            }

            var go = Selection.objects[0] as GameObject;

            // Pick where these new assets will be put
            string outputFolder = ChooseFolder(go);

            if (string.IsNullOrEmpty(outputFolder))
            {
                return;
            }

            var resultingObjects = SimmpleMeshCombine.BreakMesh(go);

            go.SetActive(false);

            foreach (var r in resultingObjects)
            {
                var newGO = SaveCombined(outputFolder, r.gameObject, r);
                if (go.isStatic)
                {
                    newGO.isStatic = true;
                }
            }
        }
コード例 #2
0
        protected static void MenuItemDoCombine()
        {
            List <GameObject> objects = new List <GameObject>();
            bool makeStatic           = true;

            foreach (var o in Selection.objects)
            {
                var go = o as GameObject;
                if (go != null)
                {
                    makeStatic &= go.isStatic;
                    objects.Add(go);
                }
            }

            if (objects.Count == 0)
            {
                EditorUtility.DisplayDialog("Error", "No suitable objects found to combine.", "Ok");
                return;
            }

            // Pick where these new assets will be put
            string outputFolder = ChooseFolder(objects[0]);

            if (string.IsNullOrEmpty(outputFolder))
            {
                return;
            }

            var combined = SimmpleMeshCombine.CombineMeshes(objects);

            // Create a prefab and mesh asset out of what we've made
            var newObjectAsPrefab = SaveCombined(outputFolder, combined, combined.GetComponent <MeshFilter>());

            // If all objects that were selected are static, make the new one static
            if (makeStatic)
            {
                newObjectAsPrefab.isStatic = makeStatic;
            }

            if (newObjectAsPrefab != null)
            {
                // Select the new GO in the hierarchy
                Selection.SetActiveObjectWithContext(newObjectAsPrefab, newObjectAsPrefab);
            }
        }