예제 #1
0
    void RemoveAction()
    {
        int actionIndex = m_ActionMapEditCopy.actions.IndexOf(selectedAction);

        m_ActionMapEditCopy.actions.RemoveAt(actionIndex);
        for (int i = 0; i < m_ActionMapEditCopy.controlSchemes.Count; i++)
        {
            m_ActionMapEditCopy.controlSchemes[i].bindings.RemoveAt(actionIndex);
        }
        // Shift indexes of actions.
        for (int i = 0; i < m_ActionMapEditCopy.actions.Count; i++)
        {
            InputAction action = m_ActionMapEditCopy.actions[i];
            action.actionIndex = i;
        }

        // Shift indexes of combined actions referencing the actions that have become shifted.
        var combinedReferences = new List <IControlReference>();

        m_ActionMapEditCopy.ExtractCombinedBindingsOfType(combinedReferences);
        for (int i = 0; i < combinedReferences.Count; i++)
        {
            // This may seem weird, but in the case of the combined references,
            // the hashes are actually just indices and thus we can compare hashes and indices.
            if (combinedReferences[i].controlHash == actionIndex)
            {
                combinedReferences[i].controlHash = -1;
            }
            if (combinedReferences[i].controlHash > actionIndex)
            {
                combinedReferences[i].controlHash = combinedReferences[i].controlHash - 1;
            }
        }

        ScriptableObject.DestroyImmediate(selectedAction, true);

        if (m_ActionMapEditCopy.actions.Count == 0)
        {
            selectedAction = null;
        }
        else
        {
            selectedAction = m_ActionMapEditCopy.actions[Mathf.Min(actionIndex, m_ActionMapEditCopy.actions.Count - 1)];
        }

        RefreshPropertyNames();
    }