public EditorGUIElementAttachment_Singular_Label_Index(EditProperty_Array a, int i, Process p) { property = a; index = i; process = p; }
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 SetElementValue(this EditProperty_Array item, int index, object value) { EditProperty_Single_Value property; if (item.TryGetElementValue(index, out property)) { property.SetContentValues(value); } }
static public bool TryGetElementValue(this EditProperty_Array item, int index, out object value) { EditProperty_Single_Value property; if (item.TryGetElementValue(index, out property)) { return(property.TryGetContentValues(out value)); } value = null; return(false); }
static public bool IsIndexValid(this EditProperty_Array item, int index) { int number_elements; if (item.TryGetNumberElements(out number_elements)) { if (index >= 0 && index < number_elements) { return(true); } } return(false); }
protected override EditorGUIElement PushState() { EditTarget target = GetProperty().GetContents(); EditorGUIElement_Container_Flow_Multiline container = new EditorGUIElement_Container_Flow_Multiline(); if (target.IsValid()) { EditProperty_Array property = target.ForcePropertyArray("percents"); container.AddFixedChild(32.0f, new EditorGUIElement_EditPropertyArray_ArraySize(property)); container.AddWeightedChild(1.0f, new EditorGUIElement_EditPropertyArray_FloatSequence(property)); } return(container); }
static public bool TryGetElementValue <T>(this EditProperty_Array item, int index, out T value) { object temp; if (item.TryGetElementValue(index, out temp)) { if (temp.Convert <T>(out value)) { return(true); } } value = default(T); return(false); }
protected override void DrawArrayInternal(Rect rect, int array_size) { EditProperty_Array property = GetProperty(); EditorGUI.DrawRect(border_rect, Color.black); EditorGUI.DrawRect(background_rect, Color.gray); float x = background_rect.xMin; float y = background_rect.yMax; float element_width = background_rect.width / array_size; float element_max_height = background_rect.height; for (int i = 0; i < array_size; i++) { float value; if (property.TryGetElementValue <float>(i, out value)) { float height = element_max_height * value.ConvertFromRangeToPercent(min_value, max_value); EditorGUI.DrawRect(RectExtensions.CreateMinMaxRect( new Vector2(x, y), new Vector2(x + element_width, y - height) ), Color.cyan); } x += element_width; } Vector2 percent; if (GUIExtensions.MousePercentArea(background_rect, out percent, true, true)) { int index = (int)(array_size * percent.x); float magnitude = 1.0f - percent.y; if (property.IsIndexValid(index)) { property.SetElementValue(index, magnitude.ConvertFromPercentToRange(min_value, max_value)); } } }
static public void InsertElementAfter(this EditProperty_Array item, EditProperty element) { item.InsertElement(item.GetIndexOfElement(element) + 1); }
public EditorGUIElement_EditPropertyArray_ArraySize(EditProperty_Array p) : base(p) { }
public EditorGUIElement_EditPropertyArray_FloatSequence(EditProperty_Array p) : this(p, 1.0f) { }
static public bool TryGetElementValue(this EditProperty_Array item, int index, out EditProperty_Single_Value value) { return(item.GetElement(index).Convert <EditProperty_Single_Value>(out value)); }
static public void MoveElement(this EditProperty_Array item, EditProperty element, int dst) { item.MoveElement(item.GetIndexOfElement(element), dst); }
static public void RemoveElement(this EditProperty_Array item, EditProperty element) { item.RemoveElement(item.GetIndexOfElement(element)); }
public EditorGUIElement_EditPropertyArray_FloatSequence(EditProperty_Array p, float min, float max) : base(p) { min_value = min; max_value = max; }
public EditorGUIElement_EditPropertyArray_FloatSequence(EditProperty_Array p, float max) : this(p, 0.0f, max) { }
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 T LabelWithIndex <T>(this T item, EditProperty_Array a, int i, Process p) where T : EditorGUIElement { item.AddAttachment(new EditorGUIElementAttachment_Singular_Label_Index(a, i, p)); return(item); }
public EditorGUIElement_Complex_EditPropertyArray_Generic(EditProperty_Array p) : base(p) { }
public EditorGUIElement_EditPropertyArray(EditProperty_Array p) { property = p; }
static public void InsertElementBefore(this EditProperty_Array item, EditProperty element) { item.InsertElement(item.GetIndexOfElement(element)); }