123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using LitJson;
- using Newtonsoft.Json;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MultiPlayerManager : MonoSingleton<MultiPlayerManager>
- {
- 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<SyncObject> qSyncObject;
- //public Queue<SyncVideoData> qSyncVideo;
- public Dictionary<string, SyncSpoit> dicSpoitValue;
- //public Dictionary<string, SyncVideo> dicVideoValue;
- //public List<SyncVideo> listVideoValue;
- public Dictionary<string, SynchronizationObject> dicPlayer;
- private void Start()
- {
- dicSpoitValue = new Dictionary<string, SyncSpoit>();
- dicPlayer = new Dictionary<string, SynchronizationObject>();
- //string test = "\u6587\u65C5\u5C55\u793A\u6F14\u793A";
- //Debug.Log("DGJ ====> "+ JsonConvert.DeserializeObject<string>("\"" + 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<GameObject>(@object as GameObject);
- GameObject player = GameObject.Instantiate(gameObject);
- SynchronizationObject SyncPlayer = player.GetComponent<SynchronizationObject>();
- 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<string>("\"" + 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<string>("\"" + data["spid"].ToString() + "\"");
- syncData.id = JsonConvert.DeserializeObject<string>("\"" + 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
- }
|