static Func <Array> drawEditActions(Array array, Type elementType, int index) { if (EntitasEditorLayout.MiniButtonLeft("↑")) { if (index > 0) { return(() => { var otherIndex = index - 1; var other = array.GetValue(otherIndex); array.SetValue(array.GetValue(index), otherIndex); array.SetValue(other, index); return array; }); } } if (EntitasEditorLayout.MiniButtonMid("↓")) { if (index < array.Length - 1) { return(() => { var otherIndex = index + 1; var other = array.GetValue(otherIndex); array.SetValue(array.GetValue(index), otherIndex); array.SetValue(other, index); return array; }); } } if (EntitasEditorLayout.MiniButtonMid("+")) { object defaultValue; if (EntityDrawer.CreateDefault(elementType, out defaultValue)) { return(() => arrayInsertAt(array, elementType, defaultValue, index + 1)); } } if (EntitasEditorLayout.MiniButtonRight("-")) { return(() => arrayRemoveAt(array, elementType, index)); } return(null); }
/* * * Rank 2 * */ Array drawRank2(Array array, string memberName, Type elementType, object target) { 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.DrawObjectMember(elementType, memberName + "[" + localIndex1 + ", " + localIndex2 + "]", array.GetValue(localIndex1, localIndex2), target, (newComponent, newValue) => array.SetValue(newValue, localIndex1, localIndex2)); } EditorGUILayout.Space(); } return(array); }
IList drawAddElement(IList list, string memberName, Type elementType) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(memberName, "empty"); if (EntitasEditorLayout.MiniButton("add " + elementType.ToCompilableString().ShortTypeName())) { object defaultValue; if (EntityDrawer.CreateDefault(elementType, out defaultValue)) { list.Add(defaultValue); } } } EditorGUILayout.EndHorizontal(); return(list); }
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target) { var list = (IList)value; var elementType = memberType.GetGenericArguments()[0]; if (list.Count == 0) { list = drawAddElement(list, memberName, elementType); } else { EditorGUILayout.LabelField(memberName); } var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = indent + 1; Func <IList> editAction = null; for (int i = 0; i < list.Count; i++) { var localIndex = i; EditorGUILayout.BeginHorizontal(); { EntityDrawer.DrawObjectMember(elementType, memberName + "[" + localIndex + "]", list[localIndex], target, (newComponent, newValue) => list[localIndex] = newValue); var action = drawEditActions(list, elementType, localIndex); if (action != null) { editAction = action; } } EditorGUILayout.EndHorizontal(); } if (editAction != null) { list = editAction(); } EditorGUI.indentLevel = indent; return(list); }
Array drawAddElement(Array array, string memberName, Type elementType) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(memberName, "empty"); if (EntitasEditorLayout.MiniButton("add " + elementType.ToCompilableString().ShortTypeName())) { object defaultValue; if (EntityDrawer.CreateDefault(elementType, out defaultValue)) { var newArray = Array.CreateInstance(elementType, 1); newArray.SetValue(defaultValue, 0); array = newArray; } } } EditorGUILayout.EndHorizontal(); return(array); }
/* * * Rank 1 * */ Array drawRank1(Array array, string memberName, Type elementType, int indent, object target) { var length = array.GetLength(0); if (length == 0) { array = drawAddElement(array, memberName, elementType); } 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.DrawObjectMember(elementType, memberName + "[" + localIndex + "]", array.GetValue(localIndex), target, (newComponent, newValue) => array.SetValue(newValue, localIndex)); var action = drawEditActions(array, elementType, localIndex); if (action != null) { editAction = action; } } EditorGUILayout.EndHorizontal(); } if (editAction != null) { array = editAction(); } return(array); }
public override void OnInspectorGUI() { if (targets.Length == 1) { var entityBehaviour = (EntityBehaviour)target; EntityDrawer.DrawEntity(entityBehaviour.pool, entityBehaviour.entity); } else { var entityBehaviour = (EntityBehaviour)target; var entities = targets .Select(t => ((EntityBehaviour)t).entity) .ToArray(); EntityDrawer.DrawMultipleEntities(entityBehaviour.pool, entities); } if (target != null) { EditorUtility.SetDirty(target); } }
/* * * Rank 3 * */ Array drawRank3(Array array, string memberName, Type elementType, IComponent component) { 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.DrawComponentMember(elementType, memberName + "[" + localIndex1 + ", " + localIndex2 + " ," + localIndex3 + "]", array.GetValue(localIndex1, localIndex2, localIndex3), component, (newComponent, newValue) => array.SetValue(newValue, localIndex1, localIndex2, localIndex3)); } EditorGUILayout.Space(); } EditorGUILayout.Space(); } return(array); }
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); }
void Awake() { EntityDrawer.Initialize(); }
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, 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); }
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target) { var dictionary = (IDictionary)value; var keyType = memberType.GetGenericArguments()[0]; var valueType = memberType.GetGenericArguments()[1]; var targetType = target.GetType(); if (!_keySearchTexts.ContainsKey(targetType)) { _keySearchTexts.Add(targetType, string.Empty); } EditorGUILayout.BeginHorizontal(); { if (dictionary.Count == 0) { EditorGUILayout.LabelField(memberName, "empty"); _keySearchTexts[targetType] = string.Empty; } else { EditorGUILayout.LabelField(memberName); } var keyTypeName = keyType.ToCompilableString().ShortTypeName(); var valueTypeName = valueType.ToCompilableString().ShortTypeName(); if (EntitasEditorLayout.MiniButton("new <" + keyTypeName + ", " + valueTypeName + ">")) { 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) { var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = indent + 1; if (dictionary.Count > 5) { EditorGUILayout.Space(); _keySearchTexts[targetType] = EntitasEditorLayout.SearchTextField(_keySearchTexts[targetType]); } EditorGUILayout.Space(); var keys = new ArrayList(dictionary.Keys); for (int i = 0; i < keys.Count; i++) { var key = keys[i]; if (EntitasEditorLayout.MatchesSearchString(key.ToString().ToLower(), _keySearchTexts[targetType].ToLower())) { EntityDrawer.DrawObjectMember(keyType, "key", key, target, (newComponent, newValue) => { var tmpValue = dictionary[key]; dictionary.Remove(key); if (newValue != null) { dictionary[newValue] = tmpValue; } }); EntityDrawer.DrawObjectMember(valueType, "value", dictionary[key], target, (newComponent, newValue) => dictionary[key] = newValue); EditorGUILayout.Space(); } } EditorGUI.indentLevel = indent; } return(dictionary); }
public object DrawAndGetNewValue(Type memberType, string memberName, object value, Entity entity, int index, IComponent component) { var elementType = memberType.GetGenericArguments()[0]; var itemsToRemove = new ArrayList(); var itemsToAdd = new ArrayList(); var isEmpty = !((IEnumerable)value).GetEnumerator().MoveNext(); EditorGUILayout.BeginHorizontal(); { if (isEmpty) { EditorGUILayout.LabelField(memberName, "empty"); } else { EditorGUILayout.LabelField(memberName); } if (GUILayout.Button("+", GUILayout.Width(19), GUILayout.Height(14))) { object defaultValue; if (EntityDrawer.CreateDefault(elementType, out defaultValue)) { itemsToAdd.Add(defaultValue); } } } EditorGUILayout.EndHorizontal(); if (!isEmpty) { EditorGUILayout.Space(); var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = indent + 1; foreach (var item in (IEnumerable)value) { EditorGUILayout.BeginHorizontal(); { var newItem = EntityDrawer.DrawAndGetNewValue(elementType, string.Empty, item, entity, index, component); if (EntityDrawer.DidValueChange(item, newItem)) { itemsToRemove.Add(item); itemsToAdd.Add(newItem); } if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) { itemsToRemove.Add(item); } } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel = indent; } foreach (var item in itemsToRemove) { memberType.GetMethod("Remove").Invoke(value, new [] { item }); } foreach (var item in itemsToAdd) { memberType.GetMethod("Add").Invoke(value, new [] { item }); } return(value); }
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target) { var elementType = memberType.GetGenericArguments()[0]; var itemsToRemove = new ArrayList(); var itemsToAdd = new ArrayList(); var isEmpty = !((IEnumerable)value).GetEnumerator().MoveNext(); EditorGUILayout.BeginHorizontal(); { if (isEmpty) { EditorGUILayout.LabelField(memberName, "empty"); } else { EditorGUILayout.LabelField(memberName); } if (EntitasEditorLayout.MiniButton("new " + elementType.ToCompilableString().ShortTypeName())) { object defaultValue; if (EntityDrawer.CreateDefault(elementType, out defaultValue)) { itemsToAdd.Add(defaultValue); } } } EditorGUILayout.EndHorizontal(); if (!isEmpty) { EditorGUILayout.Space(); var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = indent + 1; foreach (var item in (IEnumerable)value) { EditorGUILayout.BeginHorizontal(); { EntityDrawer.DrawObjectMember(elementType, string.Empty, item, target, (newComponent, newValue) => { itemsToRemove.Add(item); itemsToAdd.Add(newValue); }); if (EntitasEditorLayout.MiniButton("-")) { itemsToRemove.Add(item); } } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel = indent; } foreach (var item in itemsToRemove) { memberType.GetMethod("Remove").Invoke(value, new [] { item }); } foreach (var item in itemsToAdd) { memberType.GetMethod("Add").Invoke(value, new [] { item }); } return(value); }