using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; namespace SoftKitty.MasterCharacterCreator { [CustomEditor(typeof(CharacterManager))] public class CharacterManager_inspector : Editor { Color _activeColor = new Color(0.1F, 0.7F, 1F,1F); Color _disableColor = new Color(0.5F, 0.8F, 1F,1F); Color _buttonColor = new Color(0F, 0.8F, 0.3F); int _selMorph = 0; GUIStyle _titleButtonStyle; private bool _emotionFold = false; private bool _settingFold = false; private bool _textureToolFold = false; private bool _modelToolFold = false; private CharacterDataSetting.CharacterTextureNames selectedTextureType; private OutfitSlots selectedSlot; private Sex selectedTextureSex; private Sex selectedOutfitSex; private Texture selectedTexture; private GameObject selectedPrefab; private CharacterDataSetting DataScript; private string _packResourcePath; private Texture selectedOutfitTexture; private GameObject selectedOutfitFbx; private Material selectedOutfitMaterial; private string[] OutfitFolderName = new string[7]{ "Armor", "Helmet", "Glove", "Boot", "Armor", "Back", "Tail" }; private string[] OutfitName = new string[7]{ "Armor", "Helmet", "Glove", "Boot", "Pants", "Back", "Tail" }; public override void OnInspectorGUI() { GUI.changed = false; bool _valueChanged = false; _titleButtonStyle = new GUIStyle(GUI.skin.button); _titleButtonStyle.alignment = TextAnchor.MiddleLeft; Color _backgroundColor = GUI.backgroundColor; var script = MonoScript.FromScriptableObject(this); CharacterManager myTarget = (CharacterManager)target; DataScript = myTarget.GetComponent(); string _thePath = AssetDatabase.GetAssetPath(script); _thePath = _thePath.Replace("CharacterManager_inspector.cs", ""); _packResourcePath = _thePath.Replace("Editor/", "Resources/"); Texture logoIcon = (Texture)AssetDatabase.LoadAssetAtPath(_thePath + "Logo.png", typeof(Texture)); Texture warningIcon = (Texture)AssetDatabase.LoadAssetAtPath(_thePath + "warning.png", typeof(Texture)); GUILayout.BeginHorizontal(); GUILayout.Box(logoIcon); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.backgroundColor = _buttonColor; if (GUILayout.Button("User Guide", GUILayout.Width(100))) { Application.OpenURL(Application.dataPath.Replace("Assets", "") + _thePath.Replace("Editor/", "Documentation/") + "UserGuide.pdf"); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.color = _buttonColor; GUILayout.Label("Player's Blueprint Path in the [Character Customization] Interface:"); GUI.color = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); myTarget.useRelativePathToGameInstallFolder = GUILayout.Toggle(myTarget.useRelativePathToGameInstallFolder, "Use the relative path of [Game Install Folder]"); GUILayout.EndHorizontal(); if (myTarget.useRelativePathToGameInstallFolder) { GUILayout.BeginHorizontal(); GUILayout.Label("Relative Path:", GUILayout.Width(100)); myTarget.CharacterBlueprintRootPath = GUILayout.TextArea(myTarget.CharacterBlueprintRootPath); GUILayout.EndHorizontal(); GUI.color = _activeColor; GUILayout.BeginHorizontal(); GUILayout.Label("Editor: Assets/"+ myTarget.CharacterBlueprintRootPath+"/"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Build: [Game Install Folder]/" + myTarget.CharacterBlueprintRootPath + "/"); GUILayout.EndHorizontal(); GUI.color = Color.white; } else{ GUILayout.BeginHorizontal(); GUILayout.Label("Absolute Path:", GUILayout.Width(100)); myTarget.CharacterBlueprintRootPath = GUILayout.TextArea(myTarget.CharacterBlueprintRootPath); GUILayout.EndHorizontal(); } EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); myTarget.CacheMeshTexture = GUILayout.Toggle(myTarget.CacheMeshTexture, "Keep loaded meshes and textures in memory."); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("This will use more memory in exchange of significantly reduce the performance cost when loading character.\n" + "Call CharacterManager.ClearLoadedAssets() to free the used memory when necessary.", MessageType.Info, true); GUILayout.EndHorizontal(); EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); GUI.color = _emotionFold ? _activeColor : _disableColor; _emotionFold = EditorGUILayout.Foldout(_emotionFold, "Character Emotion Settings"); GUI.color = Color.white; GUILayout.EndHorizontal(); if (_emotionFold) { GUILayout.BeginHorizontal(); GUILayout.Space(15); EditorGUILayout.HelpBox("Use ().SetEmotion(string _uid, float _length) to play the emotion, use ().StopEmotion() to reset the emotion.", MessageType.Info,true); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(15); GUILayout.Label("Emotions List ("+myTarget.EmotionSettings.Count.ToString()+"):",GUILayout.Width(120)); GUI.backgroundColor = _buttonColor; if (GUILayout.Button("Add",GUILayout.Width(70))) { EmotionSetting _newSetting = new EmotionSetting(); _newSetting.uid = "NewEmotion" + myTarget.EmotionSettings.Count.ToString(); _newSetting.HeadMorphs.Clear(); myTarget.EmotionSettings.Add(_newSetting); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); for (int i=0;i(true) && selectedOutfitMaterial != null && selectedOutfitTexture != null); GUI.color = _go ? Color.white : Color.gray; GUI.backgroundColor = _go ? _buttonColor : Color.gray; if (GUILayout.Button("Add", GUILayout.Width(210))) { if (_go) { int _newId = GetOutfitSetting().Length; string _meshPath = _packResourcePath + "MasterCharacterCreator/Player/" + OutfitFolderName[(int)selectedSlot] + "/" + selectedOutfitSex.ToString() + OutfitName[(int)selectedSlot] + "_" + _newId.ToString()+".mesh"; string _matPath = _packResourcePath + "MasterCharacterCreator/Player/" + OutfitFolderName[(int)selectedSlot] + "/" + selectedOutfitSex.ToString() + OutfitFolderName[(int)selectedSlot] + "Mat_" + _newId.ToString() + ".mat"; string _thumbPath = _packResourcePath.Replace("Resources/", "Textures/Icons/") + selectedOutfitSex.ToString()+ selectedSlot.ToString()+"/"+ selectedOutfitSex.ToString() + selectedSlot.ToString() + _newId.ToString() + System.IO.Path.GetExtension(AssetDatabase.GetAssetPath(selectedOutfitTexture)); try { Mesh _mesh = selectedOutfitFbx.GetComponentInChildren(true).sharedMesh; Mesh _newMesh = Object.Instantiate(_mesh) as Mesh; AssetDatabase.CreateAsset(_newMesh, _meshPath); AssetDatabase.CopyAsset(AssetDatabase.GetAssetPath(selectedOutfitMaterial), _matPath); AssetDatabase.CopyAsset(AssetDatabase.GetAssetPath(selectedOutfitTexture), _thumbPath); AssetDatabase.Refresh(); OutfitInfo _newInfo = new OutfitInfo(); _newInfo.DisplayName = selectedOutfitSex.ToString() + " " + OutfitName[(int)selectedSlot] + " " + _newId.ToString(); _newInfo.Icon = (Texture)AssetDatabase.LoadAssetAtPath(_thumbPath,typeof(Texture)); _newInfo.Slot = selectedSlot; _newInfo.MeshPath = "MasterCharacterCreator/Player/" + OutfitFolderName[(int)selectedSlot] + "/" + selectedOutfitSex.ToString() + OutfitName[(int)selectedSlot] + "_" + _newId.ToString(); _newInfo.MaterialPath = "MasterCharacterCreator/Player/" + OutfitFolderName[(int)selectedSlot] + "/" + selectedOutfitSex.ToString() + OutfitFolderName[(int)selectedSlot] + "Mat_" + _newId.ToString(); _newInfo.ColorSetting = new OutfitColorSetting(); if (selectedOutfitMaterial.shader.name.Contains("CharacterSkin")) { if (selectedOutfitMaterial.GetTexture("_MaskMap1") != null) { _newInfo.ColorSetting.ToggleCustomColor1 = true; _newInfo.ColorSetting.DefaultColor1 = selectedOutfitMaterial.GetColor("_Color1"); } if (selectedOutfitMaterial.GetTexture("_MaskMap2") != null) { _newInfo.ColorSetting.ToggleCustomColor2 = true; _newInfo.ColorSetting.DefaultColor2 = selectedOutfitMaterial.GetColor("_Color2"); } if (selectedOutfitMaterial.GetTexture("_MaskMap3") != null) { _newInfo.ColorSetting.ToggleCustomColor3 = true; _newInfo.ColorSetting.DefaultColor3 = selectedOutfitMaterial.GetColor("_Color3"); } } _newInfo.BoneNames = new string[selectedOutfitFbx.GetComponentInChildren(true).bones.Length]; for (int i=0;i< _newInfo.BoneNames.Length;i++) { _newInfo.BoneNames[i] = selectedOutfitFbx.GetComponentInChildren(true).bones[i].name; } List _infoList = new List(); _infoList.AddRange(GetOutfitSetting()); _infoList.Add(_newInfo); switch (selectedSlot) { default: if(selectedOutfitSex == Sex.Male ) DataScript.MaleArmorSetting= _infoList.ToArray(); else DataScript.FemaleArmorSetting = _infoList.ToArray(); break; case OutfitSlots.Helmet: if (selectedOutfitSex == Sex.Male) DataScript.MaleHelmetSetting = _infoList.ToArray(); else DataScript.FemaleHelmetSetting = _infoList.ToArray(); break; case OutfitSlots.Boot: if (selectedOutfitSex == Sex.Male) DataScript.MaleBootSetting = _infoList.ToArray(); else DataScript.FemaleBootSetting = _infoList.ToArray(); break; case OutfitSlots.Gauntlet: if (selectedOutfitSex == Sex.Male) DataScript.MaleGloveSetting = _infoList.ToArray(); else DataScript.FemaleGloveSetting = _infoList.ToArray(); break; case OutfitSlots.Pants: if (selectedOutfitSex == Sex.Male) DataScript.MalePantsSetting = _infoList.ToArray(); else DataScript.FemalePantsSetting = _infoList.ToArray(); break; } EditorUtility.DisplayDialog("Add new [" + selectedSlot.ToString() + "] mesh", "Successfully added (" + _newInfo.DisplayName + ") " , "OK"); EditorUtility.SetDirty(DataScript); selectedOutfitFbx = null; selectedOutfitMaterial = null; selectedOutfitTexture = null; } catch { EditorUtility.DisplayDialog("Add new [" + selectedSlot.ToString()+ "] mesh", "Failed to add (" + selectedOutfitFbx.name + ")", "OK"); } } } GUILayout.EndHorizontal(); EditorGUILayout.Separator(); } } private OutfitInfo[] GetOutfitSetting() { switch (selectedSlot) { default: return selectedOutfitSex == Sex.Male ? DataScript.MaleArmorSetting : DataScript.FemaleArmorSetting; case OutfitSlots.Helmet: return selectedOutfitSex == Sex.Male ? DataScript.MaleHelmetSetting : DataScript.FemaleHelmetSetting; case OutfitSlots.Boot: return selectedOutfitSex == Sex.Male ? DataScript.MaleBootSetting : DataScript.FemaleBootSetting; case OutfitSlots.Gauntlet: return selectedOutfitSex == Sex.Male ? DataScript.MaleGloveSetting : DataScript.FemaleGloveSetting; case OutfitSlots.Pants: return selectedOutfitSex == Sex.Male ? DataScript.MalePantsSetting : DataScript.FemalePantsSetting; } } private void PrefabTool(CharacterDataSetting.CharacterTextureNames _type) { GUILayout.BeginHorizontal(); GUILayout.Space(15); GUILayout.Label("Add [" + _type.ToString().Replace("ID","") + "] prefab for ", GUILayout.Width(145)); selectedTextureSex = (Sex)EditorGUILayout.EnumPopup(selectedTextureSex, GUILayout.Width(65)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(15); GUILayout.Label("Prefab:", GUILayout.Width(60)); selectedPrefab = (GameObject)EditorGUILayout.ObjectField(selectedPrefab, typeof(GameObject), false, GUILayout.Width(150)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(15); GUILayout.Label("Thumb:", GUILayout.Width(60)); selectedTexture = (Texture)EditorGUILayout.ObjectField(selectedTexture, typeof(Texture), false, GUILayout.Width(150)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(15); GUI.color = (selectedPrefab != null && selectedTexture!=null) ? Color.white : Color.gray; GUI.backgroundColor = (selectedPrefab != null && selectedTexture != null) ? _buttonColor : Color.gray; if (GUILayout.Button("Add", GUILayout.Width(210))) { if (selectedPrefab != null && selectedTexture != null) { (selectedTextureSex == Sex.Male ? DataScript.MaleAccessorySettings : DataScript.FemaleAccessorySettings)[(int)_type - 8].MaxValue += 1; int _newId = (selectedTextureSex == Sex.Male ? DataScript.MaleAccessorySettings : DataScript.FemaleAccessorySettings)[(int)_type - 8].MaxValue; string _basePath = (selectedTextureSex == Sex.Male ? DataScript.MaleAccessorySettings : DataScript.FemaleAccessorySettings)[(int)_type - 8].PrefabPath; string _thumbPath = (selectedTextureSex == Sex.Male ? DataScript.MaleAccessorySettings : DataScript.FemaleAccessorySettings)[(int)_type - 8].ThumbPath; string _sourcePath = AssetDatabase.GetAssetPath(selectedPrefab); string _targetPath = _packResourcePath + _basePath + _newId.ToString("00") + System.IO.Path.GetExtension(_sourcePath); string _sourceThumb = AssetDatabase.GetAssetPath(selectedTexture); string _targetThumb = _packResourcePath + _thumbPath + _newId.ToString() + System.IO.Path.GetExtension(_sourceThumb); if (AssetDatabase.CopyAsset(_sourcePath, _targetPath) && AssetDatabase.CopyAsset(_sourceThumb, _targetThumb)) { EditorUtility.DisplayDialog("Add new [" + _type.ToString().Replace("ID", "") + "] prefab", "Successfully added ("+ _type.ToString().Replace("ID", "") + _newId.ToString("00") + ") to " + selectedTextureSex.ToString() + " prefabs.", "OK"); EditorUtility.SetDirty(DataScript); selectedPrefab = null; selectedTexture = null; } else { EditorUtility.DisplayDialog("Add new [" + _type.ToString().Replace("ID", "") + "] prefab", "Failed to add (" + selectedPrefab.name + ")", "OK"); } } } GUI.color = Color.white; GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(15); EditorGUILayout.HelpBox("Don't forget Apply this prefab after added textures.", MessageType.Info); GUILayout.EndHorizontal(); } private void TextureTool(CharacterDataSetting.CharacterTextureNames _type) { GUILayout.BeginHorizontal(); GUILayout.Space(15); GUILayout.Label("Add ["+ _type.ToString()+"] texture for ",GUILayout.Width(145)); selectedTextureSex = (Sex)EditorGUILayout.EnumPopup(selectedTextureSex, GUILayout.Width(65)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(15); GUILayout.Label("Texture:", GUILayout.Width(60)); selectedTexture = (Texture)EditorGUILayout.ObjectField(selectedTexture, typeof(Texture), false, GUILayout.Width(150)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(15); GUI.color= selectedTexture != null ? Color.white : Color.gray; GUI.backgroundColor = selectedTexture != null ? _buttonColor : Color.gray; if (GUILayout.Button("Add", GUILayout.Width(210))) { if (selectedTexture != null) { (selectedTextureSex == Sex.Male ? DataScript.MaleMaterialSettings : DataScript.FemaleMaterialSettings)[(int)_type + 8].TextureIdMax += 1; int _newId = (selectedTextureSex == Sex.Male ? DataScript.MaleMaterialSettings : DataScript.FemaleMaterialSettings)[(int)_type + 8].TextureIdMax; string _basePath = (selectedTextureSex == Sex.Male ? DataScript.MaleMaterialSettings : DataScript.FemaleMaterialSettings)[(int)_type + 8].TextureBaseName; string _sourcePath = AssetDatabase.GetAssetPath(selectedTexture); string _targetPath = _packResourcePath + _basePath + _newId.ToString("00")+System.IO.Path.GetExtension(_sourcePath); if (AssetDatabase.CopyAsset(_sourcePath, _targetPath)) { EditorUtility.DisplayDialog("Add new [" + _type.ToString() + "] texture", "Successfully added (" + _type.ToString()+ _newId.ToString("00") + ") to " + selectedTextureSex.ToString() + " textures.", "OK"); EditorUtility.SetDirty(DataScript); selectedTexture = null; } else { EditorUtility.DisplayDialog("Add new [" + _type.ToString() + "] texture", "Failed to add (" + selectedTexture.name+")", "OK"); } } } GUI.color = Color.white; GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(15); EditorGUILayout.HelpBox("Don't forget Apply this prefab after added textures.", MessageType.Info); GUILayout.EndHorizontal(); EditorGUILayout.Separator(); } } }