示例#1
0
    public IEnumerator AssignKey(GameObject bindObj)
    {
        changeBind = true;
        yield return(new WaitUntil(() => Input.anyKey || changeBind == false));

        //newKey = Event.current.keyCode;
        if (newKey != KeyCode.None)
        {
            if (Input.GetKey(KeyCode.Delete))
            {
                newKey = KeyCode.None;
            }

            if (!Input.GetKey(KeyCode.Escape) || !Input.GetKey(KeyCode.Delete))
            {
                CustomBinding bind = GetKey(bindObj.transform.parent.name);
                int           t    = bindObj.transform.GetSiblingIndex();
                if (t == 0)
                {
                    bind.newBind(new KeyCode[] { newKey, bind.keyCode[1] });
                }
                else if (t == 1)
                {
                    bind.newBind(new KeyCode[] { bind.keyCode[0], newKey });
                }

                bind.btn.GetChild(t).GetComponentInChildren <Text>().text = newKey.ToString();
            }
            changeBind = false;
        }
        EventSystem.current.SetSelectedGameObject(null);
        yield break;
    }