public void OnGsLiveRead(GsReadStream readStream) { MethodName = (string)readStream.ReadNext(); FullName = (string)readStream.ReadNext(); Type = (FunctionType)readStream.ReadNext(); ExtraData = (byte[])readStream.ReadNext(); }
protected override Ray ReadObject(GsReadStream readStream) { var data = (float[])readStream.ReadNext(); var origin = new Vector3(data[0], data[1], data[2]); var direction = new Vector3(data[3], data[4], data[5]); return(new Ray(origin, direction)); }
protected override Bounds ReadObject(GsReadStream readStream) { var data = (float[])readStream.ReadNext(); var center = new Vector3(data[0], data[1], data[2]); var size = new Vector3(data[3], data[4], data[5]); return(new Bounds(center, size)); }
public void OnGsLiveRead(GsReadStream readStream) { try { if (synchronizePosition) { _mNetworkPosition = (Vector3)readStream.ReadNext(); _mDirection = (Vector3)readStream.ReadNext(); if (_mFirstTake) { transform.position = _mNetworkPosition; _mDistance = 0f; } else { var lag = (float)GsLiveRealtime.GetPing() / 100; _mNetworkPosition += _mDirection * lag; _mDistance = Vector3.Distance(transform.position, _mNetworkPosition); } } if (synchronizeRotation) { _mNetworkRotation = (Quaternion)readStream.ReadNext(); if (_mFirstTake) { _mAngle = 0f; transform.rotation = _mNetworkRotation; } else { _mAngle = Quaternion.Angle(transform.rotation, _mNetworkRotation); } } if (synchronizeScale) { transform.localScale = (Vector3)readStream.ReadNext(); } if (_mFirstTake) { _mFirstTake = false; } } catch (Exception e) { Debug.LogError("GSLiveTransformObserver OnGsLiveRead Error : " + e); } }
protected override Vector2[] ReadObject(GsReadStream readStream) { var readData = (float[])readStream.ReadNext(); var data = new Vector2[readData.Length / Base]; for (var i = 0; i < readData.Length; i += Base) { data[i / Base] = new Vector2(readData[i], readData[i + 1]); } return(data); }
protected override Quaternion[] ReadObject(GsReadStream readStream) { var readData = (float[])readStream.ReadNext(); var data = new Quaternion[readData.Length / Base]; for (var i = 0; i < readData.Length; i += Base) { data[i / Base] = new Quaternion(readData[i], readData[i + 1], readData[i + 2], readData[i + 3]); } return(data); }
protected override Matrix4x4 ReadObject(GsReadStream readStream) { var data = (float[])readStream.ReadNext(); var mat = new Matrix4x4(); for (var i = 0; i < data.Length; i++) { mat[i] = data[i]; } return(mat); }
/// <summary> /// NOTE : Dont Use This Function, This Function Called By GsLiveRealtime SDK. /// Get Object From Hash and GsReadStream /// </summary> /// <param name="hash">the Object Hash</param> /// <param name="readStream">The Read Stream To Read Object</param> /// <returns></returns> /// <exception cref="GameServiceException">Throw If invalid Action Happened</exception> internal static object GetFinalObject(int hash, GsReadStream readStream) { if (!HashToType.ContainsKey(hash)) { throw new GameServiceException("Type With Hash " + hash + " is Not Registered!") .LogException(typeof(TypeUtil), DebugLocation.RealTime, "GetFinalObject"); } var serializer = ObjectsCache[hash]; if (!serializer.CanSerializeModel(HashToType[hash])) { throw new GameServiceException("Type With Hash " + hash + " is Not Serializable!") .LogException(typeof(TypeUtil), DebugLocation.RealTime, "GetFinalObject"); } return(serializer.DeserializeObject(readStream)); }
public void OnGsLiveRead(GsReadStream readStream) { try { if (synchronizePosition) { _mNetworkPosition = (Vector3)readStream.ReadNext(); } if (synchronizeRotation) { _mNetworkRotation = (Quaternion)readStream.ReadNext(); } if (synchronizeScale) { _mNetworkScale = (Vector3)readStream.ReadNext(); } } catch (Exception e) { Debug.LogError("RealtimeSmoothMoveObserver OnGsLiveRead Error : " + e); } }
public void OnGsLiveRead(GsReadStream readStream) { try { _mNetworkPosition = (Vector2)readStream.ReadNext(); _mNetworkRotation = (float)readStream.ReadNext(); if (teleportEnabled) { if (Vector2.Distance(_rBody.position, _mNetworkPosition) > teleportIfDistanceGreaterThan) { _rBody.position = _mNetworkPosition; } } if (synchronizeVelocity || synchronizeAngularVelocity) { var lag = (float)GsLiveRealtime.GetPing() / 100; if (synchronizeVelocity) { _rBody.velocity = (Vector2)readStream.ReadNext(); _mNetworkPosition += _rBody.velocity * lag; _mDistance = Vector2.Distance(_rBody.position, _mNetworkPosition); } if (synchronizeAngularVelocity) { _rBody.angularVelocity = (float)readStream.ReadNext(); _mNetworkRotation += _rBody.angularVelocity * lag; _mAngle = Mathf.Abs(_rBody.rotation - _mNetworkRotation); } } } catch (Exception e) { Debug.LogError("RealtimeRigidbody2DObserver OnGsLiveRead Error : " + e); } }
protected override RangeInt ReadObject(GsReadStream readStream) { var data = (int[])readStream.ReadNext(); return(new RangeInt(data[0], data[1])); }
public void OnGsLiveRead(GsReadStream readStream) { Name = (string)readStream.ReadNext(); Data = readStream.ReadNext(); }
/// <summary> /// the ReadObject Function You Can Read Every things Writes /// </summary> /// <param name="readStream">he Write Stream for Reads Data</param> /// <returns></returns> protected abstract T ReadObject(GsReadStream readStream);
internal override object DeserializeObject(GsReadStream readStream) { return(ReadObject(readStream)); }
internal static GsReadStream Deserialize(byte[] buffer) { var readStream = new GsReadStream(); using (var packetReader = ByteArrayReaderWriter.Get(buffer)) { var count = packetReader.ReadByte(); for (var i = 0; i < count; i++) { var type = (Types)packetReader.ReadByte(); switch (type) { case Types.Bool: readStream.Add(packetReader.ReadByte() != 0x0); break; case Types.Byte: readStream.Add(packetReader.ReadByte()); break; case Types.Char: readStream.Add(packetReader.ReadChar()); break; case Types.Double: readStream.Add(BitConverter.ToDouble(packetReader.ReadBytes(sizeof(double)), 0)); break; case Types.Float: readStream.Add(BitConverter.ToSingle(packetReader.ReadBytes(sizeof(float)), 0)); break; case Types.Short: readStream.Add(packetReader.ReadInt16()); break; case Types.Int: readStream.Add(packetReader.ReadInt32()); break; case Types.Long: readStream.Add(packetReader.ReadInt64()); break; case Types.Ushort: readStream.Add(packetReader.ReadUInt16()); break; case Types.Uint: readStream.Add(packetReader.ReadUInt32()); break; case Types.Ulong: readStream.Add(packetReader.ReadUInt64()); break; case Types.String: readStream.Add(GetStringFromBuffer(packetReader.ReadBytes(packetReader.ReadUInt16()), true)); break; case Types.ByteArray: readStream.Add(packetReader.ReadBytes(packetReader.ReadUInt16())); break; case Types.CharArray: readStream.Add(GetCharsFromBuffers(packetReader.ReadBytes(packetReader.ReadUInt16()))); break; case Types.DoubleArray: readStream.Add(GetDoublesFromBuffers(packetReader.ReadBytes(packetReader.ReadUInt16()))); break; case Types.FloatArray: readStream.Add(GetFloatsFromBuffers(packetReader.ReadBytes(packetReader.ReadUInt16()))); break; case Types.IntArray: readStream.Add(GetIntsFromBuffers(packetReader.ReadBytes(packetReader.ReadUInt16()))); break; case Types.LongArray: readStream.Add(GetLongsFromBuffers(packetReader.ReadBytes(packetReader.ReadUInt16()))); break; case Types.StringArray: readStream.Add(GetStringsFromBuffer(packetReader.ReadBytes(packetReader.ReadUInt16()))); break; case Types.Null: readStream.Add(null); break; case Types.CustomObject: var id = packetReader.ReadInt32(); var bufferData = packetReader.ReadBytes(packetReader.ReadUInt16()); readStream.Add(TypeUtil.GetFinalObject(id, Deserialize(bufferData))); break; default: throw new ArgumentOutOfRangeException(); } } } return(readStream); }
internal abstract object DeserializeObject(GsReadStream readStream);
protected override Rect ReadObject(GsReadStream readStream) { var data = (float[])readStream.ReadNext(); return(new Rect(data[0], data[1], data[2], data[3])); }
protected override Vector3 ReadObject(GsReadStream readStream) { var data = (float[])readStream.ReadNext(); return(new Vector3(data[0], data[1], data[2])); }
protected override Quaternion ReadObject(GsReadStream readStream) { var data = (float[])readStream.ReadNext(); return(new Quaternion(data[0], data[1], data[2], data[3])); }
public void OnGsLiveRead(GsReadStream readStream) { ObjectNameOrTag = (string)readStream.ReadNext(); IsTag = (bool)readStream.ReadNext(); }
protected override Color32 ReadObject(GsReadStream readStream) { var data = (byte[])readStream.ReadNext(); return(new Color32(data[0], data[1], data[2], data[3])); }
public void OnGsLiveRead(GsReadStream readStream) { PrefabName = (string)readStream.ReadNext(); Position = (Vector3)readStream.ReadNext(); Rotation = (Quaternion)readStream.ReadNext(); }