/// <summary>
        /// Custom Serialization
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="initialState"></param>
        /// <returns></returns>
        public override bool OnSerialize(NetworkWriter writer, bool initialState)
        {
            bool changed = base.OnSerialize(writer, initialState);

            if (initialState)
            {
                for (int i = 0; i < animator.layerCount; i++)
                {
                    if (animator.IsInTransition(i))
                    {
                        AnimatorStateInfo st = animator.GetNextAnimatorStateInfo(i);
                        writer.WriteInt32(st.fullPathHash);
                        writer.WriteSingle(st.normalizedTime);
                    }
                    else
                    {
                        AnimatorStateInfo st = animator.GetCurrentAnimatorStateInfo(i);
                        writer.WriteInt32(st.fullPathHash);
                        writer.WriteSingle(st.normalizedTime);
                    }
                    writer.WriteSingle(animator.GetLayerWeight(i));
                }
                WriteParameters(writer, initialState);
                return(true);
            }
            return(changed);
        }
Beispiel #2
0
 public override bool OnSerialize(NetworkWriter writer, bool initialState)
 {
     writer.WriteInt32(value);
     // one too many
     writer.WriteInt32(value);
     return(true);
 }
Beispiel #3
0
 public static void WriteArray <T>(this NetworkWriter writer, T[] array)
 {
     if (array is null)
     {
         writer.WriteInt32(-1);
         return;
     }
     writer.WriteInt32(array.Length);
     for (int i = 0; i < array.Length; i++)
     {
         writer.Write(array[i]);
     }
 }
Beispiel #4
0
 public static void WriteList <T>(this NetworkWriter writer, List <T> list)
 {
     if (list is null)
     {
         writer.WriteInt32(-1);
         return;
     }
     writer.WriteInt32(list.Count);
     for (int i = 0; i < list.Count; i++)
     {
         writer.Write(list[i]);
     }
 }
Beispiel #5
0
 public void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32(netId);
     writer.WritePackedUInt32((uint)componentIndex);
     writer.WriteInt32(functionHash);
     writer.WriteBytesAndSizeSegment(payload);
 }
        bool WriteParameters(NetworkWriter writer, bool forceAll = false)
        {
            ulong dirtyBits = forceAll ? (~0ul) : NextDirtyBits();

            writer.WriteUInt64(dirtyBits);
            for (int i = 0; i < parameters.Length; i++)
            {
                if ((dirtyBits & (1ul << i)) == 0)
                {
                    continue;
                }

                AnimatorControllerParameter par = parameters[i];
                if (par.type == AnimatorControllerParameterType.Int)
                {
                    int newIntValue = animator.GetInteger(par.nameHash);
                    writer.WriteInt32(newIntValue);
                }
                else if (par.type == AnimatorControllerParameterType.Float)
                {
                    float newFloatValue = animator.GetFloat(par.nameHash);
                    writer.WriteSingle(newFloatValue);
                }
                else if (par.type == AnimatorControllerParameterType.Bool)
                {
                    bool newBoolValue = animator.GetBool(par.nameHash);
                    writer.WriteBoolean(newBoolValue);
                }
            }
            return(dirtyBits != 0);
        }
Beispiel #7
0
        public static void WriteArraySegment <T>(this NetworkWriter writer, ArraySegment <T> segment)
        {
            int length = segment.Count;

            writer.WriteInt32(length);
            for (int i = 0; i < length; i++)
            {
                writer.Write(segment.Array[segment.Offset + i]);
            }
        }
 /// <summary>
 /// Custom Serialization
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="initialState"></param>
 /// <returns></returns>
 public override bool OnSerialize(NetworkWriter writer, bool initialState)
 {
     if (initialState)
     {
         writer.WriteInt32(m_Motion.currentState.serializationKey);
         WriteParameters(writer, initialState);
         return(true);
     }
     return(false);
 }
