using MAME.Core.run_interface; using System.Collections.Generic; using System.Linq; using UnityEngine; public class UniKeyboard : MonoBehaviour, IKeyboard { Dictionary dictKeyCfgs = new Dictionary(); KeyCode[] CheckList; MotionKey[] mCurrKey = new MotionKey[0]; List temp = new List(); #region public UILongClickButton btnP1; public UILongClickButton btnCoin1; public UILongClickButton btnA; public UILongClickButton btnB; public UILongClickButton btnC; public UILongClickButton btnD; public UILongClickButton btnE; public UILongClickButton btnF; public UILongClickButton btnAB; public UILongClickButton btnCD; public UILongClickButton btnABC; FloatingJoystick mJoystick; #endregion List mUIBtns = new List(); void Awake() { mJoystick = GameObject.Find("tfJoystick").GetComponent(); btnP1 = GameObject.Find("btnP1").GetComponent(); btnCoin1 = GameObject.Find("btnCoin1").GetComponent(); btnA = GameObject.Find("btnA").GetComponent(); btnB = GameObject.Find("btnB").GetComponent(); btnC = GameObject.Find("btnC").GetComponent(); btnD = GameObject.Find("btnD").GetComponent(); btnE = GameObject.Find("btnE").GetComponent(); btnF = GameObject.Find("btnF").GetComponent(); btnAB = GameObject.Find("btnAB").GetComponent(); btnCD = GameObject.Find("btnCD").GetComponent(); btnABC = GameObject.Find("btnABC").GetComponent(); btnE.gameObject.SetActive(false); btnF.gameObject.SetActive(false); dictKeyCfgs.Add(KeyCode.P, MotionKey.EMU_PAUSED); dictKeyCfgs.Add(KeyCode.Alpha1, MotionKey.P1_GAMESTART); dictKeyCfgs.Add(KeyCode.Alpha5, MotionKey.P1_INSERT_COIN); dictKeyCfgs.Add(KeyCode.W, MotionKey.P1_UP); dictKeyCfgs.Add(KeyCode.S, MotionKey.P1_DOWN); dictKeyCfgs.Add(KeyCode.A, MotionKey.P1_LEFT); dictKeyCfgs.Add(KeyCode.D, MotionKey.P1_RIGHT); dictKeyCfgs.Add(KeyCode.J, MotionKey.P1_BTN_1); dictKeyCfgs.Add(KeyCode.K, MotionKey.P1_BTN_2); dictKeyCfgs.Add(KeyCode.L, MotionKey.P1_BTN_3); dictKeyCfgs.Add(KeyCode.U, MotionKey.P1_BTN_4); dictKeyCfgs.Add(KeyCode.KeypadDivide, MotionKey.P2_GAMESTART); dictKeyCfgs.Add(KeyCode.KeypadMultiply, MotionKey.P2_INSERT_COIN); dictKeyCfgs.Add(KeyCode.UpArrow, MotionKey.P2_UP); dictKeyCfgs.Add(KeyCode.DownArrow, MotionKey.P2_DOWN); dictKeyCfgs.Add(KeyCode.LeftArrow, MotionKey.P2_LEFT); dictKeyCfgs.Add(KeyCode.RightArrow, MotionKey.P2_RIGHT); dictKeyCfgs.Add(KeyCode.Keypad1, MotionKey.P2_BTN_1); dictKeyCfgs.Add(KeyCode.Keypad2, MotionKey.P2_BTN_2); dictKeyCfgs.Add(KeyCode.Keypad3, MotionKey.P2_BTN_3); dictKeyCfgs.Add(KeyCode.Keypad4, MotionKey.P2_BTN_4); CheckList = dictKeyCfgs.Keys.ToArray(); btnP1.Key = new MotionKey[] { MotionKey.P1_GAMESTART }; btnCoin1.Key = new MotionKey[] { MotionKey.P1_INSERT_COIN }; btnA.Key = new MotionKey[] { MotionKey.P1_BTN_1 }; btnB.Key = new MotionKey[] { MotionKey.P1_BTN_2 }; btnC.Key = new MotionKey[] { MotionKey.P1_BTN_3 }; btnD.Key = new MotionKey[] { MotionKey.P1_BTN_4 }; btnE.Key = new MotionKey[] { MotionKey.P1_BTN_5 }; btnF.Key = new MotionKey[] { MotionKey.P1_BTN_6 }; btnAB.Key = new MotionKey[] { MotionKey.P1_BTN_1, MotionKey.P1_BTN_2 }; btnCD.Key = new MotionKey[] { MotionKey.P1_BTN_3, MotionKey.P1_BTN_4 }; btnABC.Key = new MotionKey[] { MotionKey.P1_BTN_1, MotionKey.P1_BTN_2, MotionKey.P1_BTN_3 }; mUIBtns.Add(btnP1); mUIBtns.Add(btnCoin1); mUIBtns.Add(btnA); mUIBtns.Add(btnB); mUIBtns.Add(btnC); mUIBtns.Add(btnD); mUIBtns.Add(btnE); mUIBtns.Add(btnF); mUIBtns.Add(btnAB); mUIBtns.Add(btnCD); mUIBtns.Add(btnABC); } void OnEnable() { } public MotionKey[] GetPressedKeys() { return mCurrKey; } void Update() { temp.Clear(); for (int i = 0; i < CheckList.Length; i++) { if (Input.GetKey(CheckList[i])) temp.Add(dictKeyCfgs[CheckList[i]]); } for (int i = 0; i < mUIBtns.Count; i++) { if (mUIBtns[i].bHotKey) { for (int j = 0; j < mUIBtns[i].Key.Length; j++) temp.Add(mUIBtns[i].Key[j]); } } Vector2Int inputV2 = mJoystick.RawInputV2; //Debug.Log($"{inputV2.x},{inputV2.y}"); if (inputV2.x > 0) temp.Add(MotionKey.P1_RIGHT); else if (inputV2.x < 0) temp.Add(MotionKey.P1_LEFT); if (inputV2.y > 0) temp.Add(MotionKey.P1_UP); else if (inputV2.y < 0) temp.Add(MotionKey.P1_DOWN); mCurrKey = temp.ToArray(); #if UNITY_EDITOR string TempStr = ""; foreach (var item in mCurrKey) { TempStr += $"{item.ToString()}|"; } if(!string.IsNullOrEmpty(TempStr)) Debug.Log(TempStr); #endif } }