HomeView.cs 23 KB

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