ReflectionProbeInspector.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.Collections.Generic;
  4. using BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. /** @addtogroup Inspectors
  8. * @{
  9. */
  10. /// <summary>
  11. /// Renders an inspector for the <see cref="ReflectionProbe"/> component.
  12. /// </summary>
  13. [CustomInspector(typeof(ReflectionProbe))]
  14. internal class ReflectionProbeInspector : Inspector
  15. {
  16. private GUIEnumField probeTypeField = new GUIEnumField(typeof(ReflectionProbeType), new LocEdString("Probe type"));
  17. private GUIVector3Field extentsField = new GUIVector3Field(new LocEdString("Extents"));
  18. private GUIFloatField radiusField = new GUIFloatField(new LocEdString("Radius"));
  19. private GUITextureField customTextureField = new GUITextureField(new LocEdString("Custom texture"));
  20. private GUIButton captureButton = new GUIButton(new LocEdString("Capture"));
  21. private InspectableState modifyState;
  22. /// <inheritdoc/>
  23. protected internal override void Initialize()
  24. {
  25. if (InspectedObject != null)
  26. {
  27. ReflectionProbe probe = (ReflectionProbe)InspectedObject;
  28. probeTypeField.OnSelectionChanged += x =>
  29. {
  30. probe.Type = (ReflectionProbeType)x;
  31. ToggleTypeSpecificFields((ReflectionProbeType) x);
  32. };
  33. radiusField.OnChanged += x => { probe.Radius = x; MarkAsModified(); };
  34. radiusField.OnConfirmed += ConfirmModify;
  35. radiusField.OnFocusLost += ConfirmModify;
  36. extentsField.OnChanged += x => { probe.Extents = x; MarkAsModified(); };
  37. extentsField.OnConfirmed += ConfirmModify;
  38. extentsField.OnFocusLost += ConfirmModify;
  39. customTextureField.OnChanged += x =>
  40. {
  41. probe.CustomTexture = Resources.Load<Texture>(x);
  42. MarkAsModified();
  43. ConfirmModify();
  44. };
  45. captureButton.OnClick += () => probe.Capture();
  46. Layout.AddElement(probeTypeField);
  47. Layout.AddElement(radiusField);
  48. Layout.AddElement(extentsField);
  49. Layout.AddElement(customTextureField);
  50. Layout.AddSpace(10);
  51. Layout.AddElement(captureButton);
  52. ToggleTypeSpecificFields(probe.Type);
  53. }
  54. }
  55. /// <inheritdoc/>
  56. protected internal override InspectableState Refresh()
  57. {
  58. ReflectionProbe probe = InspectedObject as ReflectionProbe;
  59. if (probe == null)
  60. return InspectableState.NotModified;
  61. ReflectionProbeType probeType = probe.Type;
  62. if (probeTypeField.Value != (ulong)probeType)
  63. ToggleTypeSpecificFields(probeType);
  64. probeTypeField.Value = (ulong)probeType;
  65. radiusField.Value = probe.Radius;
  66. extentsField.Value = probe.Extents;
  67. customTextureField.Value = probe.CustomTexture;
  68. InspectableState oldState = modifyState;
  69. if (modifyState.HasFlag(InspectableState.Modified))
  70. modifyState = InspectableState.NotModified;
  71. return oldState;
  72. }
  73. /// <summary>
  74. /// Enables or disables different GUI elements depending on the probe type.
  75. /// </summary>
  76. /// <param name="type">Probe type to show GUI elements for.</param>
  77. private void ToggleTypeSpecificFields(ReflectionProbeType type)
  78. {
  79. bool isBox = type == ReflectionProbeType.Box;
  80. radiusField.Active = !isBox;
  81. extentsField.Active = isBox;
  82. }
  83. /// <summary>
  84. /// Marks the contents of the inspector as modified.
  85. /// </summary>
  86. protected void MarkAsModified()
  87. {
  88. modifyState |= InspectableState.ModifyInProgress;
  89. }
  90. /// <summary>
  91. /// Confirms any queued modifications.
  92. /// </summary>
  93. protected void ConfirmModify()
  94. {
  95. if (modifyState.HasFlag(InspectableState.ModifyInProgress))
  96. modifyState |= InspectableState.Modified;
  97. }
  98. }
  99. /** @} */
  100. }