public void UpdateObject(ulong objectId, Protometry.Vector3 actualPosition, Protometry.Vector3 newPosition) { UpdateObject(objectId, actualPosition, new Protometry.Quaternion { X = 0, Y = 0, Z = 0, W = 0 }, newPosition, new Protometry.Quaternion { X = 0, Y = 0, Z = 0, W = 0 }); }
public void CreateObject(Protometry.Vector3 position) { UpdateObject(ulong.MaxValue, position, position); }
public static UnityEngine.Vector3 ToVector3(this Protometry.Vector3 v) { return(new UnityEngine.Vector3((float)v.X, (float)v.Y, (float)v.Z)); }
/// <summary> /// UpdateObject is a client to server method to update an object /// </summary> /// <param name="objectId"></param> /// <param name="actualPosition"></param> /// <param name="actualRotation"></param> /// <param name="newPosition"></param> /// <param name="newRotation"></param> public void UpdateObject(ulong objectId, Protometry.Vector3 actualPosition, Protometry.Quaternion actualRotation, Protometry.Vector3 newPosition, Protometry.Quaternion newRotation) { var p = new Packet { }; // Update if (Objects.ContainsKey(objectId)) { var obj = Objects[objectId]; var trans = obj.transform; var packetType = new UpdateSpaceRequestPacket { ObjectId = objectId }; foreach (var c in obj.Components) { switch (c.TypeCase) { case Component.TypeOneofCase.Space: packetType.ActualSpace = c.Space; break; } } // The requested new space will correspond to local client object's transform var newSpace = new Component.Types.SpaceComponent { Position = newPosition, Rotation = newRotation, Scale = trans.localScale.ToVector3() }; packetType.ActualSpace.Position = actualPosition; packetType.ActualSpace.Rotation = actualRotation; packetType.NewSpace = newSpace; p.UpdateSpaceRequest = packetType; SessionManager.Instance.Client.Send(p); } else { // No id, create var packetType = new UpdateObjectPacket(); // Create components from scratch packetType.Components.Add(new Component { Space = new Component.Types.SpaceComponent { Position = actualPosition, Rotation = actualRotation, Scale = new Protometry.Vector3 { X = 1, Y = 1, Z = 1 } } }); packetType.Components.Add(new Component { BehaviourType = new Component.Types.BehaviourTypeComponent { // TODO: hardcoded animal tag because we can only create animals yet Tag = Component.Types.BehaviourTypeComponent.Types.Tag.Animal } }); p.UpdateObject = packetType; SessionManager.Instance.Client.Send(p); } }
public void Move(Protometry.Vector3 position) { transform.position = position.ToVector3(); }