GeneratingTarget.cs 21 KB

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