private void CreatePrefab(bool _delete, bool _inst) { ProceduralGear g = (ProceduralGear)target; MeshFilter filter = (MeshFilter)g.GetComponent(typeof(MeshFilter)); GameObject newGO = new GameObject(); newGO.name = g.name; newGO.AddComponent(typeof(MeshFilter)); newGO.AddComponent(typeof(MeshRenderer)); SaveMesh(); MeshFilter f = (MeshFilter)newGO.GetComponent(typeof(MeshFilter)); f.sharedMesh = Mesh.Instantiate(filter.sharedMesh) as Mesh; MeshRenderer r = (MeshRenderer)newGO.GetComponent(typeof(MeshRenderer)); MeshRenderer r2 = (MeshRenderer)g.GetComponent(typeof(MeshRenderer)); r.sharedMaterials = r2.sharedMaterials; #pragma warning disable 618 Object prefab = EditorUtility.CreateEmptyPrefab(path + "/" + g.name + ".prefab"); EditorUtility.ReplacePrefab(g.gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab); #pragma warning restore 618 if (!_delete) { if (_inst) { GameObject go = (GameObject)Instantiate(g.gameObject, g.gameObject.transform.position, g.gameObject.transform.rotation); go.name = go.name.Replace("(Clone)", ""); } DestroyImmediate(newGO, true); } }
private void SaveMesh() { ProceduralGear g = (ProceduralGear)target; string meshPrefabPath = ""; meshPrefabPath = path + bSlash + g.name + ".asset"; MeshFilter filter = (MeshFilter)g.GetComponent(typeof(MeshFilter)); filter.sharedMesh.hideFlags = HideFlags.None; Unwrapping.GenerateSecondaryUVSet(filter.sharedMesh); Mesh mesh = Mesh.Instantiate(filter.sharedMesh) as Mesh; if (!System.IO.File.Exists(Application.dataPath.Replace("Assets", path) + bSlash + g.name + ".asset")) { AssetDatabase.CreateAsset(mesh, meshPrefabPath); } else { AssetDatabase.SaveAssets(); } filter.sharedMesh.hideFlags = HideFlags.HideAndDontSave; }
private void MenuMat() { MenuButtons(1); ProceduralGear g = (ProceduralGear)target; SerializedProperty bodyParts = prefs.FindPropertyRelative("bodyParts"), teethParts = prefs.FindPropertyRelative("teethParts"), calculateTangens = prefs.FindPropertyRelative("tangens"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(calculateTangens, new GUIContent("Calculate Tangens", "Check this, only if shader needs them.\nCalculate tangens needs more time on CPU.")); EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("Textures in Renderer:"); EditorGUILayout.BeginHorizontal(); int matCount = 0; foreach (Material m in g.GetComponent <Renderer>().sharedMaterials) { GUILayout.Label(matCount.ToString(), GUILayout.MaxWidth(10f)); GUILayout.Label(m.mainTexture, GUILayout.Width(50f), GUILayout.Height(50f)); matCount++; } EditorGUILayout.EndHorizontal(); MenuButtons_Parts(currenPartMenu); GUILayoutOption labelHeight = GUILayout.Height(40f); int[] indexes = GetStartEndPartIndex(bodyParts.intValue, teethParts.intValue, 0); for (int i = indexes[0]; i < indexes[1]; i++) { if (i == points.arraySize - 2) { EditorGUILayout.LabelField("Cap Body"); } else if (i == points.arraySize - 1) { EditorGUILayout.LabelField("Cap Teeth"); } SerializedProperty point = points.GetArrayElementAtIndex(i), mat = point.FindPropertyRelative("mat"); if (mat == null) { break; } if (mat.intValue > g.GetComponent <Renderer>().sharedMaterials.Length - 1) { mat.intValue = 0; } EditorGUILayout.BeginHorizontal(); InfoField(" " + indexes[2].ToString(), colors[++indexes[2]], 15f); GUILayout.Label(g.GetComponent <Renderer>().sharedMaterials[mat.intValue].mainTexture, GUILayout.Width(40f), labelHeight); GUILayout.Label(g.GetComponent <Renderer>().sharedMaterials[mat.intValue].name, GUILayout.Width(120f), labelHeight); for (int j = 0; j < matCount; j++) { if (GUILayout.Button(j.ToString(), GUILayout.MaxWidth(35f))) { mat.intValue = j; } } EditorGUILayout.LabelField(" "); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); ShowInfoField(); GUI.color = Color.gray; EditorGUILayout.LabelField(" "); if (GUILayout.Button("?", GUILayout.Width(20))) { showMatInfo = !showMatInfo; } EditorGUILayout.EndHorizontal(); if (showMatInfo) { ShowMatInfo(); } EditorGUILayout.Separator(); }