示例#1
0
        /// <summary>
        /// If k1 matches the criteria, call the k1Act action,
        /// if k2 matches the criteria, call the k2Act action,
        /// if both match, call the both action,
        /// if neither, call the neither action.
        /// </summary>
        /// <param name="k1">K1.</param>
        /// <param name="k2">K2.</param>
        /// <param name="k1Detect">K1 detect.</param>
        /// <param name="k2Detect">K2 detect.</param>
        /// <param name="k1Act">K1 act.</param>
        /// <param name="k2Act">K2 act.</param>
        /// <param name="both">Both.</param>
        /// <param name="neither">Neither.</param>
        public static void IfKeys(
            KeyCode k1, KeyCode k2,
            KeyDetectMode k1Detect, KeyDetectMode k2Detect,
            Action k1Act, Action k2Act, Action both = null, Action neither = null
            )
        {
            //k1 == true, k2 == true
            if (IsKey(k1, k1Detect) && IsKey(k2, k2Detect))
            {
                both.InvokeNull();
                return;
            }

            //k1 == true, k2 == false
            if (IsKey(k1, k1Detect) && !IsKey(k2, k2Detect))
            {
                k1Act.InvokeNull();
                return;
            }

            //k1 == false, k2 == true
            if (!IsKey(k1, k1Detect) && IsKey(k2, k2Detect))
            {
                k2Act.InvokeNull();
                return;
            }

            //k1 == false, k2 == false
            if (!IsKey(k1, k1Detect) && !IsKey(k2, k2Detect))
            {
                neither.InvokeNull();
                return;
            }
        }
示例#2
0
        /// <summary>
        /// Determines if the key input matches the criteria
        /// </summary>
        public static bool IsKey(KeyCode k, KeyDetectMode kDetect)
        {
            switch (kDetect)
            {
            case KeyDetectMode.Held:
                return(Input.GetKey(k));

            case KeyDetectMode.NotHeld:
                return(!Input.GetKey(k));

            case KeyDetectMode.Pressed:
                return(Input.GetKeyDown(k));

            case KeyDetectMode.Lifted:
                return(Input.GetKeyUp(k));
            }
            return(new bool());
        }