private void ParseBindings(TreeViewItem parent, string actionMapName, string actionName, SerializedProperty bindingsArrayProperty, int depth) { var bindingsCount = InputActionSerializationHelpers.GetBindingCount(bindingsArrayProperty, actionName); CompositeGroupTreeItem compositeGroupTreeItem = null; for (var j = 0; j < bindingsCount; j++) { var bindingProperty = InputActionSerializationHelpers.GetBinding(bindingsArrayProperty, actionName, j); var bindingsItem = new BindingTreeItem(actionMapName, bindingProperty, j); bindingsItem.depth = depth; if (bindingsItem.isComposite) { compositeGroupTreeItem = new CompositeGroupTreeItem(actionMapName, bindingProperty, j); compositeGroupTreeItem.depth = depth; parent.AddChild(compositeGroupTreeItem); continue; } if (bindingsItem.isPartOfComposite) { var compositeItem = new CompositeTreeItem(actionMapName, bindingProperty, j); compositeItem.depth = depth + 1; if (compositeGroupTreeItem != null) { compositeGroupTreeItem.AddChild(compositeItem); } continue; } compositeGroupTreeItem = null; parent.AddChild(bindingsItem); } }
private void DeleteSelectedRows() { var rows = m_TreeView.GetSelectedRows().ToArray(); var rowTypes = rows.Select(r => r.GetType()).Distinct().ToList(); // Don't allow to delete different types at once because it's hard to handle. if (rowTypes.Count() > 1) { EditorApplication.Beep(); return; } // Remove composite bindings foreach (var compositeGroup in FindRowsToDeleteOfType <CompositeGroupTreeItem>(rows)) { var action = (compositeGroup.parent as ActionTreeItem); for (var i = compositeGroup.children.Count - 1; i >= 0; i--) { var composite = (CompositeTreeItem)compositeGroup.children[i]; action.RemoveBinding(composite.index); } action.RemoveBinding(compositeGroup.index); } // Remove bindings foreach (var bindingRow in FindRowsToDeleteOfType <BindingTreeItem>(rows)) { var action = bindingRow.parent as ActionTreeItem; action.RemoveBinding(bindingRow.index); } // Remove actions foreach (var actionRow in FindRowsToDeleteOfType <ActionTreeItem>(rows)) { var action = actionRow; var actionMap = actionRow.parent as ActionMapTreeItem; var bindingsCount = InputActionSerializationHelpers.GetBindingCount(actionMap.bindingsProperty, action.actionName); for (var i = bindingsCount - 1; i >= 0; i--) { action.RemoveBinding(i); } actionMap.DeleteAction(actionRow.index); } //Remove action maps foreach (var mapRow in FindRowsToDeleteOfType <ActionMapTreeItem>(rows)) { if (m_SerializedObject == null) { throw new InvalidOperationException("Deleting action map is not a valid operation"); } InputActionSerializationHelpers.DeleteActionMap(m_SerializedObject, mapRow.index); } m_TreeView.SetSelection(new List <int>()); m_Apply(); }
void ParseActionMap(ActionMapTreeItem actionMapItem, InputActionMap actionMap, SerializedProperty actionMapProperty) { var bindingsArrayProperty = actionMapItem.bindingsProperty; var actionsArrayProperty = actionMapItem.actionsProperty; for (var i = 0; i < actionsArrayProperty.arraySize; i++) { var action = actionMap.actions[i]; var actionItem = new ActionTreeItem(actionMapProperty, action, actionsArrayProperty, i); var actionName = action.name; var bindingsCount = InputActionSerializationHelpers.GetBindingCount(bindingsArrayProperty, actionName); bool actionSearchMatched = IsSearching() && actionName.ToLower().Contains(m_NameFilter.ToLower()); CompositeGroupTreeItem compositeGroupTreeItem = null; for (var j = 0; j < bindingsCount; j++) { var bindingProperty = InputActionSerializationHelpers.GetBinding(bindingsArrayProperty, actionName, j); var binding = action.bindings[j]; if (!string.IsNullOrEmpty(m_GroupFilter) && !binding.groups.Split(';').Contains(m_GroupFilter)) { continue; } if (binding.isComposite) { compositeGroupTreeItem = new CompositeGroupTreeItem(actionMap.name, binding, bindingProperty, j); actionItem.AddChild(compositeGroupTreeItem); continue; } if (binding.isPartOfComposite) { var compositeItem = new CompositeTreeItem(actionMap.name, binding, bindingProperty, j); if (compositeGroupTreeItem != null) { compositeGroupTreeItem.AddChild(compositeItem); } continue; } compositeGroupTreeItem = null; var bindingsItem = new BindingTreeItem(actionMap.name, binding, bindingProperty, j); if (!actionSearchMatched && IsSearching() && !binding.path.ToLower().Contains(m_NameFilter.ToLower())) { continue; } actionItem.AddChild(bindingsItem); } if (actionSearchMatched || IsSearching() && actionItem.children != null && actionItem.children.Any()) { actionMapItem.AddChild(actionItem); } else if (!IsSearching()) { actionMapItem.AddChild(actionItem); } } }
public ActionTreeItem(SerializedProperty actionMapProperty, SerializedProperty setProperty, int index) : base(setProperty, index) { m_ActionMapProperty = actionMapProperty; actionName = elementProperty.FindPropertyRelative("m_Name").stringValue; bindingsStartIndex = InputActionSerializationHelpers.GetBindingsStartIndex(m_ActionMapProperty.FindPropertyRelative("m_Bindings"), actionName); bindingsCount = InputActionSerializationHelpers.GetBindingCount(m_ActionMapProperty.FindPropertyRelative("m_Bindings"), actionName); displayName = actionName; var actionMapName = m_ActionMapProperty.FindPropertyRelative("m_Name").stringValue; id = (actionMapName + "/" + displayName).GetHashCode(); }
public ActionTreeItem(SerializedProperty actionMapProperty, SerializedProperty actionProperty, int index) : base(actionProperty, index) { m_ActionMapProperty = actionMapProperty; actionName = elementProperty.FindPropertyRelative("m_Name").stringValue; if (m_ActionMapProperty != null) { bindingsStartIndex = InputActionSerializationHelpers.GetBindingsStartIndex(m_ActionMapProperty.FindPropertyRelative("m_Bindings"), actionName); bindingsCount = InputActionSerializationHelpers.GetBindingCount(m_ActionMapProperty.FindPropertyRelative("m_Bindings"), actionName); } else { bindingsStartIndex = 0; bindingsCount = InputActionSerializationHelpers.GetBindingCount(elementProperty.FindPropertyRelative("m_SingletonActionBindings"), actionName); } displayName = actionName; id = GetIdForName(displayName); }
protected void ParseBindings(TreeViewItem parent, string actionMapName, string actionName, SerializedProperty bindingsArrayProperty, int depth) { bool actionSearchMatched = IsSearching() && actionName.ToLower().Contains(m_NameFilter.ToLower()); var bindingsCount = InputActionSerializationHelpers.GetBindingCount(bindingsArrayProperty, actionName); CompositeGroupTreeItem compositeGroupTreeItem = null; for (var j = 0; j < bindingsCount; j++) { var bindingProperty = InputActionSerializationHelpers.GetBinding(bindingsArrayProperty, actionName, j); var bindingsItem = new BindingTreeItem(actionMapName, bindingProperty, j); bindingsItem.depth = depth; if (!string.IsNullOrEmpty(m_GroupFilter) && !bindingsItem.groups.Split(';').Contains(m_GroupFilter)) { continue; } if (bindingsItem.isComposite) { compositeGroupTreeItem = new CompositeGroupTreeItem(actionMapName, bindingProperty, j); compositeGroupTreeItem.depth = depth; parent.AddChild(compositeGroupTreeItem); continue; } if (bindingsItem.isPartOfComposite) { var compositeItem = new CompositeTreeItem(actionMapName, bindingProperty, j); compositeItem.depth = depth + 1; if (compositeGroupTreeItem != null) { compositeGroupTreeItem.AddChild(compositeItem); } continue; } compositeGroupTreeItem = null; if (!actionSearchMatched && IsSearching() && !bindingsItem.path.ToLower().Contains(m_NameFilter.ToLower())) { continue; } parent.AddChild(bindingsItem); } }