DNPPresetEditor.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #if UNITY_EDITOR
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEditor;
  6. namespace DamageNumbersPro.Internal
  7. {
  8. [CustomEditor(typeof(DNPPreset))]
  9. public class DNPPresetEditor : Editor
  10. {
  11. public override void OnInspectorGUI()
  12. {
  13. // Prepare
  14. GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
  15. labelStyle.richText = true;
  16. // Copying
  17. EditorGUILayout.Space(4);
  18. DamageNumber dn = (DamageNumber) EditorGUILayout.ObjectField(null, typeof(DamageNumber), true,GUILayout.Height(80));
  19. GUIStyle dropStyle = new GUIStyle(GUI.skin.box);
  20. dropStyle.alignment = TextAnchor.MiddleCenter;
  21. Rect lastRect = GUILayoutUtility.GetLastRect();
  22. GUI.Box(lastRect, "Drop damage number here.", dropStyle);
  23. if(dn != null)
  24. {
  25. DNPPreset preset = (DNPPreset)target;
  26. Undo.RegisterCompleteObjectUndo(preset, "Copied damage number.");
  27. preset.Get(dn);
  28. serializedObject.ApplyModifiedProperties();
  29. }
  30. // Get First Property
  31. SerializedProperty currentProperty = serializedObject.FindProperty("changeFontAsset");
  32. // Display Properties
  33. EditorGUILayout.BeginVertical();
  34. bool visible = true;
  35. do
  36. {
  37. bool isNewCategory = currentProperty.name.StartsWith("change") || currentProperty.name == "hideVerticalTexts";
  38. if (isNewCategory)
  39. {
  40. visible = true;
  41. EditorGUILayout.EndVertical();
  42. EditorGUILayout.Space();
  43. EditorGUILayout.BeginVertical("Helpbox");
  44. }
  45. if(visible)
  46. {
  47. if(isNewCategory)
  48. {
  49. EditorGUILayout.BeginHorizontal();
  50. EditorGUILayout.PrefixLabel("<size=14><b>" + currentProperty.displayName + "</b></size>", labelStyle);
  51. EditorGUILayout.PropertyField(currentProperty, GUIContent.none, true);
  52. EditorGUILayout.EndHorizontal();
  53. }
  54. else
  55. {
  56. EditorGUILayout.PropertyField(currentProperty, true);
  57. }
  58. }
  59. if (isNewCategory)
  60. {
  61. visible = currentProperty.boolValue;
  62. if(visible && currentProperty.name.StartsWith("change"))
  63. {
  64. DNPEditorInternal.Lines();
  65. }
  66. }
  67. } while (currentProperty.NextVisible(false));
  68. EditorGUILayout.EndVertical();
  69. // Save Changes
  70. serializedObject.ApplyModifiedProperties();
  71. }
  72. }
  73. }
  74. #endif