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); } }
void DrawBindingField(Rect rect, Rect editBtn, SerializedProperty pathProperty) { var path = pathProperty.stringValue; if (m_ManualEditMode || string.IsNullOrEmpty(BindingTreeItem.ParseName(path))) { EditorGUI.BeginChangeCheck(); path = EditorGUI.DelayedTextField(rect, path); if (EditorGUI.EndChangeCheck()) { pathProperty.stringValue = path; OnBindingModified(pathProperty); } if (GUI.Button(editBtn, "˅")) { rect.x += editBtn.width; ShowInputControlPicker(rect, pathProperty); } } else { var parsedPath = BindingTreeItem.ParseName(path); if (EditorGUI.DropdownButton(rect, new GUIContent(parsedPath), FocusType.Keyboard)) { ShowInputControlPicker(rect, pathProperty); } if (GUI.Button(editBtn, "...")) { m_ManualEditMode = true; } } }
public void OnGUI() { if (m_BindingProperty == null) { return; } EditorGUILayout.BeginVertical(); m_GeneralFoldout = DrawFoldout(m_GeneralContent, m_GeneralFoldout); if (m_GeneralFoldout) { EditorGUI.indentLevel++; var pathProperty = m_BindingProperty.FindPropertyRelative("path"); var path = BindingTreeItem.ParseName(pathProperty.stringValue); var btnRect = GUILayoutUtility.GetRect(0, EditorStyles.miniButton.lineHeight); btnRect = EditorGUI.IndentedRect(btnRect); if (EditorGUI.DropdownButton(btnRect, new GUIContent(path), FocusType.Keyboard)) { PopupWindow.Show(btnRect, new InputControlPicker(pathProperty, ref m_TreeViewState) { onPickCallback = OnBindingModified }); } EditorGUI.indentLevel--; } EditorGUILayout.Space(); m_InteractionsFoldout = DrawFoldout(m_InteractionsContent, m_InteractionsFoldout); if (m_InteractionsFoldout) { EditorGUI.indentLevel++; var listRect = GUILayoutUtility.GetRect(200, m_InteractionsListView.GetHeight()); listRect = EditorGUI.IndentedRect(listRect); m_InteractionsListView.DoList(listRect); EditorGUI.indentLevel--; } EditorGUILayout.Space(); m_ProcessorsFoldout = DrawFoldout(m_ProcessorsContent, m_ProcessorsFoldout); if (m_ProcessorsFoldout) { EditorGUI.indentLevel++; var listRect = GUILayoutUtility.GetRect(200, m_ProcessorsListView.GetHeight()); listRect = EditorGUI.IndentedRect(listRect); m_ProcessorsListView.DoList(listRect); EditorGUI.indentLevel--; } GUILayout.FlexibleSpace(); EditorGUILayout.EndVertical(); }
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 static BindingTreeItem AddTo(TreeViewItem parent, SerializedProperty bindingProperty) { var item = new BindingTreeItem(bindingProperty); item.depth = parent.depth + 1; item.displayName = item.displayPath; parent.AddChild(item); return(item); }
/// <summary> /// Add items for the bindings of just this action to the given parent tree item. /// </summary> public void AddBindingsTo(TreeViewItem parent) { var isSingleton = actionMapProperty == null; var bindingsArrayProperty = isSingleton ? property.FindPropertyRelative("m_SingletonActionBindings") : actionMapProperty.FindPropertyRelative("m_Bindings"); var bindingsCountInMap = bindingsArrayProperty.arraySize; var currentComposite = (CompositeBindingTreeItem)null; for (var i = 0; i < bindingsCountInMap; ++i) { var bindingProperty = bindingsArrayProperty.GetArrayElementAtIndex(i); // Skip if binding is not for action. var actionProperty = bindingProperty.FindPropertyRelative("m_Action"); Debug.Assert(actionProperty != null, $"Could not find m_Action in {bindingProperty}"); if (!actionProperty.stringValue.Equals(name, StringComparison.InvariantCultureIgnoreCase)) { continue; } // See what kind of binding we have. var flagsProperty = bindingProperty.FindPropertyRelative("m_Flags"); Debug.Assert(actionProperty != null, $"Could not find m_Flags in {bindingProperty}"); var flags = (InputBinding.Flags)flagsProperty.intValue; if ((flags & InputBinding.Flags.PartOfComposite) != 0 && currentComposite != null) { // Composite part binding. PartOfCompositeBindingTreeItem.AddTo(currentComposite, bindingProperty); } else if ((flags & InputBinding.Flags.Composite) != 0) { // Composite binding. currentComposite = CompositeBindingTreeItem.AddTo(parent, bindingProperty); } else { // "Normal" binding. BindingTreeItem.AddTo(parent, bindingProperty); currentComposite = null; } } }
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); } }