| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- /* 主界面 */
- public class HomeView : MonoBehaviour
- {
- [SerializeField] Image myAvatarSprite;
- [SerializeField] Text nickNameText;
- [SerializeField] GameObject[] genders;
- [SerializeField] GameObject btnConnectBow;
- [SerializeField] GameObject btnConnectArrow;
- [SerializeField] GameObject friendTip;
- public static HomeView ins;
- void Awake() {
- if (CommonConfig.needToExamine) {
- transform.Find("LeftPanel/Item (1)").gameObject.SetActive(false);
- transform.Find("RightPanel/Item/Text").GetComponent<TextAutoLanguage>().SetText(1234562);
- transform.Find("RightPanel/Item (1)/Text").GetComponent<TextAutoLanguage>().SetText(1234563);
- transform.Find("RightPanel/Item (3)").gameObject.SetActive(false);
- }
- }
- void Start()
- {
- ins = this;
- BluetoothHolder.Init();
- AudioMgr.Init();
- if (ShootCheck.ins) ShootCheck.ins.AdjustNormalOrHightMode();
- InitBtnForConnect();
- if (LoginMgr.myUserInfo.id > 0) {
- RenderNameOrGender();
- RenderMyAvatarSprite();
- RenderDeviceNames();
- }
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- }
- void FixedUpdate()
- {
- UpdateBtnForConnect();
- }
- void Update() {
- if (UserPlayer.ins != null) {
- if (UserPlayer.ins.tempData.hasFriendRequest && !friendTip.activeSelf) {
- friendTip.SetActive(true);
- }
- else if (!UserPlayer.ins.tempData.hasFriendRequest && friendTip.activeSelf) {
- friendTip.SetActive(false);
- }
- }
- }
- public void RenderNameOrGender() {
- nickNameText.text = LoginMgr.myUserInfo.nickname;
- genders[LoginMgr.myUserInfo.gender == 2 ? 1 : 0].SetActive(true);
- genders[LoginMgr.myUserInfo.gender == 2 ? 0 : 1].SetActive(false);
- LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
- }
- public void RenderMyAvatarSprite() {
- myAvatarSprite.sprite = RoleMgr.GetAvatar(LoginMgr.myUserInfo.avatarID);
- }
- public void RenderDeviceNames()
- {
- try {
- (DeviceInfo bowInfo, DeviceInfo arrowInfo) = DeviceMgr.ins.GetCurrentBowArrowInfo();
- // this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(bowInfo.config.name);
- this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(200000);
- this.transform.Find("ShowArrow/Text").GetComponent<TextAutoLanguage>().SetText(arrowInfo.config.name);
- } catch (System.Exception) {}
- }
- void InitBtnForConnect()
- {
- btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
- BluetoothAim.ins.DoConnect();
- });
- btnConnectArrow.GetComponent<Button>().onClick.AddListener(delegate() {
- BluetoothShoot.ins.DoConnect();
- });
- }
- BluetoothStatusEnum bowStatus;
- BluetoothStatusEnum arrowStatus;
- void UpdateBtnForConnect() {
- if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
- bowStatus = BluetoothAim.ins.status;
- (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
- btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
- btnConnectBow.GetComponentInChildren<Text>().color = color;
- }
- if (BluetoothShoot.ins && arrowStatus != BluetoothShoot.ins.status) {
- arrowStatus = BluetoothShoot.ins.status;
- (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
- btnConnectArrow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
- btnConnectArrow.GetComponentInChildren<Text>().color = color;
- }
- }
- public void GoTo(string target) {
- AudioMgr.ins.PlayBtn();
- switch (target)
- {
- case "开始游戏":
- if (CommonConfig.isReleaseVersion && !BluetoothStatus.IsAllConnected()) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请先连接设备"));
- return;
- }
- GameObject.Instantiate(GameObject.Find("WindowViews").transform.Find("GameStartView").gameObject).SetActive(true);
- break;
- case "联机游戏":
- if (CommonConfig.isReleaseVersion && !BluetoothStatus.IsAllConnected()) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请先连接设备"));
- return;
- }
- GlobalDataTemp.pkMatchType = PKMatchType.OnlinePK;
- GameObject.Instantiate(GameObject.Find("WindowViews").transform.Find("PKGameOptionView").gameObject).SetActive(true);
- break;
- case "好友":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/FriendView"));
- break;
- case "排行磅":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RankView"));
- break;
- case "对战":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RoleSelectView"));
- break;
- case "教程":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/CourseView"), Vector3.zero, new Quaternion());
- break;
- case "我的":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/MeView"), Vector3.zero, new Quaternion());
- break;
- case "设备":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/DeviceView"), Vector3.zero, new Quaternion());
- break;
- case "商城":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ShopView"), Vector3.zero, new Quaternion());
- break;
- default:
- break;
- }
- }
- }
|