FGUI.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditorInternal;
  4. using System.Collections.Generic;
  5. using Flux;
  6. using EventType = UnityEngine.EventType;
  7. namespace FluxEditor
  8. {
  9. public class FGUI
  10. {
  11. public const float DEFAULT_PIXEL_PER_SEC = 30;
  12. // public const float TIMELINE_SECOND_TICK_SIZE = 20;
  13. //
  14. // public const float TIMELINE_HALF_SECOND_TICK_SIZE = 10;
  15. //
  16. // public const float TIMELINE_TENTH_SECOND_TICK_SIZE = 5;
  17. public const float TIMELINE_SCRUBBER_TEXT_HEIGHT = 15;
  18. public const float TIMELINE_SCRUBBER_TICK_HEIGHT = 4;
  19. // height of the scrubber area / timer
  20. public const float TIMELINE_SCRUBBER_HEIGHT = TIMELINE_SCRUBBER_TEXT_HEIGHT + TIMELINE_SCRUBBER_TICK_HEIGHT + TIMELINE_SCRUBBER_TICK_HEIGHT;
  21. // base height of the timeline rows
  22. public const float TIMELINE_HEIGHT = 50;
  23. public static readonly Color ANIMATION_BLEND_COLOR_PRO = new Color( 0.8f, 0.8f, 0.8f, 0.2f );
  24. public static readonly Color ANIMATION_BLEND_COLOR = new Color( 0.8f, 0.8f, 0.8f, 0.2f );
  25. public static readonly Color LINE_COLOR_PRO = new Color( 0.8f, 0.8f, 0.8f, 0.4f );
  26. public static readonly Color LINE_COLOR = new Color( 0.2f, 0.2f, 0.2f, 0.8f );
  27. public static readonly Color TIMELINE_COLOR_PRO = new Color( 0.2f, 0.2f, 0.2f, 1f );
  28. public static readonly Color TIMELINE_COLOR = new Color(0.6f, 0.6f, 0.6f, 1f );
  29. public static readonly Color EVENT_COLOR_PRO = new Color( 0.24f, 0.36f, 0.60f, 0.8f );
  30. public static readonly Color EVENT_COLOR = new Color( 0.24f, 0.36f, 0.60f, 0.8f );
  31. public static readonly Color TEXT_COLOR_PRO = new Color( 1f, 1f, 1f, 1f );
  32. public static readonly Color TEXT_COLOR = new Color( 0.2f, 0.2f, 0.2f, 1f );
  33. public static readonly Color SELECTION_COLOR_PRO = new Color(0.25f, 0.372f, 0.588f, 0.5f);
  34. public static readonly Color SELECTION_COLOR = SELECTION_COLOR_PRO;
  35. public static readonly Color WINDOW_COLOR_PRO = new Color( 0.22f, 0.22f, 0.22f, 1f );
  36. public static readonly Color WINDOW_COLOR = new Color( 0.76f, 0.76f, 0.76f, 1f );
  37. public static float CalcTimelineSize( float length, float zoomLevel )
  38. {
  39. return length * zoomLevel * DEFAULT_PIXEL_PER_SEC;
  40. }
  41. public const int MIN_PIXELS_BETWEEN_FRAMES = 100;
  42. private static GUIStyle _trackHeaderStyle = null;
  43. public static GUIStyle GetTrackHeaderStyle()
  44. {
  45. if( _trackHeaderStyle == null )
  46. {
  47. _trackHeaderStyle = new GUIStyle( EditorStyles.label );
  48. _trackHeaderStyle.stretchWidth = false;
  49. }
  50. return _trackHeaderStyle;
  51. }
  52. private static GUIStyle _timelineHeaderStyle = null;
  53. public static GUIStyle GetTimelineHeaderStyle()
  54. {
  55. if( _timelineHeaderStyle == null )
  56. {
  57. _timelineHeaderStyle = new GUIStyle( EditorStyles.boldLabel );
  58. _timelineHeaderStyle.fontStyle = FontStyle.Bold;
  59. _timelineHeaderStyle.stretchWidth = false;
  60. }
  61. return _timelineHeaderStyle;
  62. }
  63. public static int TimeScrubber( Rect rect, int t, int frameRate, FrameRange range )
  64. {
  65. // Rect actualRect = rect;
  66. // actualRect.xMax -= 20; // buffer on the right
  67. Rect clickRect = rect;
  68. clickRect.yMin = clickRect.yMax - TIMELINE_SCRUBBER_HEIGHT;
  69. int length = range.Length;
  70. int controlId = EditorGUIUtility.GetControlID( FocusType.Passive );
  71. switch( Event.current.type )
  72. {
  73. case EventType.Repaint:
  74. int frames = range.Start;
  75. float width = rect.width;
  76. int maxFramesBetweenSteps = Mathf.Max( 1, Mathf.FloorToInt( width / MIN_PIXELS_BETWEEN_FRAMES ) );
  77. int numFramesPerStep = Mathf.Max( 1, length / maxFramesBetweenSteps);
  78. // multiple of 60 fps?
  79. if( numFramesPerStep < 30 )
  80. {
  81. if( numFramesPerStep <= 12 )
  82. {
  83. if( numFramesPerStep != 5 )
  84. {
  85. if( 12 % numFramesPerStep != 0 )
  86. {
  87. numFramesPerStep = 12;
  88. }
  89. }
  90. }
  91. else
  92. {
  93. numFramesPerStep = 30;
  94. }
  95. }
  96. else if( numFramesPerStep < 60 )
  97. {
  98. numFramesPerStep = 60;
  99. }
  100. else
  101. {
  102. int multiplesOf60 = numFramesPerStep / 60;
  103. numFramesPerStep = (multiplesOf60+1) * 60;
  104. }
  105. int numFramesIter = numFramesPerStep < 30 ? 1 : numFramesPerStep / 10;
  106. Vector3 pt = new Vector3(rect.x, rect.yMax-TIMELINE_SCRUBBER_TEXT_HEIGHT, 0);
  107. Rect backgroundRect = clickRect;
  108. backgroundRect.xMin = 0;
  109. backgroundRect.xMax += FSequenceEditor.RIGHT_BORDER;
  110. // GUI.color = new Color( 0.15f, 0.15f, 0.15f, 1f );//FGUI.GetTimelineColor();
  111. // GUI.DrawTexture( backgroundRect, EditorGUIUtility.whiteTexture );
  112. // GUI.color = Color.white;
  113. GUI.color = GetTextColor(); // a little darker than it is originally to stand out
  114. GUI.Label( backgroundRect, GUIContent.none, FGUI.GetTimeScrubberStyle() );
  115. Handles.color = GetLineColor();
  116. // int framesBetweenSteps = maxFramesBetweenSteps / (maxFramesBetweenSteps * 10 / MIN_PIXELS_BETWEEN_FRAMES);
  117. // float pixelsBetweenSteps = minPixelsBetweenSteps / framesBetweenSteps;
  118. //
  119. // Debug.Log ( maxFramesBetweenSteps + " " + minPixelsBetweenSteps + " vs " + framesBetweenSteps + " " + pixelsBetweenSteps );
  120. GUIStyle labelStyle = new GUIStyle(EditorStyles.boldLabel);
  121. labelStyle.normal.textColor = Color.white;
  122. labelStyle.alignment = TextAnchor.UpperCenter;
  123. GUI.contentColor = FGUI.GetLineColor();
  124. frames = (frames / numFramesIter)*numFramesIter;
  125. while( frames <= range.End )
  126. {
  127. pt.x = rect.x + (width * ((float)(frames - range.Start)/length));
  128. if( pt.x >= rect.x )
  129. {
  130. if( frames % numFramesPerStep == 0 )
  131. {
  132. Handles.DrawLine( pt, pt - new Vector3( 0, rect.height-TIMELINE_SCRUBBER_TEXT_HEIGHT, 0 ) );
  133. GUI.Label( new Rect( pt.x-30, pt.y, 60, TIMELINE_SCRUBBER_TEXT_HEIGHT ), FUtility.GetTime( frames, frameRate ), labelStyle );
  134. }
  135. else
  136. {
  137. Vector3 smallTickPt = pt;
  138. smallTickPt.y -= TIMELINE_SCRUBBER_TICK_HEIGHT;
  139. Handles.DrawLine( smallTickPt, smallTickPt - new Vector3( 0, TIMELINE_SCRUBBER_TICK_HEIGHT, 0 ) );
  140. }
  141. }
  142. frames += numFramesIter;
  143. }
  144. if( t >= 0 && range.Contains(t) )
  145. {
  146. Vector3 tStart = new Vector3( rect.x + (width * ((float)(t - range.Start)/length)), rect.yMin, 0 );
  147. Vector3 tEnd = tStart;
  148. tEnd.y = rect.yMax-TIMELINE_SCRUBBER_TEXT_HEIGHT;
  149. Handles.color = Color.red;
  150. Handles.DrawLine( tStart, tEnd );
  151. GUI.contentColor = Color.red;
  152. GUI.Label( new Rect( tEnd.x-30, tEnd.y, 60, TIMELINE_SCRUBBER_TEXT_HEIGHT ), FUtility.GetTime(t, frameRate), labelStyle );
  153. GUI.contentColor = FGUI.GetTextColor();
  154. }
  155. GUI.color = Color.white;
  156. GUI.contentColor = Color.white;
  157. Handles.color = GetLineColor();
  158. Handles.DrawLine( new Vector3( rect.x, rect.yMin, 0 ), new Vector3( rect.x, rect.yMax-TIMELINE_SCRUBBER_HEIGHT, 0 ) );
  159. break;
  160. case EventType.MouseDown:
  161. if( EditorGUIUtility.hotControl == 0 && clickRect.Contains( Event.current.mousePosition ) )
  162. {
  163. EditorGUIUtility.hotControl = controlId;
  164. }
  165. goto case EventType.MouseDrag;
  166. case EventType.MouseDrag:
  167. if( EditorGUIUtility.hotControl == controlId )
  168. {
  169. Rect touchRect = rect;
  170. touchRect.yMin = touchRect.yMax - TIMELINE_SCRUBBER_HEIGHT;
  171. // if( touchRect.Contains( Event.current.mousePosition ) )
  172. {
  173. // Debug.Log( (Event.current.mousePosition.x - touchRect.xMin /
  174. t = Mathf.Clamp( range.Start + Mathf.RoundToInt(((Event.current.mousePosition.x-touchRect.xMin) / touchRect.width)*range.Length), range.Start, range.End );
  175. Event.current.Use();
  176. }
  177. }
  178. break;
  179. case EventType.MouseUp:
  180. if( EditorGUIUtility.hotControl == controlId )
  181. {
  182. EditorGUIUtility.hotControl = 0;
  183. Event.current.Use();
  184. }
  185. break;
  186. }
  187. rect.height = TIMELINE_SCRUBBER_HEIGHT;
  188. return t;
  189. }
  190. public static Vector2 BeginTimeline( Rect rect, Vector2 scrollPos )
  191. {
  192. // scrollPos = GUI.BeginScrollView( rect, scrollPos, viewRect );
  193. // GUI.BeginScrollView( rect, Vector2.zero, viewRect );
  194. rect.yMin -= scrollPos.y;
  195. // rect.x -= 16;
  196. GUI.BeginGroup( rect );
  197. // GUI.matrix = Matrix4x4.TRS( new Vector3(0, -scrollPos.y, 0), Quaternion.identity, Vector3.one );
  198. return scrollPos;
  199. }
  200. public static void EndTimeline( bool handleScrollWheel )
  201. {
  202. // GUI.matrix = Matrix4x4.identity;
  203. // GUI.EndScrollView( handleScrollWheel );
  204. GUI.EndGroup();
  205. }
  206. private static Vector3 _offset;
  207. public static FrameRange ViewRangeBar( Rect rect, FrameRange viewRange, int totalFrames )
  208. {
  209. GUISkin previousGUI = GUI.skin;
  210. GUI.skin = null;
  211. int leftArrowId = EditorGUIUtility.GetControlID(FocusType.Passive);
  212. int rightArrowId = EditorGUIUtility.GetControlID(FocusType.Passive);
  213. int leftHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);
  214. int rightHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);
  215. int midHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);
  216. GUIStyle leftArrowStyle = GUI.skin.GetStyle("horizontalscrollbarleftbutton");
  217. GUIStyle rightArrowStyle = GUI.skin.GetStyle("horizontalscrollbarrightbutton");
  218. GUIStyle timelineScrubberStyle = GUI.skin.GetStyle("HorizontalMinMaxScrollbarThumb");
  219. Rect leftArrowRect = rect;
  220. leftArrowRect.width = leftArrowStyle.fixedWidth;
  221. Rect rightArrowRect = rect;
  222. rightArrowRect.xMin = rightArrowRect.xMax - rightArrowStyle.fixedWidth;
  223. Rect scrubberRect = rect;
  224. scrubberRect.xMin += leftArrowRect.width;
  225. scrubberRect.xMax -= rightArrowRect.width;
  226. float scrubberLeftEdge = scrubberRect.xMin;
  227. float minWidth = 50;
  228. float maxWith = scrubberRect.width-minWidth;
  229. scrubberRect.xMin += ((float)viewRange.Start / totalFrames)*maxWith;
  230. scrubberRect.width = ((float)viewRange.Length / totalFrames)*maxWith+minWidth;
  231. Rect leftHandleRect = scrubberRect;
  232. leftHandleRect.width = timelineScrubberStyle.border.left;
  233. Rect rightHandRect = scrubberRect;
  234. rightHandRect.xMin = rightHandRect.xMax - timelineScrubberStyle.border.right;
  235. switch( Event.current.type )
  236. {
  237. case EventType.MouseDown:
  238. if( Event.current.clickCount > 1 )
  239. {
  240. viewRange.Start = 0;
  241. viewRange.End = totalFrames;
  242. }
  243. else if( EditorGUIUtility.hotControl == 0 )
  244. {
  245. Vector3 mousePos = Event.current.mousePosition;
  246. if( leftArrowRect.Contains( mousePos ) )
  247. {
  248. EditorGUIUtility.hotControl = leftArrowId;
  249. }
  250. else if( rightArrowRect.Contains( mousePos ) )
  251. {
  252. EditorGUIUtility.hotControl = rightArrowId;
  253. }
  254. else if( leftHandleRect.Contains( mousePos ) )
  255. {
  256. EditorGUIUtility.hotControl = leftHandleId;
  257. }
  258. else if( rightHandRect.Contains( mousePos ) )
  259. {
  260. EditorGUIUtility.hotControl = rightHandleId;
  261. }
  262. else if( scrubberRect.Contains( mousePos ) )
  263. {
  264. EditorGUIUtility.hotControl = midHandleId;
  265. _offset = Event.current.mousePosition - new Vector2( scrubberRect.xMin, scrubberRect.yMin);
  266. }
  267. if( EditorGUIUtility.hotControl != 0 )
  268. {
  269. // cachedMousePos = Input.mousePosition;
  270. Event.current.Use();
  271. }
  272. }
  273. break;
  274. case EventType.MouseUp:
  275. if( EditorGUIUtility.hotControl == leftArrowId || EditorGUIUtility.hotControl == rightArrowId
  276. || EditorGUIUtility.hotControl == leftHandleId || EditorGUIUtility.hotControl == rightHandleId
  277. || EditorGUIUtility.hotControl == midHandleId )
  278. {
  279. EditorGUIUtility.hotControl = 0;
  280. Event.current.Use();
  281. }
  282. break;
  283. case EventType.MouseDrag:
  284. int delta = 0;
  285. if( EditorGUIUtility.hotControl == leftHandleId )
  286. {
  287. delta = Mathf.RoundToInt(((Event.current.mousePosition.x-scrubberLeftEdge)/maxWith)*totalFrames);
  288. viewRange.Start = Mathf.Clamp( delta, 0, viewRange.End-1 );
  289. GUI.changed = true;
  290. Event.current.Use();
  291. }
  292. else if( EditorGUIUtility.hotControl == rightHandleId )
  293. {
  294. delta = Mathf.RoundToInt(((Event.current.mousePosition.x-(scrubberLeftEdge+minWidth))/maxWith)*totalFrames);
  295. viewRange.End = Mathf.Clamp( delta, viewRange.Start+1, totalFrames );
  296. GUI.changed = true;
  297. Event.current.Use();
  298. }
  299. else if( EditorGUIUtility.hotControl == midHandleId )
  300. {
  301. // int startX = Mathf.RoundToInt(((cachedMousePos.x-scrubberLeftEdge)/maxWith)*totalFrames);
  302. delta = Mathf.RoundToInt(((Event.current.mousePosition.x-_offset.x-scrubberLeftEdge)/maxWith)*totalFrames);
  303. int x = delta-viewRange.Start;
  304. viewRange.Start = delta;
  305. viewRange.End += x;
  306. if( viewRange.Start < 0 )
  307. {
  308. int diff = -viewRange.Start;
  309. viewRange.Start += diff;
  310. viewRange.End += diff;
  311. }
  312. if( viewRange.End > totalFrames )
  313. {
  314. int diff = viewRange.End-totalFrames;
  315. viewRange.Start -= diff;
  316. viewRange.End -= diff;
  317. }
  318. GUI.changed = true;
  319. Event.current.Use();
  320. }
  321. break;
  322. case EventType.Repaint:
  323. GUIStyle bar = GUI.skin.GetStyle("horizontalscrollbar");
  324. bar.Draw( rect, false, false, false, false );
  325. leftArrowStyle.Draw( leftArrowRect, true, EditorGUIUtility.hotControl == leftArrowId, false, false );
  326. rightArrowStyle.Draw( rightArrowRect, true, EditorGUIUtility.hotControl == rightArrowId, false, false );
  327. timelineScrubberStyle.Draw( scrubberRect, false, false, false, false );
  328. GUIStyle label = new GUIStyle( EditorStyles.boldLabel );
  329. string viewRangeStartStr = viewRange.Start.ToString();
  330. string viewRangeEndStr = viewRange.End.ToString();
  331. string viewRangeLengthStr = viewRange.Length.ToString();
  332. scrubberRect.xMin += 20;
  333. scrubberRect.xMax -= 20;
  334. Vector2 sizeAllLabels = label.CalcSize( new GUIContent(viewRangeStartStr+viewRangeEndStr+viewRangeLengthStr ) );
  335. if( scrubberRect.width > sizeAllLabels.x + 40 )
  336. {
  337. label.Draw( scrubberRect, new GUIContent(viewRangeStartStr), 0 );
  338. label.alignment = TextAnchor.MiddleRight;
  339. label.Draw( scrubberRect, new GUIContent(viewRangeEndStr), 0 );
  340. }
  341. label.alignment = TextAnchor.MiddleCenter;
  342. label.Draw( scrubberRect, new GUIContent(viewRangeLengthStr), 0 );
  343. // GUI.HorizontalScrollbar( rect, 0, 100, 0, 100);
  344. break;
  345. }
  346. GUI.skin = previousGUI;
  347. return viewRange;
  348. }
  349. private static readonly int[] DEFAULT_FRAME_RATE_VALUES = new int[]{ 15, 30, 60 };
  350. private const string CUSTOM_FRAME_RATE_STR = "Other..";
  351. private static int[] FRAME_RATE_VALUES = null;
  352. private static string[] FRAME_RATE_OPTIONS = null;
  353. public static int FrameRatePopup( Rect rect, int frameRate )
  354. {
  355. int i = 0;
  356. if( FRAME_RATE_VALUES == null )
  357. {
  358. FRAME_RATE_VALUES = new int[DEFAULT_FRAME_RATE_VALUES.Length+1];
  359. FRAME_RATE_OPTIONS = new string[FRAME_RATE_VALUES.Length];
  360. for( ; i != DEFAULT_FRAME_RATE_VALUES.Length; ++i )
  361. {
  362. FRAME_RATE_VALUES[i] = DEFAULT_FRAME_RATE_VALUES[i];
  363. FRAME_RATE_OPTIONS[i] = FRAME_RATE_VALUES[i].ToString();
  364. }
  365. FRAME_RATE_VALUES[i] = -1;
  366. FRAME_RATE_OPTIONS[i] = CUSTOM_FRAME_RATE_STR;
  367. i = 0; // clear i for the next cycle
  368. }
  369. for( ; i != DEFAULT_FRAME_RATE_VALUES.Length; ++i )
  370. {
  371. if( frameRate == DEFAULT_FRAME_RATE_VALUES[i] )
  372. break;
  373. }
  374. // didn't find it, add it to the one before last
  375. if( i == DEFAULT_FRAME_RATE_VALUES.Length )
  376. {
  377. if( FRAME_RATE_VALUES.Length == DEFAULT_FRAME_RATE_VALUES.Length+1 ) // doesn't contain a custom value
  378. {
  379. ArrayUtility.Insert<int>( ref FRAME_RATE_VALUES, FRAME_RATE_VALUES.Length-1, frameRate );
  380. ArrayUtility.Insert<string>( ref FRAME_RATE_OPTIONS, FRAME_RATE_OPTIONS.Length-1, frameRate.ToString() );
  381. }
  382. else if( FRAME_RATE_VALUES[FRAME_RATE_VALUES.Length-2] != frameRate ) // already contains, lets see if different
  383. {
  384. FRAME_RATE_VALUES[FRAME_RATE_VALUES.Length-2] = frameRate;
  385. FRAME_RATE_OPTIONS[FRAME_RATE_OPTIONS.Length-2] = frameRate.ToString();
  386. }
  387. }
  388. // if( GUI.Button( rect, frameRate.ToString(), EditorStyles.popup ) )
  389. // {
  390. // GenericMenu frameRateMenu = new GenericMenu();
  391. // for( i = 0; i != FRAME_RATE_VALUES.Length; ++i )
  392. // frameRateMenu.AddItem( new GUIContent(FRAME_RATE_OPTIONS[i]), false, ChangeFrameRateFunc, FRAME_RATE_VALUES[i] );
  393. //// frameRateMenu.ShowAsContext();
  394. // frameRateMenu.DropDown( rect );
  395. // }
  396. return EditorGUI.IntPopup( rect, frameRate, FRAME_RATE_OPTIONS, FRAME_RATE_VALUES );
  397. }
  398. private static void ChangeFrameRateFunc( object obj )
  399. {
  400. Debug.Log( (int)obj + " chosen" );
  401. }
  402. public static Color GetAnimationBlendingColor()
  403. {
  404. return EditorGUIUtility.isProSkin ? ANIMATION_BLEND_COLOR_PRO : ANIMATION_BLEND_COLOR;
  405. }
  406. public static Color GetLineColor()
  407. {
  408. return EditorGUIUtility.isProSkin ? LINE_COLOR_PRO : LINE_COLOR;
  409. }
  410. public static Color GetTimelineColor()
  411. {
  412. return EditorGUIUtility.isProSkin ? TIMELINE_COLOR_PRO : TIMELINE_COLOR;
  413. }
  414. public static Color GetEventColor()
  415. {
  416. return EditorGUIUtility.isProSkin ? EVENT_COLOR_PRO : EVENT_COLOR;
  417. }
  418. public static Color GetTextColor()
  419. {
  420. return EditorGUIUtility.isProSkin ? TEXT_COLOR_PRO : TEXT_COLOR;
  421. }
  422. public static Color GetSelectionColor()
  423. {
  424. return EditorGUIUtility.isProSkin ? SELECTION_COLOR_PRO : SELECTION_COLOR;
  425. }
  426. public static Color GetIconColor()
  427. {
  428. // Color c = EditorGUIUtility.isProSkin ? TEXT_COLOR_PRO : TEXT_COLOR;
  429. Color c = TEXT_COLOR_PRO;
  430. if( Application.isPlaying )
  431. c.a *= 0.5f;
  432. return c;
  433. }
  434. public static Color GetWindowColor()
  435. {
  436. return EditorGUIUtility.isProSkin ? WINDOW_COLOR_PRO : WINDOW_COLOR;
  437. }
  438. public static Color DefaultContainerColor()
  439. {
  440. return FContainer.DEFAULT_COLOR;
  441. }
  442. public static GUIStyle GetTimeScrubberStyle()
  443. {
  444. if( EditorGUIUtility.isProSkin )
  445. {
  446. GUIStyle toolbarStyle = new GUIStyle(EditorStyles.toolbar);
  447. toolbarStyle.fixedHeight = 0;
  448. return toolbarStyle;
  449. }
  450. return GUIStyle.none;
  451. }
  452. public static bool ButtonLogic( Rect rect )
  453. {
  454. int buttonGuid = EditorGUIUtility.GetControlID( FocusType.Passive );
  455. bool result = false;
  456. switch( Event.current.type )
  457. {
  458. case EventType.MouseDown:
  459. if( rect.Contains(Event.current.mousePosition) )
  460. {
  461. GUIUtility.hotControl = buttonGuid;
  462. Event.current.Use();
  463. }
  464. break;
  465. case EventType.MouseUp:
  466. if( GUIUtility.hotControl == buttonGuid )
  467. {
  468. if( rect.Contains(Event.current.mousePosition) )
  469. {
  470. result = true;
  471. Event.current.Use();
  472. }
  473. GUIUtility.hotControl = 0;
  474. }
  475. break;
  476. }
  477. return result;
  478. }
  479. public static bool Button( Rect rect, GUIContent content )
  480. {
  481. bool result = false;
  482. GUIStyle style = new GUIStyle();
  483. Color prevColor = GUI.color;
  484. if( Event.current.type == EventType.Repaint && GUIUtility.hotControl != 0 && rect.Contains(Event.current.mousePosition) )
  485. {
  486. style.padding = new RectOffset(1, 1, 1, 1);
  487. Color pressedColor = prevColor;
  488. pressedColor.a = 0.5f;
  489. GUI.color = pressedColor;
  490. }
  491. result = GUI.Button(rect, content, style);
  492. if( Event.current.type == EventType.Repaint )
  493. GUI.color = prevColor;
  494. return result;
  495. }
  496. // private static string _smartFieldText = "";
  497. // public static int SmartIntField( Rect rect, int value )
  498. // {
  499. //
  500. //// int id = EditorGUIUtility.GetControlID(FocusType.Keyboard);
  501. ////
  502. //// string text = EditorGUIUtility.keyboardControl == id ? _smartFieldText : (value == int.MinValue ? "--" : value.ToString());
  503. //
  504. // GUIStyle textFieldStyle = EditorStyles.textField;
  505. //
  506. // EditorGUI.BeginChangeCheck();
  507. //
  508. // TextEditor editor = GUIUtility.GetStateObject( typeof(TextEditor), EditorGUIUtility.keyboardControl );
  509. //
  510. // if( editor.con
  511. //
  512. // if( EditorGUI.EndChangeCheck() )
  513. // {
  514. //
  515. // }
  516. // }
  517. }
  518. }