using System; using System.Collections; using System.Collections.Generic; using System.Linq; using BeinLab.Util; using LitJson; using ShadowStudio.Mgr; using ShadowStudio.Model; using ShadowStudio.UI; using UnityEngine; using UnityEngine.SceneManagement; using XRTool.Util; public class ShowViewMgr : UnitySingleton { public event Action, bool> OnUserChange; public event Action OnRoomPageChange;//第一个是total,第二个是当前的 public event Action, SceneConfig> OnChangeRoom; public string roomId; public List artContainerList; public List SceneList; public Transform Target; public static Action ChooseSenceAction;//选择场景的监听 public static Action> RemoteSenceAction;//移除场景的监听 protected override void Awake() { base.Awake(); artContainerList = new List(); SceneList = new List(); ArtInfoMgr.Instance.ContainerCreate -= CreateSuccess; ArtInfoMgr.ContainerSelect -= OnContainerSelect; ArtInfoMgr.Instance.ContainerDel -= DeleteContainer; WSHandler.Room.OnOtherUserJoinRoom -= OtherUserJoinRoom; WSHandler.Room.OnOtherUserLeaveRoom -= OtherUserLeaveRoom; WSHandler.Room.onChangeScene -= ChangeScene; OnChangeRoom -= OnLocalChangeRoom; WSHandler.Room.OnClose -= Close; ArtInfoMgr.Instance.ContainerCreate += CreateSuccess; ArtInfoMgr.ContainerSelect += OnContainerSelect; ArtInfoMgr.Instance.ContainerDel += DeleteContainer; WSHandler.Room.OnOtherUserJoinRoom += OtherUserJoinRoom; WSHandler.Room.OnOtherUserLeaveRoom += OtherUserLeaveRoom; WSHandler.Room.onChangeScene += ChangeScene; OnChangeRoom += OnLocalChangeRoom; WSHandler.Room.OnClose += Close; } private void Close(JsonData data) { CommonMethod.ShowNetErrorAbnormalOutPop(); } private void ChangeScene(string peerId, List scenes, SceneConfig currentScene) { List sceneList = new List(); for (int i = 0; i < scenes.Count; i++) { sceneList.Add(scenes[i]); } OnRoomPageChange?.Invoke(scenes.Count, currentScene.Id); CompareList(SceneList, scenes, currentScene); SceneList.Clear(); for (int i = 0; i < sceneList.Count; i++) { SceneList.Add(sceneList[i]); } CommonMethod.currentScene = currentScene; } private void OnLocalChangeRoom(string method, List remainscene, SceneConfig currentScene) { switch (method) { case "RemoveSence": RemoteSenceAction.Invoke(remainscene); if (ItemSenceList.Instance) { ItemSenceList.Instance.SetCreateSenceBtnBtn(true); } break; case "AddSence": ItemSenceList.Instance.Init(remainscene, currentScene); ItemSenceSmallList.Instance.Init(remainscene, currentScene); break; case "ChangeSence": break; } ChooseSenceAction?.Invoke(currentScene); } void Start() { ArtInfoMgr.Instance.ListenPage(); ArtInfoMgr.Instance.ListenUser(); roomId = CommonMethod.roomConfig.Id; //WSHandler.User.OnRoomChange += roomChange; TimerMgr.Instance.CreateTimer(Init, 0.5f); } private void CreateSuccess(ArtContainer artContainer) { if (artContainer.GetGoodsInfo().art_id != "ArtId_GameObject") { Texture2D icon; if (artContainer.GetContainerIcon()) { icon = artContainer.GetContainerIcon() as Texture2D; artContainerList.Add(artContainer); ItemFileList.Instance.AddFileIcon(icon, artContainer); } else { //icon = new Texture2D(100, 100); artContainer.GetContainerIcon((tex) => { if (tex) { icon = tex as Texture2D; } else { icon = new Texture2D(64, 64); } artContainerList.Add(artContainer); ItemFileList.Instance.AddFileIcon(icon, artContainer); }); } } } private void DeleteContainer(ArtContainer artContainer) { if (artContainer!=null&& artContainer.GetGoodsInfo().art_id != "ArtId_GameObject") { for (int i = 0; i < ItemFileList.Instance.Itemfilelist.Count; i++) { ItemFileView itemFileView = ItemFileList.Instance.Itemfilelist[i].transform.GetComponent(); if (artContainer == itemFileView.artContainer) { DestroyImmediate(ItemFileList.Instance.Itemfilelist[i]); ItemFileList.Instance.Itemfilelist.RemoveAt(i); } } artContainerList.Remove(artContainer); //FileListDlg.Instance.fileCountText.text = LanguageMgr.Instance.GetMessage("1069").Message + artContainerList.Count + LanguageMgr.Instance.GetMessage("1070").Message; } } private void OnContainerSelect(ArtContainer artContainer, bool isSelect) { if (artContainer.GetGoodsInfo().art_id != "ArtId_GameObject"&& artContainer.GetGoodsInfo().art_id != "ArtId_PlayerView") { FileListDlg.ChooseFileAction?.Invoke(artContainer,isSelect); } } private void OtherUserJoinRoom(JsonData data) { List peerList = new List(); Peer peer = new Peer(); peer.PeerId = data["data"]["peerId"].ToString(); peer.NickName = data["data"]["nickName"].ToString(); peer.Avatar = data["data"]["avatar"].ToString(); peerList.Add(peer); if (UserItemList.Instance != null) { UserItemList.Instance.AddUserItem(peer); } OnUserChange?.Invoke(peerList, true); } public void SelfLeaveRoom() { List peerList = new List(); peerList.Add(CommonMethod.MyPeer); OnUserChange?.Invoke(peerList, false); } private void OtherUserLeaveRoom(JsonData data) { List peerList = new List(); Peer peer = new Peer(); peer.PeerId = data["data"]["peerId"].ToString(); peer.NickName = data["data"]["nickName"].ToString(); peerList.Add(peer); if (UserItemList.Instance != null) { UserItemList.Instance.DeleteUserItem(peer.PeerId); } OnUserChange?.Invoke(peerList, false); } public void Init() { OnRoomPageChange?.Invoke(CommonMethod.scenes.Count, CommonMethod.currentScene.Id); WSHandler.Room.BroadcastGoodReceived(CommonMethod.GoodsInfoList); for (int i = 0; i < CommonMethod.scenes.Count; i++) { SceneList.Add(CommonMethod.scenes[i]); } List peerList = new List(); for (int i = 0; i < CommonMethod.PeerList.Count; i++) { peerList.Add(CommonMethod.PeerList[i]); } peerList.Add(CommonMethod.MyPeer); for (int i = 0; i < peerList.Count; i++) { Debug.LogWarning(peerList[i].PeerId); } OnUserChange?.Invoke(peerList, true); if (UserItemList.Instance != null) { UserItemList.Instance.Init(peerList); } if (ItemSenceList.Instance && ItemSenceSmallList.Instance) { ItemSenceList.Instance.Init(CommonMethod.scenes, CommonMethod.currentScene); ItemSenceSmallList.Instance.Init(CommonMethod.scenes, CommonMethod.currentScene); } CommonMethod.GoodsInfoList.Clear(); CommonMethod.PeerList.Clear(); CommonMethod.scenes.Clear(); CommonMethod.IsReceive = false; } //private void roomChange(JsonData data) //{ // roomId = data["data"]["roomId"].ToString(); //} public void LoadHomeSence() { CommonMethod.ShowLoading(); Invoke("AllowLoadSence", 0.1f); CommonMethod.LoadSence("Home"); this.gameObject.SetActive(false); } public void LoadLoginSence() { CommonMethod.ShowLoading(); Invoke("AllowLoadSence", 0.1f); CommonMethod.LoadSence("Login"); this.gameObject.SetActive(false); } public void AllowLoadSence() { CommonMethod.HideLoading(); CommonMethod.AllowLoadSence(); } protected override void OnDestroy() { base.OnDestroy(); ArtInfoMgr.Instance.ContainerCreate -= CreateSuccess; WSHandler.Room.OnOtherUserJoinRoom -= OtherUserJoinRoom; WSHandler.Room.OnOtherUserLeaveRoom -= OtherUserLeaveRoom; ArtInfoMgr.ContainerSelect -= OnContainerSelect; ArtInfoMgr.Instance.ContainerDel -= DeleteContainer; WSHandler.Room.onChangeScene -= ChangeScene; OnChangeRoom -= OnLocalChangeRoom; WSHandler.Room.OnClose -= Close; } public void CompareList(List aListA, List aListB, SceneConfig currentScene) { if (aListA.Count > aListB.Count) { OnChangeRoom?.Invoke("RemoveSence", ClearRepeatItem(aListA, aListB), currentScene); } else if (aListA.Count < aListB.Count) { OnChangeRoom?.Invoke("AddSence", ClearRepeatItem(aListB, aListA), currentScene); } else { OnChangeRoom?.Invoke("ChangeSence", ClearRepeatItem(aListB, aListA), currentScene); } } private List ClearRepeatItem(List bigList, List SmallList) { List intolist = bigList.Where(a => !SmallList.Select(b => b.Id).Contains(a.Id)).ToList(); //Debug.Log(intolist.Count + "AAA"); return intolist; } }