public void Read(BinaryReader reader) { if (_bitArray != null) { _bitArray.ReleaseReference(); } _bitArray = reader.ReadBitArray(); ParamType = _bitArray[0] ? (AnimatorControllerParameterType)reader.ReadByte() : ParamType; NameHash = _bitArray[1] ? reader.ReadInt32() : NameHash; BoolValue = _bitArray[2] ? reader.ReadBoolean() : BoolValue; FloatValue = _bitArray[3] ? reader.ReadSingle() : FloatValue; IntValue = _bitArray[4] ? reader.ReadInt32() : IntValue; }
public void Read(BinaryReader reader) { if (_bitArray != null) { _bitArray.ReleaseReference(); } _bitArray = reader.ReadBitArray(); LayerIndex = _bitArray[0] ? reader.ReadInt32() : LayerIndex; Weight = _bitArray[1] ? reader.ReadSingle() : Weight; CurrentStateHash = _bitArray[2] ? reader.ReadInt32() : CurrentStateHash; NormalizedTime = _bitArray[3] ? reader.ReadSingle() : NormalizedTime; StateDuration = _bitArray[4] ? reader.ReadSingle() : StateDuration; TransitionNormalizedTime = _bitArray[5] ? reader.ReadSingle() : TransitionNormalizedTime; TransitionDuration = _bitArray[6] ? reader.ReadSingle() : TransitionDuration; }
/// <summary> /// 判断与比较值不相同的情况下,将当前值写入Wirter /// </summary> /// <param name="comparedInfo"></param> /// <param name="writer"></param> public void Write(WeaponBagContainer comparedInfo, MyBinaryWriter writer) { writer.Write(HeldSlotPointer); writer.Write(LastSlotPointer); BitArrayWrapper bitArray = BitArrayWrapper.Allocate(GameGlobalConst.WeaponSlotMaxLength, false); // return new BitArray(5, true); if (comparedInfo == null) { bitArray.SetAll(true); } else { for (int i = 0; i < GameGlobalConst.WeaponSlotMaxLength; i++) { bitArray[i] = slotWeapons[i] != comparedInfo.slotWeapons[i]; } } writer.Write(bitArray); for (int i = 0; i < GameGlobalConst.WeaponSlotMaxLength; i++) { if (bitArray[i]) { writer.Write(slotWeapons[i].WeaponKey.EntityId); writer.Write(slotWeapons[i].WeaponKey.EntityType); } } bitArray.ReleaseReference(); }
/// <summary> /// 判断与比较值不相同的情况下,将当前值写入Wirter /// </summary> /// <param name="comparedInfo"></param> /// <param name="writer"></param> //public void Write(WeaponBagContainer comparedInfo, MyBinaryWriter writer) //{ // BitArrayWrapper bitArray = BitArrayWrapper.Allocate(2+ GameGlobalConst.WeaponSlotMaxLength, false); // if (comparedInfo == null) // { // bitArray.SetAll(true); // } // else // { // bitArray[0] = true; // bitArray[1] = true; // for (int i = 0; i < GameGlobalConst.WeaponSlotMaxLength; i++) // { // bitArray[i+2] = slotWeapons[i] != comparedInfo.slotWeapons[i]; // } // } // writer.Write(bitArray); // writer.Write(HeldSlotPointer); // writer.Write(LastSlotPointer); // for (int i = 0; i < GameGlobalConst.WeaponSlotMaxLength; i++) // { // if(bitArray[i + 2]) // { // writer.Write(slotWeapons[i].WeaponKey.EntityId); // writer.Write(slotWeapons[i].WeaponKey.EntityType); // } // } // bitArray.ReleaseReference(); //} public void Dispose() { if (_bitArray != null) { _bitArray.ReleaseReference(); } }
public void Read(BinaryReader reader) { HeldSlotPointer = reader.ReadInt32(); LastSlotPointer = reader.ReadInt32(); if (bitArrayWraper != null) { bitArrayWraper.ReleaseReference(); } bitArrayWraper = reader.ReadBitArray(); for (int i = 0; i < GameGlobalConst.WeaponSlotMaxLength; i++) { if (bitArrayWraper[i]) { var entityId = reader.ReadInt32(); var entityType = reader.ReadInt16(); var weaponKey = new EntityKey(entityId, entityType); slotWeapons[i].Sync(weaponKey); } } }
public void Write(NetworkAnimatorLayer right, MyBinaryWriter writer) { BitArrayWrapper bitArray = BitArrayWrapper.Allocate(7, false); if (right == null) { bitArray.SetAll(true); } else { bitArray[0] = !CompareUtility.IsApproximatelyEqual(LayerIndex, right.LayerIndex); bitArray[1] = Weight != right.Weight; bitArray[2] = !CompareUtility.IsApproximatelyEqual(CurrentStateHash, right.CurrentStateHash); bitArray[3] = NormalizedTime != right.NormalizedTime; bitArray[4] = StateDuration != right.StateDuration; bitArray[5] = TransitionNormalizedTime != right.TransitionNormalizedTime; bitArray[6] = TransitionDuration != right.TransitionDuration; } writer.Write(bitArray); if (bitArray[0]) { writer.Write(LayerIndex); } if (bitArray[1]) { writer.Write(Weight); } if (bitArray[2]) { writer.Write(CurrentStateHash); } if (bitArray[3]) { writer.Write(NormalizedTime); } if (bitArray[4]) { writer.Write(StateDuration); } if (bitArray[5]) { writer.Write(TransitionNormalizedTime); } if (bitArray[6]) { writer.Write(TransitionDuration); } bitArray.ReleaseReference(); }
public void Write(NetworkAnimatorParameter right, MyBinaryWriter writer) { BitArrayWrapper bitArray = BitArrayWrapper.Allocate(5, false); // return new BitArray(5, true); if (right == null) { bitArray.SetAll(true); } else { bitArray[0] = ParamType != right.ParamType; bitArray[1] = !CompareUtility.IsApproximatelyEqual(NameHash, right.NameHash); bitArray[2] = !CompareUtility.IsApproximatelyEqual(BoolValue, right.BoolValue); bitArray[3] = !CompareUtility.IsApproximatelyEqual(FloatValue, right.FloatValue, 0.0001f); bitArray[4] = !CompareUtility.IsApproximatelyEqual(IntValue, right.IntValue); } writer.Write(bitArray); if (bitArray[0]) { writer.Write((byte)ParamType); } if (bitArray[1]) { writer.Write(NameHash); } if (bitArray[2]) { writer.Write(BoolValue); } if (bitArray[3]) { writer.Write(FloatValue); } if (bitArray[4]) { writer.Write(IntValue); } bitArray.ReleaseReference(); }
public static void Serialize <T>(T[] currArr, Core.Utils.MyBinaryWriter writer, T[] lastArr = null, bool writeAll = false) where T : class, IPatchClass <T>, new() { BitArrayWrapper bitArray = GetDiffBitArray(lastArr, currArr, writeAll); var count = currArr == null ? 0 : currArr.Length; var lastCount = lastArr == null ? 0 : lastArr.Length; writer.Write(bitArray); for (int i = 0; i < count; i++) { if (bitArray[i] == false) { continue; } var last = i >= lastCount || writeAll ? default(T) : lastArr[i]; Serialize(currArr[i], last, writer); } bitArray.ReleaseReference(); }
public static void Serialize <T>(List <T> list, Core.Utils.MyBinaryWriter writer, List <T> lastList = null, bool writeAll = false) where T : IPatchClass <T>, new() { BitArrayWrapper bitArray = GetDiffBitArray(lastList, list, writeAll); var count = list == null ? 0 : list.Count; var lastCount = lastList == null ? 0 : lastList.Count; writer.Write(bitArray); for (int i = 0; i < count; i++) { if (bitArray[i] == false) { continue; } var last = i >= lastCount || writeAll ? default(T) : lastList[i]; PatchPropertySerializer.Write(list[i], last, writer); } bitArray.ReleaseReference(); }
/// <summary> ///Shared.Components\Generated\Serializer\xxComponentSerializer.Deserialize ///差异值反序列化 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="arr"></param> /// <param name="reader"></param> /// <returns></returns> public static T[] Deserialize <T>(T[] arr, BinaryReader reader) where T : class, IPatchClass <T>, new() { BitArrayWrapper bitArray = reader.ReadBitArray(); int length = bitArray.Length; arr = Resize(arr, length); for (int i = 0; i < bitArray.Length; i++) { if (bitArray[i]) { Deserialize(arr[i], reader); arr[i].HasValue = true; } else { arr[i].HasValue = false; } } bitArray.ReleaseReference(); return(arr); }
public static List <T> Deserialize <T>(List <T> list, BinaryReader reader) where T : class, IPatchClass <T>, new() { BitArrayWrapper bitArray = reader.ReadBitArray(); int length = bitArray.Length; list = Resize(list, length); for (int i = 0; i < bitArray.Length; i++) { if (bitArray[i]) { Deserialize(list[i], reader); list[i].HasValue = true; } else { list[i].HasValue = false; } } bitArray.ReleaseReference(); return(list); }
public void ClearBitArray() { BitArray.ReleaseReference(); BitArray = null; }