123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- 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 UnityEngine.UI;
- using XRTool.Util;
- public class ShowViewMgr : UnitySingleton<ShowViewMgr>
- {
- public event Action<List<Peer>, bool> OnUserChange;
- public event Action<int, int> OnRoomPageChange;//第一个是total,第二个是当前的
- public event Action<string, List<SceneConfig>, SceneConfig> OnChangeRoom;
- public string roomId;
- public List<ArtContainer> artContainerList;
- public List<SceneConfig> SceneList;
- public Transform Target;
- public static Action<SceneConfig> ChooseSenceAction;//选择场景的监听
- public static Action<List<SceneConfig>> RemoteSenceAction;//移除场景的监听
- protected override void Awake()
- {
- base.Awake();
- artContainerList = new List<ArtContainer>();
- SceneList = new List<SceneConfig>();
- 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<SceneConfig> scenes, SceneConfig currentScene)
- {
- List<SceneConfig> sceneList = new List<SceneConfig>();
- 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<SceneConfig> 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);
- if (CommonMethod.roomConfig.Is_created == "0")
- {
- GameObject.Find("CreateSenceBtn").GetComponent<Button>().enabled = false;
- Debug.LogError("非房主进入房间");
- }
- else
- Debug.LogError("房主进入房间");
- }
- 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<ItemFileView>();
- 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<Peer> peerList = new List<Peer>();
- 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<Peer> peerList = new List<Peer>();
- peerList.Add(CommonMethod.MyPeer);
- OnUserChange?.Invoke(peerList, false);
- }
- private void OtherUserLeaveRoom(JsonData data)
- {
- List<Peer> peerList = new List<Peer>();
- 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<Peer> peerList = new List<Peer>();
- 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<SceneConfig> aListA, List<SceneConfig> 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<SceneConfig> ClearRepeatItem(List<SceneConfig> bigList, List<SceneConfig> SmallList)
- {
- List<SceneConfig> intolist = bigList.Where(a => !SmallList.Select(b => b.Id).Contains(a.Id)).ToList();
- //Debug.Log(intolist.Count + "AAA");
- return intolist;
- }
- }
|