HomeView.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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. //进行一次蓝牙连接
  210. BluetoothAim.ins.HomeViewConnectBLE();
  211. }
  212. IEnumerator testTip() {
  213. yield return new WaitForSeconds(1.0f);
  214. GameObject settingsViewObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_HomeViewTip);
  215. settingsViewObj.GetComponent<HomeView_Tip>().setHomeTip(0);
  216. }
  217. void OnDestroy()
  218. {
  219. if (ins == this) ins = null;
  220. TopBarView.DontNeedShowIt(this);
  221. }
  222. void Update() {
  223. UpdateCheckRenderFriendTip();
  224. UpdateBtnForConnect();
  225. //更新电池显示
  226. updateBatteryStatus();
  227. }
  228. // float countingTime1 = 0;
  229. BluetoothStatusEnum bowStatus;
  230. void UpdateBtnForConnect() {
  231. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
  232. bowStatus = BluetoothAim.ins.status;
  233. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  234. //btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  235. //btnConnectBow.GetComponentInChildren<Text>().color = color;
  236. //btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus == BluetoothStatusEnum.ConnectSuccess);
  237. }
  238. }
  239. public static bool ShowProminentBeforeConnectBLE(Action onAgree = null)
  240. {
  241. if (CommonConfig.StandaloneMode) return false;
  242. if (SceneManager.GetActiveScene().name.Equals("HeartRateBand")) return false;
  243. if (PlayerPrefs.GetInt("Location-Prominent", 0) == 0) {
  244. ModalView m = ModalView.Show();
  245. string pName = Application.productName;
  246. m.textKey = "Model_Location-Prominent";
  247. m.onAgreeTextKey = "common_next";
  248. m.onRejectTextKey = "common_cancel";
  249. m.textFormatArgs = new object[] {pName};
  250. m.onAgree = () => {
  251. PlayerPrefs.SetInt("Location-Prominent", 1);
  252. try {
  253. onAgree?.Invoke();
  254. } catch (System.Exception e) {
  255. Debug.LogError(e.Message + "\n" + e.StackTrace);
  256. }
  257. };
  258. return true;
  259. }
  260. return false;
  261. }
  262. public static bool ShowProminentBeforeConnectBLE_Event(Action onAgree = null,Action onReject = null)
  263. {
  264. if (CommonConfig.StandaloneMode) return false;
  265. if (SceneManager.GetActiveScene().name.Equals("HeartRateBand")) return false;
  266. if (PlayerPrefs.GetInt("Location-Prominent", 0) == 0)
  267. {
  268. ModalView m = ModalView.Show();
  269. string pName = Application.productName;
  270. m.textKey = "Model_Location-Prominent";
  271. m.onAgreeTextKey = "common_next";
  272. m.onRejectTextKey = "common_cancel";
  273. m.textFormatArgs = new object[] { pName };
  274. m.onAgree = () => {
  275. PlayerPrefs.SetInt("Location-Prominent", 1);
  276. try
  277. {
  278. onAgree?.Invoke();
  279. }
  280. catch (System.Exception e)
  281. {
  282. Debug.LogError(e.Message + "\n" + e.StackTrace);
  283. }
  284. };
  285. m.onReject = () =>
  286. {
  287. try
  288. {
  289. onReject?.Invoke();
  290. }
  291. catch (System.Exception e)
  292. {
  293. Debug.LogError(e.Message + "\n" + e.StackTrace);
  294. }
  295. };
  296. return true;
  297. }
  298. return false;
  299. }
  300. public void OnClick_ConnectBLE() {
  301. if (ShowProminentBeforeConnectBLE()) return;
  302. BluetoothAim.ins.DoConnect();
  303. }
  304. public void OnClick_ShowDeviceView() {
  305. AudioMgr.ins.PlayBtn();
  306. ViewMgr.Instance.ShowView<DeviceViewInfrared>();
  307. }
  308. public void RenderNameOrGender() {
  309. nickNameText.text = LoginMgr.myUserInfo.nickname;
  310. genders[LoginMgr.myUserInfo.gender == 2 ? 1 : 0].SetActive(true);
  311. genders[LoginMgr.myUserInfo.gender == 2 ? 0 : 1].SetActive(false);
  312. LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
  313. }
  314. public void RenderMyAvatarSprite() {
  315. RoleMgr.SetAvatarToImage(myAvatarSprite, LoginMgr.myUserInfo.avatarID, LoginMgr.myUserInfo.avatarUrl);
  316. }
  317. public void RenderDeviceNames()
  318. {
  319. try {
  320. (DeviceInfo bowInfo, DeviceInfo arrowInfo) = DeviceMgr.ins.GetCurrentBowArrowInfo();
  321. // this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(bowInfo.config.name);
  322. this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(200000);
  323. this.transform.Find("ShowArrow/Text").GetComponent<TextAutoLanguage>().SetText(arrowInfo.config.name);
  324. } catch (System.Exception) {}
  325. }
  326. public Action action_OnClickStartGame;
  327. public void GoTo(string target) {
  328. AudioMgr.ins.PlayBtn();
  329. switch (target)
  330. {
  331. case "开始游戏":
  332. #if !UNITY_EDITOR
  333. if ((CommonConfig.isReleaseVersion || CommonConfig.StandaloneMode) && !BluetoothStatus.IsAllConnected())
  334. {
  335. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请先连接设备"));
  336. return;
  337. }
  338. #endif
  339. ViewMgr.Instance.ShowView<GameStartView>();
  340. action_OnClickStartGame?.Invoke();
  341. break;
  342. case "联机游戏":
  343. if (CommonConfig.isReleaseVersion && !BluetoothStatus.IsAllConnected()) {
  344. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请先连接设备"));
  345. return;
  346. }
  347. GlobalDataTemp.pkMatchType = PKMatchType.OnlinePK;
  348. ViewMgr.Instance.ShowView<PKGameOptionView>();
  349. break;
  350. case "我的":
  351. //ViewMgr.Instance.ShowView<MeView>();
  352. if (!CommonConfig.StandaloneMode)
  353. ViewManager2.ShowView(ViewManager2.Path_PersonalView);
  354. break;
  355. default:
  356. break;
  357. }
  358. }
  359. /* FriendBar */
  360. GameObject friendItemPrefab = null;
  361. Transform friendBarContent = null;
  362. IEnumerator RefreshFriendBar() {
  363. yield return null;
  364. //if (friendItemPrefab == null) {
  365. // friendItemPrefab = transform.Find("FriendBar/Scroll View/Viewport/Content/Item").gameObject;
  366. // Destroy(friendItemPrefab.GetComponent<Image>());
  367. // friendItemPrefab.SetActive(false);
  368. //}
  369. //if (friendBarContent == null) {
  370. // friendBarContent = transform.Find("FriendBar/Scroll View/Viewport/Content");
  371. //}
  372. //while (UserPlayer.ins == null || !UserPlayer.ins.loginAuthed || !UserPlayer.ins.hasGetUserInfo) {
  373. // yield return null;
  374. //}
  375. //Action<JArray> cb = RenderFriendList;
  376. //UserPlayer.ins.call("friendComp.getMyFriends", null, cb);
  377. }
  378. public void RenderFriendList(JArray list) {
  379. if (flag_SwapFriendAndRank != 0) return;
  380. for (int i = 1; i < friendBarContent.childCount; i++) {
  381. Destroy(friendBarContent.GetChild(i).gameObject);
  382. }
  383. if (list.Count > 0) {
  384. Color outColor;
  385. foreach (var itemInfo in list) {
  386. int friendID = itemInfo.Value<int>("friendID");
  387. int avatarID = itemInfo.Value<int>("avatarID");
  388. string avatarUrl = itemInfo.Value<string>("avatarUrl");
  389. string nickname = itemInfo.Value<string>("nickname");
  390. bool online = itemInfo.Value<bool>("online");
  391. long offlineTime = itemInfo.Value<long>("offlineTime");
  392. GameObject o = GameObject.Instantiate(friendItemPrefab, friendBarContent);
  393. o.SetActive(true);
  394. o.name = friendID.ToString();
  395. Image avatarImage = o.transform.Find("Avatar").GetComponent<Image>();
  396. RoleMgr.SetAvatarToImage(avatarImage, avatarID, avatarUrl);
  397. o.transform.Find("Nickname").GetComponent<Text>().text = nickname;
  398. TextAutoLanguage2 timeTip = o.transform.Find("Avatar/Line/Text").GetComponent<TextAutoLanguage2>();
  399. TimeUtil.SetOfflineTimeTextKey(offlineTime, online, timeTip);
  400. if (online) {
  401. ColorUtility.TryParseHtmlString("#12B525", out outColor);
  402. } else {
  403. ColorUtility.TryParseHtmlString("#A8B2BD", out outColor);
  404. }
  405. timeTip.GetComponent<Text>().color = outColor;
  406. }
  407. }
  408. }
  409. IEnumerator RefreshFriendRankBar() {
  410. if (friendItemPrefab == null) {
  411. friendItemPrefab = transform.Find("FriendBar/Scroll View/Viewport/Content/Item").gameObject;
  412. Destroy(friendItemPrefab.GetComponent<Image>());
  413. friendItemPrefab.SetActive(false);
  414. }
  415. if (friendBarContent == null) {
  416. friendBarContent = transform.Find("FriendBar/Scroll View/Viewport/Content");
  417. }
  418. while (UserPlayer.ins == null || !UserPlayer.ins.loginAuthed || !UserPlayer.ins.hasGetUserInfo) {
  419. yield return null;
  420. }
  421. Action<JArray> cb = RenderFriendRankList;
  422. UserPlayer.ins.call("rankComp.getFriendRankList", null, cb);
  423. }
  424. void RenderFriendRankList(JArray list) {
  425. if (flag_SwapFriendAndRank != 1) return;
  426. for (int i = 1; i < friendBarContent.childCount; i++) {
  427. Destroy(friendBarContent.GetChild(i).gameObject);
  428. }
  429. if (list.Count > 0) {
  430. foreach (var itemInfo in list) {
  431. int userID = itemInfo.Value<int>("id");
  432. int avatarID = itemInfo.Value<int>("avatarID");
  433. string avatarUrl = itemInfo.Value<string>("avatarUrl");
  434. string nickname = itemInfo.Value<string>("nickname");
  435. bool online = itemInfo.Value<bool>("online");
  436. long offlineTime = itemInfo.Value<long>("offlineTime");
  437. int rankNum = itemInfo.Value<int>("rankNum");
  438. GameObject o = GameObject.Instantiate(friendItemPrefab, friendBarContent);
  439. o.SetActive(true);
  440. o.name = userID.ToString();
  441. Image avatarImage = o.transform.Find("Avatar").GetComponent<Image>();
  442. RoleMgr.SetAvatarToImage(avatarImage, avatarID, avatarUrl);
  443. o.transform.Find("Nickname").GetComponent<Text>().text = nickname;
  444. TextAutoLanguage2 timeTip = o.transform.Find("Avatar/Line/Text").GetComponent<TextAutoLanguage2>();
  445. Action<Text> onApplyToNext = (t) => {
  446. if (TextAutoLanguage2.GetLanguage() == 0) {
  447. t.text = $"第{rankNum}名";
  448. } else {
  449. string str = rankNum.ToString();
  450. if (str.EndsWith("1")) t.text = $"{rankNum}st";
  451. else if (str.EndsWith("2")) t.text = $"{rankNum}nd";
  452. else if (str.EndsWith("3")) t.text = $"{rankNum}rd";
  453. else t.text = $"{rankNum}th";
  454. }
  455. Color outColor;
  456. if (rankNum == 1) ColorUtility.TryParseHtmlString("#F0E68C", out outColor);
  457. else if (rankNum == 2) ColorUtility.TryParseHtmlString("#E0FFFF", out outColor);
  458. else if (rankNum == 3) ColorUtility.TryParseHtmlString("#CD8162", out outColor);
  459. else ColorUtility.TryParseHtmlString("#EEE5DE", out outColor);
  460. t.color = outColor;
  461. };
  462. timeTip.onApplyToNext += onApplyToNext;
  463. }
  464. }
  465. }
  466. int flag_SwapFriendAndRank = 0;
  467. public void OnClick_SwapFriendAndRank() {
  468. AudioMgr.ins.PlayBtn();
  469. if (flag_SwapFriendAndRank == 0) {
  470. flag_SwapFriendAndRank = 1;
  471. transform.Find("FriendBar/FrameBtnTop").GetComponentInChildren<TextAutoLanguage2>().SetTextKey("rank_title");
  472. } else if (flag_SwapFriendAndRank == 1) {
  473. flag_SwapFriendAndRank = 0;
  474. transform.Find("FriendBar/FrameBtnTop").GetComponentInChildren<TextAutoLanguage2>().SetTextKey("friend_title");
  475. }
  476. RefreshFriendBarAccordingCurrentBar();
  477. }
  478. //根据栏目类型,调用对应的接口请求
  479. public void RefreshFriendBarAccordingCurrentBar()
  480. {
  481. if (flag_SwapFriendAndRank == 0)
  482. StartCoroutine(RefreshFriendBar());
  483. else if (flag_SwapFriendAndRank == 1)
  484. StartCoroutine(RefreshFriendRankBar());
  485. }
  486. public void OnClick_ShowDetail() {
  487. AudioMgr.ins.PlayBtn();
  488. if (flag_SwapFriendAndRank == 0) {
  489. ViewMgr.Instance.ShowView<FriendView>();
  490. } else if (flag_SwapFriendAndRank == 1) {
  491. ViewMgr.Instance.ShowView<RankView>();
  492. }
  493. }
  494. //检测是否需要提示有人加我好友
  495. bool _old_hasFriendRequest = false;
  496. int _old_flag_SwapFriendAndRank = 0;
  497. void UpdateCheckRenderFriendTip()
  498. {
  499. if (UserPlayer.ins == null) return;
  500. if (
  501. UserPlayer.ins.tempData.hasFriendRequest == _old_hasFriendRequest &&
  502. flag_SwapFriendAndRank == _old_flag_SwapFriendAndRank
  503. ) return;
  504. _old_hasFriendRequest = UserPlayer.ins.tempData.hasFriendRequest;
  505. _old_flag_SwapFriendAndRank = flag_SwapFriendAndRank;
  506. friendBarTipTop.SetActive(
  507. flag_SwapFriendAndRank == 1 &&
  508. UserPlayer.ins.tempData.hasFriendRequest);
  509. friendBarTipBottom.SetActive(
  510. flag_SwapFriendAndRank == 0 &&
  511. UserPlayer.ins.tempData.hasFriendRequest);
  512. }
  513. public void RenderBattery(int deviceID, int value)
  514. {
  515. Image img = betteryBar.GetComponent<Image>();
  516. img.fillAmount = value / 100f;
  517. }
  518. public void RenderBattery2() {
  519. int value = BluetoothAim.ins.get2PBattery();
  520. Image img = betteryBar2.GetComponent<Image>();
  521. img.fillAmount = value / 100f;
  522. }
  523. public void UpdateParent() {
  524. TopBarButtonInfo topBarButtonInfo = topBarView.GetCurrentTopBarButtonInfo();
  525. if (bettery != null)
  526. {
  527. bettery.transform.SetParent(topBarButtonInfo.container.transform);
  528. }
  529. if (bettery2 != null)
  530. {
  531. bettery2.transform.SetParent(topBarButtonInfo.container.transform);
  532. }
  533. }
  534. void updateBatteryStatus() {
  535. if (BluetoothAim.ins == null) return;
  536. //更新电池图标显示
  537. if (BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess)
  538. {
  539. if (!bettery.activeSelf)
  540. {
  541. TopBarButtonInfo topBarButtonInfo = topBarView.GetCurrentTopBarButtonInfo();
  542. bettery.transform.SetParent(topBarButtonInfo.container.transform);
  543. bettery.SetActive(true);
  544. }
  545. }
  546. else
  547. {
  548. if (bettery.activeSelf)
  549. {
  550. bettery.SetActive(false);
  551. }
  552. }
  553. //更新设备2电池图标显示
  554. if (BluetoothAim.ins.getSmartBowHelper2P() != null &&
  555. BluetoothAim.ins.getSmartBowHelper2P().GetBluetoothStatus() == SmartBowSDK.BluetoothStatusEnum.Connected)
  556. {
  557. if (!bettery2.activeSelf)
  558. {
  559. TopBarButtonInfo topBarButtonInfo = topBarView.GetCurrentTopBarButtonInfo();
  560. bettery2.transform.SetParent(topBarButtonInfo.container.transform);
  561. bettery2.SetActive(true);
  562. }
  563. }
  564. else
  565. {
  566. if (bettery2.activeSelf)
  567. {
  568. bettery2.SetActive(false);
  569. }
  570. }
  571. }
  572. }