public void Animate(MainJsonObject obj) { SendMessageJson jsonObj = new SendMessageJson(); jsonObj.action = obj.action; jsonObj.msgId = obj.msgId; string message = JsonConvert.SerializeObject(jsonObj); NetworkManager.Instance.Send(message); float dt = obj.contentObj.dt; JObject token = JObject.Parse(JObject.Parse(obj.content)["frames"].ToString()); foreach (string key in token.Properties().Select(p => p.Name).ToList()) { List <List <float> > array = JArray.Parse(token[key].ToString()).ToObject <List <List <float> > >(); List <Vector3> positions = new List <Vector3>(); List <Vector3> rotations = new List <Vector3>(); foreach (List <float> frame in array) { positions.Add(new Vector3(frame[0], frame[1], frame[2])); rotations.Add(new Vector3(frame[3], frame[4], frame[5])); } ObjectAnimation animation = new ObjectAnimation(dt, positions, rotations); AnimationManager.Instance.AddAnimation(objects[int.Parse(key)], animation); } }
void OnMessageReceived(string message) { MainJsonObject jsonObj = JsonConvert.DeserializeObject <MainJsonObject>(message); jsonObj.contentObj = JsonConvert.DeserializeObject <ContentJsonObject>(jsonObj.content); followingActions.Enqueue(new TCPAction(jsonObj)); }
public void GetObject(MainJsonObject obj) { if (!objects.ContainsKey(obj.contentObj.id)) { throw new Exception("Id not used !"); } SendMessage(obj, obj.contentObj); }
void OnMessageReceived(string message) { //Debug.Log("Received: " + message); MainJsonObject jsonObj = JsonUtility.FromJson <MainJsonObject>(message); jsonObj.contentObj = JsonUtility.FromJson <ContentJsonObject>(jsonObj.content); followingActions.Enqueue(new TCPAction(jsonObj)); }
public void GetObject(MainJsonObject obj) { MainObject o = objects[obj.contentObj.id]; ContentJsonObject content = obj.contentObj; String message = JsonUtility.ToJson(content); NetworkManager.Instance.Send(message); }
public void UpdateObject(MainJsonObject obj) { MainObject o = objects[obj.contentObj.id]; ContentJsonObject content = obj.contentObj; o.SetPosition(content.coordX, content.coordY, content.coordZ); o.SetEulerRotation(obj.contentObj.rotX, obj.contentObj.rotY, obj.contentObj.rotZ); o.SetSize(content.dimX, content.dimY, content.dimZ); //o.SetColor(); }
public void DeleteObject(MainJsonObject obj) { if (!objects.ContainsKey(obj.contentObj.id)) { throw new Exception("Id not used !"); } MainObject o = objects[obj.contentObj.id]; objects.Remove(o.GetId()); Destroy(o.gameObject); Debug.Log("Destroy " + o.type); }
public void InitFigure(MainJsonObject obj) { String typeFigure = obj.contentObj.typeFig; if (typeFigure == "2D") { CameraManager.Instance.Set2D(); } else { CameraManager.Instance.Set3D(); } }
public void UpdateObject(MainJsonObject obj) { if (!objects.ContainsKey(obj.contentObj.id)) { throw new Exception("Id not used !"); } MainObject o = objects[obj.contentObj.id]; ContentJsonObject content = obj.contentObj; o.SetPosition(content.coordX, content.coordY, content.coordZ); o.SetEulerRotation(obj.contentObj.rotX, obj.contentObj.rotY, obj.contentObj.rotZ); o.SetSize(content.dimX, content.dimY, content.dimZ); o.SetColor(content.color); SendMessage(obj); }
public void CreateObject(MainJsonObject obj) { if (objects.ContainsKey(obj.contentObj.id)) { throw new Exception("Id already used"); } ObjectType type = (ObjectType)obj.contentObj.type; MainObject prefab = prefabs[type]; Vector3 position = new Vector3(obj.contentObj.coordX, obj.contentObj.coordY, obj.contentObj.coordZ); GameObject go = Instantiate(prefab.gameObject, position, Quaternion.identity); MainObject o = go.GetComponent <Object3D>(); o.SetId(obj.contentObj.id); o.SetEulerRotation(obj.contentObj.rotX, obj.contentObj.rotY, obj.contentObj.rotZ); o.SetSize(obj.contentObj.dimX, obj.contentObj.dimY, obj.contentObj.dimZ); objects.Add(o.GetId(), o); Debug.Log("Created " + o.type); }
private void SendMessage(MainJsonObject obj, ContentJsonObject contentObj = null) { MainObject o = objects[obj.contentObj.id]; int id = o.GetId(); SendMessageJson jsonObj = new SendMessageJson(); ObjectType type = (ObjectType)obj.contentObj.type; jsonObj.action = obj.action; jsonObj.type = prefabs[type].ToString(); jsonObj.msgId = obj.msgId; jsonObj.objId = id; if (contentObj != null) { jsonObj.contentObj = contentObj; } string message = JsonConvert.SerializeObject(jsonObj); NetworkManager.Instance.Send(message); }
public void TrackObject(MainJsonObject obj) { MainObject o = objects[obj.contentObj.id]; CameraManager.Instance.TrackObject(o); }
public TCPAction(MainJsonObject obj) { this.obj = obj; }