Beispiel #9
0
 public override bool OnSerialize(NetworkWriter writer, bool forceAll)
 {
     if (forceAll)
     {
         if (animator.IsInTransition(0))
         {
             AnimatorStateInfo st = animator.GetNextAnimatorStateInfo(0);
             writer.WriteInt32(st.fullPathHash);
             writer.WriteSingle(st.normalizedTime);
         }
         else
         {
             AnimatorStateInfo st = animator.GetCurrentAnimatorStateInfo(0);
             writer.WriteInt32(st.fullPathHash);
             writer.WriteSingle(st.normalizedTime);
         }
         WriteParameters(writer);
         return(true);
     }
     return(false);
 }
 /// <summary>
 /// Custom Serialization
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="initialState"></param>
 /// <returns></returns>
 public override bool OnSerialize(NetworkWriter writer, bool initialState)
 {
     if (initialState)
     {
         for (int i = 0; i < Animator.layerCount; i++)
         {
             if (Animator.IsInTransition(i))
             {
                 AnimatorStateInfo st = Animator.GetNextAnimatorStateInfo(i);
                 writer.WriteInt32(st.fullPathHash);
                 writer.WriteSingle(st.normalizedTime);
             }
             else
             {
                 AnimatorStateInfo st = Animator.GetCurrentAnimatorStateInfo(i);
                 writer.WriteInt32(st.fullPathHash);
                 writer.WriteSingle(st.normalizedTime);
             }
         }
         WriteParameters(writer, initialState);
         return(true);
     }
     return(false);
 }
Beispiel #11
0
 public static void WriteVector3Int(this NetworkWriter writer, Vector3Int value)
 {
     writer.WriteInt32(value.x);
     writer.WriteInt32(value.y);
     writer.WriteInt32(value.z);
 }
Beispiel #12
0
 public void Serialize(NetworkWriter writer)
 {
     writer.WriteInt16(command);
     writer.WriteInt32(connectionId);
     playerData.Serialize(writer);
 }
Beispiel #13
0
        public override bool OnSerialize(NetworkWriter writer, bool initialState)
        {
            if (initialState)
            {
                // Write number of dirty variables, in this case all of them are considered dirty.
                writer.WriteByte((byte)hashToType.Count);

                // Write all.
                foreach (var pair in hashToType)
                {
                    int hash = pair.Key;
                    var type = pair.Value;

                    writer.WriteInt32(hash);

                    switch (type)
                    {
                    case AnimatorControllerParameterType.Float:
                        writer.WriteSingle(floats[hash]);
                        break;

                    case AnimatorControllerParameterType.Int:
                        writer.WriteInt32(ints[hash]);
                        break;

                    case AnimatorControllerParameterType.Bool:
                        writer.WriteBoolean(bools[hash]);
                        break;
                    }
                }
            }
            else
            {
                ulong dirtyMask = this.syncVarDirtyBits;

                // Count the number of dirty variables and write that number to stream.
                byte dirtyCount = 0;
                for (int i = 0; i < 64; i++)
                {
                    ulong mask  = 1UL << i;
                    bool  isOne = (dirtyMask & mask) == mask;

                    if (isOne)
                    {
                        dirtyCount++;
                    }
                }
                writer.WriteByte(dirtyCount);

                // Write only changed variables.
                for (int i = 0; i < hashToType.Count; i++)
                {
                    ulong mask = 1UL << i;

                    bool changed = (dirtyMask & mask) == mask;

                    if (changed)
                    {
                        int hash = maskToHash[mask];
                        var type = hashToType[hash];

                        writer.WriteInt32(hash);
                        switch (type)
                        {
                        case AnimatorControllerParameterType.Float:
                            writer.WriteSingle(floats[hash]);
                            break;

                        case AnimatorControllerParameterType.Int:
                            writer.WriteInt32(ints[hash]);
                            break;

                        case AnimatorControllerParameterType.Bool:
                            writer.WriteBoolean(bools[hash]);
                            break;
                        }
                    }
                }
            }

            return(true);
        }