//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System;
using System.Runtime.CompilerServices;
using bs;
namespace bs.Editor
{
/** @addtogroup GUI-Editor
* @{
*/
///
/// Editor GUI element that displays a reference to a and an optional label. Game objects can
/// be dragged and dropped onto the field to update the reference.
///
public sealed class GUIGameObjectField : GUIElement
{
public delegate void OnChangedDelegate(GameObject newValue);
///
/// Triggered when the value in the field changes.
///
public event OnChangedDelegate OnChanged;
///
/// referenced by the field.
///
public GameObject Value
{
get
{
GameObject value;
Internal_GetValue(mCachedPtr, out value);
return value;
}
set { Internal_SetValue(mCachedPtr, value); }
}
///
/// Creates a new game object field element with a label.
///
/// Specific type of this field accepts.
/// Content to display on the label.
/// Width of the title label in pixels.
/// Optional style to use for the element. Style controls the look of the element, as well as
/// default layout options. Style will be retrieved from the active GUISkin. If not specified
/// default element style is used.
/// Options that allow you to control how is the element positioned and sized. This will
/// override any similar options set by style.
public GUIGameObjectField(Type type, GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options)
{
Internal_CreateInstance(this, type, ref title, titleWidth, style, options, true);
}
///
/// Creates a new game object field element without a label.
///
/// Specific type of this field accepts.
/// Optional style to use for the element. Style controls the look of the element, as well as
/// default layout options. Style will be retrieved from the active GUISkin. If not specified
/// default element style is used.
/// Options that allow you to control how is the element positioned and sized. This will
/// override any similar options set by style.
public GUIGameObjectField(Type type, string style = "", params GUIOption[] options)
{
GUIContent emptyContent = new GUIContent();
Internal_CreateInstance(this, type, ref emptyContent, 0, style, options, false);
}
///
/// Colors the element with a specific tint.
///
/// Tint to apply to the element.
public void SetTint(Color color)
{
Internal_SetTint(mCachedPtr, ref color);
}
///
/// Triggered by the runtime when the value of the field changes.
///
/// New game object referenced by the field.
private void DoOnChanged(GameObject newValue)
{
if (OnChanged != null)
OnChanged(newValue);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(GUIGameObjectField instance, Type type, ref GUIContent title,
int titleWidth, string style, GUIOption[] options, bool withTitle);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_GetValue(IntPtr nativeInstance, out GameObject value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetValue(IntPtr nativeInstance, GameObject value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
}
/** @} */
}