//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using BansheeEngine;
namespace BansheeEditor
{
/** @addtogroup Inspectors
* @{
*/
///
/// Renders an inspector for the component.
///
[CustomInspector(typeof(CapsuleCollider))]
internal class CapsuleColliderInspector : ColliderInspector
{
private GUIVector3Field centerField = new GUIVector3Field(new LocEdString("Center"));
private GUIVector3Field orientationField = new GUIVector3Field(new LocEdString("Orientation"));
private GUIFloatField radiusField = new GUIFloatField(new LocEdString("Radius"));
private GUIFloatField halfHeightField = new GUIFloatField(new LocEdString("Half height"));
private Vector3 orientation;
///
protected internal override void Initialize()
{
CapsuleCollider collider = InspectedObject as CapsuleCollider;
if (collider != null)
BuildGUI(collider);
}
///
protected internal override InspectableState Refresh()
{
CapsuleCollider collider = InspectedObject as CapsuleCollider;
if (collider == null)
return InspectableState.NotModified;
Refresh(collider);
InspectableState oldState = modifyState;
if (modifyState.HasFlag(InspectableState.Modified))
modifyState = InspectableState.NotModified;
return oldState;
}
///
/// Creates GUI elements for fields specific to the capsule collider.
///
protected void BuildGUI(CapsuleCollider collider)
{
centerField.OnChanged += x => { collider.Center = x; MarkAsModified(); };
centerField.OnFocusLost += ConfirmModify;
centerField.OnConfirmed += ConfirmModify;
orientationField.OnChanged += x =>
{
orientation = x;
Quaternion rotation = Quaternion.FromEuler(x);
collider.Normal = rotation.Rotate(Vector3.YAxis);
MarkAsModified();
};
orientationField.OnFocusLost += ConfirmModify;
orientationField.OnConfirmed += ConfirmModify;
radiusField.OnChanged += x => { collider.Radius = x; MarkAsModified(); };
radiusField.OnFocusLost += ConfirmModify;
radiusField.OnConfirmed += ConfirmModify;
halfHeightField.OnChanged += x => { collider.HalfHeight = x; MarkAsModified(); };
halfHeightField.OnFocusLost += ConfirmModify;
halfHeightField.OnConfirmed += ConfirmModify;
Layout.AddElement(centerField);
Layout.AddElement(orientationField);
Layout.AddElement(radiusField);
Layout.AddElement(halfHeightField);
orientation = Quaternion.FromToRotation(Vector3.YAxis, collider.Normal).ToEuler();
base.BuildGUI(collider);
}
///
/// Updates all GUI elements from current values in the collider.
///
/// Collider to update the GUI from.
protected void Refresh(CapsuleCollider collider)
{
if (!centerField.HasInputFocus)
centerField.Value = collider.Center;
if (!orientationField.HasInputFocus)
orientationField.Value = orientation;
if (!radiusField.HasInputFocus)
radiusField.Value = collider.Radius;
if (!halfHeightField.HasInputFocus)
halfHeightField.Value = collider.HalfHeight;
base.Refresh(collider);
}
}
/** @} */
}