GeneratingTarget.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. using AppUI.Bluetooth;
  2. using BestHTTP.SignalR.Hubs;
  3. using HyperspaceGame;
  4. using MathNet.Numerics;
  5. using ShotSimulator.Train;
  6. using SmartBowSDK;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using TMPro;
  11. using UnityEngine;
  12. using UnityEngine.EventSystems;
  13. using UnityEngine.SceneManagement;
  14. using UnityEngine.UI;
  15. public class GeneratingTarget : MonoBehaviour
  16. {
  17. // 最小时间间隔(秒)
  18. float _minTimeBetweenEvents = 1.0f;
  19. public float minTimeBetweenEvents { get { return _minTimeBetweenEvents; } set { _minTimeBetweenEvents = value; } }
  20. float _maxTimeBetweenEvents = 3.0f;// 最大时间间隔(秒)
  21. public float maxTimeBetweenEvents { get { return _maxTimeBetweenEvents; } set { _maxTimeBetweenEvents = value; } }
  22. public GameObject target;
  23. public Transform UI;
  24. public TextMeshProUGUI scoreUI;
  25. public TextMeshProUGUI scoreUI1;
  26. public Text countDownUI;
  27. public TextMeshProUGUI clipsizeUI;
  28. public TextMeshProUGUI hitCountUI;
  29. public TextMeshProUGUI shootRate;
  30. public GameObject GameOver;
  31. public Score scoreCom;
  32. public Score scoreCom1;
  33. public GameObject Miss;
  34. public Image grade;
  35. public Transform tp;
  36. public GameObject bulletNull;//子弹不足UI
  37. public Sprite bulletHalf;
  38. public Sprite bulletFull;
  39. public GameObject[] bulletImages;//子弹图片数组
  40. private bool isThirtyBulletMode = false;
  41. public GameObject SelectLv;
  42. public Image imgSlider;
  43. public Text TopScore;
  44. public Text CurLvTxt;
  45. public Text MaxLvTxt;
  46. public int bulletCount;//子弹数量
  47. public int hitCount;//击中数量
  48. private float rate;//命中率
  49. public Button BtnRestart;
  50. public Button BtnNext;
  51. public Button BtnLast;
  52. int _score;
  53. public bool stop = false;
  54. public int score { get { return _score; }
  55. set {
  56. _score = value;
  57. ShowScore();
  58. }
  59. }
  60. /// <summary>
  61. /// 游戏时间
  62. /// </summary>
  63. private float countDownTime;
  64. int countDownTimeCache;
  65. /// <summary>
  66. /// 子弹数量
  67. /// </summary>
  68. private int clipsize;
  69. private int BulletCount = 15;
  70. /// <summary>
  71. /// 靶子存在最长时间
  72. /// </summary>
  73. float _targetExistenceTimeMax = 5;
  74. public float TargetExistenceTimeMax { get { return _targetExistenceTimeMax; } set { _targetExistenceTimeMax = value; } }
  75. /// <summary>
  76. /// 靶子存在最短时间
  77. /// </summary>
  78. float _targetExistenceTimeMin = 3;
  79. public float TargetExistenceTimeMin { get { return _targetExistenceTimeMin; } set { _targetExistenceTimeMin = value; } }
  80. float _scaleMin = 1.3f;
  81. public float ScaleMin { get { return _scaleMin; } set { _scaleMin = value; } }
  82. float _scaleMax = 1.8f;
  83. public float ScaleMax { get { return _scaleMax; } set { _scaleMax = value; } }
  84. public HyperspaceGame.Font font;
  85. public AudioSource ShootingSound;
  86. public AudioSource gameSatrtSound;
  87. public AudioClip[] gameSatrtClips;
  88. //public GameObject perfect;
  89. //public GameObject gaeat;
  90. //public GameObject good;
  91. //public Image goodImage;
  92. //public Image greatImage;
  93. public static GeneratingTarget gm { get; set; }
  94. public ShootingEvent shootingEvent;
  95. /// <summary>
  96. /// 记录当前射箭是否记录分数
  97. /// </summary>
  98. private bool bAddCountScore { get; set; } = false;
  99. [HideInInspector] public bool getAddCountScore => bAddCountScore;
  100. //分数统计
  101. [HideInInspector] public UserGameAnalyse1 userGameAnalyse1;
  102. public int Index = 0;
  103. private bool unload = false;
  104. /// <summary>
  105. /// 当前难度的配置
  106. /// </summary>
  107. public Level LvCfg = null;
  108. /// <summary>
  109. /// 当前序列的配置
  110. /// </summary>
  111. public Order orderCfg = null;
  112. float nextOrderWaitTime;
  113. int curOrderIdx;
  114. bool canEnterNextOrder = true;
  115. bool isbegin = false;
  116. int tragetLeftNum;
  117. /// <summary>
  118. /// 当前序列
  119. /// </summary>
  120. public int CurOrder = 0;
  121. public static int MaxLevel = 3;
  122. public List<Sprite> ScoreLevel;
  123. public List<Sprite> EnScoreLevel;
  124. public List<Sprite> JPScoreLevel;
  125. [SerializeField]
  126. RectTransform _canvasRectTransform;
  127. private void Awake()
  128. {
  129. gm = this;
  130. var scene = SceneManager.GetActiveScene();
  131. if(scene.name == "Hyperspace01")
  132. Index = 0;
  133. else if (scene.name == "Hyperspace02")
  134. Index = 1;
  135. else if(scene.name == "Hyperspace03")
  136. Index = 2;
  137. //初始化关卡配置
  138. LvCfg = Config.levels[Index];
  139. countDownTime = LvCfg.TotalTime;
  140. curOrderIdx = 0;
  141. UpdateCountDown(LvCfg.TotalTime);
  142. CurLvTxt.text = $"{Index + 1}";
  143. MaxLvTxt.text = $"/<color=#0F92D4>{MaxLevel}</color>";
  144. shootingEvent = FindObjectOfType<ShootingEvent>();
  145. scoreCom.gameObject.SetActive(false);
  146. scoreCom1.gameObject.SetActive(false);
  147. Miss.SetActive(false);
  148. stop = false;
  149. imgSlider.fillAmount = 1;
  150. ShowScore();
  151. bulletNull.SetActive(false);
  152. BtnRestart.onClick.AddListener(OnRestart);
  153. BtnNext.onClick.AddListener(OnBtnNext);
  154. BtnNext.gameObject.SetActive(Index + 1 < MaxLevel);
  155. BtnLast.onClick.AddListener(OnBtnLast);
  156. BtnLast.gameObject.SetActive(true);
  157. GameOver.SetActive(false);
  158. CreateUIManager();
  159. CreateTargetObject2D();
  160. //是否关闭背景音效
  161. if (!UserSettings.ins.openBGM) {
  162. AudioSource bgm = GetComponent<AudioSource>();
  163. bgm.Stop();
  164. }
  165. if (SmartBowDeviceHub.ins && SmartBowDeviceHub.ins.IsMainConnectToGun() && SmartBowDeviceHub.ins.GetMainConnectGunType().gunType == AimDeviceType.RifleM416)
  166. {
  167. BulletCount = 30;
  168. isThirtyBulletMode = true;
  169. }
  170. else
  171. {
  172. BulletCount = 15;
  173. isThirtyBulletMode = false;
  174. }
  175. }
  176. public void OnRestart()
  177. {
  178. Restart(Index);
  179. }
  180. public void OnBtnNext()
  181. {
  182. Restart(Index + 1);
  183. }
  184. public void OnBtnLast()
  185. {
  186. //Restart(Index - 1);
  187. onUploadScore();
  188. ////结束游戏页面
  189. //userGameAnalyse1.UploadData(true);
  190. //userGameAnalyse1.onResetOverlayData();
  191. //SceneManager.LoadScene("Home", LoadSceneMode.Single);
  192. //结束游戏页面
  193. userGameAnalyse1.showResultView(() =>
  194. {
  195. gm = null;
  196. SceneManager.LoadScene("Home", LoadSceneMode.Single);
  197. });
  198. }
  199. void Start()
  200. {
  201. SmartBowDeviceHub hub = SmartBowDeviceHub.ins;
  202. if (hub == null) return;
  203. hub.SubscribeBleDeviceState(OnSeparationStatus);
  204. //初始化同步一次
  205. OnSeparationStatus(BluetoothDeviceType.NONE, hub.GetBleDeviceState());
  206. //Screen.SetResolution(1280, 720, false); // 设置分辨率为1920x1080,‌并设置为全屏模式
  207. Invoke("GameStart", 4);
  208. Game1();
  209. Invoke("Game2", 1);
  210. Invoke("Game3", 2);
  211. var canvases = FindObjectsByType<Canvas>(FindObjectsSortMode.InstanceID);
  212. foreach (var canvas in canvases)
  213. {
  214. if (canvas.name == "Canvas")
  215. {
  216. _canvasRectTransform = canvas.GetComponent<RectTransform>();
  217. break;
  218. }
  219. }
  220. //靶子默认状态
  221. var show = UIManager._ins.GetArrowBtnState();
  222. var arrow = shootingEvent.GetComponent<Image>();
  223. var color = arrow.color;
  224. if (show)
  225. color.a = 1;
  226. else
  227. color.a = 0;
  228. arrow.color = color;
  229. UIManager._ins.ShowQuit();
  230. }
  231. private void OnDestroy()
  232. {
  233. SmartBowDeviceHub.ins.UnsubscribeBleDeviceState(OnSeparationStatus);
  234. }
  235. public void OpenSelectLevel()
  236. {
  237. SelectLv.SetActive(true);
  238. }
  239. public Vector2 GetCanvasSize()
  240. {
  241. return _canvasRectTransform.sizeDelta;
  242. }
  243. void Game1()
  244. {
  245. gameSatrtSound.clip = gameSatrtClips[0];
  246. if (UserSettings.ins.openEffect) gameSatrtSound.Play();
  247. }
  248. void Game2()
  249. {
  250. gameSatrtSound.clip = gameSatrtClips[1];
  251. if (UserSettings.ins.openEffect) gameSatrtSound.Play();
  252. }
  253. void Game3()
  254. {
  255. gameSatrtSound.clip = gameSatrtClips[2];
  256. if (UserSettings.ins.openEffect) gameSatrtSound.Play();
  257. }
  258. void GameStart()
  259. {
  260. isbegin = true;
  261. }
  262. private float reloadTime = 0;
  263. private void Reload(bool delay = false)
  264. {
  265. if (delay)
  266. {
  267. reloadTime = 3f;
  268. }
  269. else
  270. {
  271. clipsize = BulletCount;
  272. bulletCount -= font.Clip;
  273. bulletCount += clipsize;
  274. font.Clip = clipsize;
  275. bulletNull.SetActive(false);
  276. //for (int i = 0; i < bulletImages.Length; i++)
  277. //{
  278. // bulletImages[i].SetActive(true);
  279. //}
  280. UpdateBulletUI();
  281. }
  282. }
  283. public bool Reloading()
  284. {
  285. return unload;
  286. //return reloadTime > 0;
  287. }
  288. float _lastShootTime = 0;
  289. /// <summary>
  290. /// 射击
  291. /// </summary>
  292. /// <param name="bAddCount">是否是有效射箭</param>
  293. public void Shooting(bool bAddCount = false)
  294. {
  295. //枪情况下间隔时间0.2,
  296. float interval = GlobalData.MyDeviceMode == DeviceMode.Gun ? 0.2f : 0.5f;
  297. //加个间隔
  298. if (Time.realtimeSinceStartup - _lastShootTime < interval) return;
  299. _lastShootTime = Time.realtimeSinceStartup;
  300. bAddCountScore = bAddCount;
  301. DoShoot();
  302. }
  303. private void DoShoot()
  304. {
  305. if (shootingEvent.ShootUIBtn())
  306. return;
  307. if (unload || clipsize <= 0)
  308. {
  309. Debug.Log("卸了弹夹 或者 没子弹了!");
  310. //没有子弹的声音
  311. //ShootingSound.Play();
  312. bulletImages[0].SetActive(false);
  313. bulletNull.SetActive(true);
  314. return;
  315. }
  316. else
  317. {
  318. //正常发射的声音
  319. if (UserSettings.ins.openEffect) ShootingSound.Play();
  320. }
  321. clipsize--;
  322. if (clipsize <= 0)
  323. {
  324. //Reload(true);//不自动装弹
  325. }
  326. font.Clip = clipsize;
  327. //bulletImages[clipsize].SetActive(false);
  328. UpdateBulletUI();
  329. shootingEvent.OnShooting();
  330. }
  331. private void UpdateBulletUI()
  332. {
  333. if (isThirtyBulletMode)
  334. {
  335. // 每2发对应1格,总共15格
  336. int fullGrids = clipsize / 2;
  337. bool hasHalf = (clipsize % 2 == 1);
  338. for (int i = 0; i < bulletImages.Length; i++)
  339. {
  340. Image raw = bulletImages[i].GetComponent<Image>();
  341. if (i < fullGrids)
  342. {
  343. bulletImages[i].SetActive(true);
  344. raw.sprite = bulletFull; // 默认满格图
  345. }
  346. else if (i == fullGrids && hasHalf)
  347. {
  348. bulletImages[i].SetActive(true);
  349. raw.sprite = bulletHalf;
  350. }
  351. else
  352. {
  353. bulletImages[i].SetActive(false);
  354. }
  355. }
  356. }
  357. else
  358. {
  359. // 正常模式,每发子弹对应一个格
  360. for (int i = 0; i < bulletImages.Length; i++)
  361. {
  362. bulletImages[i].SetActive(i < clipsize);
  363. }
  364. }
  365. }
  366. //int tempScore = 0;
  367. private void Update()
  368. {
  369. //if (reloadTime > 0)
  370. //{
  371. // reloadTime -= Time.deltaTime;
  372. // if (reloadTime <= 0)
  373. // Reload();
  374. //}
  375. #if UNITY_EDITOR
  376. if (Input.GetMouseButtonDown(0))
  377. {
  378. shootingEvent.OnPositionUpdate(Input.mousePosition);
  379. Shooting(true);
  380. }
  381. if (Input.GetKeyDown(KeyCode.W))
  382. {
  383. countDownTime = 0;
  384. }
  385. if (Input.GetKeyDown(KeyCode.R))
  386. {
  387. UIManager._ins.Reload();
  388. }
  389. //if (Input.GetKeyDown(KeyCode.T))
  390. //{
  391. // GameOverGrade(tempScore);
  392. // tempScore += 10;
  393. //}
  394. #endif
  395. if (isbegin)
  396. {
  397. if (canEnterNextOrder)//靶子全消失了 开始走序列休息时间
  398. {
  399. if (nextOrderWaitTime <= 0)
  400. {
  401. //开始下一序列
  402. TriggerRandomEvent();
  403. }
  404. nextOrderWaitTime -= Time.deltaTime;
  405. }
  406. //游戏倒计时
  407. if (countDownTime <= 0)
  408. {
  409. //游戏时间到了 结束
  410. GameEnd();
  411. }
  412. else
  413. {
  414. countDownTime -= Time.deltaTime;
  415. var timeInt = Mathf.CeilToInt(countDownTime);
  416. if(timeInt != countDownTimeCache)
  417. {
  418. countDownTimeCache = timeInt;
  419. UpdateCountDown(countDownTimeCache);
  420. }
  421. imgSlider.fillAmount = countDownTime / (float)LvCfg.TotalTime;
  422. }
  423. if (curMoveCtrl != null && curMoveCtrl is IUpdate)
  424. {
  425. (curMoveCtrl as IUpdate).Update();
  426. }
  427. }
  428. }
  429. private void UpdateCountDown(int value)
  430. {
  431. countDownUI.text = $"{value}";
  432. }
  433. private void GameEnd()
  434. {
  435. stop = true;
  436. GameOver.SetActive(true);
  437. GameOverGrade(score);
  438. isbegin = false;
  439. countDownTimeCache = 0;
  440. //游戏结束上传分数
  441. onUploadScore();
  442. }
  443. /// <summary>
  444. /// 下一轮
  445. /// </summary>
  446. void TriggerRandomEvent()
  447. {
  448. canEnterNextOrder = false;
  449. Debug.Log($"新一轮创建 curOrderIdx={curOrderIdx}");
  450. if (LvCfg.orders.Length > curOrderIdx)
  451. {
  452. orderCfg = LvCfg.orders[curOrderIdx];
  453. CreateTargets();
  454. curOrderIdx++;
  455. }
  456. else
  457. GameEnd();
  458. }
  459. Dictionary<MoveType, Move> movesCtrl = new Dictionary<MoveType, Move>()
  460. {
  461. [MoveType.Stay] = new Stay(),
  462. [MoveType.VET] = new VET(),
  463. [MoveType.ROT] = new ROT(),
  464. [MoveType.W] = new W(),
  465. [MoveType.W2] = new W2(),
  466. [MoveType.RelativeHor] = new RelativeHor(),
  467. [MoveType.RelativeVet] = new RelativeVet(),
  468. [MoveType.HOR] = new HOR(),
  469. [MoveType.Diagonal] = new Diagonal(),
  470. [MoveType.LeftToRight] = new LeftToRight(),
  471. [MoveType.RightToLeft] = new RightToLeft(),
  472. };
  473. private Move curMoveCtrl;
  474. /// <summary>
  475. /// 创建当前轮靶子
  476. /// </summary>
  477. private void CreateTargets()
  478. {
  479. var createCount = orderCfg.Big + orderCfg.Middle + orderCfg.Small;
  480. Debug.Log($"创建数量 Big={orderCfg.Big} Middle={orderCfg.Middle} Small={orderCfg.Small}");
  481. tragetLeftNum = createCount;
  482. List<SpineAnimationLoader> gos = new List<SpineAnimationLoader>();
  483. for (int i = 0; i < createCount; i++)
  484. {
  485. var go = Instantiate(target, tp);
  486. var targetIns = go.GetComponent<SpineAnimationLoader>();
  487. if(i < orderCfg.Big)
  488. targetIns.Init(0.8f * 0.732f, orderCfg, OnTargetDestory);
  489. else if (i < orderCfg.Big + orderCfg.Middle)
  490. targetIns.Init(0.5f * 0.692f, orderCfg, OnTargetDestory);
  491. else
  492. targetIns.Init(0.3f * 0.733f, orderCfg, OnTargetDestory);
  493. go.SetActive(true);
  494. gos.Add(targetIns);
  495. }
  496. movesCtrl.TryGetValue(orderCfg.MoveType, out curMoveCtrl);
  497. if (curMoveCtrl == null)
  498. curMoveCtrl = movesCtrl[MoveType.Stay];
  499. curMoveCtrl.SetGo(gos);
  500. }
  501. /// <summary>
  502. /// 靶子被射击或者到时间销毁
  503. /// </summary>
  504. private void OnTargetDestory()
  505. {
  506. tragetLeftNum--;
  507. if (tragetLeftNum <= 0)
  508. {
  509. curMoveCtrl = null;
  510. Debug.Log("当前轮结束");
  511. canEnterNextOrder = true;
  512. //重置休息时间
  513. nextOrderWaitTime = orderCfg.WaitTime;
  514. }
  515. }
  516. public void ShowScore()
  517. {
  518. //font.Text = score;
  519. TopScore.text = score.ToString().PadLeft(3, '0');
  520. }
  521. public Score scoreSprite;
  522. public void ShowScoreCom(int score, Vector3 pos, Vector2 scorepos, Transform tf, int posIdx)
  523. {
  524. Debug.Log($"得分 score{score}");
  525. if (score >= 6)
  526. {
  527. var go = GameObject.Instantiate(scoreCom, pos, Quaternion.identity, _canvasRectTransform);
  528. go.gameObject.SetActive(true);
  529. go.transform.localScale = Vector3.one * 0.55f;
  530. go.ShowScore(score, scorepos);
  531. }
  532. else
  533. {
  534. var go = GameObject.Instantiate(scoreCom1, tf.position, Quaternion.identity, _canvasRectTransform);
  535. go.gameObject.SetActive(true);
  536. var halfRadius = 547f * 0.5f;
  537. var offest = tf.localScale.x * halfRadius + 80f;
  538. var x = (posIdx == 1 || posIdx == 2) ? offest : -offest;
  539. var y = (posIdx == 1 || posIdx == 4) ? offest : -offest;
  540. go.ShowScore(score, new Vector3(x, y, 0));
  541. }
  542. }
  543. public void ShowMiss(Vector3 position)
  544. {
  545. Debug.LogWarning("MISS");
  546. if (stop)
  547. return;
  548. var go = GameObject.Instantiate(Miss, position, Quaternion.identity, tp);//_canvasRectTransform
  549. go.AddComponent<CountDown>().time = 5f;
  550. go.transform.SetAsFirstSibling();
  551. go.SetActive(true);
  552. }
  553. public void GameOverGrade(int score)
  554. {
  555. hitCountUI.text = hitCount.ToString();
  556. var bulletUse = bulletCount - font.Clip;
  557. clipsizeUI.text = bulletUse.ToString();
  558. float rate = 0;
  559. if (hitCount != 0)
  560. rate = (float)hitCount / (float)bulletUse;
  561. if(rate == 0)
  562. {
  563. rate = 0;
  564. }
  565. shootRate.text = string.Format("{0:P0}", rate);
  566. font.Text = score;
  567. var maxScore = 0;
  568. foreach (var item in LvCfg.orders)
  569. {
  570. maxScore += item.Big + item.Middle + item.Small;
  571. }
  572. maxScore *= 10;
  573. var percent = (float)score / (float)maxScore * 100f;
  574. Debug.Log($"得分比例:{percent} score={score} maxScore={maxScore}");
  575. var index = Mathf.CeilToInt(percent / 10) - 1;
  576. if (index < 0) index = 0;
  577. RectTransform rectTransform = grade.GetComponent<RectTransform>();
  578. //grade.sprite = TextAutoLanguage2.GetLanguage() == LanguageEnum.Chinese ? ScoreLevel[index]: EnScoreLevel[index];
  579. // 设置图片
  580. LanguageEnum lang = TextAutoLanguage2.GetLanguage(); // 获取当前语言
  581. switch (lang)
  582. {
  583. case LanguageEnum.Chinese:
  584. grade.sprite = ScoreLevel[index];
  585. grade.SetNativeSize();
  586. break;
  587. case LanguageEnum.English:
  588. grade.sprite = EnScoreLevel[index];
  589. grade.SetNativeSize();
  590. break;
  591. case LanguageEnum.Japan:
  592. grade.sprite = JPScoreLevel[index];
  593. rectTransform.sizeDelta = new Vector2(500,500);
  594. break;
  595. default:
  596. grade.sprite = ScoreLevel[index]; // 默认中文
  597. grade.SetNativeSize();
  598. break;
  599. }
  600. rectTransform.anchoredPosition = TextAutoLanguage2.GetLanguage() == LanguageEnum.Chinese ? new Vector3(-152, 15, 1) : new Vector3(-144, 15, 1);
  601. rectTransform.localScale = TextAutoLanguage2.GetLanguage() == LanguageEnum.Chinese ? new Vector3(0.55f, 0.55f, 1) : new Vector3(0.25f, 0.25f, 1);
  602. //
  603. }
  604. public void Restart(int index)
  605. {
  606. string name = "";
  607. if (index == 0)
  608. name = "Hyperspace01";
  609. else if (index == 1)
  610. name = "Hyperspace02";
  611. else if (index == 2)
  612. name = "Hyperspace03";
  613. SceneManager.LoadScene(name);
  614. }
  615. //public void SetTarget(int index)
  616. //{
  617. // goodImage.sprite = font.sprites[index];
  618. // good.SetActive(true);
  619. //}
  620. //public void SetGreat(int index)
  621. //{
  622. // greatImage.sprite = font.sprites[index];
  623. // gaeat.SetActive(true);
  624. //}
  625. public void OnSeparationStatus(BluetoothDeviceType bleDeviceType, BluetoothDeviceStatus gunStatusEnum)
  626. {
  627. if (gunStatusEnum == BluetoothDeviceStatus.MagazineLoading)
  628. {
  629. OnLoading();
  630. }
  631. else
  632. {
  633. OnSeparation();
  634. }
  635. }
  636. /// <summary>
  637. /// 弹夹分离
  638. /// </summary>
  639. public void OnSeparation()
  640. {
  641. unload = true;
  642. clipsize = 0;
  643. bulletCount -= font.Clip;
  644. font.Clip = clipsize;
  645. }
  646. /// <summary>
  647. /// 弹夹上膛
  648. /// </summary>
  649. public void OnLoading()
  650. {
  651. unload = false;
  652. Reload();
  653. }
  654. #region 新增 UIManager 和 TargetObject2D
  655. private GameObject uiManagerInstance;
  656. private GameObject targetObject2D;
  657. // 动态加载并生成 UIManager
  658. public void CreateUIManager()
  659. {
  660. GameObject uiManagerPrefab = Resources.Load<GameObject>("UIManager"); // 从 Resources 中加载 UIManager 预制
  661. uiManagerInstance = Instantiate(uiManagerPrefab); // 实例化 UIManager
  662. //管理分数上传
  663. userGameAnalyse1 = UserGameAnalyse1.CreateWhenGameStartAndReturn(16);
  664. }
  665. //校准靶子
  666. public void CreateTargetObject2D() {
  667. GameObject targetObject2DPrefab = Resources.Load<GameObject>("TargetObject2D");
  668. targetObject2D = Instantiate(targetObject2DPrefab, UI);
  669. }
  670. // 销毁 UIManager 实例
  671. public void DestroyUIManager()
  672. {
  673. if (UIManager._ins != null)
  674. {
  675. Destroy(UIManager._ins.gameObject); // 销毁 UIManager 实例
  676. uiManagerInstance = null;
  677. }
  678. }
  679. /// <summary>
  680. /// 射击次数
  681. /// </summary>
  682. /// <param name="count"></param>
  683. public void onShootCount(int count)
  684. {
  685. userGameAnalyse1.changeShootingCount(count);
  686. }
  687. /// <summary>
  688. /// 上传分数到服务器
  689. /// </summary>
  690. public void onUploadScore()
  691. {
  692. if (_score > 0)
  693. {
  694. Debug.Log("上传的积分为:" + _score);
  695. RankComp.Instance.uploadSinglePlayerGameRes(_score);
  696. _score = 0;
  697. }
  698. }
  699. #endregion
  700. }