public static DrawAndSetElement ( |
||
memberType | ||
memberName | string | |
value | object | |
entity | System.Entity | |
index | int | |
component | IComponent | |
setValue | object>.Action | |
Résultat | void |
public object DrawAndGetNewValue(Type memberType, string memberName, object value, Entity entity, int index, IComponent component) { var dictionary = (IDictionary)value; var keyType = memberType.GetGenericArguments()[0]; var valueType = memberType.GetGenericArguments()[1]; EditorGUILayout.BeginHorizontal(); { if (dictionary.Count == 0) { EditorGUILayout.LabelField(memberName, "empty"); } else { EditorGUILayout.LabelField(memberName); } if (GUILayout.Button("+", GUILayout.Width(19), GUILayout.Height(14))) { object defaultKey; if (EntityDrawer.CreateDefault(keyType, out defaultKey)) { object defaultValue; if (EntityDrawer.CreateDefault(valueType, out defaultValue)) { dictionary[defaultKey] = defaultValue; } } } } EditorGUILayout.EndHorizontal(); if (dictionary.Count > 0) { EditorGUILayout.Space(); var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = indent + 1; var keys = new ArrayList(dictionary.Keys); for (int i = 0; i < keys.Count; i++) { var key = keys[i]; EntityDrawer.DrawAndSetElement(keyType, "key", key, entity, index, component, (newComponent, newValue) => { var tmpValue = dictionary[key]; dictionary.Remove(key); if (newValue != null) { dictionary[newValue] = tmpValue; } }); EntityDrawer.DrawAndSetElement(valueType, "value", dictionary[key], entity, index, component, (newComponent, newValue) => dictionary[key] = newValue); EditorGUILayout.Space(); } EditorGUI.indentLevel = indent; } return(dictionary); }
public object DrawAndGetNewValue(Type memberType, string memberName, object value, IEntity entity, int index, IComponent component) { var list = (IList)value; var elementType = memberType.GetGenericArguments()[0]; if (list.Count == 0) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(memberName, "empty"); if (GUILayout.Button("Add element", GUILayout.Height(14))) { object defaultValue; if (EntityDrawer.CreateDefault(elementType, out defaultValue)) { list.Add(defaultValue); } } } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.LabelField(memberName); } var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = indent + 1; Action editAction = null; for (int i = 0; i < list.Count; i++) { EditorGUILayout.BeginHorizontal(); { EntityDrawer.DrawAndSetElement(elementType, memberName + "[" + i + "]", list[i], entity, index, component, (newComponent, newValue) => list[i] = newValue); if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) { var removeAt = i; editAction = () => list.RemoveAt(removeAt); } if (GUILayout.Button("▴", GUILayout.Width(19), GUILayout.Height(14))) { object defaultValue; if (EntityDrawer.CreateDefault(elementType, out defaultValue)) { var insertAt = i; editAction = () => list.Insert(insertAt, defaultValue); } } if (GUILayout.Button("▾", GUILayout.Width(19), GUILayout.Height(14))) { object defaultValue; if (EntityDrawer.CreateDefault(elementType, out defaultValue)) { var insertAt = i + 1; editAction = () => list.Insert(insertAt, defaultValue); } } } EditorGUILayout.EndHorizontal(); } if (editAction != null) { editAction(); } EditorGUI.indentLevel = indent; return(list); }
public object DrawAndGetNewValue(Type memberType, string memberName, object value, Entity entity, int index, IComponent component) { var array = (Array)value; var elementType = memberType.GetElementType(); var indent = EditorGUI.indentLevel; if (array.Rank == 1) { var length = array.GetLength(0); if (length == 0) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(memberName, "empty"); if (GUILayout.Button("Add element", GUILayout.Height(14))) { object defaultValue; if (EntityDrawer.CreateDefault(elementType, out defaultValue)) { var newArray = Array.CreateInstance(elementType, 1); newArray.SetValue(defaultValue, 0); array = newArray; } } } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.LabelField(memberName); } EditorGUI.indentLevel = indent + 1; Func <Array> editAction = null; for (int i = 0; i < length; i++) { var localIndex = i; EditorGUILayout.BeginHorizontal(); { EntityDrawer.DrawAndSetElement(elementType, memberName + "[" + localIndex + "]", array.GetValue(localIndex), entity, index, component, (newComponent, newValue) => array.SetValue(newValue, localIndex)); var action = drawEditActions(array, elementType, localIndex); if (action != null) { editAction = action; } } EditorGUILayout.EndHorizontal(); } if (editAction != null) { array = editAction(); } } else if (array.Rank == 2) { EditorGUILayout.LabelField(memberName); for (int i = 0; i < array.GetLength(0); i++) { var localIndex1 = i; for (int j = 0; j < array.GetLength(1); j++) { var localIndex2 = j; EntityDrawer.DrawAndSetElement(elementType, memberName + "[" + localIndex1 + ", " + localIndex2 + "]", array.GetValue(localIndex1, localIndex2), entity, index, component, (newComponent, newValue) => array.SetValue(newValue, localIndex1, localIndex2)); } EditorGUILayout.Space(); } } else if (array.Rank == 3) { EditorGUILayout.LabelField(memberName); for (int i = 0; i < array.GetLength(0); i++) { var localIndex1 = i; for (int j = 0; j < array.GetLength(1); j++) { var localIndex2 = j; for (int k = 0; k < array.GetLength(2); k++) { var localIndex3 = k; EntityDrawer.DrawAndSetElement(elementType, memberName + "[" + localIndex1 + ", " + localIndex2 + " ," + localIndex3 + "]", array.GetValue(localIndex1, localIndex2, localIndex3), entity, index, component, (newComponent, newValue) => array.SetValue(newValue, localIndex1, localIndex2, localIndex3)); } EditorGUILayout.Space(); } EditorGUILayout.Space(); } } EditorGUI.indentLevel = indent; return(array); }