static public void Resize(this EditProperty_Array item, int new_size) { int current_size; if (item.TryGetNumberElements(out current_size)) { if (new_size < 0) { new_size = 0; } if (new_size != current_size) { if (new_size > current_size) { for (int i = current_size; i < new_size; i++) { item.InsertElement(i); } } else { for (int i = current_size - 1; i >= new_size; i--) { item.RemoveElement(i); } } } } }
static public void InsertElementAfter(this EditProperty_Array item, EditProperty element) { item.InsertElement(item.GetIndexOfElement(element) + 1); }
protected override EditorGUIElement PushState() { int number_elements; EditProperty_Array property = GetEditPropertyArray(); EditorGUIElement_Container_Auto container = new EditorGUIElement_Container_Auto_Simple_VerticalStrip(); Type array_type = property.GetPropertyType().GetIEnumerableType(); if (property.TryGetNumberElements(out number_elements)) { EditorGUIElement_Container_Flow_Line length_strip = container.AddChild(new EditorGUIElement_Container_Flow_Line()) .LabelWithGUIContent("Length"); length_strip.AddWeightedChild(0.6f, new EditorGUIElement_EditPropertyArray_ArraySize(property)); length_strip.AddWeightedChild(0.4f, new EditorGUIElement_Button("+", delegate() { property.InsertElement(0); })); if (number_elements <= 0) { if (array_type.CanBeTreatedAs <UnityEngine.Object>()) { length_strip.AddWeightedChild(0.6f, new EditorGUIElement_DropZone("Drag + Drop", array_type, l => property.ForceContentValues(l) )); } } else { for (int i = 0; i < number_elements; i++) { EditProperty sub_property = property.GetElement(i); EditorGUIElement control = sub_property.CreateEditorGUIElement(); EditorGUIElement_Container_Auto_Simple_HorizontalStrip buttons = new EditorGUIElement_Container_Auto_Simple_HorizontalStrip(); buttons.AddChild(new EditorGUIElement_Button("+v", delegate() { property.InsertElementAfter(sub_property); })); buttons.AddChild(new EditorGUIElement_Button("+^", delegate() { property.InsertElementBefore(sub_property); })); buttons.AddChild(new EditorGUIElement_Button("-", delegate() { property.RemoveElement(sub_property); })); container.AddChild(new EditorGUIElement_Sideboard( new EditorGUIFlowElement(control, EditorGUIElementDimension.Weighted(1.0f)), new EditorGUIFlowElement(buttons, EditorGUIElementDimension.Fixed(100.0f)) )).LabelWithIndex(property, i, () => ForceRecreation()); } } } else { container.AddChild(new EditorGUIElement_Text("--Disabled(Array lengths are not unified)--")); } return(container); }
static public void InsertElementBefore(this EditProperty_Array item, EditProperty element) { item.InsertElement(item.GetIndexOfElement(element)); }