public void OnGsLiveWrite(GsWriteStream writeStream) { writeStream.WriteNext(MethodName); writeStream.WriteNext(FullName); writeStream.WriteNext((byte)Type); writeStream.WriteNext(ExtraData); }
/// <summary> /// NOTE : Dont Use This Function, This Function Called By GsLiveRealtime SDK. /// Internal Get Hash And WriteStream of Registered Object /// </summary> /// <param name="obj"> Your Object You Want To Get Stream</param> /// <returns></returns> /// <exception cref="GameServiceException">Throw If invalid Action Happened</exception> internal static Tuple <int, GsWriteStream> GetWriteStream(object obj) { var type = obj.GetType(); if (!TypeToHash.ContainsKey(type)) { throw new GameServiceException("The Type " + type + " is Not Registered as New Type!") .LogException(typeof(TypeUtil), DebugLocation.RealTime, "GetWriteStream"); } var serializer = ObjectsCache[TypeToHash[type]]; if (!serializer.CanSerializeModel(obj)) { throw new GameServiceException("The Type " + type + " Not Serializable!") .LogException(typeof(TypeUtil), DebugLocation.RealTime, "GetWriteStream"); } var writeStream = new GsWriteStream(); serializer.SerializeObject(obj, writeStream); return(Tuple.Create(TypeToHash[type], writeStream)); }
public void OnGsLiveWrite(GsWriteStream writeStream) { try { if (synchronizePosition) { _mDirection = transform.position - _mStoredPosition; _mStoredPosition = transform.position; writeStream.WriteNext(transform.position); writeStream.WriteNext(_mDirection); } if (synchronizeRotation) { writeStream.WriteNext(transform.rotation); } if (synchronizeScale) { writeStream.WriteNext(transform.localScale); } } catch (Exception e) { Debug.LogError("GSLiveTransformObserver OnGsLiveWrite Error : " + e); } }
protected override void WriteObject(Matrix4x4 obj, GsWriteStream writeStream) { var data = new float[ColumnCount * ColumnCount]; for (var i = 0; i < ColumnCount * ColumnCount; i++) { data[i] = obj[i]; } writeStream.WriteNext(data); }
protected override void WriteObject(Vector2[] obj, GsWriteStream writeStream) { var data = new float[obj.Length * Base]; for (var i = 0; i < obj.Length; i++) { data[Base * i] = obj[i].x; data[Base * i + 1] = obj[i].y; } writeStream.WriteNext(data); }
/// <summary> /// NOTE : Dont Use This Function, This Function Called By GsLiveRealtime SDK. /// Get Buffer From IGsLiveSerializable /// </summary> /// <param name="serializable"> The serializable Object</param> /// <returns></returns> /// <exception cref="GameServiceException">Throw If invalid Action Happened</exception> public static byte[] GetBuffer(IGsLiveSerializable serializable) { if (serializable == null) { throw new GameServiceException("GsSerializer Err -> serializable cant be Null") .LogException(typeof(GsSerializer), DebugLocation.RealTime, "GetBuffer"); } var writeStream = new GsWriteStream(); serializable.OnGsLiveWrite(writeStream); return(SerializerUtil.Serialize(writeStream)); }
public void OnGsLiveWrite(GsWriteStream writeStream) { try { writeStream.WriteNext(_rBody.position); writeStream.WriteNext(_rBody.rotation); if (synchronizeVelocity) { writeStream.WriteNext(_rBody.velocity); } if (synchronizeAngularVelocity) { writeStream.WriteNext(_rBody.angularVelocity); } } catch (Exception e) { Debug.LogError("RealtimeRigidbody2DObserver OnGsLiveWrite Error : " + e); } }
public void OnGsLiveWrite(GsWriteStream writeStream) { try { // send to server var newPos = _transform.position; var newRot = _transform.rotation; var newScale = _transform.localScale; if (Vector3.Distance(_oldPosition, newPos) > posThreshold) { _oldPosition = newPos; } if (Quaternion.Angle(_oldRotation, newRot) > rotThreshold) { _oldRotation = newRot; } if (synchronizePosition) { writeStream.WriteNext(newPos); } if (synchronizeRotation) { writeStream.WriteNext(newRot); } if (synchronizeScale) { writeStream.WriteNext(newScale); } } catch (Exception e) { Debug.LogError("RealtimeSmoothMoveObserver OnGsLiveWrite Error : " + e); } }
/// <summary> /// NOTE : Dont Use This Function, This Function Called By GsLiveRealtime SDK. /// Get WriteStream For object params /// </summary> /// <param name="data">the Objects</param> /// <returns></returns> /// <exception cref="GameServiceException">Throw If invalid Action Happened</exception> internal static GsWriteStream GetWriteStreamFromParams(params object[] data) { if (data == null) { throw new GameServiceException("Params Cant Be Null") .LogException(typeof(TypeUtil), DebugLocation.RealTime, "GetWriteStreamFromParams"); } if (data.Length == 0) { throw new GameServiceException("Params Cant Be Empty") .LogException(typeof(TypeUtil), DebugLocation.RealTime, "GetWriteStreamFromParams"); } var writeStream = new GsWriteStream(); foreach (var obj in data) { writeStream.WriteNext(obj); } return(writeStream); }
protected override void WriteObject(Ray obj, GsWriteStream writeStream) { writeStream.WriteNext(new [] { obj.origin.x, obj.origin.y, obj.origin.z, obj.direction.x, obj.direction.y, obj.direction.z }); }
protected override void WriteObject(Rect obj, GsWriteStream writeStream) { writeStream.WriteNext(new [] { obj.position.x, obj.position.y, obj.size.x, obj.size.y }); }
internal abstract void SerializeObject(object obj, GsWriteStream writeStream);
protected override void WriteObject(Vector3 obj, GsWriteStream writeStream) { writeStream.WriteNext(new[] { obj.x, obj.y, obj.z }); }
public void OnGsLiveWrite(GsWriteStream writeStream) { writeStream.WriteNext(Name); writeStream.WriteNext(Data); }
protected override void WriteObject(Plane obj, GsWriteStream writeStream) { writeStream.WriteNext(new [] { obj.normal.x, obj.normal.y, obj.normal.z, obj.distance }); }
protected override void WriteObject(Color obj, GsWriteStream writeStream) { writeStream.WriteNext(new[] { obj.r, obj.g, obj.b, obj.a }); }
internal static byte[] Serialize(GsWriteStream writeStream) { var(bufferSize, objectInfos) = GetInfos(writeStream); var packetBuffer = BufferPool.GetBuffer(bufferSize); using (var packetWriter = ByteArrayReaderWriter.Get(packetBuffer)) { packetWriter.Write((byte)objectInfos.Count); foreach (var objectInfo in objectInfos) { packetWriter.Write((byte)objectInfo.Type); switch (objectInfo.Type) { case Types.Byte: packetWriter.Write((byte)objectInfo.Src); break; case Types.Char: packetWriter.Write((char)objectInfo.Src); break; case Types.Double: packetWriter.Write(BitConverter.GetBytes((double)objectInfo.Src)); break; case Types.Float: packetWriter.Write(BitConverter.GetBytes((float)objectInfo.Src)); break; case Types.Int: packetWriter.Write((int)objectInfo.Src); break; case Types.Long: packetWriter.Write((long)objectInfo.Src); break; case Types.Short: packetWriter.Write((short)objectInfo.Src); break; case Types.Uint: packetWriter.Write((uint)objectInfo.Src); break; case Types.Ushort: packetWriter.Write((ushort)objectInfo.Src); break; case Types.Ulong: packetWriter.Write((ulong)objectInfo.Src); break; case Types.Bool: byte data = 0x0; if ((bool)objectInfo.Src) { data = 0x1; } packetWriter.Write(data); break; case Types.CustomObject: var bufferDataObject = (byte[])objectInfo.Src; packetWriter.Write((int)objectInfo.Extra); packetWriter.Write((ushort)bufferDataObject.Length); packetWriter.Write(bufferDataObject); break; case Types.String: case Types.ByteArray: case Types.CharArray: case Types.DoubleArray: case Types.FloatArray: case Types.IntArray: case Types.LongArray: case Types.StringArray: var bArray = (byte[])objectInfo.Src; packetWriter.Write((ushort)bArray.Length); packetWriter.Write(bArray); break; case Types.Null: break; default: throw new ArgumentOutOfRangeException(); } } } return(packetBuffer); }
internal override void SerializeObject(object obj, GsWriteStream writeStream) { WriteObject((T)obj, writeStream); }
public void OnGsLiveWrite(GsWriteStream writeStream) { writeStream.WriteNext(PrefabName); writeStream.WriteNext(Position); writeStream.WriteNext(Rotation); }
private static Tuple <ushort, List <ObjectInfo> > GetInfos(GsWriteStream writeStream) { var infos = new List <ObjectInfo>(); var bufferSize = sizeof(byte); // Size of ObjectsInfo while (writeStream.CanRead()) { bufferSize += sizeof(byte); // Add Type Size var obj = writeStream.GetObject(); switch (obj) { case null: infos.Add(new ObjectInfo(null, Types.Null)); break; case bool _: infos.Add(new ObjectInfo(obj, Types.Bool)); bufferSize += sizeof(byte); break; case byte _: infos.Add(new ObjectInfo(obj, Types.Byte)); bufferSize += sizeof(byte); break; case char _: infos.Add(new ObjectInfo(obj, Types.Char)); bufferSize += sizeof(char); break; case double _: infos.Add(new ObjectInfo(obj, Types.Double)); bufferSize += sizeof(double); break; case float _: infos.Add(new ObjectInfo(obj, Types.Float)); bufferSize += sizeof(float); break; case int _: infos.Add(new ObjectInfo(obj, Types.Int)); bufferSize += sizeof(int); break; case long _: infos.Add(new ObjectInfo(obj, Types.Long)); bufferSize += sizeof(long); break; case short _: infos.Add(new ObjectInfo(obj, Types.Short)); bufferSize += sizeof(short); break; case uint _: infos.Add(new ObjectInfo(obj, Types.Uint)); bufferSize += sizeof(uint); break; case ulong _: infos.Add(new ObjectInfo(obj, Types.Ulong)); bufferSize += sizeof(ulong); break; case ushort _: infos.Add(new ObjectInfo(obj, Types.Ushort)); bufferSize += sizeof(ushort); break; case string s: var sBuffer = GetBuffer(s, true); infos.Add(new ObjectInfo(sBuffer, Types.String)); bufferSize += sizeof(ushort) + sBuffer.Length; break; case byte[] ba: infos.Add(new ObjectInfo(ba, Types.ByteArray)); bufferSize += sizeof(ushort) + ba.Length; break; case char[] ca: var cBuffer = GetBuffer(ca, true); infos.Add(new ObjectInfo(cBuffer, Types.CharArray)); bufferSize += sizeof(ushort) + cBuffer.Length; break; case double[] da: var dBuffer = GetBuffer(da); infos.Add(new ObjectInfo(dBuffer, Types.DoubleArray)); bufferSize += sizeof(ushort) + dBuffer.Length; break; case float[] fa: var fBuffer = GetBuffer(fa); infos.Add(new ObjectInfo(fBuffer, Types.FloatArray)); bufferSize += sizeof(ushort) + fBuffer.Length; break; case int[] ia: var iBuffer = GetBuffer(ia); infos.Add(new ObjectInfo(iBuffer, Types.IntArray)); bufferSize += sizeof(ushort) + iBuffer.Length; break; case long[] la: var lBuffer = GetBuffer(la); infos.Add(new ObjectInfo(lBuffer, Types.LongArray)); bufferSize += sizeof(ushort) + lBuffer.Length; break; case string[] sa: var saBuffer = GetBuffer(sa); infos.Add(new ObjectInfo(saBuffer, Types.StringArray)); bufferSize += sizeof(ushort) + saBuffer.Length; break; case BaseSerializer _: infos.Add(new ObjectInfo(obj, Types.CustomObject)); break; default: if (TypeUtil.HaveType(obj)) { var(hash, stream) = TypeUtil.GetWriteStream(obj); var bufferObj = Serialize(stream); infos.Add(new ObjectInfo(bufferObj, Types.CustomObject, hash)); bufferSize += sizeof(int) + sizeof(ushort) + bufferObj.Length; } else { throw new GameServiceException("SerializerUtil -> The Type " + obj.GetType() + " is Not Supported") .LogException(typeof(SerializerUtil), DebugLocation.RealTime, "GetInfos"); } break; } } if (bufferSize >= ushort.MaxValue) { throw new GameServiceException("SerializerUtil -> The Buffer is Too Large!") .LogException(typeof(SerializerUtil), DebugLocation.RealTime, "GetInfos"); } return(Tuple.Create((ushort)bufferSize, infos)); }
public void OnGsLiveWrite(GsWriteStream writeStream) { writeStream.WriteNext(ObjectNameOrTag); writeStream.WriteNext(IsTag); }
/// <summary> /// the WriteObject Function You Can Write Every things Of T To writeStream /// </summary> /// <param name="obj">Your Serializable Object</param> /// <param name="writeStream">The Write Stream for Writes Data</param> protected abstract void WriteObject(T obj, GsWriteStream writeStream);
protected override void WriteObject(RangeInt obj, GsWriteStream writeStream) { writeStream.WriteNext(new [] { obj.start, obj.length }); }
protected override void WriteObject(Quaternion obj, GsWriteStream writeStream) { writeStream.WriteNext(new[] { obj.x, obj.y, obj.z, obj.w }); }
protected override void WriteObject(Bounds obj, GsWriteStream writeStream) { writeStream.WriteNext(new [] { obj.center.x, obj.center.y, obj.center.z, obj.size.x, obj.size.y, obj.size.z }); }