Пример #1
0
 public static void WriteMatrix4x4(this NetworkWriter writer, Matrix4x4 value)
 {
     writer.WriteSingle(value.m00);
     writer.WriteSingle(value.m01);
     writer.WriteSingle(value.m02);
     writer.WriteSingle(value.m03);
     writer.WriteSingle(value.m10);
     writer.WriteSingle(value.m11);
     writer.WriteSingle(value.m12);
     writer.WriteSingle(value.m13);
     writer.WriteSingle(value.m20);
     writer.WriteSingle(value.m21);
     writer.WriteSingle(value.m22);
     writer.WriteSingle(value.m23);
     writer.WriteSingle(value.m30);
     writer.WriteSingle(value.m31);
     writer.WriteSingle(value.m32);
     writer.WriteSingle(value.m33);
 }
Пример #2
0
 public static void WritePlane(this NetworkWriter writer, Plane value)
 {
     writer.WriteVector3(value.normal);
     writer.WriteSingle(value.distance);
 }
Пример #3
0
 protected override void SerializeItem(NetworkWriter writer, float item) => writer.WriteSingle(item);
Пример #4
0
 public static void WriteVector3(this NetworkWriter writer, Vector3 value)
 {
     writer.WriteSingle(value.x);
     writer.WriteSingle(value.y);
     writer.WriteSingle(value.z);
 }
Пример #5
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);
        }