FCommentTrackEditor.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEditor;
  5. using UnityEditor.AnimatedValues;
  6. using Flux;
  7. namespace FluxEditor
  8. {
  9. [FEditor(typeof(FCommentTrack))]
  10. public class FCommentTrackEditor : FTrackEditor
  11. {
  12. #region Texture Handling
  13. public const int INITIAL_TEXTURE_POOL_SIZE = 64;
  14. public const int TEXTURE_WIDTH = 160;
  15. public const int TEXTURE_HEIGHT = 100;
  16. public const int TEXTURE_DEPTH = 0;
  17. private static Stack<RenderTexture> __texturePool = null;
  18. public static Stack<RenderTexture> TexturePool
  19. {
  20. get
  21. {
  22. if( __texturePool == null )
  23. {
  24. __texturePool = new Stack<RenderTexture>(INITIAL_TEXTURE_POOL_SIZE);
  25. for( int i = 0; i != INITIAL_TEXTURE_POOL_SIZE; ++i )
  26. {
  27. __texturePool.Push(CreateTexture());
  28. }
  29. }
  30. return __texturePool;
  31. }
  32. }
  33. public static RenderTexture RequestTexture()
  34. {
  35. if( TexturePool.Count == 0 )
  36. {
  37. for( int i = 0; i != INITIAL_TEXTURE_POOL_SIZE; ++i )
  38. {
  39. __texturePool.Push(CreateTexture());
  40. }
  41. }
  42. return TexturePool.Pop();
  43. }
  44. public static void ReleaseTexture( RenderTexture texture )
  45. {
  46. TexturePool.Push( texture );
  47. }
  48. private static RenderTexture CreateTexture()
  49. {
  50. RenderTexture texture = new RenderTexture(TEXTURE_WIDTH, TEXTURE_HEIGHT, 32, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
  51. texture.hideFlags = HideFlags.DontSave;
  52. return texture;
  53. }
  54. #endregion Texture Handling
  55. public override float Height { get { return Mathf.Lerp( DEFAULT_TRACK_HEIGHT, TEXTURE_HEIGHT, ShowTextures.faded ); } }
  56. public AnimBool ShowTextures { get; private set; }
  57. protected override void RenderHeader( Rect labelRect, GUIContent label )
  58. {
  59. if( Event.current.type == EventType.MouseDown && Event.current.clickCount > 1 && labelRect.Contains(Event.current.mousePosition) )
  60. {
  61. ShowTextures.target = !ShowTextures.target;
  62. }
  63. base.RenderHeader( labelRect, label );
  64. }
  65. public override void Init (FObject obj, FEditor owner)
  66. {
  67. ShowTextures = new AnimBool(!FUtility.CollapseCommentTracks);
  68. base.Init(obj, owner);
  69. ShowTextures.valueChanged.AddListener( SequenceEditor.Repaint );
  70. }
  71. }
  72. }