HomeView.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. using System;
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Linq;
  9. /* 主界面 */
  10. public class HomeView : JCUnityLib.ViewBase
  11. {
  12. public static bool bOpenOtherView = false;
  13. public static string openName = "";
  14. [SerializeField] Image myAvatarSprite;
  15. [SerializeField] Text nickNameText;
  16. [SerializeField] GameObject[] genders;
  17. [SerializeField] GameObject btnConnectBow;
  18. [SerializeField] Text gameVersion;
  19. [SerializeField] GameObject friendBarTipTop;
  20. [SerializeField] GameObject friendBarTipBottom;
  21. [SerializeField] GameObject bettery;
  22. [SerializeField] GameObject betteryBar;
  23. [SerializeField] GameObject bettery2;
  24. [SerializeField] GameObject betteryBar2;
  25. [SerializeField] RawImage QRImage;
  26. [SerializeField] Text CoinCount;
  27. [SerializeField] HomeView_ChallengeOption challengeOption;
  28. public HomeView_ChallengeOption MyChallengeOption => challengeOption;
  29. [SerializeField] HomeView_TopBarView topBarView;
  30. public HomeView_TopBarView MyTopBarView => topBarView;
  31. public static HomeView ins;
  32. void Awake() {
  33. gameVersion.text = "V" + Application.version;
  34. gameVersion.gameObject.SetActive(false); //隐藏版本号
  35. if (CommonConfig.needToExamine) {
  36. transform.Find("LeftPanel/Item (1)").gameObject.SetActive(false);
  37. transform.Find("RightPanel/Item/Text").GetComponent<TextAutoLanguage>().SetText(1234562);
  38. transform.Find("RightPanel/Item (1)/Text").GetComponent<TextAutoLanguage>().SetText(1234563);
  39. transform.Find("RightPanel/Item (3)").gameObject.SetActive(false);
  40. }
  41. if (topBarView && challengeOption) topBarView.onChangeTypeEvent.AddListener(challengeOption.refreshList);
  42. FlushUrlQR();
  43. }
  44. public void FlushUrlQR()
  45. {
  46. QRImage.texture = StandaloneAPI.GetQR();
  47. }
  48. public void selectGame(int _startGameType)
  49. {
  50. // 获取父对象上的 HomeView_ChallengeOption 脚本
  51. HomeView_ChallengeOption challengeOption = GetComponentInParent<HomeView_ChallengeOption>();
  52. if (challengeOption != null)
  53. {
  54. Debug.Log("Found HomeView_ChallengeOption script on object: " + challengeOption.gameObject.name);
  55. }
  56. else
  57. {
  58. Debug.LogError("HomeView_ChallengeOption script not found on the parent object.");
  59. }
  60. //ModeSelectView modeSelectView = GetComponentInParent<ModeSelectView>();
  61. //if (modeSelectView != null)
  62. //{
  63. // Debug.Log("Found ModeSelectView script on object: " + modeSelectView.gameObject.name);
  64. //}
  65. //else
  66. //{
  67. // Debug.LogError("ModeSelectView script not found on the parent object.");
  68. //}
  69. switch (_startGameType)
  70. {
  71. case 1: //奥运射箭
  72. {
  73. GameMgr.judgmentGameType = 1;
  74. GoToLocalByName("SINGLE_PLYAER");
  75. }
  76. break;
  77. case 2: //打鸭子
  78. {
  79. challengeOption.StartGame(13);
  80. }
  81. break;
  82. case 3: //水果达人
  83. {
  84. challengeOption.StartGame(15);
  85. }
  86. break;
  87. case 4: //荒野射击
  88. {
  89. challengeOption.StartGame(14);
  90. }
  91. break;
  92. case 5: //打野狼
  93. {
  94. GameMgr.judgmentGameType = 5;
  95. GoToLocalByName("SINGLE_PLYAER");
  96. }
  97. break;
  98. case 6: //打野鸡
  99. {
  100. GameMgr.judgmentGameType = 4;
  101. GoToLocalByName("SINGLE_PLYAER");
  102. }
  103. break;
  104. case 7: //打野兔
  105. {
  106. GameMgr.judgmentGameType = 3;
  107. GoToLocalByName("SINGLE_PLYAER");
  108. }
  109. break;
  110. case 16: {
  111. //MovingTarget
  112. challengeOption.StartGame(16);
  113. }
  114. break;
  115. default:
  116. break;
  117. }
  118. }
  119. public void GoToLocalByName(string _gotoName)
  120. {
  121. switch (_gotoName)
  122. {
  123. case "SINGLE_PLYAER": //本地游戏(单人模式)
  124. GlobalDataTemp.pkMatchType = PKMatchType.None;
  125. if (GameMgr.judgmentGameType == 1)
  126. {
  127. //限时射箭
  128. GlobalData.pkMatchType = PKMatchType.None;
  129. GameMgr.gameType = 1;
  130. SceneManager.LoadScene("Game", LoadSceneMode.Single);
  131. }
  132. else
  133. {
  134. //打野鸡,打野兔,打野狼
  135. GameMgr.gameType = GameMgr.judgmentGameType;
  136. SceneManager.LoadScene("GameChallenge", LoadSceneMode.Single);
  137. }
  138. break;
  139. case "PLAY_LOCALLY": //本地对战
  140. Debug.Log("触发本地对战:PLAY_LOCALLY");
  141. GlobalDataTemp.pkMatchType = PKMatchType.LocalPK;
  142. ViewMgr.Instance.ShowView<RoleSelectView>();
  143. break;
  144. case "PLAY_GLOBALLY": //联网
  145. Debug.Log("触发联网:PLAY_GLOBALLY");
  146. GlobalDataTemp.pkMatchType = PKMatchType.OnlinePK;
  147. //ViewMgr.Instance.ShowView<PKGameOptionView>();
  148. if (GameMgr.judgmentGameType == 1)
  149. {
  150. //射箭
  151. //GlobalDataTemp.pkMatchType = PKMatchType.OnlinePK;
  152. GlobalDataTemp.matchGameType = 9;
  153. ViewMgr.Instance.ShowView<PKMatchView>();
  154. }
  155. else
  156. {
  157. //打野鸡,打野兔,打野狼
  158. int newGameType = 0;
  159. if (GameMgr.judgmentGameType == 3) newGameType = 10;
  160. else if (GameMgr.judgmentGameType == 4) newGameType = 11;
  161. else if (GameMgr.judgmentGameType == 5) newGameType = 12;
  162. GlobalDataTemp.matchGameType = newGameType;
  163. ViewMgr.Instance.ShowView<PKMatchView>();
  164. }
  165. break;
  166. case "DOUBLE_PLYAER": //双人游戏,目前包括(奥运射箭,塔防)
  167. Debug.Log("DOUBLE_PLYAER");
  168. SceneManager.LoadScene("GameDouble", LoadSceneMode.Single);
  169. break;
  170. default:
  171. break;
  172. }
  173. }
  174. IEnumerator Start()
  175. {
  176. ins = this;
  177. transform.SetSiblingIndex(0); //放在ui最底层
  178. BluetoothHolder.Init();
  179. AudioMgr.Init();
  180. TopBarView.NeedShowIt(this);
  181. // if (ShootCheck.ins) ShootCheck.ins.AdjustNormalOrHightMode();
  182. if (LoginMgr.myUserInfo.id > 0 || (CommonConfig.StandaloneMode && UserPlayer.ins != null && UserPlayer.ins.hasGetUserInfo)) {
  183. RenderNameOrGender();
  184. RenderMyAvatarSprite();
  185. RenderDeviceNames();
  186. }
  187. if (CommonConfig.StandaloneMode)
  188. {
  189. transform.Find("FriendBar").gameObject.SetActive(false);
  190. transform.Find("RightPanel/Line (1)").gameObject.SetActive(false);
  191. transform.Find("RightPanel/Item (1)").gameObject.SetActive(false);
  192. }
  193. else StartCoroutine(RefreshFriendBar());
  194. //如果需要初始化跳转页面,这里处理
  195. Debug.Log("bOpenOtherView:"+ bOpenOtherView);
  196. if (bOpenOtherView) {
  197. bOpenOtherView = false;
  198. switch (openName)
  199. {
  200. case "DeviceView":
  201. // ViewMgr.Instance.ShowView<DeviceView>();
  202. break;
  203. default:
  204. break;
  205. }
  206. }
  207. //StartCoroutine(testTip());
  208. yield return new WaitForSeconds(1.0f);
  209. //不是B 端进行蓝牙连接
  210. if (!CommonConfig.bDisableBluetooth)
  211. {
  212. //进行一次蓝牙连接
  213. BluetoothAim.ins.HomeViewConnectBLE();
  214. }
  215. }
  216. IEnumerator testTip() {
  217. yield return new WaitForSeconds(1.0f);
  218. GameObject settingsViewObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_HomeViewTip);
  219. settingsViewObj.GetComponent<HomeView_Tip>().setHomeTip(0);
  220. }
  221. void OnDestroy()
  222. {
  223. if (ins == this) ins = null;
  224. TopBarView.DontNeedShowIt(this);
  225. }
  226. void Update() {
  227. UpdateCheckRenderFriendTip();
  228. UpdateBtnForConnect();
  229. //更新电池显示
  230. updateBatteryStatus();
  231. }
  232. // float countingTime1 = 0;
  233. BluetoothStatusEnum bowStatus;
  234. void UpdateBtnForConnect() {
  235. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
  236. bowStatus = BluetoothAim.ins.status;
  237. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  238. //btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  239. //btnConnectBow.GetComponentInChildren<Text>().color = color;
  240. //btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus == BluetoothStatusEnum.ConnectSuccess);
  241. }
  242. }
  243. public static bool ShowProminentBeforeConnectBLE(Action onAgree = null)
  244. {
  245. if (CommonConfig.StandaloneMode) return false;
  246. if (SceneManager.GetActiveScene().name.Equals("HeartRateBand")) return false;
  247. if (PlayerPrefs.GetInt("Location-Prominent", 0) == 0) {
  248. ModalView m = ModalView.Show();
  249. string pName = Application.productName;
  250. m.textKey = "Model_Location-Prominent";
  251. m.onAgreeTextKey = "common_next";
  252. m.onRejectTextKey = "common_cancel";
  253. m.textFormatArgs = new object[] {pName};
  254. m.onAgree = () => {
  255. PlayerPrefs.SetInt("Location-Prominent", 1);
  256. try {
  257. onAgree?.Invoke();
  258. } catch (System.Exception e) {
  259. Debug.LogError(e.Message + "\n" + e.StackTrace);
  260. }
  261. };
  262. return true;
  263. }
  264. return false;
  265. }
  266. public static bool ShowProminentBeforeConnectBLE_Event(Action onAgree = null,Action onReject = null)
  267. {
  268. if (CommonConfig.StandaloneMode) return false;
  269. if (SceneManager.GetActiveScene().name.Equals("HeartRateBand")) return false;
  270. if (PlayerPrefs.GetInt("Location-Prominent", 0) == 0)
  271. {
  272. ModalView m = ModalView.Show();
  273. string pName = Application.productName;
  274. m.textKey = "Model_Location-Prominent";
  275. m.onAgreeTextKey = "common_next";
  276. m.onRejectTextKey = "common_cancel";
  277. m.textFormatArgs = new object[] { pName };
  278. m.onAgree = () => {
  279. PlayerPrefs.SetInt("Location-Prominent", 1);
  280. try
  281. {
  282. onAgree?.Invoke();
  283. }
  284. catch (System.Exception e)
  285. {
  286. Debug.LogError(e.Message + "\n" + e.StackTrace);
  287. }
  288. };
  289. m.onReject = () =>
  290. {
  291. try
  292. {
  293. onReject?.Invoke();
  294. }
  295. catch (System.Exception e)
  296. {
  297. Debug.LogError(e.Message + "\n" + e.StackTrace);
  298. }
  299. };
  300. return true;
  301. }
  302. return false;
  303. }
  304. public void OnClick_ConnectBLE() {
  305. if (ShowProminentBeforeConnectBLE()) return;
  306. BluetoothAim.ins.DoConnect();
  307. }
  308. public void OnClick_ShowDeviceView() {
  309. AudioMgr.ins.PlayBtn();
  310. ViewMgr.Instance.ShowView<DeviceViewInfrared>();
  311. }
  312. public void RenderNameOrGender() {
  313. nickNameText.text = LoginMgr.myUserInfo.nickname;
  314. genders[LoginMgr.myUserInfo.gender == 2 ? 1 : 0].SetActive(true);
  315. genders[LoginMgr.myUserInfo.gender == 2 ? 0 : 1].SetActive(false);
  316. LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
  317. }
  318. public void RenderMyAvatarSprite() {
  319. RoleMgr.SetAvatarToImage(myAvatarSprite, LoginMgr.myUserInfo.avatarID, LoginMgr.myUserInfo.avatarUrl);
  320. }
  321. public void RenderDeviceNames()
  322. {
  323. try {
  324. (DeviceInfo bowInfo, DeviceInfo arrowInfo) = DeviceMgr.ins.GetCurrentBowArrowInfo();
  325. // this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(bowInfo.config.name);
  326. this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(200000);
  327. this.transform.Find("ShowArrow/Text").GetComponent<TextAutoLanguage>().SetText(arrowInfo.config.name);
  328. } catch (System.Exception) {}
  329. }
  330. public Action action_OnClickStartGame;
  331. public void GoTo(string target) {
  332. AudioMgr.ins.PlayBtn();
  333. switch (target)
  334. {
  335. case "开始游戏":
  336. #if !UNITY_EDITOR
  337. if ((CommonConfig.isReleaseVersion || CommonConfig.StandaloneMode) && !BluetoothStatus.IsAllConnected())
  338. {
  339. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请先连接设备"));
  340. return;
  341. }
  342. #endif
  343. ViewMgr.Instance.ShowView<GameStartView>();
  344. action_OnClickStartGame?.Invoke();
  345. break;
  346. case "联机游戏":
  347. if (CommonConfig.isReleaseVersion && !BluetoothStatus.IsAllConnected()) {
  348. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请先连接设备"));
  349. return;
  350. }
  351. GlobalDataTemp.pkMatchType = PKMatchType.OnlinePK;
  352. ViewMgr.Instance.ShowView<PKGameOptionView>();
  353. break;
  354. case "我的":
  355. //ViewMgr.Instance.ShowView<MeView>();
  356. if (!CommonConfig.StandaloneMode)
  357. ViewManager2.ShowView(ViewManager2.Path_PersonalView);
  358. break;
  359. default:
  360. break;
  361. }
  362. }
  363. /* FriendBar */
  364. GameObject friendItemPrefab = null;
  365. Transform friendBarContent = null;
  366. IEnumerator RefreshFriendBar() {
  367. yield return null;
  368. //if (friendItemPrefab == null) {
  369. // friendItemPrefab = transform.Find("FriendBar/Scroll View/Viewport/Content/Item").gameObject;
  370. // Destroy(friendItemPrefab.GetComponent<Image>());
  371. // friendItemPrefab.SetActive(false);
  372. //}
  373. //if (friendBarContent == null) {
  374. // friendBarContent = transform.Find("FriendBar/Scroll View/Viewport/Content");
  375. //}
  376. //while (UserPlayer.ins == null || !UserPlayer.ins.loginAuthed || !UserPlayer.ins.hasGetUserInfo) {
  377. // yield return null;
  378. //}
  379. //Action<JArray> cb = RenderFriendList;
  380. //UserPlayer.ins.call("friendComp.getMyFriends", null, cb);
  381. }
  382. public void RenderFriendList(JArray list) {
  383. if (flag_SwapFriendAndRank != 0) return;
  384. for (int i = 1; i < friendBarContent.childCount; i++) {
  385. Destroy(friendBarContent.GetChild(i).gameObject);
  386. }
  387. if (list.Count > 0) {
  388. Color outColor;
  389. foreach (var itemInfo in list) {
  390. int friendID = itemInfo.Value<int>("friendID");
  391. int avatarID = itemInfo.Value<int>("avatarID");
  392. string avatarUrl = itemInfo.Value<string>("avatarUrl");
  393. string nickname = itemInfo.Value<string>("nickname");
  394. bool online = itemInfo.Value<bool>("online");
  395. long offlineTime = itemInfo.Value<long>("offlineTime");
  396. GameObject o = GameObject.Instantiate(friendItemPrefab, friendBarContent);
  397. o.SetActive(true);
  398. o.name = friendID.ToString();
  399. Image avatarImage = o.transform.Find("Avatar").GetComponent<Image>();
  400. RoleMgr.SetAvatarToImage(avatarImage, avatarID, avatarUrl);
  401. o.transform.Find("Nickname").GetComponent<Text>().text = nickname;
  402. TextAutoLanguage2 timeTip = o.transform.Find("Avatar/Line/Text").GetComponent<TextAutoLanguage2>();
  403. TimeUtil.SetOfflineTimeTextKey(offlineTime, online, timeTip);
  404. if (online) {
  405. ColorUtility.TryParseHtmlString("#12B525", out outColor);
  406. } else {
  407. ColorUtility.TryParseHtmlString("#A8B2BD", out outColor);
  408. }
  409. timeTip.GetComponent<Text>().color = outColor;
  410. }
  411. }
  412. }
  413. IEnumerator RefreshFriendRankBar() {
  414. if (friendItemPrefab == null) {
  415. friendItemPrefab = transform.Find("FriendBar/Scroll View/Viewport/Content/Item").gameObject;
  416. Destroy(friendItemPrefab.GetComponent<Image>());
  417. friendItemPrefab.SetActive(false);
  418. }
  419. if (friendBarContent == null) {
  420. friendBarContent = transform.Find("FriendBar/Scroll View/Viewport/Content");
  421. }
  422. while (UserPlayer.ins == null || !UserPlayer.ins.loginAuthed || !UserPlayer.ins.hasGetUserInfo) {
  423. yield return null;
  424. }
  425. Action<JArray> cb = RenderFriendRankList;
  426. UserPlayer.ins.call("rankComp.getFriendRankList", null, cb);
  427. }
  428. void RenderFriendRankList(JArray list) {
  429. if (flag_SwapFriendAndRank != 1) return;
  430. for (int i = 1; i < friendBarContent.childCount; i++) {
  431. Destroy(friendBarContent.GetChild(i).gameObject);
  432. }
  433. if (list.Count > 0) {
  434. foreach (var itemInfo in list) {
  435. int userID = itemInfo.Value<int>("id");
  436. int avatarID = itemInfo.Value<int>("avatarID");
  437. string avatarUrl = itemInfo.Value<string>("avatarUrl");
  438. string nickname = itemInfo.Value<string>("nickname");
  439. bool online = itemInfo.Value<bool>("online");
  440. long offlineTime = itemInfo.Value<long>("offlineTime");
  441. int rankNum = itemInfo.Value<int>("rankNum");
  442. GameObject o = GameObject.Instantiate(friendItemPrefab, friendBarContent);
  443. o.SetActive(true);
  444. o.name = userID.ToString();
  445. Image avatarImage = o.transform.Find("Avatar").GetComponent<Image>();
  446. RoleMgr.SetAvatarToImage(avatarImage, avatarID, avatarUrl);
  447. o.transform.Find("Nickname").GetComponent<Text>().text = nickname;
  448. TextAutoLanguage2 timeTip = o.transform.Find("Avatar/Line/Text").GetComponent<TextAutoLanguage2>();
  449. Action<Text> onApplyToNext = (t) => {
  450. if (TextAutoLanguage2.GetLanguage() == 0) {
  451. t.text = $"第{rankNum}名";
  452. } else {
  453. string str = rankNum.ToString();
  454. if (str.EndsWith("1")) t.text = $"{rankNum}st";
  455. else if (str.EndsWith("2")) t.text = $"{rankNum}nd";
  456. else if (str.EndsWith("3")) t.text = $"{rankNum}rd";
  457. else t.text = $"{rankNum}th";
  458. }
  459. Color outColor;
  460. if (rankNum == 1) ColorUtility.TryParseHtmlString("#F0E68C", out outColor);
  461. else if (rankNum == 2) ColorUtility.TryParseHtmlString("#E0FFFF", out outColor);
  462. else if (rankNum == 3) ColorUtility.TryParseHtmlString("#CD8162", out outColor);
  463. else ColorUtility.TryParseHtmlString("#EEE5DE", out outColor);
  464. t.color = outColor;
  465. };
  466. timeTip.onApplyToNext += onApplyToNext;
  467. }
  468. }
  469. }
  470. int flag_SwapFriendAndRank = 0;
  471. public void OnClick_SwapFriendAndRank() {
  472. AudioMgr.ins.PlayBtn();
  473. if (flag_SwapFriendAndRank == 0) {
  474. flag_SwapFriendAndRank = 1;
  475. transform.Find("FriendBar/FrameBtnTop").GetComponentInChildren<TextAutoLanguage2>().SetTextKey("rank_title");
  476. } else if (flag_SwapFriendAndRank == 1) {
  477. flag_SwapFriendAndRank = 0;
  478. transform.Find("FriendBar/FrameBtnTop").GetComponentInChildren<TextAutoLanguage2>().SetTextKey("friend_title");
  479. }
  480. RefreshFriendBarAccordingCurrentBar();
  481. }
  482. //根据栏目类型,调用对应的接口请求
  483. public void RefreshFriendBarAccordingCurrentBar()
  484. {
  485. if (flag_SwapFriendAndRank == 0)
  486. StartCoroutine(RefreshFriendBar());
  487. else if (flag_SwapFriendAndRank == 1)
  488. StartCoroutine(RefreshFriendRankBar());
  489. }
  490. public void OnClick_ShowDetail() {
  491. AudioMgr.ins.PlayBtn();
  492. if (flag_SwapFriendAndRank == 0) {
  493. ViewMgr.Instance.ShowView<FriendView>();
  494. } else if (flag_SwapFriendAndRank == 1) {
  495. ViewMgr.Instance.ShowView<RankView>();
  496. }
  497. }
  498. //检测是否需要提示有人加我好友
  499. bool _old_hasFriendRequest = false;
  500. int _old_flag_SwapFriendAndRank = 0;
  501. void UpdateCheckRenderFriendTip()
  502. {
  503. if (UserPlayer.ins == null) return;
  504. if (
  505. UserPlayer.ins.tempData.hasFriendRequest == _old_hasFriendRequest &&
  506. flag_SwapFriendAndRank == _old_flag_SwapFriendAndRank
  507. ) return;
  508. _old_hasFriendRequest = UserPlayer.ins.tempData.hasFriendRequest;
  509. _old_flag_SwapFriendAndRank = flag_SwapFriendAndRank;
  510. friendBarTipTop.SetActive(
  511. flag_SwapFriendAndRank == 1 &&
  512. UserPlayer.ins.tempData.hasFriendRequest);
  513. friendBarTipBottom.SetActive(
  514. flag_SwapFriendAndRank == 0 &&
  515. UserPlayer.ins.tempData.hasFriendRequest);
  516. }
  517. public void RenderBattery(int deviceID, int value)
  518. {
  519. Image img = betteryBar.GetComponent<Image>();
  520. img.fillAmount = value / 100f;
  521. }
  522. public void RenderBattery2() {
  523. int value = BluetoothAim.ins.get2PBattery();
  524. Image img = betteryBar2.GetComponent<Image>();
  525. img.fillAmount = value / 100f;
  526. }
  527. public void UpdateParent() {
  528. TopBarButtonInfo topBarButtonInfo = topBarView.GetCurrentTopBarButtonInfo();
  529. if (bettery != null)
  530. {
  531. bettery.transform.SetParent(topBarButtonInfo.container.transform);
  532. }
  533. if (bettery2 != null)
  534. {
  535. bettery2.transform.SetParent(topBarButtonInfo.container.transform);
  536. }
  537. }
  538. void updateBatteryStatus() {
  539. if (BluetoothAim.ins == null) return;
  540. //更新电池图标显示
  541. if (BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess)
  542. {
  543. if (!bettery.activeSelf)
  544. {
  545. TopBarButtonInfo topBarButtonInfo = topBarView.GetCurrentTopBarButtonInfo();
  546. bettery.transform.SetParent(topBarButtonInfo.container.transform);
  547. bettery.SetActive(true);
  548. }
  549. }
  550. else
  551. {
  552. if (bettery.activeSelf)
  553. {
  554. bettery.SetActive(false);
  555. }
  556. }
  557. //更新设备2电池图标显示
  558. if (BluetoothAim.ins.getSmartBowHelper2P() != null &&
  559. BluetoothAim.ins.getSmartBowHelper2P().GetBluetoothStatus() == SmartBowSDK.BluetoothStatusEnum.Connected)
  560. {
  561. if (!bettery2.activeSelf)
  562. {
  563. TopBarButtonInfo topBarButtonInfo = topBarView.GetCurrentTopBarButtonInfo();
  564. bettery2.transform.SetParent(topBarButtonInfo.container.transform);
  565. bettery2.SetActive(true);
  566. }
  567. }
  568. else
  569. {
  570. if (bettery2.activeSelf)
  571. {
  572. bettery2.SetActive(false);
  573. }
  574. }
  575. }
  576. }