|
|
@@ -1,8 +1,4 @@
|
|
|
using System;
|
|
|
-using System.Collections;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
-using System.Text;
|
|
|
using BansheeEngine;
|
|
|
|
|
|
namespace BansheeEditor
|
|
|
@@ -13,90 +9,9 @@ namespace BansheeEditor
|
|
|
/// </summary>
|
|
|
public class InspectableArray : InspectableField
|
|
|
{
|
|
|
- /// <summary>
|
|
|
- /// Contains GUI elements for a single entry in the array.
|
|
|
- /// </summary>
|
|
|
- private class EntryRow
|
|
|
- {
|
|
|
- public GUILayoutY contentLayout;
|
|
|
- private GUILayoutX rowLayout;
|
|
|
- private GUILayoutX titleLayout;
|
|
|
- private bool ownsTitleLayout;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Constructs a new entry row object.
|
|
|
- /// </summary>
|
|
|
- /// <param name="parentLayout">Parent layout that row GUI elements will be added to.</param>
|
|
|
- public EntryRow(GUILayout parentLayout)
|
|
|
- {
|
|
|
- rowLayout = parentLayout.AddLayoutX();
|
|
|
- contentLayout = rowLayout.AddLayoutY();
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Recreates all row GUI elements.
|
|
|
- /// </summary>
|
|
|
- /// <param name="child">Inspectable field of the array entry.</param>
|
|
|
- /// <param name="seqIndex">Sequential index of the array entry.</param>
|
|
|
- /// <param name="parent">Parent array object that the entry is contained in.</param>
|
|
|
- public void Refresh(InspectableField child, int seqIndex, InspectableArray parent)
|
|
|
- {
|
|
|
- if (ownsTitleLayout || (titleLayout != null && titleLayout == child.GetTitleLayout()))
|
|
|
- return;
|
|
|
-
|
|
|
- titleLayout = child.GetTitleLayout();
|
|
|
- if (titleLayout == null)
|
|
|
- {
|
|
|
- GUILayoutY buttonCenter = rowLayout.AddLayoutY();
|
|
|
- buttonCenter.AddFlexibleSpace();
|
|
|
- titleLayout = buttonCenter.AddLayoutX();
|
|
|
- buttonCenter.AddFlexibleSpace();
|
|
|
-
|
|
|
- ownsTitleLayout = true;
|
|
|
- }
|
|
|
-
|
|
|
- GUIContent cloneIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clone));
|
|
|
- GUIContent deleteIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Delete));
|
|
|
- GUIContent moveUp = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.MoveUp));
|
|
|
- GUIContent moveDown = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.MoveDown));
|
|
|
-
|
|
|
- GUIButton cloneBtn = new GUIButton(cloneIcon, GUIOption.FixedWidth(30));
|
|
|
- GUIButton deleteBtn = new GUIButton(deleteIcon, GUIOption.FixedWidth(30));
|
|
|
- GUIButton moveUpBtn = new GUIButton(moveUp, GUIOption.FixedWidth(30));
|
|
|
- GUIButton moveDownBtn = new GUIButton(moveDown, GUIOption.FixedWidth(30));
|
|
|
-
|
|
|
- cloneBtn.OnClick += () => parent.OnCloneButtonClicked(seqIndex);
|
|
|
- deleteBtn.OnClick += () => parent.OnDeleteButtonClicked(seqIndex);
|
|
|
- moveUpBtn.OnClick += () => parent.OnMoveUpButtonClicked(seqIndex);
|
|
|
- moveDownBtn.OnClick += () => parent.OnMoveDownButtonClicked(seqIndex);
|
|
|
-
|
|
|
- titleLayout.AddElement(cloneBtn);
|
|
|
- titleLayout.AddElement(deleteBtn);
|
|
|
- titleLayout.AddElement(moveUpBtn);
|
|
|
- titleLayout.AddElement(moveDownBtn);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Destroys all row GUI elements.
|
|
|
- /// </summary>
|
|
|
- public void Destroy()
|
|
|
- {
|
|
|
- rowLayout.Destroy();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private const int IndentAmount = 5;
|
|
|
-
|
|
|
private object propertyValue; // TODO - This will unnecessarily hold references to the object
|
|
|
private int numArrayElements;
|
|
|
-
|
|
|
- private List<EntryRow> rows = new List<EntryRow>();
|
|
|
- private GUIIntField guiSizeField;
|
|
|
- private GUILayoutX guiChildLayout;
|
|
|
- private GUILayoutX guiTitleLayout;
|
|
|
- private bool isExpanded;
|
|
|
-
|
|
|
- private bool forceUpdate = true;
|
|
|
+ private InspectableArrayGUI arrayGUIField;
|
|
|
|
|
|
/// <summary>
|
|
|
/// Creates a new inspectable array GUI for the specified property.
|
|
|
@@ -115,317 +30,254 @@ namespace BansheeEditor
|
|
|
/// <inheritdoc/>
|
|
|
public override GUILayoutX GetTitleLayout()
|
|
|
{
|
|
|
- return guiTitleLayout;
|
|
|
+ return arrayGUIField.GetTitleLayout();
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
- protected override bool IsModified(out bool rebuildGUI)
|
|
|
+ public override bool IsModified()
|
|
|
{
|
|
|
- if (forceUpdate)
|
|
|
- {
|
|
|
- rebuildGUI = true;
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
object newPropertyValue = property.GetValue<object>();
|
|
|
if (propertyValue == null)
|
|
|
- {
|
|
|
- rebuildGUI = newPropertyValue != null;
|
|
|
- return rebuildGUI;
|
|
|
- }
|
|
|
+ return newPropertyValue != null;
|
|
|
|
|
|
if (newPropertyValue == null)
|
|
|
- {
|
|
|
- rebuildGUI = propertyValue != null;
|
|
|
- return rebuildGUI;
|
|
|
- }
|
|
|
+ return propertyValue != null;
|
|
|
|
|
|
SerializableArray array = property.GetArray();
|
|
|
if (array.GetLength() != numArrayElements)
|
|
|
- {
|
|
|
- rebuildGUI = true;
|
|
|
return true;
|
|
|
- }
|
|
|
-
|
|
|
- return base.IsModified(out rebuildGUI);
|
|
|
+
|
|
|
+ return base.IsModified();
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
- public override bool Refresh(int layoutIndex, out bool updateGUI)
|
|
|
+ public override bool Refresh(int layoutIndex)
|
|
|
{
|
|
|
- bool anythingModified = false;
|
|
|
-
|
|
|
- if (IsModified(out updateGUI))
|
|
|
- {
|
|
|
- Update(layoutIndex, updateGUI);
|
|
|
- anythingModified = true;
|
|
|
- }
|
|
|
-
|
|
|
- for (int i = 0; i < ChildCount; i++)
|
|
|
- {
|
|
|
- bool dummy;
|
|
|
-
|
|
|
- InspectableField child = GetChild(i);
|
|
|
- bool childModified = child.Refresh(0, out dummy);
|
|
|
-
|
|
|
- if (childModified)
|
|
|
- rows[i].Refresh(child, i, this);
|
|
|
-
|
|
|
- anythingModified |= childModified;
|
|
|
- }
|
|
|
+ bool anythingModified = IsModified();
|
|
|
|
|
|
+ anythingModified |= arrayGUIField.Refresh();
|
|
|
return anythingModified;
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
- protected override void BuildGUI(int layoutIndex)
|
|
|
+ public override bool GetRebuildOnModify()
|
|
|
{
|
|
|
- guiTitleLayout = null;
|
|
|
- guiChildLayout = null;
|
|
|
-
|
|
|
- foreach (var row in rows)
|
|
|
- row.Destroy();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- rows.Clear();
|
|
|
- layout.DestroyElements();
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected internal override void BuildGUI(int layoutIndex)
|
|
|
+ {
|
|
|
+ GUILayout arrayLayout = layout.AddLayoutY(layoutIndex);
|
|
|
|
|
|
- if (property.Type != SerializableProperty.FieldType.Array || property.InternalType.GetArrayRank() != 1) // We don't support multirank arrays
|
|
|
- return;
|
|
|
+ arrayGUIField = InspectableArrayGUI.Create(title, property, arrayLayout);
|
|
|
+ }
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected internal override void Update(int layoutIndex)
|
|
|
+ {
|
|
|
propertyValue = property.GetValue<object>();
|
|
|
- if (propertyValue == null)
|
|
|
+ if (propertyValue != null)
|
|
|
{
|
|
|
- guiChildLayout = null;
|
|
|
- guiTitleLayout = layout.AddLayoutX(layoutIndex);
|
|
|
+ SerializableArray array = property.GetArray();
|
|
|
+ numArrayElements = array.GetLength();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ numArrayElements = 0;
|
|
|
|
|
|
- guiTitleLayout.AddElement(new GUILabel(title));
|
|
|
- guiTitleLayout.AddElement(new GUILabel("Empty", GUIOption.FixedWidth(100)));
|
|
|
+ layout.DestroyElements();
|
|
|
+ BuildGUI(layoutIndex);
|
|
|
+ }
|
|
|
|
|
|
- if (!property.IsValueType)
|
|
|
- {
|
|
|
- GUIContent createIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Create));
|
|
|
- GUIButton createBtn = new GUIButton(createIcon, GUIOption.FixedWidth(30));
|
|
|
- createBtn.OnClick += OnCreateButtonClicked;
|
|
|
- guiTitleLayout.AddElement(createBtn);
|
|
|
- }
|
|
|
+ /// <summary>
|
|
|
+ /// Handles creation of GUI elements for a GUI list field that displays a <see cref="SerializableArray"/> object.
|
|
|
+ /// </summary>
|
|
|
+ private class InspectableArrayGUI : GUIListFieldBase
|
|
|
+ {
|
|
|
+ private SerializableProperty property;
|
|
|
|
|
|
- numArrayElements = 0;
|
|
|
- }
|
|
|
- else
|
|
|
+ /// <summary>
|
|
|
+ /// Creates a new inspectable GUI array.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="title">Label to display on the list GUI title.</param>
|
|
|
+ /// <param name="property">Serializable property referencing a single-dimensional array.</param>
|
|
|
+ /// <param name="layout">Layout to which to append the list GUI elements to.</param>
|
|
|
+ /// <returns>Newly created inspectable GUI array object.</returns>
|
|
|
+ public static InspectableArrayGUI Create(LocString title, SerializableProperty property, GUILayout layout)
|
|
|
{
|
|
|
- GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
|
|
|
- guiFoldout.Value = isExpanded;
|
|
|
- guiFoldout.OnToggled += OnFoldoutToggled;
|
|
|
- guiSizeField = new GUIIntField("", GUIOption.FixedWidth(50));
|
|
|
- guiSizeField.SetRange(0, int.MaxValue);
|
|
|
-
|
|
|
- GUIContent resizeIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Resize));
|
|
|
- GUIButton guiResizeBtn = new GUIButton(resizeIcon, GUIOption.FixedWidth(30));
|
|
|
- guiResizeBtn.OnClick += OnResizeButtonClicked;
|
|
|
-
|
|
|
- GUIContent clearIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear));
|
|
|
- GUIButton guiClearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(30));
|
|
|
- guiClearBtn.OnClick += OnClearButtonClicked;
|
|
|
-
|
|
|
- guiTitleLayout = layout.AddLayoutX(layoutIndex);
|
|
|
- guiTitleLayout.AddElement(guiFoldout);
|
|
|
- guiTitleLayout.AddElement(guiSizeField);
|
|
|
- guiTitleLayout.AddElement(guiResizeBtn);
|
|
|
- guiTitleLayout.AddElement(guiClearBtn);
|
|
|
+ InspectableArrayGUI newArrayField = new InspectableArrayGUI();
|
|
|
|
|
|
- SerializableArray array = property.GetArray();
|
|
|
- numArrayElements = array.GetLength();
|
|
|
- guiSizeField.Value = numArrayElements;
|
|
|
-
|
|
|
- if (isExpanded)
|
|
|
+ object propertyValue = property.GetValue<object>();
|
|
|
+ if (propertyValue != null)
|
|
|
{
|
|
|
- if (numArrayElements > 0)
|
|
|
- {
|
|
|
- guiChildLayout = layout.AddLayoutX(layoutIndex);
|
|
|
- guiChildLayout.AddSpace(IndentAmount);
|
|
|
-
|
|
|
- GUIPanel guiContentPanel = guiChildLayout.AddPanel();
|
|
|
- GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
|
|
|
- guiIndentLayoutX.AddSpace(IndentAmount);
|
|
|
- GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
|
|
|
- guiIndentLayoutY.AddSpace(IndentAmount);
|
|
|
- GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
|
|
|
- guiIndentLayoutY.AddSpace(IndentAmount);
|
|
|
- guiIndentLayoutX.AddSpace(IndentAmount);
|
|
|
- guiChildLayout.AddSpace(IndentAmount);
|
|
|
-
|
|
|
- short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
|
|
|
- string bgPanelStyle = depth % 2 == 0
|
|
|
- ? EditorStyles.InspectorContentBgAlternate
|
|
|
- : EditorStyles.InspectorContentBg;
|
|
|
-
|
|
|
- GUIPanel backgroundPanel = guiContentPanel.AddPanel(backgroundDepth);
|
|
|
- GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
|
|
|
- backgroundPanel.AddElement(inspectorContentBg);
|
|
|
-
|
|
|
- for (int i = 0; i < numArrayElements; i++)
|
|
|
- {
|
|
|
- EntryRow newRow = new EntryRow(guiContentLayout);
|
|
|
- rows.Add(newRow);
|
|
|
-
|
|
|
- InspectableField childObj = CreateInspectable(i + ".", 0, depth + 1,
|
|
|
- new InspectableFieldLayout(newRow.contentLayout), array.GetProperty(i));
|
|
|
- AddChild(childObj);
|
|
|
-
|
|
|
- rows[i].Refresh(childObj, i, this);
|
|
|
- }
|
|
|
- }
|
|
|
+ SerializableArray array = property.GetArray();
|
|
|
+ newArrayField.Construct<InspectableArrayGUIRow>(title, false, array.GetLength(), layout);
|
|
|
}
|
|
|
else
|
|
|
- guiChildLayout = null;
|
|
|
+ newArrayField.Construct<InspectableArrayGUIRow>(title, true, 0, layout);
|
|
|
+
|
|
|
+ newArrayField.property = property;
|
|
|
+
|
|
|
+ return newArrayField;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- /// <inheritdoc/>
|
|
|
- protected override void Update(int layoutIndex, bool rebuildGUI)
|
|
|
- {
|
|
|
- base.Update(layoutIndex, true);
|
|
|
- BuildGUI(layoutIndex);
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected internal override object GetValue(int seqIndex)
|
|
|
+ {
|
|
|
+ SerializableArray array = property.GetArray();
|
|
|
|
|
|
- forceUpdate = false;
|
|
|
-
|
|
|
- }
|
|
|
+ return array.GetProperty(seqIndex);
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Triggered when the user clicks on the expand/collapse toggle in the title bar.
|
|
|
- /// </summary>
|
|
|
- /// <param name="expanded">Determines whether the contents were expanded or collapsed.</param>
|
|
|
- private void OnFoldoutToggled(bool expanded)
|
|
|
- {
|
|
|
- isExpanded = expanded;
|
|
|
- forceUpdate = true;
|
|
|
- }
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected internal override void SetValue(int seqIndex, object value)
|
|
|
+ {
|
|
|
+ // Setting the value should be done through the property
|
|
|
+ throw new InvalidOperationException();
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Triggered when the user clicks on the resize button on the title bar. Changes the size of the array while
|
|
|
- /// preserving existing contents.
|
|
|
- /// </summary>
|
|
|
- private void OnResizeButtonClicked()
|
|
|
- {
|
|
|
- int size = guiSizeField.Value; // TODO - Support multi-rank arrays
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected override void OnCreateButtonClicked()
|
|
|
+ {
|
|
|
+ property.SetValue(property.CreateArrayInstance(new int[1] { 0 }));
|
|
|
+ }
|
|
|
|
|
|
- Array newArray = property.CreateArrayInstance(new int[] {size});
|
|
|
- Array array = property.GetValue<Array>();
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected override void OnResizeButtonClicked()
|
|
|
+ {
|
|
|
+ int size = guiSizeField.Value; // TODO - Support multi-rank arrays
|
|
|
|
|
|
- int maxSize = MathEx.Min(size, array.Length);
|
|
|
+ Array newArray = property.CreateArrayInstance(new int[] { size });
|
|
|
+ Array array = property.GetValue<Array>();
|
|
|
|
|
|
- for (int i = 0; i < maxSize; i++)
|
|
|
- newArray.SetValue(array.GetValue(i), i);
|
|
|
+ int maxSize = MathEx.Min(size, array.Length);
|
|
|
|
|
|
- property.SetValue(newArray);
|
|
|
- }
|
|
|
+ for (int i = 0; i < maxSize; i++)
|
|
|
+ newArray.SetValue(array.GetValue(i), i);
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Triggered when the user clicks on the delete button next to the array entry. Deletes an element in the array.
|
|
|
- /// </summary>
|
|
|
- /// <param name="index">Sequential index of the element in the array to remove.</param>
|
|
|
- private void OnDeleteButtonClicked(int index)
|
|
|
- {
|
|
|
- Array array = property.GetValue<Array>();
|
|
|
+ property.SetValue(newArray);
|
|
|
+ }
|
|
|
|
|
|
- int size = MathEx.Max(0, array.Length - 1);
|
|
|
- Array newArray = property.CreateArrayInstance(new int[] { size });
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected override void OnClearButtonClicked()
|
|
|
+ {
|
|
|
+ property.SetValue<object>(null);
|
|
|
+ }
|
|
|
|
|
|
- int destIdx = 0;
|
|
|
- for (int i = 0; i < array.Length; i++)
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected internal override void OnDeleteButtonClicked(int index)
|
|
|
{
|
|
|
- if (i == index)
|
|
|
- continue;
|
|
|
+ Array array = property.GetValue<Array>();
|
|
|
|
|
|
- newArray.SetValue(array.GetValue(i), destIdx);
|
|
|
- destIdx++;
|
|
|
- }
|
|
|
+ int size = MathEx.Max(0, array.Length - 1);
|
|
|
+ Array newArray = property.CreateArrayInstance(new int[] { size });
|
|
|
|
|
|
- property.SetValue(newArray);
|
|
|
- }
|
|
|
+ int destIdx = 0;
|
|
|
+ for (int i = 0; i < array.Length; i++)
|
|
|
+ {
|
|
|
+ if (i == index)
|
|
|
+ continue;
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Triggered when the user clicks on the clone button next to the array entry. Clones an element in the array and
|
|
|
- /// adds the clone to the back of the array.
|
|
|
- /// </summary>
|
|
|
- /// <param name="index">Sequential index of the element in the array to clone.</param>
|
|
|
- private void OnCloneButtonClicked(int index)
|
|
|
- {
|
|
|
- SerializableArray array = property.GetArray();
|
|
|
+ newArray.SetValue(array.GetValue(i), destIdx);
|
|
|
+ destIdx++;
|
|
|
+ }
|
|
|
|
|
|
- int size = array.GetLength() + 1;
|
|
|
- Array newArray = property.CreateArrayInstance(new int[] { size });
|
|
|
+ property.SetValue(newArray);
|
|
|
+ }
|
|
|
|
|
|
- object clonedEntry = null;
|
|
|
- for (int i = 0; i < array.GetLength(); i++)
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected internal override void OnCloneButtonClicked(int index)
|
|
|
{
|
|
|
- object value = array.GetProperty(i).GetValue<object>();
|
|
|
+ SerializableArray array = property.GetArray();
|
|
|
|
|
|
- newArray.SetValue(value, i);
|
|
|
+ int size = array.GetLength() + 1;
|
|
|
+ Array newArray = property.CreateArrayInstance(new int[] { size });
|
|
|
|
|
|
- if (i == index)
|
|
|
+ object clonedEntry = null;
|
|
|
+ for (int i = 0; i < array.GetLength(); i++)
|
|
|
{
|
|
|
- clonedEntry = array.GetProperty(i).GetValueCopy<object>();
|
|
|
+ object value = array.GetProperty(i).GetValue<object>();
|
|
|
+
|
|
|
+ newArray.SetValue(value, i);
|
|
|
+
|
|
|
+ if (i == index)
|
|
|
+ {
|
|
|
+ clonedEntry = array.GetProperty(i).GetValueCopy<object>();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ newArray.SetValue(clonedEntry, size - 1);
|
|
|
+
|
|
|
+ property.SetValue(newArray);
|
|
|
}
|
|
|
|
|
|
- newArray.SetValue(clonedEntry, size - 1);
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected internal override void OnMoveUpButtonClicked(int index)
|
|
|
+ {
|
|
|
+ Array array = property.GetValue<Array>();
|
|
|
|
|
|
- property.SetValue(newArray);
|
|
|
- }
|
|
|
+ if ((index - 1) >= 0)
|
|
|
+ {
|
|
|
+ object previousEntry = array.GetValue(index - 1);
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Triggered when the user clicks on the move up button next to the array entry. Moves an element from the current
|
|
|
- /// array index to the one right before it, if not at zero.
|
|
|
- /// </summary>
|
|
|
- /// <param name="index">Sequential index of the element in the array to move.</param>
|
|
|
- private void OnMoveUpButtonClicked(int index)
|
|
|
- {
|
|
|
- Array array = property.GetValue<Array>();
|
|
|
+ array.SetValue(array.GetValue(index), index - 1);
|
|
|
+ array.SetValue(previousEntry, index);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if ((index - 1) >= 0)
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected internal override void OnMoveDownButtonClicked(int index)
|
|
|
{
|
|
|
- object previousEntry = array.GetValue(index - 1);
|
|
|
+ Array array = property.GetValue<Array>();
|
|
|
+
|
|
|
+ if ((index + 1) < array.Length)
|
|
|
+ {
|
|
|
+ object nextEntry = array.GetValue(index + 1);
|
|
|
|
|
|
- array.SetValue(array.GetValue(index), index - 1);
|
|
|
- array.SetValue(previousEntry, index);
|
|
|
+ array.SetValue(array.GetValue(index), index + 1);
|
|
|
+ array.SetValue(nextEntry, index);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Triggered when the user clicks on the move down button next to the array entry. Moves an element from the current
|
|
|
- /// array index to the one right after it, if the element isn't already the last element.
|
|
|
+ /// Contains GUI elements for a single entry in the array.
|
|
|
/// </summary>
|
|
|
- /// <param name="index">Sequential index of the element in the array to move.</param>
|
|
|
- private void OnMoveDownButtonClicked(int index)
|
|
|
+ private class InspectableArrayGUIRow : GUIListFieldRow
|
|
|
{
|
|
|
- Array array = property.GetValue<Array>();
|
|
|
+ private InspectableField field;
|
|
|
|
|
|
- if ((index + 1) < array.Length)
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected override GUILayoutX CreateGUI(GUILayoutY layout)
|
|
|
{
|
|
|
- object nextEntry = array.GetValue(index + 1);
|
|
|
+ SerializableProperty property = GetValue<SerializableProperty>();
|
|
|
|
|
|
- array.SetValue(array.GetValue(index), index + 1);
|
|
|
- array.SetValue(nextEntry, index);
|
|
|
+ field = CreateInspectable(seqIndex + ".", 0, 0,
|
|
|
+ new InspectableFieldLayout(layout), property);
|
|
|
+
|
|
|
+ return field.GetTitleLayout();
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Triggered when the user clicks on the create button on the title bar. Creates a brand new array with zero
|
|
|
- /// elements in the place of the current array.
|
|
|
- /// </summary>
|
|
|
- private void OnCreateButtonClicked()
|
|
|
- {
|
|
|
- property.SetValue(property.CreateArrayInstance(new int[1] { 0 }));
|
|
|
- }
|
|
|
+ /// <inheritdoc/>
|
|
|
+ protected internal override bool Refresh(out bool rebuildGUI)
|
|
|
+ {
|
|
|
+ if (field.IsModified())
|
|
|
+ {
|
|
|
+ // If rebuild GUI is set to true, we will just rebuild the entire inspectable field, so no need to
|
|
|
+ // call Update on the existing one.
|
|
|
+ if (!field.GetRebuildOnModify())
|
|
|
+ {
|
|
|
+ rebuildGUI = false;
|
|
|
+ return field.Refresh(0);
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Triggered when the user clicks on the clear button on the title bar. Deletes the current array and sets
|
|
|
- /// the reference to the array in the parent object to null.
|
|
|
- /// </summary>
|
|
|
- private void OnClearButtonClicked()
|
|
|
- {
|
|
|
- property.SetValue<object>(null);
|
|
|
+ rebuildGUI = true;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ rebuildGUI = false;
|
|
|
+ return field.Refresh(0);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|