EquipmentAppearanceDrawerUIE.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using UnityEditor;
  2. using UnityEditor.UIElements;
  3. using UnityEngine.UIElements;
  4. using UnityEngine;
  5. namespace SoftKitty.MasterCharacterCreator
  6. {
  7. [CustomPropertyDrawer(typeof(EquipmentAppearance))]
  8. public class EquipmentAppearanceDrawerUIE : PropertyDrawer
  9. {
  10. private CharacterDataSetting _data;
  11. private GUIContent[] _maleMeshList = new GUIContent[1];
  12. private GUIContent[] _femaleMeshList = new GUIContent[1];
  13. private OutfitSlots _oldSlot;
  14. private void GetDataScript()
  15. {
  16. GameObject _dataObj = Resources.Load<GameObject>("MasterCharacterCreator/Core/CharacterData");
  17. _data = _dataObj.GetComponent<CharacterDataSetting>();
  18. }
  19. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  20. {
  21. EditorGUI.BeginProperty(position, label, property);
  22. label.text += " :";
  23. position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
  24. var indent = EditorGUI.indentLevel;
  25. EditorGUI.indentLevel = 0;
  26. var _pos = position;
  27. EditorGUI.PropertyField(new Rect(_pos.x, _pos.y, 100, 20), property.FindPropertyRelative("Type"), GUIContent.none);
  28. _pos.x += 130;
  29. property.FindPropertyRelative("uiFold").boolValue = EditorGUI.Foldout(new Rect(_pos.x, _pos.y, 50, 20), property.FindPropertyRelative("uiFold").boolValue, "Settings");
  30. if (property.FindPropertyRelative("uiFold").boolValue)
  31. {
  32. if (_data == null) GetDataScript();
  33. OutfitSlots _slot = (OutfitSlots)property.FindPropertyRelative("Type").enumValueIndex;
  34. OutfitInfo[] _maleInfos = _data.GetOutfitSettings(Sex.Male, _slot);
  35. OutfitInfo[] _femaleInfos = _data.GetOutfitSettings(Sex.Female, _slot);
  36. if (_maleMeshList.Length != _maleInfos.Length || _oldSlot != _slot || _femaleMeshList.Length != _femaleInfos.Length)
  37. {
  38. _maleMeshList = new GUIContent[_maleInfos.Length];
  39. for (int i = 0; i < _maleMeshList.Length; i++) _maleMeshList[i] =new GUIContent(" "+_maleInfos[i].DisplayName, _maleInfos[i].Icon, "Model ID: " + i.ToString());
  40. _femaleMeshList = new GUIContent[_femaleInfos.Length];
  41. for (int i = 0; i < _femaleMeshList.Length; i++) _femaleMeshList[i] = new GUIContent(" " + _femaleInfos[i].DisplayName, _femaleInfos[i].Icon, "Model ID: " + i.ToString());
  42. _oldSlot = _slot;
  43. }
  44. _pos.y += 20;
  45. _pos.x = position.x;
  46. GUI.color = new Color(0F,1F,0F);
  47. EditorGUI.LabelField(new Rect(_pos.x, _pos.y, 70, 20), "Model ID:");
  48. GUI.color = Color.white;
  49. _pos.y += 20;
  50. _pos.x = position.x;
  51. EditorGUI.LabelField(new Rect(_pos.x, _pos.y, 35, 20), "Male");
  52. _pos.x += 50;
  53. property.FindPropertyRelative("MaleMeshId").intValue= EditorGUI.Popup(new Rect(_pos.x, _pos.y, 150, 18), property.FindPropertyRelative("MaleMeshId").intValue, _maleMeshList);
  54. _pos.x += 160;
  55. if (EditorGUI.LinkButton(new Rect(_pos.x, _pos.y, 30, 18),"View")) {
  56. if (MeshPreview.instance != null) MeshPreview.instance.Close();
  57. if (_data!=null)
  58. {
  59. int _id = property.FindPropertyRelative("MaleMeshId").intValue;
  60. if (_slot == OutfitSlots.Back || _slot == OutfitSlots.Tail)
  61. {
  62. if (_id > 0) MeshPreview.ShowPreview("", "", "Assets/SoftKitty/MasterCharacterCreator/Resources/" + _maleInfos[_id].MeshPath + ".prefab");
  63. }
  64. else
  65. {
  66. string _path = AssetDatabase.GetAssetPath(_data.gameObject).Replace("CharacterData", "PreviewModel");
  67. MeshPreview.ShowPreview(_maleInfos[_id].MeshPath, _maleInfos[_id].MaterialPath, _path);
  68. }
  69. }
  70. }
  71. _pos.y += 20;
  72. _pos.x = position.x;
  73. EditorGUI.LabelField(new Rect(_pos.x, _pos.y, 50, 20), "Female");
  74. _pos.x += 50;
  75. property.FindPropertyRelative("FemaleMeshId").intValue = EditorGUI.Popup(new Rect(_pos.x, _pos.y, 150, 18), property.FindPropertyRelative("FemaleMeshId").intValue, _femaleMeshList);
  76. _pos.x += 160;
  77. if (EditorGUI.LinkButton(new Rect(_pos.x, _pos.y, 30, 18), "View"))
  78. {
  79. if (MeshPreview.instance != null) MeshPreview.instance.Close();
  80. if (_data != null)
  81. {
  82. int _id = property.FindPropertyRelative("FemaleMeshId").intValue;
  83. if (_slot == OutfitSlots.Back || _slot == OutfitSlots.Tail)
  84. {
  85. if(_id>0) MeshPreview.ShowPreview("", "", "Assets/SoftKitty/MasterCharacterCreator/Resources/" + _femaleInfos[_id].MeshPath + ".prefab");
  86. }
  87. else
  88. {
  89. string _path = AssetDatabase.GetAssetPath(_data.gameObject).Replace("CharacterData", "PreviewModel");
  90. MeshPreview.ShowPreview(_femaleInfos[_id].MeshPath, _femaleInfos[_id].MaterialPath, _path);
  91. }
  92. }
  93. }
  94. _pos.x = position.x;
  95. _pos.y += 30;
  96. EditorGUI.PropertyField(new Rect(_pos.x, _pos.y, 20, 20), property.FindPropertyRelative("UseCustomColor"), GUIContent.none);
  97. _pos.x += 20;
  98. GUI.color = new Color(0F, 1F, 0F);
  99. EditorGUI.LabelField(new Rect(_pos.x, _pos.y, 90, 20), "Custom color:");
  100. GUI.color = Color.white;
  101. _pos.x += 90;
  102. if (property.FindPropertyRelative("UseCustomColor").boolValue)
  103. {
  104. EditorGUI.PropertyField(new Rect(_pos.x, _pos.y, 40, 20), property.FindPropertyRelative("CustomColor1"), GUIContent.none);
  105. _pos.x += 40;
  106. EditorGUI.PropertyField(new Rect(_pos.x, _pos.y, 40, 20), property.FindPropertyRelative("CustomColor2"), GUIContent.none);
  107. _pos.x += 40;
  108. EditorGUI.PropertyField(new Rect(_pos.x, _pos.y, 40, 20), property.FindPropertyRelative("CustomColor3"), GUIContent.none);
  109. _pos.x += 40;
  110. }
  111. }
  112. EditorGUI.indentLevel = indent;
  113. EditorGUI.EndProperty();
  114. }
  115. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  116. {
  117. return property.FindPropertyRelative("uiFold").boolValue ? 120:20;
  118. }
  119. }
  120. }