public void OnNetworkReceive(NetPeer peer, NetDataReader reader) { _newBallPosX = reader.GetFloat(); var pos = _clientBall.transform.position; _oldBallPosX = pos.x; pos.x = _newBallPosX; _clientBall.transform.position = pos; _lerpTime = 0f; }
public static Vector4 GetVector4(this NetDataReader reader) { return(new Vector4(reader.GetFloat(), reader.GetFloat(), reader.GetFloat(), reader.GetFloat())); }
public static Quaternion GetQuaternion(this NetDataReader reader) { Vector3 vector3 = new Vector3(reader.GetFloat(), reader.GetFloat(), reader.GetFloat()); return(vector3.sqrMagnitude <= 0 ? Quaternion.identity : Quaternion.Euler(vector3)); }
public static object GetValue(this NetDataReader reader, Type type) { #region Generic Values if (type.IsEnum) { type = type.GetEnumUnderlyingType(); } if (type == typeof(bool)) { return(reader.GetBool()); } if (type == typeof(byte)) { return(reader.GetByte()); } if (type == typeof(char)) { return(reader.GetChar()); } if (type == typeof(double)) { return(reader.GetDouble()); } if (type == typeof(float)) { return(reader.GetFloat()); } if (type == typeof(int)) { return(reader.GetPackedInt()); } if (type == typeof(long)) { return(reader.GetPackedLong()); } if (type == typeof(sbyte)) { return(reader.GetSByte()); } if (type == typeof(short)) { return(reader.GetPackedShort()); } if (type == typeof(string)) { return(reader.GetString()); } if (type == typeof(uint)) { return(reader.GetPackedUInt()); } if (type == typeof(ulong)) { return(reader.GetPackedULong()); } if (type == typeof(ushort)) { return(reader.GetPackedUShort()); } #endregion #region Unity Values if (type == typeof(Color)) { return(reader.GetColor()); } if (type == typeof(Quaternion)) { return(reader.GetQuaternion()); } if (type == typeof(Vector2)) { return(reader.GetVector2()); } if (type == typeof(Vector2Int)) { return(reader.GetVector2Int()); } if (type == typeof(Vector3)) { return(reader.GetVector3()); } if (type == typeof(Vector3Int)) { return(reader.GetVector3Int()); } if (type == typeof(Vector4)) { return(reader.GetVector4()); } #endregion if (typeof(INetSerializable).IsAssignableFrom(type)) { object instance = Activator.CreateInstance(type); (instance as INetSerializable).Deserialize(reader); return(instance); } throw new ArgumentException("NetDataReader cannot read type " + type.Name); }
public override void Read(T inf, NetDataReader r) { Setter(inf, r.GetFloat()); }
public static Quaternion GetQuaternion(this NetDataReader reader) { return(new Quaternion(reader.GetFloat(), reader.GetFloat(), reader.GetFloat(), reader.GetFloat())); }
public static object GetValue(this NetDataReader reader, Type type) { #region Generic Values if (type.IsPrimitive) { if (type == typeof(bool)) { return(reader.GetBool()); } if (type == typeof(byte)) { return(reader.GetByte()); } if (type == typeof(ushort)) { return(reader.GetUShort()); } if (type == typeof(int)) { return(reader.GetInt()); } if (type == typeof(float)) { return(reader.GetFloat()); } if (type == typeof(short)) { return(reader.GetShort()); } if (type == typeof(string)) { return(reader.GetString()); } if (type == typeof(uint)) { return(reader.GetUInt()); } if (type == typeof(long)) { return(reader.GetLong()); } if (type == typeof(char)) { return(reader.GetChar()); } if (type == typeof(double)) { return(reader.GetDouble()); } if (type == typeof(sbyte)) { return(reader.GetSByte()); } if (type == typeof(ulong)) { return(reader.GetULong()); } throw new ArgumentException("NetDataReader cannot read type " + type.Name); } else if (type.IsArray) { if (type == typeof(bool[])) { return(reader.GetBoolArray()); } if (type == typeof(byte[])) { return(reader.GetBytesWithLength()); } if (type == typeof(double[])) { return(reader.GetDoubleArray()); } if (type == typeof(float[])) { return(reader.GetFloatArray()); } if (type == typeof(int[])) { return(reader.GetIntArray()); } if (type == typeof(long[])) { return(reader.GetLongArray()); } if (type == typeof(short[])) { return(reader.GetShortArray()); } if (type == typeof(uint[])) { return(reader.GetUIntArray()); } if (type == typeof(ulong[])) { return(reader.GetULongArray()); } if (type == typeof(ushort[])) { return(reader.GetUShortArray()); } throw new ArgumentException("NetDataReader cannot read type " + type.Name); } else if (typeof(INetSerializable).IsAssignableFrom(type)) { object instance = Activator.CreateInstance(type); ((INetSerializable)instance).Deserialize(reader); return(instance); } else { #region Unity Values #if UNITY_2019 if (type == typeof(Color)) { return(reader.GetColor()); } if (type == typeof(Quaternion)) { return(reader.GetQuaternion()); } if (type == typeof(Vector2)) { return(reader.GetVector2()); } if (type == typeof(Vector2Int)) { return(reader.GetVector2Int()); } if (type == typeof(Vector3)) { return(reader.GetVector3()); } if (type == typeof(Vector3Int)) { return(reader.GetVector3Int()); } if (type == typeof(Vector4)) { return(reader.GetVector4()); } #endif #endregion if (type == typeof(string)) { return(reader.GetString()); } throw new ArgumentException("NetDataReader cannot read type " + type.Name); } #endregion }