From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/GameSirControl/XGameSirControl.cs | 123 +++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Client/Assets/Scripts/GameSirControl/XGameSirControl.cs (limited to 'Client/Assets/Scripts/GameSirControl/XGameSirControl.cs') diff --git a/Client/Assets/Scripts/GameSirControl/XGameSirControl.cs b/Client/Assets/Scripts/GameSirControl/XGameSirControl.cs new file mode 100644 index 00000000..e8e0e371 --- /dev/null +++ b/Client/Assets/Scripts/GameSirControl/XGameSirControl.cs @@ -0,0 +1,123 @@ +using UnityEngine; +using System.Collections; +#if (UNITY_IOS || UNITY_ANDROID ) && GAMESIR && !UNITY_EDITOR +using Gamesir; +#endif + +using XUtliPoolLib; +public class XGameSirControl : MonoBehaviour,IXGameSirControl +{ + private bool mIsOpen = false; + public void ShowGameSirDialog() + { +#if (UNITY_IOS || UNITY_ANDROID ) && GAMESIR && !UNITY_EDITOR + if(mIsOpen){ + GamesirInput.Instance().OpenConnectDialog(); + } +#endif + } + + public int GetGameSirState() + { + #if (UNITY_IOS || UNITY_ANDROID )&& GAMESIR && !UNITY_EDITOR + if(mIsOpen) + return GamesirInput.Instance().GetGameSirState(); + else + return 0; +#else + return 0; +#endif + } + + + public float GetAxis(string axisName) + { + #if (UNITY_IOS || UNITY_ANDROID ) && GAMESIR && !UNITY_EDITOR + if(mIsOpen) + return GamesirInput.Instance().GetAxis(axisName); + else + return 0; + +#else + return 0; +#endif + } + + public bool GetButton(string buttonName) + { +#if (UNITY_IOS || UNITY_ANDROID )&& GAMESIR && !UNITY_EDITOR + if(mIsOpen) + return GamesirInput.Instance().GetButton(buttonName); + else + return false; +#else + return false; +#endif + } + + public bool IsOpen + { + get{ return mIsOpen;} + } + + public void Init() + { + + } + + void Start() + { + //GamesirInput.Instance().SetDebug (true); + #if(UNITY_IOS || UNITY_ANDROID)&& GAMESIR && !UNITY_EDITOR + GamesirInput.Instance().SetIconLocation(IconLocation.BOTTOM_CENTER); + GamesirInput.Instance().setHiddenConnectIcon(true); + GamesirInput.Instance().onStart(); + mIsOpen = true; + #else + mIsOpen = false; + #endif + } + + public void StartSir() + { + + #if(UNITY_IOS || UNITY_ANDROID) && GAMESIR && !UNITY_EDITOR + if(!IsConnected()) + GamesirInput.Instance().AutoConnectToGCM(); + #endif + } + + public void StopSir() + { +#if(UNITY_IOS || UNITY_ANDROID) && GAMESIR && !UNITY_EDITOR + if(IsConnected()) + GamesirInput.Instance().DisConnectGCM(); +#endif + } + + public bool IsConnected() + { + #if (UNITY_IOS || UNITY_ANDROID )&& GAMESIR && !UNITY_EDITOR + return mIsOpen && GetGameSirState() == 3; +#else + return false; +#endif + } + + + void OnDestroy() + { +#if (UNITY_IOS || UNITY_ANDROID ) && GAMESIR&& !UNITY_EDITOR + if(mIsOpen) + GamesirInput.Instance().OnDestory(); +#endif + } + + void OnApplicationQuit() + { +#if (UNITY_IOS || UNITY_ANDROID )&& GAMESIR && !UNITY_EDITOR + if(mIsOpen) + GamesirInput.Instance().OnQuit(); +#endif + } +} -- cgit v1.1-26-g67d0