HomeView.cs 24 KB

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