GUIGameObjectField.cs 4.6 KB

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