AnimationInspector.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /** @addtogroup Inspectors
  7. * @{
  8. */
  9. /// <summary>
  10. /// Renders an inspector for the <see cref="Animation"/> component.
  11. /// </summary>
  12. [CustomInspector(typeof(Animation))]
  13. internal class AnimationInspector : Inspector
  14. {
  15. private GUIResourceField animationClipField = new GUIResourceField(typeof(AnimationClip), new LocEdString("Clip"));
  16. private GUIEnumField wrapModeField = new GUIEnumField(typeof(AnimWrapMode), new LocEdString("Wrap mode"));
  17. private GUIFloatField speedField = new GUIFloatField(new LocEdString("Speed"));
  18. private InspectableState modifyState;
  19. /// <inheritdoc/>
  20. protected internal override void Initialize()
  21. {
  22. BuildGUI();
  23. }
  24. /// <inheritdoc/>
  25. protected internal override InspectableState Refresh()
  26. {
  27. Animation animation = InspectedObject as Animation;
  28. if (animation == null)
  29. return InspectableState.NotModified;
  30. animationClipField.Value = animation.DefaultClip;
  31. wrapModeField.Value = (ulong)animation.WrapMode;
  32. speedField.Value = animation.Speed;
  33. InspectableState oldState = modifyState;
  34. if (modifyState.HasFlag(InspectableState.Modified))
  35. modifyState = InspectableState.NotModified;
  36. return oldState;
  37. }
  38. /// <summary>
  39. /// Recreates all the GUI elements used by this inspector.
  40. /// </summary>
  41. private void BuildGUI()
  42. {
  43. Layout.Clear();
  44. Animation animation = InspectedObject as Animation;
  45. if (animation == null)
  46. return;
  47. animationClipField.OnChanged += x =>
  48. {
  49. AnimationClip clip = Resources.Load<AnimationClip>(x);
  50. animation.DefaultClip = clip;
  51. MarkAsModified();
  52. ConfirmModify();
  53. };
  54. wrapModeField.OnSelectionChanged += x =>
  55. {
  56. animation.WrapMode = (AnimWrapMode)x;
  57. MarkAsModified();
  58. ConfirmModify();
  59. };
  60. speedField.OnChanged += x => { animation.Speed = x; MarkAsModified(); };
  61. speedField.OnConfirmed += ConfirmModify;
  62. speedField.OnFocusLost += ConfirmModify;
  63. Layout.AddElement(animationClipField);
  64. Layout.AddElement(wrapModeField);
  65. Layout.AddElement(speedField);
  66. }
  67. /// <summary>
  68. /// Marks the contents of the inspector as modified.
  69. /// </summary>
  70. protected void MarkAsModified()
  71. {
  72. modifyState |= InspectableState.ModifyInProgress;
  73. }
  74. /// <summary>
  75. /// Confirms any queued modifications.
  76. /// </summary>
  77. protected void ConfirmModify()
  78. {
  79. if (modifyState.HasFlag(InspectableState.ModifyInProgress))
  80. modifyState |= InspectableState.Modified;
  81. }
  82. }
  83. /** @} */
  84. }