public static void DrawComponents(IEntity entity) { var unfoldedComponents = GetUnfoldedComponents(entity); var componentMemberSearch = GetComponentMemberSearch(entity); EditorGUILayoutTools.BeginVerticalBox(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel); if (EditorGUILayoutTools.MiniButtonLeft("▸")) { for (var i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = false; } } if (EditorGUILayoutTools.MiniButtonRight("▾")) { for (var i = 0; i < unfoldedComponents.Length; i++) { unfoldedComponents[i] = true; } } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); var index = DrawAddComponentMenu(entity); if (index >= 0) { var componentType = entity.ContextInfo.componentTypes[index]; var component = entity.CreateComponent(index, componentType); entity.AddComponent(index, component); } EditorGUILayout.Space(); ComponentNameSearchString = EditorGUILayoutTools.SearchTextField(ComponentNameSearchString); EditorGUILayout.Space(); var indices = entity.GetComponentIndices(); var components = entity.GetComponents(); for (var i = 0; i < components.Length; i++) { DrawComponent( unfoldedComponents, componentMemberSearch, entity, indices[i], components[i]); } EditorGUILayoutTools.EndVerticalBox(); }
private static Func <IList> DrawEditActions(IList list, Type elementType, int index) { if (EditorGUILayoutTools.MiniButtonLeft("↑")) { if (index > 0) { return(() => { var otherIndex = index - 1; var other = list[otherIndex]; list[otherIndex] = list[index]; list[index] = other; return list; }); } } if (EditorGUILayoutTools.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 (EditorGUILayoutTools.MiniButtonMid("+")) { if (EntityDrawer.CreateDefault(elementType, out var defaultValue)) { var insertAt = index + 1; return(() => { list.Insert(insertAt, defaultValue); return list; }); } } if (EditorGUILayoutTools.MiniButtonRight("-")) { var removeAt = index; return(() => { list.RemoveAt(removeAt); return list; }); } return(null); }
private static Func <Array> DrawEditActions(Array array, Type elementType, int index) { if (EditorGUILayoutTools.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 (EditorGUILayoutTools.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 (EditorGUILayoutTools.MiniButtonMid("+")) { if (EntityDrawer.CreateDefault(elementType, out var defaultValue)) { return(() => ArrayInsertAt( array, elementType, defaultValue, index + 1)); } } if (EditorGUILayoutTools.MiniButtonRight("-")) { return(() => ArrayRemoveAt(array, elementType, index)); } return(null); }