static Func <IList> drawEditActions(IList list, Type elementType, int index) { if (EntitasEditorLayout.MiniButtonLeft("↑")) { if (index > 0) { return(() => { var otherIndex = index - 1; var other = list[otherIndex]; list[otherIndex] = list[index]; list[index] = other; return list; }); } } if (EntitasEditorLayout.MiniButtonMid("↓")) { if (index < list.Count - 1) { return(() => { var otherIndex = index + 1; var other = list[otherIndex]; list[otherIndex] = list[index]; list[index] = other; return list; }); } } if (EntitasEditorLayout.MiniButtonMid("+")) { object defaultValue; if (EntityDrawer.CreateDefault(elementType, out defaultValue)) { var insertAt = index + 1; return(() => { list.Insert(insertAt, defaultValue); return list; }); } } if (EntitasEditorLayout.MiniButtonRight("-")) { var removeAt = index; return(() => { list.RemoveAt(removeAt); return list; }); } return(null); }
public static void DrawComponents(IContext context, IEntity entity) { var unfoldedComponents = getUnfoldedComponents(context); var componentMemberSearch = getComponentMemberSearch(context); EntitasEditorLayout.BeginVerticalBox(); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel); if (EntitasEditorLayout.MiniButtonLeft("▸")) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = false; } } if (EntitasEditorLayout.MiniButtonRight("▾")) { for (int i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); var index = drawAddComponentMenu(context); if (index >= 0) { var componentType = entity.ContextInfo.ComponentTypes[index]; var component = entity.CreateComponent(index, componentType); entity.AddComponent(index, component); } EditorGUILayout.Space(); componentNameSearchString = EntitasEditorLayout.SearchTextField(componentNameSearchString); EditorGUILayout.Space(); var indices = entity.GetComponentIndices(); var components = entity.GetComponents(); for (int i = 0; i < components.Length; i++) { DrawComponent(unfoldedComponents, componentMemberSearch, context, entity, indices[i], components[i]); } } EntitasEditorLayout.EndVerticalBox(); }
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); }