/* * * Rank 3 * */ private Array DrawRank3(Array array, string memberName, Type elementType, object target) { EditorGUILayout.LabelField(memberName); for (var i = 0; i < array.GetLength(0); i++) { var localIndex1 = i; for (var j = 0; j < array.GetLength(1); j++) { var localIndex2 = j; for (var k = 0; k < array.GetLength(2); k++) { var localIndex3 = k; EntityDrawer.DrawObjectMember( elementType, memberName + "[" + localIndex1 + ", " + localIndex2 + " ," + localIndex3 + "]", array.GetValue(localIndex1, localIndex2, localIndex3), target, (newComponent, newValue) => array.SetValue( newValue, localIndex1, localIndex2, localIndex3)); } EditorGUILayout.Space(); } EditorGUILayout.Space(); } return(array); }
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 (var 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); }
/* * * Rank 1 * */ private 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 (var 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 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 (EditorGUILayoutTools.MiniButton("new <" + keyTypeName + ", " + valueTypeName + ">")) { if (EntityDrawer.CreateDefault(keyType, out var defaultKey)) { if (EntityDrawer.CreateDefault(valueType, out var 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] = EditorGUILayoutTools.SearchTextField(_keySearchTexts[targetType]); } EditorGUILayout.Space(); var keys = new ArrayList(dictionary.Keys); for (var i = 0; i < keys.Count; i++) { var key = keys[i]; if (EditorGUILayoutTools.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, 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 (EditorGUILayoutTools.MiniButton("new " + elementType.ToCompilableString().ShortTypeName())) { if (EntityDrawer.CreateDefault(elementType, out var 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 (EditorGUILayoutTools.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); }