123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using TMPro;
- using System;
- using LitJson;
- using ShadowStudio.Model;
- using XRTool.Util;
- using ShadowStudio.Mgr;
- using ShadowStudio.UI;
- using DG.Tweening;
- using BeinLab.Util;
- using UnityEngine.EventSystems;
- using Studio.Scripts;
- public class MenuIcon : MonoBehaviour, IPointerDownHandler, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
- {
- private DoubleLinkNode<RoomConfig> _dataConfig;
- /// <summary>
- /// 存储房间的数据信息
- /// </summary>
- public DoubleLinkNode<RoomConfig> DataConfig { get => _dataConfig; set => _dataConfig = value; }
- Button _deleteBtn;//删除按钮
- GameObject _show;//显示房间界面
- GameObject _showK;//无房间时显示默认界面
- TextMesh _peopleNum;//房间人数文本
- TextMesh _roomName;//房间名称文本
- string _id;//房间ID
- string _passWord;//房间密码
- bool isClick = false;//房间是否被点击
- float _clickTime = 0.2f;//点击按下房间的间隔时间
- float _lastTime = 0;//记录开始点击房间时所处的时间
- public bool _isDrag = false;//房间是否被拖拽
- public static bool isjoinRoom;
- /// <summary>
- /// 记录物体的缩放值
- /// </summary>
- public Vector3 initAV3
- {
- get;
- set;
- }
- /// <summary>
- /// 记录所进入房间的ID,用于退出房间时显示指定房间的动画效果
- /// </summary>
- public static string inID;
- bool isRoomShow;
- bool isInit;
- bool isHide;
- /// <summary>
- /// 所处的位置索引(用于设置动画延迟)
- /// </summary>
- public int RoomIndex
- {
- get;
- set;
- }
- /// <summary>
- /// 进入或者退出房间时的位置变换记录
- /// </summary>
- public static Vector3 itemPos;
- public void Init()//初始化
- {
- HomeProxy.Instance.DeleteRoomAction += DeleteRoomHandler;
- _deleteBtn = transform.Find("DeleteBtn").GetComponent<Button>();
- _show = transform.Find("Show").gameObject;
- _showK = transform.Find("ShowK").gameObject;
- _peopleNum = transform.Find("Text/UIRoot/PeopleNumText").GetComponent<TextMesh>();
- _roomName = transform.Find("Text/UIRoot/FangzhuText").GetComponent<TextMesh>();
- _deleteBtn.onClick.AddListener(ClickDeleteBtn);
- EventTool._displayDelete += DisplayDeleteBtn;//注册点击删除按钮的事件
- if (CommonMethod.isZiDong)
- {
- if (!isjoinRoom)
- {
- isjoinRoom = true;
- Invoke("joinZIDONG", 2f);
- }
- }
- }
- void joinZIDONG()
- {
- WSHandler.Room.OnInit -= onInit;
- WSHandler.Room.OnJoinRoom -= onJoinRoom;
- WSHandler.Rtc.onRtcInit -= onRtcInit;
- WSHandler.Room.OnInit += onInit;
- WSHandler.Room.OnJoinRoom += onJoinRoom;
- WSHandler.Rtc.onRtcInit += onRtcInit;
- _id = "43";
- WSHandler.roominit(_id);
- }
- /// <summary>
- /// "x"按钮是否显示
- /// </summary>
- bool _isShow = false;
- void DisplayDeleteBtn()//点击删除按钮后,显示“x”按钮
- {
- _isShow = !_isShow;
- if (_id != "" && _deleteBtn != null)
- _deleteBtn.gameObject.SetActive(_isShow);
- }
- void ClickDeleteBtn()// 回调方法:点击“ x ”删除按钮
- {
- _deleteBtn.enabled = false;
- Invoke("ReDeleteBtn", 1f);
- CommonMethod.ShowPopUp(PopType.Cancel, LanguageMgr.Instance.GetMessage("1063").Message, LanguageMgr.Instance.GetMessage("1064").Message, () =>
- {
- SendDelete();
- }, LanguageMgr.Instance.GetMessage("1065").Message, null, LanguageMgr.Instance.GetMessage("1058").Message);
- }
- private void ReDeleteBtn()
- {
- _deleteBtn.enabled = true;
- }
- /// <summary>
- /// 发送删除房间消息
- /// </summary>
- public void SendDelete()
- {
- HomeProxy.Instance.RequestDeleteRoom(int.Parse(_id.Trim()));
- }
- /// <summary>
- /// 回调函数: 在删除房间成功后,刷新删除按钮的显示状态
- /// </summary>
- public void ChangeDteBtn()
- {
- if (_deleteBtn != null)
- {
- if (_id == "")
- {
- _deleteBtn.gameObject.SetActive(false);
- }
- else
- {
- _deleteBtn.gameObject.SetActive(true);
- }
- }
- }
- /// <summary>
- /// 刷新房间数据显示
- /// </summary>
- public void RefreshData()
- {
- if (_dataConfig != null)
- {
- gameObject.SetActive(true);
- _roomName.text = "房间名" + DataConfig.Value.Room_name;
- _id = DataConfig.Value.Id;
- if (DataConfig.Value.Room_password != null)
- {
- _passWord = DataConfig.Value.Room_password;
- }
- switch (DataConfig.Value.Type)
- {
- case "1":
- _peopleNum.text = "个人房间";
- break;
- case "2":
- _peopleNum.text = "房间人数" + DataConfig.Value.Number + "/" + DataConfig.Value.Max_member;
- break;
- default:
- break;
- }
- if (_id == "")
- {
- _show.SetActive(false);
- _showK.SetActive(true);
- _roomName.text = "Studio";
- _peopleNum.text = "添加房间";
- if (_deleteBtn != null)
- {
- _deleteBtn.gameObject.SetActive(false);
- }
- }
- else
- {
- _show.SetActive(true);
- _showK.SetActive(false);
- _deleteBtn.gameObject.SetActive(_isShow);
- }
- }
- else
- {
- gameObject.SetActive(false);
- }
- isInit = true;
- }
- /// <summary>
- /// 当点击房间元素时,执行的方法
- /// </summary>
- public void ClickSelf()
- {
- if (!isClick)
- {
- isClick = true;
- AgoraRTCManager.Instance.ChannelName = _id;
- // AgoraVideoAudioManager.Instance.JoinChannel();
- ClickSelf2();
- //if (_id != "")
- //{
- // Debug.Log(".................." + _id);
- // AgoraVideoAudioManager.Instance.SetChinnelName(_id);
- // AgoraVideoAudioManager.Instance.JoinChannel();
- // WSHandler.Room.OnInit -= onInit;
- // WSHandler.Room.OnJoinRoom -= onJoinRoom;
- // WSHandler.Rtc.onRtcInit -= onRtcInit;
- // WSHandler.Room.OnInit += onInit;
- // WSHandler.Room.OnJoinRoom += onJoinRoom;
- // WSHandler.Rtc.onRtcInit += onRtcInit;
- // WSHandler.roominit(_id);
- //}
- //else
- //{
- // OnClickCreateRoom();
- //}
- }
- }
- public void ClickSelf2()
- {
- Debug.Log("ClickSelf2");
- if (_id != "")
- {
-
- WSHandler.Room.OnInit -= onInit;
- WSHandler.Room.OnJoinRoom -= onJoinRoom;
- WSHandler.Rtc.onRtcInit -= onRtcInit;
- WSHandler.Room.OnInit += onInit;
- WSHandler.Room.OnJoinRoom += onJoinRoom;
- WSHandler.Rtc.onRtcInit += onRtcInit;
- WSHandler.roominit(_id);
- // effectRoom();
- }
- else
- {
- OnClickCreateRoom();
- }
- }
- /// <summary>
- /// 点击创建房间执行的操作
- /// </summary>
- private void OnClickCreateRoom()
- {
- isClick = false;
- HomeMgr.Instance._menuListDlg.Hide();
- CreateSearchRoomDlg.Instance.dlg.hideDlg();
- Invoke("GotoView", 1.3f);
- }
- /// <summary>
- /// 打开创建房间界面,关闭房间游戏对象界面
- /// </summary>
- private void GotoView()
- {
- if (CreateRoomDlg.Instance)
- {
- CreateRoomDlg.Instance.Init();
- }
- HomeMgr.Instance.ShowView(HomeMgr.CREATROOMDLG);
- HomeMgr.Instance.roomListDlg.SetActive(false);
- }
- private void onRtcInit(JsonData data)
- {
- // effectRoom();
- }
- private GameObject _showObj;
- /// <summary>
- /// 处于显示状态的房间游戏对象
- /// </summary>
- private GameObject Show
- {
- get
- {
- if (_id != "")
- {
- _showObj = _show;
- }
- else
- {
- _showObj = _showK;
- }
- return _showObj;
- }
- }
- GameObject frontBG;
- /// <summary>
- /// 房间游戏对象的背景板
- /// </summary>
- public GameObject FrontBG
- {
- get
- {
- if (!frontBG)
- {
- frontBG = UnityUtil.GetBreadthChild<Transform>(Show.transform, "FrontBG").gameObject;
- }
- return frontBG;
- }
- }
- GameObject bottom;
- /// <summary>
- /// 房间游戏对象的地板
- /// </summary>
- public GameObject Bottom
- {
- get
- {
- if (!bottom)
- {
- bottom = UnityUtil.GetBreadthChild<Transform>(Show.transform, "dibu").gameObject;
- }
- return bottom;
- }
- }
- GameObject picture;
- /// <summary>
- /// 房间游戏对象里的照片
- /// </summary>
- public GameObject Picture
- {
- get
- {
- if (!picture)
- {
- picture = UnityUtil.GetBreadthChild<Transform>(Show.transform, "Picture").gameObject;
- }
- return picture;
- }
- }
- GameObject people;
- /// <summary>
- /// 房间游戏对象里的人
- /// </summary>
- public GameObject People
- {
- get
- {
- if (!people)
- {
- people = UnityUtil.GetBreadthChild<Transform>(Show.transform, "People").gameObject;
- }
- return people;
- }
- }
- /// <summary>
- /// 执行进入场景的动画
- /// </summary>
- private void effectRoom()
- {
- itemPos = this.transform.parent.TransformPoint(new Vector3(-130, 0, -400));
- Show.transform.parent = null;
- this.transform.localScale = initAV3;
- HomeMgr.Instance._menuListDlg.Hide();
- CreateSearchRoomDlg.Instance.dlg.hideDlg();
- Show.transform.DOScale(Show.transform.localScale * 1.5f, 1);
- Show.transform.DOMove(itemPos, 1).OnComplete(() =>
- {
- DontDestroyOnLoad(Show.gameObject);
- itemPos = FrontBG.transform.position;
- // Picture.transform.LeanRotateY(360, 0.5f).setOnComplete(() => {
- // Picture.transform.LeanRotateY(180, 0.5f).setOnComplete(() =>
- // {
- Bottom.transform.DOMoveY(-1f, 2).SetEase(Ease.InCubic);
- Bottom.transform.DOScale(Bottom.transform.localScale * 20, 1f).SetEase(Ease.InCubic);
- // Bottom.transform.DOScaleZ(Bottom.transform.localScale.z * 20, 1f);
- Bottom.transform.LeanRotateY(180, 1f);
- GameEffect.setAlpha(Bottom, 0, 2);
- TimerMgr.Instance.CreateTimer(() =>
- {
- Picture.transform.localEulerAngles = new Vector3(0, 0, 0);
- //People.transform.DOScale(People.transform.localScale * 10, 2);
- Picture.transform.DOScale(People.transform.localScale * 10, 2).OnComplete<Tween>(() =>
- {
- Destroy(Show);
- });
- GameEffect.setAlpha(People, 0, 0.3f);
- GameEffect.setAlpha(Picture, 0, 0.2f);
- FrontBG.SetActive(false);
- }, 0.5f);
- Picture.transform.DOScale(new Vector3(0, 0, 0), 0.5f).SetEase(Ease.InBack).OnComplete<Tween>(() => { });
- People.transform.DOScale(new Vector3(0, 0, 0), 0.5f).SetEase(Ease.InBack).OnComplete<Tween>(() => { });
- HomeMgr.Instance.LoadSence();
- });
- inID = _id;
- }
- /// <summary>
- /// 点击进入房间后,隐藏房间游戏对象
- /// </summary>
- public void HideItem()
- {
- if (Show.transform.parent != null)
- {
- Vector3 v3 = Show.transform.localScale;
- // show.transform.localScale = new Vector3(v3.x, 0, v3.z);
- Vector3 pv3 = Show.transform.position;
- // show.transform.position = new Vector3(pv3.x, pv3.y + 0.1f, pv3.z);
- Show.transform.DOScale(new Vector3(v3.x, 0, v3.z), 0.3f).SetDelay<Tween>(RoomIndex * 0.3f * 0.5f).SetEase<Tween>(Ease.InBack).OnKill<Tween>(() =>
- {
- Show.transform.localScale = v3;
- Show.SetActive(false);
- this.gameObject.SetActive(false);
- }).OnComplete<Tween>(() =>
- {
- Show.transform.localScale = v3;
- Show.SetActive(false);
- this.gameObject.SetActive(false);
- });
- }
- else
- {
- this.gameObject.SetActive(false);
- }
- }
- /// <summary>
- /// 显示房间游戏对象
- /// </summary>
- public void ShowItem()
- {
- if (inID != null && inID == _id)
- {
- Vector3 v3 = MenuListDlg.Instance._menuUI._bezierPointGroup[RoomIndex];
- Vector3 v3L = this.transform.localScale;
- this.transform.position = itemPos;
- this.transform.localScale = v3L * 5f;
- this.transform.DOLocalMove(v3, 1);
- this.transform.DOScale(v3L, 1);
- isRoomShow = true;
- Show.transform.DOKill(true);
- inID = "None";
- Show.SetActive(true);
- //这两个参数影响是否在退出房间后,点击这个房间是否还有有放大效果
- //isInit = true;
- //isRoomShow = false;
- }
- else
- {
- isRoomShow = true;
- Show.transform.DOKill(true);
- Vector3 v3 = Show.transform.localScale;
- Show.transform.localScale = new Vector3(v3.x, 0, v3.z);
- Show.transform.DOScale(v3, 0.5f).SetDelay<Tween>(RoomIndex * 0.5f * 0.2f).SetEase<Tween>(Ease.OutBack).OnKill<Tween>(() =>
- {
- isRoomShow = false;
- isInit = true;
- Show.transform.localScale = v3;
- }).OnComplete<Tween>(() =>
- {
- isRoomShow = false;
- Show.transform.localScale = v3;
- isInit = true;
- }).OnStart<Tween>(() =>
- {
- Show.SetActive(true);
- });
- }
- }
- private void OnEnable()
- {
- if (initAV3 == Vector3.zero)
- initAV3 = this.transform.localScale;
- }
- /// <summary>
- /// 进入房间时,(跳转场景)存储数据
- /// </summary>
- /// <param name="goods"></param>
- /// <param name="peers"></param>
- /// <param name="scenes"></param>
- /// <param name="currentScene"></param>
- private void onJoinRoom(List<GoodsInfo> goods, List<Peer> peers, List<SceneConfig> scenes, SceneConfig currentScene)
- {
- effectRoom();
- CommonMethod.GoodsInfoList = new List<GoodsInfo>();
- CommonMethod.IsReceive = true;
- CommonMethod.HideLoading();
- CommonMethod.GoodsInfoList = goods;
- CommonMethod.PeerList = peers;
- CommonMethod.scenes = scenes;
- CommonMethod.currentScene = currentScene;
- CommonMethod.roomConfig = this.DataConfig.Value;
- if (!string.IsNullOrEmpty(this._passWord) && this._passWord != DataConfig.Value.Room_password)
- {
- CommonMethod.roomPassWord = this._passWord;
- }
- }
- /// <summary>
- /// 进入房间的初始化操作
- /// </summary>
- /// <param name="data"></param>
- private void onInit(JsonData data)
- {
- CommonMethod.SelfPeer(data["data"]["peerId"].ToString(), UserInfoMgr.Instance.userConfig.Nick_name);
- _passWord = this.DataConfig.Value.Room_password;
- if (string.IsNullOrEmpty( _passWord))//如果没有密码,则直接进入房间
- {
- WSHandler.Room.JoinRoom(_id, "");
- // effectRoom();
- }
- else//否则。。。。
- {
- // CommonMethod.HideLoading();
- CommonMethod.ShowPopUp(PopType.Cancel, LanguageMgr.Instance.GetMessage("1085").Message, LanguageMgr.Instance.GetMessage("1084").Message, null
- , LanguageMgr.Instance.GetMessage("1066").Message, () => { CanelJoinRoom(); }, LanguageMgr.Instance.GetMessage("1058").Message, true, (string pass) => { InputJoinRoom(pass); });
- }
- }
- /// <summary>
- /// 进入房间(输入密码进入)
- /// </summary>
- /// <param name="password"></param>
- private void InputJoinRoom(string password)
- {
- CommonMethod.ShowLoading();
- WSHandler.Room.JoinRoom(_id, password);
-
- if (password != "")
- {
- this._passWord = password;
- }
- }
- /// <summary>
- /// 当进入房间失败时,取消事件监听
- /// </summary>
- public void Refeshbool()
- {
- if (isClick)
- {
- isClick = false;
- WSHandler.Room.OnInit -= onInit;
- WSHandler.Room.OnJoinRoom -= onJoinRoom;
- WSHandler.Rtc.onRtcInit -= onRtcInit;
- }
- }
- /// <summary>
- /// 取消进入房间
- /// </summary>
- private void CanelJoinRoom()
- {
- isClick = false;
- WSHandler.Room.OnInit -= onInit;
- WSHandler.Room.OnJoinRoom -= onJoinRoom;
- WSHandler.Rtc.onRtcInit -= onRtcInit;
- WSHandler.roomCloes();
- }
- private void OnDestroy()
- {
- EventTool._displayDelete -= DisplayDeleteBtn;
- WSHandler.Room.OnInit -= onInit;
- WSHandler.Room.OnJoinRoom -= onJoinRoom;
- WSHandler.Rtc.onRtcInit -= onRtcInit;
- if (HomeProxy.Instance)
- {
- HomeProxy.Instance.DeleteRoomAction -= DeleteRoomHandler;
- }
- }
- /// <summary>
- /// 删除房间成功时的回调函数
- /// </summary>
- private void DeleteRoomHandler(int roomId)
- {
- if (!string.IsNullOrEmpty(_id))
- {
- int result = int.Parse(_id);
- if (roomId == result)
- {
- ConfigModel.Instance.RemoveElement(_dataConfig);//删除该数据
- if (HomeMgr.Instance.SelfRoomConfigList.Contains(_dataConfig.Value))
- {
- HomeMgr.Instance.SelfRoomConfigList.Remove(_dataConfig.Value);
- }
- //如果删除完数据之后,数据个数少于5,则造假一个数据
- if (ConfigModel.Instance.Count < 5 && HomeMgr.Instance.SelfRoomConfigList.Count < 5)
- {
- ConfigModel.Instance.AddElement(new RoomConfig("", "1", "教育", "", "", "", "", "", "", ""));
- HomeMgr.Instance.SelfRoomConfigList.Add(new RoomConfig("", "1", "教育", "", "", "", "", "", "", ""));
- }
- else
- {
- Debug.Log("数据个数:" + ConfigModel.Instance.Count);
- Debug.Log("备份个数:" + HomeMgr.Instance.SelfRoomConfigList.Count);
- //Debug.LogError("原始数据与备份数据不同步");
- }
- EventTool.RearrangeMethod(transform);//通知进行游戏对象和数据的移位
- RefreshData();//刷新数据
- MenuListDlg.Instance.UpdateBtn();//统一刷新所有按钮状态
- }
- }
- }
- public void OnPointerEnter(PointerEventData eventData)
- {
- if (!isHide && !isRoomShow && isInit)
- //LeanTween.scale(this.gameObject, initAV3 * 1.1f, 0.1f);
- transform.DOScale(initAV3 * 1.1f, 0.1f);
- }
- public void OnPointerExit(PointerEventData eventData)
- {
- if (!isHide && !isRoomShow && isInit)
- //LeanTween.scale(this.gameObject, initAV3, 0.1f);
- transform.DOScale(initAV3, 0.1f);
- }
- public void OnPointerDown(PointerEventData eventData)
- {
- _lastTime = Time.time;
- if (!isHide && !isRoomShow && isInit)
- //LeanTween.scale(this.gameObject, initAV3 * 0.9f, 0.1f);
- transform.DOScale(initAV3 * 0.9f, 0.1f);
- }
- public void OnPointerClick(PointerEventData eventData)
- {
- if (Time.time - _lastTime <= _clickTime)
- {
- if (!_isDrag)
- {
- ClickSelf();
- }
- }
- if (!isHide && !isRoomShow && isInit)
- //LeanTween.scale(this.gameObject, initAV3, 0.1f);.
- transform.DOScale(initAV3, 0.1f);
- }
- }
|