using LitJson; using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using UnityEngine; public class MultiPlayerManager : MonoSingleton { public delegate void JoinRoom(SyncObject sycObj); public delegate void QuitRoom(SyncObject sycObj); public delegate void SynObject(SyncObject sycObj); public delegate void SynVideo(SyncVideoData sycVideo); public JoinRoom OnJoinRoom; public QuitRoom OnQuitRoom; public SynObject OnSynObject; public SynVideo OnSynVideo; //public Queue qSyncObject; //public Queue qSyncVideo; public Dictionary dicSpoitValue; //public Dictionary dicVideoValue; //public List listVideoValue; public Dictionary dicPlayer; private void Start() { dicSpoitValue = new Dictionary(); dicPlayer = new Dictionary(); //string test = "\u6587\u65C5\u5C55\u793A\u6F14\u793A"; //Debug.Log("DGJ ====> "+ JsonConvert.DeserializeObject("\"" + test + "\"")); } public void ReceivedCamPos(string uid, JsonData data) { Debug.Log("DGJ ===> ReceivedCamPos " + uid); SyncObject syncData = new SyncObject(); syncData.id = uid; syncData.pos = new Vector3(float.Parse(data["x"].ToString()), float.Parse(data["y"].ToString()), float.Parse(data["z"].ToString())); foreach (var item in dicPlayer) { Debug.Log("DGJ dicPlayer =====> " + item.Key); } if (!dicPlayer.ContainsKey(uid)) { Debug.LogError("DGJ ====> " + uid); // 创建 UnityEngine.Object @object = ResMgr.Instance.Load("Player"); GameObject gameObject = UnityEngine.Object.Instantiate(@object as GameObject); GameObject player = GameObject.Instantiate(gameObject); SynchronizationObject SyncPlayer = player.GetComponent(); player.transform.SetParent(GameManager.Instance.Player.transform.parent); SyncPlayer.uid = uid; SyncPlayer.InitData(syncData); dicPlayer.Add(SyncPlayer.uid, SyncPlayer); } OnSynObject(syncData); } public void ReceivedActiveSp(JsonData data) { string spid = JsonConvert.DeserializeObject("\"" + data["spid"].ToString() + "\""); Debug.Log("DGJ ====> " + spid); foreach (var item in dicSpoitValue) { Debug.Log("DGJ ====> " + item.Key); } dicSpoitValue[spid].spoitObj.SetActive(bool.Parse(data["isOpen"].ToString())); } public void ReceivedActiveVideo(JsonData data) { SyncVideoData syncData = new SyncVideoData(); syncData.spid = JsonConvert.DeserializeObject("\"" + data["spid"].ToString() + "\""); syncData.id = JsonConvert.DeserializeObject("\"" + data["videoId"].ToString() + "\""); syncData.isPlay = bool.Parse(data["isplay"].ToString()); syncData.times = float.Parse(data["jindu"].ToString()); OnSynVideo(syncData); } } public class SyncSpoit { public string spoitId; public GameObject spoitObj; } public class SyncVideo { public string spoitId; public string videoId; public AVProVideoPlayer aVProVideo; } public class SyncObject { public string id { get; set; } // public bool isSelect { get; set; } // public bool objAction { get; set; } public Vector3 pos { get; set; } // public Vector3 rot { get; set; } } public class SyncVideoData { public string spid { get; set; } public string id { get; set; } public bool isPlay { get; set; } public float times { get; set; } } public enum SyncObjectType { Object, Video, Player }