示例#1
0
        public static InputActionTreeView Create(SerializedProperty actionSetProperty, Action applyAction, ref TreeViewState treeViewState, ref MultiColumnHeaderState headerViewState)
        {
            if (treeViewState == null)
            {
                treeViewState = new TreeViewState();
            }

            var newHeaderState = CreateHeaderState();

            if (headerViewState != null)
            {
                MultiColumnHeaderState.OverwriteSerializedFields(headerViewState, newHeaderState);
            }
            headerViewState = newHeaderState;

            var header   = new MultiColumnHeader(headerViewState);
            var treeView = new InputActionTreeView(actionSetProperty, applyAction, treeViewState, header);

            // Expand all action set items.
            foreach (var item in treeView.rootItem.children)
            {
                treeView.SetExpanded(item.id, true);
            }

            return(treeView);
        }
        private static void ToggleFocusUsingKeyboard(KeyCode key, InputActionTreeView fromTree,
                                                     InputActionTreeView toTree)
        {
            var uiEvent = Event.current;

            if (uiEvent.type == EventType.KeyDown && uiEvent.keyCode == key && fromTree.HasFocus())
            {
                if (!toTree.HasSelection())
                {
                    toTree.SelectFirstToplevelItem();
                }
                toTree.SetFocus();
                uiEvent.Use();
            }
        }
        private void InitializeTrees()
        {
            // We persist tree view states (most importantly, they contain our selection states),
            // so only create those if we don't have any yet.
            if (m_ActionMapsTreeState == null)
            {
                m_ActionMapsTreeState = new TreeViewState();
            }
            if (m_ActionsTreeState == null)
            {
                m_ActionsTreeState = new TreeViewState();
            }

            // Create tree in middle pane showing actions and bindings. We initially
            // leave this tree empty and populate it by selecting an action map in the
            // left pane tree.
            m_ActionsTree = new InputActionTreeView(m_ActionAssetManager.serializedObject, m_ActionsTreeState)
            {
                onSelectionChanged         = OnActionTreeSelectionChanged,
                onSerializedObjectModified = ApplyAndReloadTrees,
                drawMinusButton            = false,
                title = "Actions",
            };

            // Create tree in left pane showing action maps.
            m_ActionMapsTree = new InputActionTreeView(m_ActionAssetManager.serializedObject, m_ActionMapsTreeState)
            {
                onBuildTree = () =>
                              InputActionTreeView.BuildWithJustActionMapsFromAsset(m_ActionAssetManager.serializedObject),
                onSelectionChanged         = OnActionMapTreeSelectionChanged,
                onSerializedObjectModified = ApplyAndReloadTrees,
                onHandleAddNewAction       = m_ActionsTree.AddNewAction,
                drawMinusButton            = false,
                title = "Action Maps",
            };
            m_ActionMapsTree.Reload();
            m_ActionMapsTree.ExpandAll();

            RebuildActionTree();
            LoadPropertiesForSelection();

            // Sync current search status in toolbar.
            OnToolbarSearchChanged();
        }
        private void RebuildActionTree()
        {
            var selectedActionMapItem =
                m_ActionMapsTree.GetSelectedItems().OfType <ActionMapTreeItem>().FirstOrDefault();

            if (selectedActionMapItem == null)
            {
                // Nothing selected. Wipe middle and right pane.
                m_ActionsTree.onBuildTree = () => new TreeViewItem(0, -1, "");
            }
            else
            {
                m_ActionsTree.onBuildTree = () =>
                                            InputActionTreeView.BuildWithJustActionsAndBindingsFromMap(selectedActionMapItem.property);
            }

            // Rebuild tree.
            m_ActionsTree.Reload();
            m_ActionsTree.ExpandAll();
        }
示例#5
0
        private void InitTreeIfNeeded(SerializedProperty property)
        {
            // NOTE: Unlike InputActionEditorWindow, we do not need to protect against the SerializedObject
            //       changing behind our backs by undo/redo here. Being a PropertyDrawer, we will automatically
            //       get recreated by Unity when it touches our serialized data.

            if (m_TreeView == null)
            {
                // Create tree and populate it.
                m_TreeView = new InputActionTreeView(property.serializedObject)
                {
                    onBuildTree   = () => BuildTree(property),
                    onDoubleClick = OnItemDoubleClicked,
                    title         = property.displayName,
                    // With the tree in the inspector, the foldouts are drawn too far to the left. I don't
                    // really know where this is coming from. This works around it by adding an arbitrary offset...
                    foldoutOffset = 14
                };
                m_TreeView.Reload();
            }
        }
 protected override TreeViewItem BuildTree(SerializedProperty property)
 {
     return(InputActionTreeView.BuildWithJustActionsAndBindingsFromMap(property));
 }
示例#7
0
 private void InitializeActionTreeView()
 {
     m_ActionTreeView = InputActionTreeView.Create(serializedObject.FindProperty("m_ActionMaps"), Apply,
                                                   ref m_ActionTreeViewState, ref m_ActionTreeViewHeaderState);
 }