public void SendNetworkObjs() { if (NetworkObj.allObjs.Count == 0) { return; } ObjsStructure objs = new ObjsStructure(); //objs.ns = Time. objs.ms = (int)(Client.ms + 0.5d); List <string> allInfo = new List <string>(); string info; foreach (var obj in NetworkObj.allObjs) { info = obj.CollectInfo(); if (info != "" && info != null) { allInfo.Add(info); } } objs.objs = allInfo.ToArray(); BackendEvents evt = BackendEvents.SendObjects; objs.evt = (int)evt; string json = JsonUtility.ToJson(objs); if (Client.instance != null && Client.instance.socket != null) { Client.instance.socket.SendMessage(json); } }
override public void HandleMessage(ref string msg) { base.HandleMessage(ref msg); MsgStructure data = JsonUtility.FromJson <MsgStructure>(msg); FrontendEvents evt = (FrontendEvents)data.evt; switch (evt) { case FrontendEvents.Error: Debug.Log("ROOM ERROR"); error = data.error; Client.SetState(Client.signedInState); break; case FrontendEvents.Exit: Client.SetState(Client.signedInState); break; case FrontendEvents.AddPlayer: var info = new UserInfo(); info.id = data.id; info.isHost = data.isHost; info.isClient = data.isClient; info.bodyType = data.avatar_bodyType; info.skinTone = data.avatar_skinTone; info.color = data.avatar_color; info.face = data.avatar_face; info.hat = data.avatar_hat; info.frame = data.avatar_frame; waitingDict.Add(info.id, info); if (data.spawned) { goto case FrontendEvents.Spawn; } break; case FrontendEvents.Spawn: Debug.Log("Spawning " + data.id); UserInfo userInfo; if (waitingDict.TryGetValue(data.id, out userInfo)) { waitingDict.Remove(data.id); PlayerJoiner.queuedUsers.Enqueue(userInfo); } break; case FrontendEvents.RemovePlayer: //TODO: sacar de waiting dict if (waitingDict.ContainsKey(data.id)) { waitingDict.Remove(data.id); } Player player; if (players.TryGetValue(data.id, out player)) { GameObject.Destroy(player.gameObject); players.Remove(data.id); } break; case FrontendEvents.GetInfo: NetworkObj.BasicStructure structure; ObjsStructure objsStructure = JsonUtility.FromJson <ObjsStructure>(msg); if (objsStructure.ms < lastMs && GameManager.isClient) { Debug.Log("Ignoring info msg"); return; } lastMs = objsStructure.ms; NetworkObj obj; foreach (var str in objsStructure.objs) { structure = JsonUtility.FromJson <NetworkObj.BasicStructure>(str); if (NetworkObj.objsDict.TryGetValue(structure.key, out obj)) { obj.SetInfo(str); } } break; case FrontendEvents.ChangeScene: if (GameManager.isClient) { SceneLoader.instance.LoadScene(data.id); } break; } }