public override void OnInspectorGUI() { DrawDefaultInspector(); void SaveToPrefab() { cc.ResetBodyMaterial(); cc.StartupSerializationApplied = cc.GetSetup().SerializeToJson(); PrefabUtility.ApplyPrefabInstance(cc.gameObject, InteractionMode.UserAction); var allPrefabs = FindObjectsOfType <CharacterCustomization>(); foreach (var obj in allPrefabs) { obj.StartupSerializationApply(); } } if (GUIStyle == null) { GUIStyle = new GUIStyle(); GUIStyle.fontStyle = FontStyle.Bold; GUIStyle.normal.textColor = Color.grey; } if (GUIStyleReset == null) { GUIStyleReset = new GUIStyle(GUI.skin.button); GUIStyleReset.fontStyle = FontStyle.Bold; GUIStyleReset.normal.textColor = Color.red; } if (GUIStyleSave == null) { GUIStyleSave = new GUIStyle(GUI.skin.button); GUIStyleSave.fontStyle = FontStyle.Bold; GUIStyleSave.normal.textColor = Color.blue; } EditorGUILayout.Space(); EditorGUI.BeginDisabledGroup(!valid || Application.isPlaying); GUILayout.BeginVertical("GroupBox"); selectedEmotionTest = EditorGUILayout.Popup("Select emotion", selectedEmotionTest, emotionsList.ToArray()); EditorGUILayout.Space(); if (cc.currentEmotion != null) { EditorGUI.BeginDisabledGroup(cc.currentEmotion != null); } if (GUILayout.Button((cc.currentEmotion != null) ? string.Format("Playback {0:0.00}", 1 - cc.currentEmotion.timer) : "Emotion Test")) { cc.PlayEmotion(emotionsList[selectedEmotionTest], 2); } EditorGUI.EndDisabledGroup(); GUILayout.EndVertical(); EditorGUI.BeginDisabledGroup(cc.bakeSkinnedMeshRenderers.Count > 0); GUILayout.BeginVertical("GroupBox"); EditorGUILayout.LabelField("LOD Levels:", string.Format("LOD{0} - LOD{1}", minLod, maxLod)); EditorGUILayout.MinMaxSlider(ref minLod, ref maxLod, 0, 3); minLod = Mathf.RoundToInt(minLod); maxLod = Mathf.RoundToInt(maxLod); if (GUILayout.Button("Apply LOD Levels")) { var path = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(cc.gameObject); GameObject contentsRoot = PrefabUtility.LoadPrefabContents(path); var childs = contentsRoot.transform.GetChild(0).childCount; var defaultGroup = contentsRoot.transform.GetChild(0); for (var d = childs - 1; d > -1; d--) { DestroyImmediate(defaultGroup.GetChild(0).gameObject); } PrefabUtility.SaveAsPrefabAsset(contentsRoot, path); PrefabUtility.UnloadPrefabContents(contentsRoot); cc.SetLODRange((int)minLod, (int)maxLod); PrefabUtility.ApplyPrefabInstance(cc.gameObject, InteractionMode.UserAction); cc.StartupSerializationApply(); } EditorGUILayout.Space(); EditorGUILayout.LabelField("LOD Levels Combined:", string.Format("LOD{0} - LOD{1}", minCombinedLod, maxCombinedLod)); EditorGUILayout.MinMaxSlider(ref minCombinedLod, ref maxCombinedLod, minLod, maxLod); if (minCombinedLod != cc.MinLODLevelsCombined || maxCombinedLod != cc.MaxLODLevelsCombined || minLod != cc.MinLODLevels || maxLod != cc.MaxLODLevels) { minCombinedLod = Mathf.RoundToInt(minCombinedLod); maxCombinedLod = Mathf.RoundToInt(maxCombinedLod); minCombinedLod = Mathf.Clamp(minCombinedLod, minLod, maxLod); maxCombinedLod = Mathf.Clamp(maxCombinedLod, minLod, maxLod); if (cc.MinLODLevelsCombined != (int)minCombinedLod && !Application.isPlaying) { cc.MinLODLevelsCombined = (int)minCombinedLod; } if (cc.MaxLODLevelsCombined != (int)maxCombinedLod && !Application.isPlaying) { cc.MaxLODLevelsCombined = (int)maxCombinedLod; } } GUILayout.EndVertical(); EditorGUI.EndDisabledGroup(); GUILayout.BeginVertical("GroupBox"); combinedCharacter = (CombinedCharacter)EditorGUILayout.ObjectField(combinedCharacter, typeof(CombinedCharacter), false); if (combinedCharacter == null && cc.combinedCharacter != null) { cc.combinedCharacter = combinedCharacter; } EditorGUI.BeginDisabledGroup(combinedCharacter == null); if (GUILayout.Button("Delete Combined Character From Project")) { EditorUtility.DisplayProgressBar("Delete Combined Character", "Process", 1f); cc.DeleteCombinedMeshFromProject(); cc.ClearBake(); SaveToPrefab(); EditorUtility.ClearProgressBar(); OnEnable(); } EditorGUI.EndDisabledGroup(); GUILayout.EndVertical(); EditorGUI.EndDisabledGroup(); EditorGUILayout.Space(); GUILayout.Label("EDIT PREFAB IN THE EDITOR", GUIStyle); foldout = EditorGUILayout.Foldout(foldout, (foldout) ? new GUIContent(" SETTINGS", EditorGUIUtility.FindTexture("winbtn_mac_close")) : new GUIContent(" SETTINGS", EditorGUIUtility.FindTexture("winbtn_mac_max"))); if (!valid && !Application.isPlaying) { if (foldout) { EditorGUI.indentLevel++; EditorGUILayout.HelpBox("Please move an object to the scene to edit.", MessageType.Warning); } return; } if (Application.isPlaying) { if (foldout) { EditorGUI.indentLevel++; EditorGUILayout.HelpBox("Please exit from play mode to edit.", MessageType.Warning); } return; } if (foldout) { GUILayout.BeginVertical("GroupBox"); GUILayout.Space(10); var level = EditorGUI.indentLevel; EditorGUI.indentLevel++; var SkinColor = EditorGUILayout.ColorField("Skin Color", SkinColorNew); var EyeColor = EditorGUILayout.ColorField("Eye Color", EyeColorNew); var HairColor = EditorGUILayout.ColorField("Hair Color", HairColorNew); var UnderpantsColor = EditorGUILayout.ColorField("Underpants Color", UnderpantsColorNew); if (SkinColor != SkinColorNew) { cc.SetBodyColor(BodyColorPart.Skin, SkinColor); SkinColorNew = SkinColor; } if (EyeColor != EyeColorNew) { cc.SetBodyColor(BodyColorPart.Eye, EyeColor); EyeColorNew = EyeColor; } if (HairColor != HairColorNew) { cc.SetBodyColor(BodyColorPart.Hair, HairColor); HairColorNew = HairColor; } if (UnderpantsColor != UnderpantsColorNew) { cc.SetBodyColor(BodyColorPart.Underpants, UnderpantsColor); UnderpantsColorNew = UnderpantsColor; } EditorGUILayout.Space(); if (GUILayout.Button("Reset Body Colors")) { cc.ResetBodyColors(); GetColors(cc); } EditorGUILayout.Space(); if (hairList.Count == 0) { hairList.Add("None"); foreach (var hair in cc.hairPresets) { hairList.Add(hair.name); } } if (beardList.Count == 0) { beardList.Add("None"); foreach (var hair in cc.beardPresets) { beardList.Add(hair.name); } } if (hatList.Count == 0) { hatList.Add("None"); foreach (var hat in cc.hatsPresets) { hatList.Add(hat.name); } } if (accessoryList.Count == 0) { accessoryList.Add("None"); foreach (var accessory in cc.accessoryPresets) { accessoryList.Add(accessory.name); } } if (shirtList.Count == 0) { shirtList.Add("None"); foreach (var shirt in cc.shirtsPresets) { shirtList.Add(shirt.name); } } if (pantsList.Count == 0) { pantsList.Add("None"); foreach (var pants in cc.pantsPresets) { pantsList.Add(pants.name); } } if (shoesList.Count == 0) { shoesList.Add("None"); foreach (var shoes in cc.shoesPresets) { shoesList.Add(shoes.name); } } EditorGUI.BeginDisabledGroup(cc.bakeSkinnedMeshRenderers.Count > 0); selectedHair = EditorGUILayout.Popup("Hair", selectedHair, hairList.ToArray()); selectedBeard = EditorGUILayout.Popup("Beard", selectedBeard, beardList.ToArray()); selectedHat = EditorGUILayout.Popup("Hat", selectedHat, hatList.ToArray()); selectedAccessory = EditorGUILayout.Popup("Accessory", selectedAccessory, accessoryList.ToArray()); selectedShirt = EditorGUILayout.Popup("Shirt", selectedShirt, shirtList.ToArray()); selectedPants = EditorGUILayout.Popup("Pants", selectedPants, pantsList.ToArray()); selectedShoes = EditorGUILayout.Popup("Shoes", selectedShoes, shoesList.ToArray()); if (selectedHair - 1 != cc.hairActiveIndex) { cc.SetHairByIndex(selectedHair - 1); } if (selectedBeard - 1 != cc.beardActiveIndex) { cc.SetBeardByIndex(selectedBeard - 1); } if (selectedHat - 1 != cc.clothesActiveIndexes[ClothesPartType.Hat]) { cc.SetElementByIndex(ClothesPartType.Hat, selectedHat - 1); } if (selectedAccessory - 1 != cc.clothesActiveIndexes[ClothesPartType.Accessory]) { cc.SetElementByIndex(ClothesPartType.Accessory, selectedAccessory - 1); } if (selectedShirt - 1 != cc.clothesActiveIndexes[ClothesPartType.Shirt]) { cc.SetElementByIndex(ClothesPartType.Shirt, selectedShirt - 1); } if (selectedPants - 1 != cc.clothesActiveIndexes[ClothesPartType.Pants]) { cc.SetElementByIndex(ClothesPartType.Pants, selectedPants - 1); } if (selectedShoes - 1 != cc.clothesActiveIndexes[ClothesPartType.Shoes]) { cc.SetElementByIndex(ClothesPartType.Shoes, selectedShoes - 1); } headSize = EditorGUILayout.Slider("Head Size", headSize, -0.25f, 0.25f); headOffset = EditorGUILayout.Slider("Head Offset", headOffset, -100f, 100f); height = EditorGUILayout.Slider("Height", height, -0.06f, 0.06f); if (headSize != cc.headSizeValue) { cc.SetHeadSize(headSize); } if (headOffset != cc.GetBodyShapeWeight("Head_Offset")) { cc.SetHeadOffset(headOffset); } if (height != cc.heightValue) { cc.SetHeight(height); } EditorGUI.EndDisabledGroup(); bodyShape = EditorGUILayout.Foldout(bodyShape, "BODY SHAPES"); if (bodyShape) { EditorGUI.indentLevel++; EditorGUILayout.HelpBox("Shapes <Slimness> and <BreastSize> for female only!", MessageType.None); foreach (var bsw in bodyShapeWeight.Keys.ToList()) { var val = EditorGUILayout.Slider(bsw.ToString(), bodyShapeWeight[bsw], 0f, 100f); if (val != bodyShapeWeight[bsw]) { cc.SetBodyShape(bsw, val); bodyShapeWeight[bsw] = val; } } EditorGUI.indentLevel--; } faceShape = EditorGUILayout.Foldout(faceShape, "FACE SHAPES"); if (faceShape) { EditorGUI.indentLevel++; foreach (var fsw in faceShapeWeight.Keys.ToList()) { var val = EditorGUILayout.Slider(fsw.ToString(), faceShapeWeight[fsw], -100f, 100f); if (val != faceShapeWeight[fsw]) { cc.SetFaceShape(fsw, val); faceShapeWeight[fsw] = val; } } EditorGUI.indentLevel--; } EditorGUILayout.Space(); if (GUILayout.Button("Randomize")) { cc.Randomize(); selectedHair = cc.hairActiveIndex + 1; selectedBeard = cc.beardActiveIndex + 1; selectedHat = cc.clothesActiveIndexes[ClothesPartType.Hat] + 1; selectedAccessory = cc.clothesActiveIndexes[ClothesPartType.Accessory] + 1; selectedShirt = cc.clothesActiveIndexes[ClothesPartType.Shirt] + 1; selectedPants = cc.clothesActiveIndexes[ClothesPartType.Pants] + 1; selectedShoes = cc.clothesActiveIndexes[ClothesPartType.Shoes] + 1; } EditorGUILayout.Space(); if (GUILayout.Button("Reset All", GUIStyleReset)) { cc.ResetBodyColors(); GetColors(cc); cc.StartupSerializationApplied = string.Empty; selectedHair = 1; selectedBeard = 0; selectedHat = 0; selectedAccessory = 0; selectedShirt = 0; selectedPants = 0; selectedShoes = 0; foreach (var bsw in bodyShapeWeight.Keys.ToArray()) { bodyShapeWeight[bsw] = 0f; cc.SetBodyShape(bsw, bodyShapeWeight[bsw]); } foreach (var fsw in faceShapeWeight.Keys.ToArray()) { faceShapeWeight[fsw] = 0f; cc.SetFaceShape(fsw, faceShapeWeight[fsw]); } headSize = 0; headOffset = 0; height = 0; cc.SetHeadSize(headSize); cc.SetHeadOffset(headOffset); cc.SetHeight(height); } EditorGUILayout.Space(); EditorGUI.BeginDisabledGroup(cc.combinedCharacter != null); if (GUILayout.Button("Combine Character & Apply To Prefab", GUIStyleSave) && cc.combinedCharacter == null) { EditorUtility.DisplayProgressBar("Combine Character", "Process", 1f); cc.RecalculateLOD(); cc.BakeCharacter(true, true); PrefabUtility.ApplyPrefabInstance(cc.gameObject, InteractionMode.AutomatedAction); EditorUtility.ClearProgressBar(); OnEnable(); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(cc.bakeSkinnedMeshRenderers.Count == 0); if (GUILayout.Button("Clear Combined Character", GUIStyleSave)) { EditorUtility.DisplayProgressBar("Clear Combine Character", "Process", 1f); cc.ClearBake(); EditorUtility.ClearProgressBar(); OnEnable(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.Space(); if (GUILayout.Button("Recalculate LODs", GUIStyleSave)) { cc.RecalculateLOD(); } if (GUILayout.Button("Save & Apply To Prefab", GUIStyleSave)) { SaveToPrefab(); GUIUtility.ExitGUI(); } EditorGUI.indentLevel = level; GUILayout.EndVertical(); } EditorUtility.SetDirty(cc); }
public void CombineMesh() { characterCustomization.BakeCharacter(); }