QiuQiuEditor.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System.IO;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Text.RegularExpressions;
  9. public class QiuQiuEditor : EditorWindow
  10. {
  11. private string m_DynamicBonePrefabPath;
  12. private static QiuQiuEditor m_Window;
  13. // 界面相关
  14. Color m_BlueColor = new Color(129 / 255f, 209 / 255f, 248 / 255f, 1);
  15. Color m_PinkColor = new Color(253 / 255f, 184 / 255f, 225 / 255f, 1);
  16. Color m_RedColor = new Color(233 / 255f, 74 / 255f, 110 / 255f, 1);
  17. Color m_PurpColor = new Color(125 / 255f, 128 / 255f, 227 / 255f, 1);
  18. float m_RowHeight = 20f;
  19. int m_RowFontSize = 12;
  20. GUIStyle m_MainHeaderStyle;
  21. GUIStyle m_SubHeaderStyle;
  22. GUIStyle m_ButtonStyle;
  23. GUIStyle m_TipsStyle;
  24. GUIStyle m_RedTipsStyle;
  25. GUIStyle m_LabelStyle;
  26. GUIStyle m_TagLabelStyle;
  27. GUIStyle m_ParamsLabelStyle;
  28. [MenuItem("球球测试/UI工具", false, 1)]
  29. static void ShowWindow()
  30. {
  31. if (m_Window == null)
  32. {
  33. m_Window = (QiuQiuEditor)GetWindow(typeof(QiuQiuEditor), true, "QiuQiuEditor");
  34. m_Window.Show();
  35. }
  36. else
  37. {
  38. m_Window.Close();
  39. m_Window = null;
  40. }
  41. }
  42. #region GUI
  43. void OnGUI()
  44. {
  45. InitStyle();
  46. EditorGUILayout.BeginVertical();
  47. EditorGUILayout.LabelField("球球 编辑器", m_MainHeaderStyle, GUILayout.Height(30));
  48. DrawSplitLine(25);
  49. if (GUILayout.Button("测试按钮", m_ButtonStyle, GUILayout.Width(150), GUILayout.Height(m_RowHeight)))
  50. {
  51. }
  52. EditorGUILayout.TextArea("部件模型路径", m_LabelStyle);
  53. Rect modelRect = EditorGUILayout.GetControlRect(GUILayout.Width(500));
  54. m_DynamicBonePrefabPath = EditorGUI.TextField(modelRect, m_DynamicBonePrefabPath);
  55. EditorGUILayout.Space();
  56. if ((Event.current.type == EventType.DragUpdated)
  57. && modelRect.Contains(Event.current.mousePosition))
  58. {
  59. DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
  60. }
  61. if ((Event.current.type == EventType.DragPerform) && modelRect.Contains(Event.current.mousePosition))
  62. {
  63. if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
  64. {
  65. m_DynamicBonePrefabPath = DragAndDrop.paths[0];
  66. }
  67. }
  68. if (GUILayout.Button("生成DynamicBone参数", m_ButtonStyle, GUILayout.Width(150),
  69. GUILayout.Height(m_RowHeight)))
  70. {
  71. OnClickCreateDynamicBoneParams();
  72. }
  73. EditorGUILayout.Space();
  74. EditorGUILayout.TextArea("测试文本:\n", m_TipsStyle);
  75. EditorGUILayout.TextArea("测试列表 \n", m_RedTipsStyle);
  76. EditorGUILayout.Space();
  77. OnDrawListView();
  78. EditorGUILayout.EndVertical();
  79. }
  80. #endregion
  81. void InitStyle()
  82. {
  83. if (m_MainHeaderStyle == null)
  84. {
  85. m_MainHeaderStyle = new GUIStyle(GUI.skin.label);
  86. m_MainHeaderStyle.fontSize = 20;
  87. m_MainHeaderStyle.fontStyle = FontStyle.Bold;
  88. m_MainHeaderStyle.normal.textColor = m_BlueColor;
  89. }
  90. if (m_ButtonStyle == null)
  91. {
  92. m_ButtonStyle = new GUIStyle(GUI.skin.button);
  93. m_ButtonStyle.fontSize = 14;
  94. }
  95. if (m_TipsStyle == null)
  96. {
  97. m_TipsStyle = new GUIStyle(GUI.skin.label);
  98. m_TipsStyle.normal.textColor = m_PinkColor;
  99. m_TipsStyle.fontSize = m_RowFontSize;
  100. }
  101. if (m_RedTipsStyle == null)
  102. {
  103. m_RedTipsStyle = new GUIStyle(GUI.skin.label);
  104. m_RedTipsStyle.normal.textColor = m_RedColor;
  105. m_RedTipsStyle.fontSize = m_RowFontSize;
  106. }
  107. if (m_TagLabelStyle == null)
  108. {
  109. m_TagLabelStyle = new GUIStyle(GUI.skin.label);
  110. m_TagLabelStyle.normal.textColor = m_PinkColor;
  111. m_TagLabelStyle.fontSize = 16;
  112. }
  113. if (m_ParamsLabelStyle == null)
  114. {
  115. m_ParamsLabelStyle = new GUIStyle(GUI.skin.label);
  116. m_ParamsLabelStyle.normal.textColor = m_PurpColor;
  117. m_ParamsLabelStyle.fontSize = 13;
  118. }
  119. if (m_LabelStyle == null)
  120. {
  121. m_LabelStyle = new GUIStyle(GUI.skin.label);
  122. m_LabelStyle.normal.textColor = m_BlueColor;
  123. m_LabelStyle.fontSize = 18;
  124. }
  125. }
  126. void DrawSplitLine(float height)
  127. {
  128. GUI.Box(new Rect(0, height, position.width, 1), string.Empty);
  129. }
  130. #region ScrollView
  131. Vector2 _scrollPos;
  132. void OnDrawListView()
  133. {
  134. _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, false, false, GUILayout.Width(500), GUILayout.Height(400));
  135. for (int i = 0; i < 100; i++)
  136. {
  137. var Damping = EditorGUILayout.FloatField("Damping",i , m_ParamsLabelStyle);
  138. EditorGUILayout.BeginHorizontal();
  139. if (GUILayout.Button("+", m_ButtonStyle, GUILayout.Width(50), GUILayout.Height(m_RowHeight)))
  140. {
  141. Debug.Log("+");
  142. }
  143. if (GUILayout.Button("-", m_ButtonStyle, GUILayout.Width(50), GUILayout.Height(m_RowHeight)))
  144. {
  145. Debug.Log("-");
  146. }
  147. EditorGUILayout.EndHorizontal();
  148. }
  149. EditorGUILayout.EndScrollView(); // 组结束
  150. }
  151. void OnClickCreateDynamicBoneParams()
  152. {
  153. if (string.IsNullOrEmpty(m_DynamicBonePrefabPath))
  154. {
  155. return;
  156. }
  157. Debug.Log(m_DynamicBonePrefabPath);
  158. }
  159. #endregion
  160. }