protected override float DeserializeItem(NetworkReader reader) { return(reader.ReadSingle()); }
public static Matrix4x4 ReadMatrix4x4(this NetworkReader reader) { return(new Matrix4x4 { m00 = reader.ReadSingle(), m01 = reader.ReadSingle(), m02 = reader.ReadSingle(), m03 = reader.ReadSingle(), m10 = reader.ReadSingle(), m11 = reader.ReadSingle(), m12 = reader.ReadSingle(), m13 = reader.ReadSingle(), m20 = reader.ReadSingle(), m21 = reader.ReadSingle(), m22 = reader.ReadSingle(), m23 = reader.ReadSingle(), m30 = reader.ReadSingle(), m31 = reader.ReadSingle(), m32 = reader.ReadSingle(), m33 = reader.ReadSingle() }); }
// serialization is needed by OnSerialize and by manual sending from authority void DeserializeFromReader(NetworkReader reader) { // put it into a data point immediately DataPoint temp = new DataPoint(); // deserialize position temp.position = reader.ReadVector3(); // deserialize rotation if (compressRotation == Compression.None) { // read 3 floats = 16 byte float x = reader.ReadSingle(); float y = reader.ReadSingle(); float z = reader.ReadSingle(); temp.rotation = Quaternion.Euler(x, y, z); } else if (compressRotation == Compression.Much) { // read 3 byte. scaling [0,255] to [0,360] float x = Utils.ScaleByteToFloat(reader.ReadByte(), byte.MinValue, byte.MaxValue, 0, 360); float y = Utils.ScaleByteToFloat(reader.ReadByte(), byte.MinValue, byte.MaxValue, 0, 360); float z = Utils.ScaleByteToFloat(reader.ReadByte(), byte.MinValue, byte.MaxValue, 0, 360); temp.rotation = Quaternion.Euler(x, y, z); } else if (compressRotation == Compression.Lots) { // read 2 byte, 5 bits per float float[] xyz = Utils.UnpackUShortIntoThreeFloats(reader.ReadUInt16(), 0, 360); temp.rotation = Quaternion.Euler(xyz[0], xyz[1], xyz[2]); } // timestamp temp.timeStamp = Time.time; // movement speed: based on how far it moved since last time // has to be calculated before 'start' is overwritten temp.movementSpeed = EstimateMovementSpeed(goal, temp, targetComponent.transform, syncInterval); // reassign start wisely // -> first ever data point? then make something up for previous one // so that we can start interpolation without waiting for next. if (start == null) { start = new DataPoint { timeStamp = Time.time - syncInterval, position = targetComponent.transform.position, rotation = targetComponent.transform.rotation, movementSpeed = temp.movementSpeed }; } // -> second or nth data point? then update previous, but: // we start at where ever we are right now, so that it's // perfectly smooth and we don't jump anywhere // // example if we are at 'x': // // A--x->B // // and then receive a new point C: // // A--x--B // | // | // C // // then we don't want to just jump to B and start interpolation: // // x // | // | // C // // we stay at 'x' and interpolate from there to C: // // x..B // \ . // \. // C // else { float oldDistance = Vector3.Distance(start.position, goal.position); float newDistance = Vector3.Distance(goal.position, temp.position); start = goal; // teleport / lag / obstacle detection: only continue at current // position if we aren't too far away if (Vector3.Distance(targetComponent.transform.position, start.position) < oldDistance + newDistance) { start.position = targetComponent.transform.position; start.rotation = targetComponent.transform.rotation; } } // set new destination in any case. new data is best data. goal = temp; }
public static Rect ReadRect(this NetworkReader reader) => new Rect(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
public static Plane ReadPlane(this NetworkReader reader) => new Plane(reader.ReadVector3(), reader.ReadSingle());
public static Color ReadColor(this NetworkReader reader) => new Color(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
public static Quaternion ReadQuaternion(this NetworkReader reader) => new Quaternion(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
public static Vector4 ReadVector4(this NetworkReader reader) => new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
protected override float DeserializeItem(NetworkReader reader) => reader.ReadSingle();
public static Rect ReadRect(this NetworkReader reader) { return(new Rect(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle())); }
public static Color ReadColor(this NetworkReader reader) { return(new Color(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle())); }
public static Vector3 ReadVector3(this NetworkReader reader) { return(new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle())); }