AnimationInspector.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.Collections.Generic;
  4. using bs;
  5. namespace bs.Editor
  6. {
  7. /** @addtogroup Inspectors
  8. * @{
  9. */
  10. /// <summary>
  11. /// Renders an inspector for the <see cref="Animation"/> component.
  12. /// </summary>
  13. [CustomInspector(typeof(Animation))]
  14. internal class AnimationInspector : Inspector
  15. {
  16. /// <inheritdoc/>
  17. protected internal override void Initialize()
  18. {
  19. Animation animation = (Animation)InspectedObject;
  20. drawer.AddDefault(animation);
  21. // Morph shapes
  22. Renderable renderable = animation.SceneObject.GetComponent<Renderable>();
  23. MorphShapes morphShapes = renderable?.Mesh.Value?.MorphShapes;
  24. if (morphShapes != null)
  25. {
  26. GUIToggle morphShapesToggle = new GUIToggle(new LocEdString("Morph shapes"), EditorStyles.Foldout);
  27. Layout.AddElement(morphShapesToggle);
  28. GUILayoutY channelsLayout = Layout.AddLayoutY();
  29. morphShapesToggle.OnToggled += x =>
  30. {
  31. channelsLayout.Active = x;
  32. Persistent.SetBool("Channels_Expanded", x);
  33. };
  34. channelsLayout.Active = Persistent.GetBool("Channels_Expanded");
  35. MorphChannel[] channels = morphShapes.Channels;
  36. for (int i = 0; i < channels.Length; i++)
  37. {
  38. GUILayoutY channelLayout = channelsLayout.AddLayoutY();
  39. GUILayoutX channelTitleLayout = channelLayout.AddLayoutX();
  40. channelLayout.AddSpace(5);
  41. GUILayoutY channelContentLayout = channelLayout.AddLayoutY();
  42. string channelName = channels[i].Name;
  43. GUIToggle channelNameField = new GUIToggle(channelName, EditorStyles.Expand, GUIOption.FlexibleWidth());
  44. channelTitleLayout.AddSpace(15); // Indent
  45. channelTitleLayout.AddElement(channelNameField);
  46. channelTitleLayout.AddFlexibleSpace();
  47. channelNameField.OnToggled += x =>
  48. {
  49. channelContentLayout.Active = x;
  50. Persistent.SetBool(channelName + "_Expanded", x);
  51. };
  52. channelContentLayout.Active = Persistent.GetBool(channelName + "_Expanded");
  53. MorphShape[] shapes = channels[i].Shapes;
  54. for (int j = 0; j < shapes.Length; j++)
  55. {
  56. GUILayoutX shapeLayout = channelContentLayout.AddLayoutX();
  57. channelContentLayout.AddSpace(5);
  58. LocString nameString = new LocString("[{0}]. {1}");
  59. nameString.SetParameter(0, j.ToString());
  60. nameString.SetParameter(1, shapes[j].Name);
  61. GUILabel shapeNameField = new GUILabel(shapes[j].Name);
  62. LocString weightString = new LocEdString("Weight: {0}");
  63. weightString.SetParameter(0, shapes[j].Weight.ToString());
  64. GUILabel weightField = new GUILabel(weightString);
  65. shapeLayout.AddSpace(30); // Indent
  66. shapeLayout.AddElement(shapeNameField);
  67. shapeLayout.AddFlexibleSpace();
  68. shapeLayout.AddElement(weightField);
  69. }
  70. }
  71. }
  72. }
  73. }
  74. /** @} */
  75. }