| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- using Newtonsoft.Json;
- using ProjectBase.UI;
- using ShotSimulator.Screen;
- using ShotSimulator.Train;
- using ShotSimulator.UI;
- using ShotSimulator.User;
- using SmartBowSDK;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- namespace ShotSimulator
- {
- public class Main : MonoSingleton<Main>
- {
- private void Awake()
- {
- //Application.targetFrameRate = 60;
- SoundManager.GetInstance().InitManager();
- ScreenEffectManager.GetInstance().InitManager();
- VirtualMouse.GetInstance().InitManager();
- UIManager.GetInstance().InitManager();
- UserManager.GetInstance().InitManager();
- InitExternalCallback();
- }
- private void Start()
- {
- SimulateMouseController.ins?.RemoveOpenLocker("NotGame");
- UIManager.GetInstance().ShowUIView("CursorUIView", CursorType.UICursor);
- UIManager.GetInstance().ShowUIView("TrainTaskInfoUIView");
- //UIManager.GetInstance().ShowUIView("MainScreenUIView");
- }
- private void Update()
- {
- //if (Input.GetKeyDown(KeyCode.U))
- //{
- // RankingFilter filter = new RankingFilter()
- // {
- // trainTaskType = TrainTaskType.MemoryShot ,
- // difficultyType = DifficultyType.Advance ,
- // modeType = ModeType.Tactical,
- // firearmDeviceType = FirearmDeviceType.M17
- // };
- // UserManager.GetInstance().UploadCustomLeaderboard(filter, 800, (result) =>
- // {
- // List<RankingData> datas = JsonConvert.DeserializeObject<List<RankingData>>(JsonConvert.SerializeObject(result.data, Formatting.Indented));
- // foreach (var item in datas)
- // {
- // Debug.Log($"Rank: {item.rank}, Name: {item.userName}, Score: {item.score}, Avatar: {item.avatarUrl}, IsSelf: {item.isSelf}");
- // }
- // });
- //}
- #if UNITY_EDITOR
- if (Input.GetKeyDown(KeyCode.U))
- {
- //模拟拉栓
- List<byte> data = new List<byte>();
- data.Add(0x60);
- data.Add(0x00);
- data.Add(0x02);
- data.Add(0x5D);
- ShootCheck.ins.UpdateChamberState(data.ToArray());
- }
- if (Input.GetKeyUp(KeyCode.U))
- {
- //模拟拉栓
- List<byte> data = new List<byte>();
- data.Add(0x60);
- data.Add(0x01);
- data.Add(0x02);
- data.Add(0x5D);
- ShootCheck.ins.UpdateChamberState(data.ToArray());
- }
- #endif
- }
- private void OnDestroy()
- {
- ResetExternalCallback();
- }
- private void InitExternalCallback()
- {
- if (ShootCheck.ins) {
- ShootCheck.ins.OnGameShoot += MainShoot;
- }
- if (BluetoothAim.ins) {
- BluetoothAim.ins.OnBleDeviceState += TrainTaskLoader.GetInstance().ChangedMagazineStatus;
- BluetoothAim.ins.OnDeviceAndSystemInfoEvent += OnDeviceAndSystemInfoEvent;
- //获取一次响应的信息
- BluetoothAim.ins.GetDeviceAndSystemInfoEvent();
- }
- // UserManager.GetInstance().Login(LoginCallBack);
- }
- float _lastShootTime = 0;
- /// <summary>
- /// 添加一个设计间隔,防止多次触发
- /// </summary>
- /// <param name="speed"></param>
- private void MainShoot(float speed) {
- if (CurrentFirearmDevice == FirearmDeviceType.M416)
- {
- //Rifle M416在训练游戏(新)中,要响应连发,APP正常响应蓝牙发过来的射击命令
- VirtualMouse.GetInstance().OnShooting(speed);
- TrainTaskLoader.GetInstance().Shoot(speed);
- }
- else {
- //Pisto1M17在新游戏中保持和M9一样的功能
- //枪情况下间隔时间0.2,弓箭按0.5
- float interval = GlobalData.MyDeviceMode == DeviceMode.Gun ? 0.2f : 0.5f;
- //加个间隔
- if (Time.realtimeSinceStartup - _lastShootTime < interval) return;
- _lastShootTime = Time.realtimeSinceStartup;
- VirtualMouse.GetInstance().OnShooting(speed);
- TrainTaskLoader.GetInstance().Shoot(speed);
- }
-
- }
- private void LoginCallBack(LoginResult result)
- {
- }
- private void ResetExternalCallback()
- {
- if (ShootCheck.ins)
- {
- ShootCheck.ins.OnGameShoot -= MainShoot;
- }
- if (BluetoothAim.ins)
- {
- BluetoothAim.ins.OnBleDeviceState -= TrainTaskLoader.GetInstance().ChangedMagazineStatus;
- BluetoothAim.ins.OnDeviceAndSystemInfoEvent -= OnDeviceAndSystemInfoEvent;
- }
- }
- public void ResetAim()
- {
- InfraredDemo._ins.SetAdjustPointsOffset(PlayerType.FirstPlayer);
- }
- #region 接入训练游戏时候添加
- public FirearmDeviceType CurrentFirearmDevice;
- public void OnDeviceAndSystemInfoEvent(ConnectPlatform connectPlatform, BluetoothDeviceType bleDeviceType)
- {
- Debug.Log("[Main]OnDeviceAndSystemInfoEvent:" + connectPlatform + ",bleDeviceType:" + bleDeviceType);
- //CurrentFirearmDevice = FirearmDeviceType.M416;
- switch (bleDeviceType)
- {
- case BluetoothDeviceType.NONE:
- break;
- case BluetoothDeviceType.HOUYIPro:
- break;
- case BluetoothDeviceType.ARTEMISPro:
- break;
- case BluetoothDeviceType.Pistol1:
- case BluetoothDeviceType.PistolM9:
- CurrentFirearmDevice = FirearmDeviceType.M9;
- break;
- case BluetoothDeviceType.APOLLO:
- break;
- case BluetoothDeviceType.PistolM17:
- CurrentFirearmDevice = FirearmDeviceType.M17;
- break;
- case BluetoothDeviceType.RifleM416:
- CurrentFirearmDevice = FirearmDeviceType.M416;
- break;
- default:
- break;
- }
- }
- #endregion
- }
- }
|