GUIGameObjectField.cs 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /// <summary>
  7. /// Editor GUI element that displays a reference to a <see cref="GameObject"/> and an optional label. Game objects can
  8. /// be dragged and dropped onto the field to update the reference.
  9. /// </summary>
  10. public sealed class GUIGameObjectField : GUIElement
  11. {
  12. public delegate void OnChangedDelegate(GameObject newValue);
  13. /// <summary>
  14. /// Triggered when the value in the field changes.
  15. /// </summary>
  16. public event OnChangedDelegate OnChanged;
  17. /// <summary>
  18. /// <see cref="GameObject"/> referenced by the field.
  19. /// </summary>
  20. public GameObject Value
  21. {
  22. get
  23. {
  24. GameObject value;
  25. Internal_GetValue(mCachedPtr, out value);
  26. return value;
  27. }
  28. set { Internal_SetValue(mCachedPtr, value); }
  29. }
  30. /// <summary>
  31. /// Creates a new game object field element with a label.
  32. /// </summary>
  33. /// <param name="type">Specific type of <see cref="GameObject"/> this field accepts.</param>
  34. /// <param name="title">Content to display on the label.</param>
  35. /// <param name="titleWidth">Width of the title label in pixels.</param>
  36. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  37. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  38. /// default element style is used.</param>
  39. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  40. /// override any similar options set by style.</param>
  41. public GUIGameObjectField(Type type, GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options)
  42. {
  43. Internal_CreateInstance(this, type, title, titleWidth, style, options, true);
  44. }
  45. /// <summary>
  46. /// Creates a new game object field element without a label.
  47. /// </summary>
  48. /// <param name="type">Specific type of <see cref="GameObject"/> this field accepts.</param>
  49. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  50. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  51. /// default element style is used.</param>
  52. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  53. /// override any similar options set by style.</param>
  54. public GUIGameObjectField(Type type, string style = "", params GUIOption[] options)
  55. {
  56. Internal_CreateInstance(this, type, null, 0, style, options, false);
  57. }
  58. /// <summary>
  59. /// Colors the element with a specific tint.
  60. /// </summary>
  61. /// <param name="color">Tint to apply to the element.</param>
  62. public void SetTint(Color color)
  63. {
  64. Internal_SetTint(mCachedPtr, color);
  65. }
  66. /// <summary>
  67. /// Triggered by the runtime when the value of the field changes.
  68. /// </summary>
  69. /// <param name="newValue">New game object referenced by the field.</param>
  70. private void DoOnChanged(GameObject newValue)
  71. {
  72. if (OnChanged != null)
  73. OnChanged(newValue);
  74. }
  75. [MethodImpl(MethodImplOptions.InternalCall)]
  76. private static extern void Internal_CreateInstance(GUIGameObjectField instance, Type type, GUIContent title, int titleWidth,
  77. string style, GUIOption[] options, bool withTitle);
  78. [MethodImpl(MethodImplOptions.InternalCall)]
  79. private static extern void Internal_GetValue(IntPtr nativeInstance, out GameObject value);
  80. [MethodImpl(MethodImplOptions.InternalCall)]
  81. private static extern void Internal_SetValue(IntPtr nativeInstance, GameObject value);
  82. [MethodImpl(MethodImplOptions.InternalCall)]
  83. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  84. }
  85. }