diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita.meta new file mode 100644 index 00000000..610d8c13 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cc24c846f7867a14596f757006216ee3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchEmuKey.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchEmuKey.cs new file mode 100644 index 00000000..b3f3542b --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchEmuKey.cs @@ -0,0 +1,104 @@ +/// +/// Axibug PSVita 背面触摸板模拟触摸(by 皓月) +/// +using UnityEngine; +using System.Collections.Generic; + +namespace AxiInputSP +{ + public enum AxiPSVBackTouchType : byte + { + LeftHalf,//左半触摸板 + RigthHalf,//右半触摸板 + LeftTop,//左上部分触摸板 + LeftBotton,//左下部分触摸板 + RightTop,//右上部分触摸板 + RightBotton,//右下部分触摸板 + } + public class AxiPSVBackTouchEmuKey : MonoBehaviour + { + public static bool GetKey(AxiPSVBackTouchType btnType) { return _instance.m_TouckState[btnType].GetKey(); } + public static bool GetKeyUp(AxiPSVBackTouchType btnType) { return _instance.m_TouckState[btnType].GetKeyUp(); } + public static bool GetKeyDown(AxiPSVBackTouchType btnType) { return _instance.m_TouckState[btnType].GetKeyDown(); } + + #region 静态管理 + static AxiPSVBackTouchEmuKey instance + { + get + { + if (_instance == null) + { + _instance = new GameObject("[AxiPSVBackTouch]").AddComponent(); + GameObject.DontDestroyOnLoad(_instance.gameObject); + } + return _instance; + } + } + static AxiPSVBackTouchEmuKey _instance; + const int PSVScreenWidth = 960; + const int PSVScreenHeight = 544; + static Dictionary> dictType2Range = new Dictionary() + { + { AxiPSVBackTouchType.LeftHalf,new System.ValueTuple(Vector2.zero,new Vector2(PSVScreenWidth*0.5f,PSVScreenHeight* 1f))}, + { AxiPSVBackTouchType.RigthHalf,new System.ValueTuple(new Vector2(PSVScreenWidth*0.5f,0),new Vector2(PSVScreenWidth*1f,PSVScreenHeight * 1f))}, + { AxiPSVBackTouchType.LeftTop,new System.ValueTuple(new Vector2(0,PSVScreenHeight*0.5f),new Vector2(PSVScreenWidth*0.5f,PSVScreenHeight * 1f))}, + { AxiPSVBackTouchType.LeftBotton,new System.ValueTuple(new Vector2(0,PSVScreenHeight*0f),new Vector2(PSVScreenWidth*0.5f,PSVScreenHeight* 0.5f))}, + { AxiPSVBackTouchType.RightTop,new System.ValueTuple(new Vector2(PSVScreenWidth*0.5f,PSVScreenHeight*0.5f),new Vector2(PSVScreenWidth*1f,PSVScreenHeight* 1f))}, + { AxiPSVBackTouchType.RightBotton,new System.ValueTuple(new Vector2(0,PSVScreenHeight*0.5f),new Vector2(PSVScreenWidth*1f,PSVScreenHeight* 0.5f))}, + }; + #endregion + + + #region Mono驱动 + Dictionary m_TouckState = new Dictionary(); + List m_PSVTouchPosList = new List(); + private void Awake() + { + m_TouckState[AxiPSVBackTouchType.LeftHalf] = new AxiPSVBackTouchState(AxiPSVBackTouchType.LeftHalf); + m_TouckState[AxiPSVBackTouchType.RigthHalf] = new AxiPSVBackTouchState(AxiPSVBackTouchType.RigthHalf); + m_TouckState[AxiPSVBackTouchType.LeftTop] = new AxiPSVBackTouchState(AxiPSVBackTouchType.LeftTop); + m_TouckState[AxiPSVBackTouchType.LeftBotton] = new AxiPSVBackTouchState(AxiPSVBackTouchType.LeftBotton); + m_TouckState[AxiPSVBackTouchType.RightTop] = new AxiPSVBackTouchState(AxiPSVBackTouchType.RightTop); + m_TouckState[AxiPSVBackTouchType.RightBotton] = new AxiPSVBackTouchState(AxiPSVBackTouchType.RightBotton); + } + + private void OnEnable() + { + } + + private void OnDisable() + { + _instance = null; + } + + private void Update() + { + m_PSVTouchPosList.Clear(); + +#if UNITY_PSP2 && !UNITY_EDITOR + for (int i = 0; i < PSVitaInput.touchesSecondary.Length; i++) + { + Touch touch = PSVitaInput.touchesSecondary[i]; + m_PSVTouchPosList.Add(touch.position); + } +#endif + //收集按下的区域类型 + foreach (var pos in m_PSVTouchPosList) + { + foreach (var rangeKV in dictType2Range) + { + bool bIsIn = (rangeKV.Value.Item2.x < pos.x && pos.x < rangeKV.Value.Item2.x + && + rangeKV.Value.Item1.x < pos.y && pos.y < rangeKV.Value.Item1.y); + + if (bIsIn) + m_TouckState[rangeKV.Key].UpdateStateForIn(); + else + m_TouckState[rangeKV.Key].UpdateStateForOut(); + } + } + + } + #endregion + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchEmuKey.cs.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchEmuKey.cs.meta new file mode 100644 index 00000000..0cfaa421 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchEmuKey.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: cf2539e0bdd3606478b5bef714104846 \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchState.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchState.cs new file mode 100644 index 00000000..aeb754f4 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchState.cs @@ -0,0 +1,57 @@ +using static AxiInputSP.AxiPSVBackTouchEmuKey; + +namespace AxiInputSP +{ + public class AxiPSVBackTouchState + { + enum AxiButtonState + { + None, + KeyUp, + KeyDown, + KeyHold + } + + AxiButtonState m_state = AxiButtonState.None; + /// + /// 键值(支持组合键) + /// + public AxiPSVBackTouchType touchtype; + public AxiPSVBackTouchState(AxiPSVBackTouchType touchtype) + { + this.touchtype = touchtype; + } + + public bool GetKey() + { + return m_state >= AxiButtonState.KeyDown; + } + public bool GetKeyUp() + { + return m_state == AxiButtonState.KeyUp; + } + public bool GetKeyDown() + { + return m_state == AxiButtonState.KeyDown; + } + + public void UpdateStateForIn() + { + //如果之前帧是KeyUp或None,则为KeyDown|KeyHold + if (m_state <= AxiButtonState.KeyUp) + m_state = AxiButtonState.KeyDown; + //如果之前帧是KeyDown,则为KeyHold + else if (m_state == AxiButtonState.KeyDown) + m_state = AxiButtonState.KeyHold; + } + public void UpdateStateForOut() + { + //如果之前帧是KeyDown|KeyHold,则为KeyUp|None + if (m_state >= AxiButtonState.KeyDown) + m_state = AxiButtonState.KeyUp; + //如果之前帧是KeyUp,则为None + else if (m_state == AxiButtonState.KeyUp) + m_state = AxiButtonState.None; + } + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchState.cs.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchState.cs.meta new file mode 100644 index 00000000..6932b3ca --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiInputSP/PSVita/AxiPSVBackTouchState.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 26ec9c9c85df52a4a970c4c093fa6dbf \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiPlayerPrefs/AxiPlayerPrefsForFileSystem.cs.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiPlayerPrefs/AxiPlayerPrefsForFileSystem.cs.meta index 80247a7f..d34aedb8 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiPlayerPrefs/AxiPlayerPrefsForFileSystem.cs.meta +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiPlayerPrefs/AxiPlayerPrefsForFileSystem.cs.meta @@ -1,2 +1,2 @@ fileFormatVersion: 2 -guid: b767f1eb97209254095985d8f6ba13fd \ No newline at end of file +guid: dc469226382c3b74da840a13dae17c10 \ No newline at end of file