HomeView.cs 23 KB

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