//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System.Collections.Generic;
using System;
using System.Reflection;
using BansheeEngine;
namespace BansheeEditor
{
/** @addtogroup Inspector
* @{
*/
///
/// Displays GUI for a serializable property containing a generic object. Inspectable object fields are displayed
/// in separate rows.
///
public class InspectableObject : InspectableField
{
private const int IndentAmount = 5;
private object propertyValue;
private List children = new List();
private InspectableFieldStyleInfo style;
private GUILayoutY guiLayout;
private GUILayoutX guiChildLayout;
private GUILayoutX guiTitleLayout;
private GUILayoutX guiInternalTitleLayout;
private GUIButton guiCreateBtn;
private ContextMenu createContextMenu;
private bool isExpanded;
private bool forceUpdate = true;
private State state;
///
/// Creates a new inspectable array GUI for the specified property.
///
/// Parent Inspector this field belongs to.
/// Name of the property, or some other value to set as the title.
/// Full path to this property (includes name of this property and all parent properties).
/// Determines how deep within the inspector nesting hierarchy is this field. Some fields may
/// contain other fields, in which case you should increase this value by one.
/// Parent layout that all the field elements will be added to.
/// Serializable property referencing the object whose contents to display.
/// Information that can be used for customizing field rendering and behaviour.
public InspectableObject(Inspector parent, string title, string path, int depth, InspectableFieldLayout layout,
SerializableProperty property, InspectableFieldStyleInfo style)
: base(parent, title, path, SerializableProperty.FieldType.Object, depth, layout, property)
{
this.style = style;
isExpanded = parent.Persistent.GetBool(path + "_Expanded");
// Builds a context menu that lets the user create objects to assign to this field.
Type[] types = GetInstantiableTypes(property.InternalType);
if (types.Length > 0)
{
createContextMenu = new ContextMenu();
Array.Sort(types, (x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal));
foreach (var type in types)
{
createContextMenu.AddItem(type.Namespace + "." + type.Name,
() => property.SetValue(Activator.CreateInstance(type)));
}
}
}
///
public override GUILayoutX GetTitleLayout()
{
return guiTitleLayout;
}
///
public override InspectableState Refresh(int layoutIndex)
{
// Check if modified internally and rebuild if needed
object newPropertyValue = property.GetValue