DatePickerSettingsEditor.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. using System.Linq;
  6. using UnityEngine.UI;
  7. namespace Bitsplash.DatePicker.Editors
  8. {
  9. [CustomEditor(typeof(DatePickerSettings))]
  10. public class DatePickerSettingsEditor : Editor
  11. {
  12. void DoButton(SerializedObject serialized)
  13. {
  14. var im = serialized.FindProperty("TargetImage");
  15. if (im.objectReferenceValue != null)
  16. {
  17. var serilizedIm = new SerializedObject(im.objectReferenceValue);
  18. EditorGUILayout.LabelField("Button Image", EditorStyles.boldLabel);
  19. var imSprite = serilizedIm.FindProperty("m_Sprite");
  20. EditorGUILayout.PropertyField(imSprite);
  21. var imColor = serilizedIm.FindProperty("m_Color");
  22. EditorGUILayout.PropertyField(imColor);
  23. serilizedIm.ApplyModifiedProperties();
  24. }
  25. var tx = serialized.FindProperty("TargetText");
  26. if (tx.objectReferenceValue != null)
  27. {
  28. EditorGUILayout.LabelField("Button Text", EditorStyles.boldLabel);
  29. var serilizedTx = new SerializedObject(tx.objectReferenceValue);
  30. var itTx = serilizedTx.GetIterator();
  31. bool flagTx = true;
  32. while (itTx.NextVisible(flagTx))
  33. {
  34. flagTx = false;
  35. if (itTx.name.ToLower() == "m_script")
  36. continue;
  37. EditorGUILayout.PropertyField(itTx, includeChildren: true);
  38. }
  39. serilizedTx.ApplyModifiedProperties();
  40. }
  41. }
  42. void DoBackgroundSetting(UnityEngine.Object obj)
  43. {
  44. var mono = (obj as MonoBehaviour);
  45. if (mono == null)
  46. return;
  47. var image = mono.GetComponent<Image>();
  48. if (image == null)
  49. return;
  50. var serilizedIm = new SerializedObject(image);
  51. var imSprite = serilizedIm.FindProperty("m_Sprite");
  52. EditorGUILayout.PropertyField(imSprite);
  53. var imColor = serilizedIm.FindProperty("m_Color");
  54. EditorGUILayout.PropertyField(imColor);
  55. serilizedIm.ApplyModifiedProperties();
  56. }
  57. void DoCellTemplate(UnityEngine.Object obj)
  58. {
  59. var mono = (obj as MonoBehaviour);
  60. if (mono == null)
  61. return;
  62. var cell = mono.GetComponent<StandardDatePickerCell>();
  63. if (cell == null)
  64. return;
  65. var serialized = new SerializedObject(cell);
  66. var it = serialized.GetIterator();
  67. bool flag = true;
  68. while (it.NextVisible(flag))
  69. {
  70. flag = false;
  71. if (it.name.ToLower() == "m_script")
  72. continue;
  73. if (it.name.ToLower() == "textitem")
  74. continue;
  75. if (it.name.ToLower() == "mark")
  76. continue;
  77. if (it.name.ToLower() == "background")
  78. continue;
  79. EditorGUILayout.PropertyField(it, includeChildren: true);
  80. }
  81. serialized.ApplyModifiedProperties();
  82. }
  83. public override void OnInspectorGUI()
  84. {
  85. base.OnInspectorGUI();
  86. var picker = target as DatePickerSettings;
  87. foreach(var item in picker.GetComponentsInChildren<IDatePickerSettingsItem>(true).OrderBy(x=> x.Order))
  88. {
  89. var obj = (UnityEngine.Object)item;
  90. var serialized = new SerializedObject(obj);
  91. var openProp = serialized.FindProperty("isOpen");
  92. if (openProp == null)
  93. continue;
  94. openProp.boolValue = EditorGUILayout.Foldout(openProp.boolValue, item.EditorTitle);
  95. if (openProp.boolValue)
  96. {
  97. EditorGUI.indentLevel++;
  98. if(item is DatePickerBackgroundSetting)
  99. {
  100. DoBackgroundSetting(obj);
  101. }
  102. if (item is DatePickerCellTemplate)
  103. {
  104. DoCellTemplate(obj);
  105. }
  106. else if (item is DatePickerButton)
  107. {
  108. DoButton(serialized);
  109. }
  110. else
  111. {
  112. var it = serialized.GetIterator();
  113. bool flag = true;
  114. while (it.NextVisible(flag))
  115. {
  116. flag = false;
  117. if (it.name.ToLower() == "m_script")
  118. continue;
  119. if (it.name.ToLower() == "m_material")
  120. continue;
  121. if (it.name.ToLower() == "m_raycasttarget")
  122. continue;
  123. if (it.name.ToLower() == "cellprefab")
  124. continue;
  125. if (it.name.ToLower() == "totalrows")
  126. continue;
  127. if (it.name.ToLower() == "totalcolumns")
  128. continue;
  129. if (it.name.ToLower() == "texturetile")
  130. continue;
  131. if (it.name.ToLower() == "m_oncullstatechanged")
  132. continue;
  133. if (it.name.ToLower() == "targettext")
  134. continue;
  135. if (it.name.ToLower() == "targetimage")
  136. continue;
  137. EditorGUILayout.PropertyField(it, includeChildren: true);
  138. }
  139. }
  140. EditorGUI.indentLevel--;
  141. }
  142. serialized.ApplyModifiedProperties();
  143. }
  144. }
  145. }
  146. }