public override void Deserialize(NetworkReader reader)
 {
     base.Deserialize(reader);
     AntagName       = reader.ReadString();
     AntagSound      = reader.ReadString();
     TextColor       = reader.ReadColor();
     BackgroundColor = reader.ReadColor();
     PlaySound       = reader.ReadBoolean();
 }
示例#2
0
            public override void Deserialize(NetworkReader reader)
            {
                base.Deserialize(reader);

                BackgroundWidth  = reader.ReadSingle();
                BackgroundHeight = reader.ReadSingle();
                BackgroundColor  = reader.ReadColor();
                CrawlerBeltColor = reader.ReadColor();
            }
示例#3
0
    public override void Deserialize(NetworkReader reader)
    {
        String name     = reader.ReadString();
        Color  hatColor = reader.ReadColor();

        Profile = new PlayerProfile(name, hatColor);
    }
示例#4
0
                public override void OnDeserialize(NetworkReader reader, bool initialState)
                {
                    if (initialState)
                    {
                        while (reader.Position < reader.Length)
                        {
                            Color color = reader.ReadColor();

                            uint positionCount = reader.ReadPackedUInt32();

                            Vector3[] positions = new Vector3[positionCount];

                            for (uint i = 0; i < positionCount; ++i)
                            {
                                positions[i] = reader.ReadVector3();
                            }

                            Stroke stroke = GenerateNewStroke();
                            stroke.SetStrokeColor(color);
                            stroke.SetStrokePointPositions(positions);
                        }

                        return;
                    }
                }
示例#5
0
        public override void Deserialize(NetworkReader reader)
        {
            string typeString = reader.ReadString();
            Type   type       = TypeUtility.GetType(typeString);

            if (variable == null)
            {
                variable = ScriptableObject.CreateInstance(type) as FsmVariable;
            }
            if (type == typeof(FsmInt))
            {
                variable.SetValue(reader.ReadInt32());
            }
            else if (type == typeof(FsmString))
            {
                variable.SetValue(reader.ReadString());
            }
            else if (type == typeof(FsmFloat))
            {
                variable.SetValue(reader.ReadSingle());
            }
            else if (type == typeof(FsmColor))
            {
                variable.SetValue(reader.ReadColor());
            }
            else if (type == typeof(FsmVector2))
            {
                variable.SetValue(reader.ReadVector2());
            }
            else if (type == typeof(FsmVector3))
            {
                variable.SetValue(reader.ReadVector3());
            }
        }
示例#6
0
    protected override string DeserializeItem(NetworkReader reader)
    {
        string item = base.DeserializeItem(reader);

        colors.Add(reader.ReadColor());
        return(item);
    }
示例#7
0
        public void TestColor(Color input)
        {
            writer.WriteColor(input);
            var   reader = new NetworkReader(writer.ToArray());
            Color output = reader.ReadColor();

            Assert.That(output, Is.EqualTo(input));
        }
示例#8
0
 public void Deserialzie(NetworkReader reader)
 {
     guid     = reader.ReadString();
     pos      = reader.ReadVector3();
     rotation = reader.ReadQuaternion();
     scale    = reader.ReadVector3();
     color    = reader.ReadColor();
 }
示例#9
0
        public void TestColor(Color input)
        {
            writer.WriteColor(input);
            reader.Reset(writer.ToArraySegment());
            Color output = reader.ReadColor();

            Assert.That(output, Is.EqualTo(input));
        }
        public override void OnDeserialize(NetworkReader reader, bool initialState)
        {
            base.OnDeserialize(reader, initialState);

            if (initialState)
            {
                this.SetPlayerInfo(new PlayerInfo(reader.ReadString(), reader.ReadColor()));
            }
        }
示例#11
0
        public static UpdateTileMessage.NetMessage Deserialize(this NetworkReader reader)
        {
            var message = new UpdateTileMessage.NetMessage();

            message.Changes         = new List <UpdateTileMessage.DelayedData>();
            message.MatrixSyncNetID = reader.ReadUInt();
            while (true)
            {
                var Continue = reader.ReadBool();
                if (Continue == false)
                {
                    break;
                }

                var WorkingOn = new UpdateTileMessage.DelayedData
                {
                    Position        = reader.ReadVector3Int(),
                    TileType        = (TileType)reader.ReadInt(),
                    layerType       = (LayerType)reader.ReadInt(),
                    TileName        = reader.ReadString(),
                    MatrixSyncNetID = message.MatrixSyncNetID,
                    TransformMatrix = Matrix4x4.identity,
                    Colour          = Color.white
                };



                while (true)
                {
                    byte Operation = reader.ReadByte();

                    if (Operation == (byte)EnumOperation.NoMoreData)
                    {
                        break;
                    }

                    if (Operation == (byte)EnumOperation.Colour)
                    {
                        WorkingOn.Colour = reader.ReadColor();
                    }

                    if (Operation == (byte)EnumOperation.Matrix4x4)
                    {
                        WorkingOn.TransformMatrix = reader.ReadMatrix4x4();
                    }
                }
                message.Changes.Add(WorkingOn);
            }

            return(message);
        }
    void Deserialize(NetworkReader _reader, GameNetworkManager net)
    {
        State currentState = (State)_reader.ReadInt32();

        net.AskForState(currentState);
        int playerCount = _reader.ReadInt32();

        net.m_players = new List <PlayerParam>();
        for (int i = 0; i < playerCount; i++)
        {
            var player = new PlayerParam();
            player.m_ID    = _reader.ReadInt32();
            player.m_name  = _reader.ReadString();
            player.m_color = _reader.ReadColor();
            net.m_players.Add(player);
        }
    }
示例#13
0
 public void TestColor()
 {
     Color[] inputs = new Color[] {
         Color.black,
         Color.blue,
         Color.cyan,
         Color.yellow,
         Color.magenta,
         Color.white,
         new Color(0.401f, 0.2f, 1.0f, 0.123f)
     };
     foreach (Color input in inputs)
     {
         NetworkWriter writer = new NetworkWriter();
         writer.Write(input);
         NetworkReader reader = new NetworkReader(writer.ToArray());
         Color         output = reader.ReadColor();
         Assert.That(output, Is.EqualTo(input));
     }
 }
示例#14
0
 public override void Deserialize(NetworkReader reader)
 {
     id   = reader.ReadInt64();
     type = (UpdateType)reader.ReadInt32();
     if (type.IsFlagSet(UpdateType.Color))
     {
         color = reader.ReadColor();
     }
     if (type.IsFlagSet(UpdateType.Position))
     {
         position = reader.ReadVector3();
     }
     if (type.IsFlagSet(UpdateType.Rotation))
     {
         rotation = reader.ReadQuaternion();
     }
     if (type.IsFlagSet(UpdateType.Scale))
     {
         scale = reader.ReadVector3();
     }
 }
示例#15
0
    public static MessageGameInfo Deserialize(this NetworkReader reader)
    {
        MessageGameInfo value = new MessageGameInfo();

        value.VictimVision           = reader.ReadSingle();
        value.VictimLives            = reader.ReadInt32();
        value.VictimSpeed            = reader.ReadSingle();
        value.HunterVision           = reader.ReadSingle();
        value.HunterKillCooldown     = reader.ReadSingle();
        value.HunterSpeed            = reader.ReadSingle();
        value.Hunters                = reader.ReadInt32();
        value.DisplayHunters         = reader.ReadBoolean();
        value.VictimTaskDistance     = reader.ReadSingle();
        value.HunterKillDistance     = reader.ReadSingle();
        value.HunterVisionOnCooldown = reader.ReadSingle();
        value.VictimCommonTasks      = reader.ReadInt32();
        value.VictimLongTasks        = reader.ReadInt32();
        value.VictimShortTasks       = reader.ReadInt32();
        value.TimeLimit              = reader.ReadSingle();
        value.DefaultColor           = reader.ReadColor();
        value.TasksBalancedDamage    = reader.ReadBoolean();
        return(value);
    }
示例#16
0
        public static object ReadObject(this NetworkReader reader, Type type)
        {
            var @switch = new Dictionary <Type, Func <object> >
            {
                { typeof(Color), () => reader.ReadColor() },
                { typeof(Color32), () => reader.ReadInt32() },
                { typeof(GameObject), reader.ReadGameObject },
                { typeof(Matrix4x4), () => reader.ReadMatrix4x4() },
                { typeof(NetworkHash128), () => reader.ReadNetworkHash128() },
                { typeof(NetworkIdentity), reader.ReadNetworkIdentity },
                { typeof(NetworkInstanceId), () => reader.ReadNetworkId() },
                { typeof(NetworkSceneId), () => reader.ReadSceneId() },
                { typeof(Plane), () => reader.ReadPlane() },
                { typeof(Quaternion), () => reader.ReadQuaternion() },
                { typeof(Ray), () => reader.ReadRay() },
                { typeof(Rect), () => reader.ReadRect() },
                { typeof(Transform), reader.ReadTransform },
                { typeof(Vector2), () => reader.ReadVector2() },
                { typeof(Vector3), () => reader.ReadVector3() },
                { typeof(Vector4), () => reader.ReadVector4() },

                { typeof(bool), () => reader.ReadBoolean() },
                { typeof(byte[]), reader.ReadBytesAndSize },
                { typeof(char), () => reader.ReadChar() },
                { typeof(decimal), () => reader.ReadDecimal() },
                { typeof(double), () => reader.ReadDouble() },
                { typeof(float), () => reader.ReadSingle() },

                { typeof(sbyte), () => reader.ReadSByte() },
                { typeof(string), reader.ReadString },

                { typeof(short), () => reader.ReadInt16() },
                { typeof(int), () => reader.ReadInt32() },
                { typeof(long), () => reader.ReadInt64() },

                { typeof(ushort), () => reader.ReadUInt16() },
                { typeof(uint), () => reader.ReadUInt32() },
                { typeof(ulong), () => reader.ReadUInt64() },
            };

            if ([email protected](type))
            {
                if (typeof(MessageBase).IsAssignableFrom(type))
                {
                    MessageBase instance;
                    var         constructor = type.GetConstructor(Type.EmptyTypes);

                    if (constructor != null)
                    {
                        instance = (MessageBase)constructor.Invoke(null);
                    }
                    else
                    {
                        instance = (MessageBase)FormatterServices.GetUninitializedObject(type);
                    }

                    instance.Deserialize(reader);
                    return(instance);
                }

                throw new ArgumentException($"The type ({type}) passed to ReadObject is not a type supported by NetworkReader.", nameof(type));
            }

            return(@switch[type]());
        }
示例#17
0
            public override void Deserialize(NetworkReader reader)
            {
                name = reader.ReadString();

                var isNull = reader.ReadBoolean();
                if (isNull){
                    value = null;
                    return;
                }

                var typeName = reader.ReadString();
                var t = System.Type.GetType(typeName);

                if (t == typeof(string)){
                    value = reader.ReadString();
                    return;
                }
                if (t == typeof(bool)){
                    value = reader.ReadBoolean();
                    return;
                }
                if (t == typeof(int)){
                    value = reader.ReadInt32();
                    return;
                }
                if (t == typeof(float)){
                    value = reader.ReadSingle();
                    return;
                }
                if (t == typeof(Color)){
                    value = reader.ReadColor();
                    return;
                }
                if (t == typeof(Vector2)){
                    value = reader.ReadVector2();
                    return;
                }
                if (t == typeof(Vector3)){
                    value = reader.ReadVector3();
                    return;
                }
                if (t == typeof(Vector4)){
                    value = reader.ReadVector4();
                    return;
                }
                if (t == typeof(Quaternion)){
                    value = reader.ReadQuaternion();
                    return;
                }
                if (t == typeof(GameObject)){
                    value = reader.ReadGameObject();
                    return;
                }
                if (typeof(Component).RTIsAssignableFrom(t)){
                    var go = reader.ReadGameObject();
                    if (go != null){
                        value = go.GetComponent(t);
                    }
                    return;
                }
            }
示例#18
0
 protected override Color DeserializeItem(NetworkReader reader)
 {
     return(reader.ReadColor());
 }
示例#19
0
            public override void Deserialize(NetworkReader reader)
            {
                name = reader.ReadString();

                var isNull = reader.ReadBoolean();

                if (isNull)
                {
                    value = null;
                    return;
                }

                var typeName = reader.ReadString();
                var t        = System.Type.GetType(typeName);

                if (t == typeof(string))
                {
                    value = reader.ReadString();
                    return;
                }
                if (t == typeof(bool))
                {
                    value = reader.ReadBoolean();
                    return;
                }
                if (t == typeof(int))
                {
                    value = reader.ReadInt32();
                    return;
                }
                if (t == typeof(float))
                {
                    value = reader.ReadSingle();
                    return;
                }
                if (t == typeof(Color))
                {
                    value = reader.ReadColor();
                    return;
                }
                if (t == typeof(Vector2))
                {
                    value = reader.ReadVector2();
                    return;
                }
                if (t == typeof(Vector3))
                {
                    value = reader.ReadVector3();
                    return;
                }
                if (t == typeof(Vector4))
                {
                    value = reader.ReadVector4();
                    return;
                }
                if (t == typeof(Quaternion))
                {
                    value = reader.ReadQuaternion();
                    return;
                }
                if (t == typeof(GameObject))
                {
                    value = reader.ReadGameObject();
                    return;
                }
                if (typeof(Component).RTIsAssignableFrom(t))
                {
                    var go = reader.ReadGameObject();
                    if (go != null)
                    {
                        value = go.GetComponent(t);
                    }
                    return;
                }
            }
示例#20
0
 public object Read(NetworkReader reader)
 {
     return(reader.ReadColor());
 }
示例#21
0
        public static SpriteUpdateMessage.NetMessage Deserialize(this NetworkReader reader)
        {
            var message = new SpriteUpdateMessage.NetMessage();

            SpriteUpdateMessage.SpriteUpdateEntry UnprocessedData = null;
            while (true)
            {
                UnprocessedData = null;
                bool ProcessSection = true;
                uint NetID          = reader.ReadUInt32();
                if (NetID == 0)
                {
                    break;
                }

                if (NetworkIdentity.spawned.ContainsKey(NetID) == false || NetworkIdentity.spawned[NetID] == null)
                {
                    ProcessSection = false;
                }

                string Name = reader.ReadString();
                if (ProcessSection == false ||
                    NetworkIdentity.spawned.ContainsKey(NetID) == false ||
                    SpriteHandlerManager.PresentSprites.ContainsKey(NetworkIdentity.spawned[NetID]) == false ||
                    SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]].ContainsKey(Name) == false)
                {
                    ProcessSection = false;
                }

                if (ProcessSection == false)
                {
                    UnprocessedData      = new SpriteUpdateMessage.SpriteUpdateEntry();
                    UnprocessedData.name = Name;
                    UnprocessedData.id   = NetID;
                }

                SpriteHandler SP = null;
                if (ProcessSection)
                {
                    SP = SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]][Name];
                }

                while (true)
                {
                    byte Operation = reader.ReadByte();

                    if (Operation == 255)
                    {
                        if (ProcessSection == false)
                        {
                            SpriteUpdateMessage.UnprocessedData.Add(UnprocessedData);
                        }

                        break;
                    }

                    if (Operation == 1)
                    {
                        int SpriteID = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.SetSpriteSO(SpriteCatalogue.Instance.Catalogue[SpriteID], Network: false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PresentSpriteSet);
                            UnprocessedData.arg.Add(SpriteID);
                        }
                    }


                    if (Operation == 2)
                    {
                        int Variant = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.ChangeSpriteVariant(Variant, NetWork: false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.VariantIndex);
                            UnprocessedData.arg.Add(Variant);
                        }
                    }

                    if (Operation == 3)
                    {
                        int Sprite = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.ChangeSprite(Sprite, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.CataloguePage);
                            UnprocessedData.arg.Add(Sprite);
                        }
                    }

                    if (Operation == 4)
                    {
                        int SpriteAnimate = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.AnimateOnce(SpriteAnimate, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.AnimateOnce);
                            UnprocessedData.arg.Add(SpriteAnimate);
                        }
                    }

                    if (Operation == 5)
                    {
                        if (ProcessSection)
                        {
                            SP.PushTexture(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushTexture);
                        }
                    }

                    if (Operation == 6)
                    {
                        if (ProcessSection)
                        {
                            SP.Empty(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Empty);
                        }
                    }


                    if (Operation == 7)
                    {
                        if (ProcessSection)
                        {
                            SP.PushClear(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushClear);
                        }
                    }

                    if (Operation == 8)
                    {
                        if (ProcessSection)
                        {
                            SP.ClearPallet(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.ClearPallet);
                        }
                    }


                    if (Operation == 9)
                    {
                        Color TheColour = reader.ReadColor();
                        if (ProcessSection)
                        {
                            SP.SetColor(TheColour, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.SetColour);
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.r * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.g * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.b * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.a * 255)));
                        }
                    }

                    if (Operation == 10)
                    {
                        int          paletteCount = reader.ReadByte();
                        List <Color> Colours      = new List <Color>();
                        for (int i = 0; i < paletteCount; i++)
                        {
                            Colours.Add(reader.ReadColor());
                        }

                        if (ProcessSection)
                        {
                            SP.SetPaletteOfCurrentSprite(Colours, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Pallet);
                            UnprocessedData.arg.Add(Convert.ToChar(paletteCount));
                            foreach (var color in Colours)
                            {
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.r * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.g * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.b * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.a * 255)));
                            }
                        }
                    }
                }
            }

            return(message);
        }
示例#22
0
    // Read
    public static object Read(NetworkReader reader, Type type)
    {
        if (type == typeof(byte))
        {
            return(reader.ReadByte());
        }

        if (type == typeof(short))
        {
            return(reader.ReadInt16());
        }

        if (type == typeof(int))
        {
            return(reader.ReadInt32());
        }

        if (type == typeof(long))
        {
            return(reader.ReadInt64());
        }

        if (type == typeof(string))
        {
            return(reader.ReadString());
        }

        if (type == typeof(float))
        {
            return(reader.ReadSingle());
        }

        if (type == typeof(double))
        {
            return(reader.ReadDouble());
        }

        if (type == typeof(Vector2))
        {
            return(reader.ReadVector2());
        }

        if (type == typeof(Vector3))
        {
            return(reader.ReadVector3());
        }

        if (type == typeof(Vector4))
        {
            return(reader.ReadVector4());
        }

        if (type == typeof(Color))
        {
            return(reader.ReadColor());
        }

        if (type == typeof(Color32))
        {
            return(reader.ReadColor32());
        }

        if (type == typeof(Quaternion))
        {
            return(reader.ReadQuaternion());
        }

        if (type.IsValueType)
        {
            return(Activator.CreateInstance(type));
        }

        return(null);
    }
        public static SpriteUpdateMessage.NetMessage Deserialize(this NetworkReader reader)
        {
            var message = new SpriteUpdateMessage.NetMessage();

            SpriteUpdateMessage.SpriteUpdateEntry UnprocessedData = null;
            while (true)
            {
                UnprocessedData = null;
                bool ProcessSection = true;
                uint NetID          = reader.ReadUInt32();
                if (NetID == 0)
                {
                    break;
                }

                if (NetworkIdentity.spawned.ContainsKey(NetID) == false || NetworkIdentity.spawned[NetID] == null)
                {
                    ProcessSection = false;
                }

                string Name = reader.ReadString();
                if (ProcessSection == false ||
                    NetworkIdentity.spawned.ContainsKey(NetID) == false ||
                    SpriteHandlerManager.PresentSprites.ContainsKey(NetworkIdentity.spawned[NetID]) == false ||
                    SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]].ContainsKey(Name) == false)
                {
                    ProcessSection = false;
                }

                if (ProcessSection == false)
                {
                    UnprocessedData      = new SpriteUpdateMessage.SpriteUpdateEntry();
                    UnprocessedData.name = Name;
                    UnprocessedData.id   = NetID;
                }

                SpriteHandler SP = null;
                if (ProcessSection)
                {
                    SP = SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]][Name];
                }

                while (true)
                {
                    byte Operation = reader.ReadByte();

                    if (Operation == 255)
                    {
                        if (ProcessSection == false)
                        {
                            SpriteUpdateMessage.UnprocessedData.Add(UnprocessedData);
                        }

                        break;
                    }

                    if (Operation == 1)
                    {
                        int SpriteID = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            try
                            {
                                SP.SetSpriteSO(SpriteCatalogue.Instance.Catalogue[SpriteID], networked: false);
                            }
                            catch (Exception e)
                            {
                                Logger.Log("ddD");
                            }
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PresentSpriteSet);
                            UnprocessedData.arg.Add(SpriteID);
                        }
                    }


                    if (Operation == 2)
                    {
                        int Variant = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.ChangeSpriteVariant(Variant, networked: false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.VariantIndex);
                            UnprocessedData.arg.Add(Variant);
                        }
                    }

                    if (Operation == 3)
                    {
                        int Sprite = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.ChangeSprite(Sprite, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.CataloguePage);
                            UnprocessedData.arg.Add(Sprite);
                        }
                    }

                    if (Operation == 4)
                    {
                        int SpriteAnimate = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.AnimateOnce(SpriteAnimate, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.AnimateOnce);
                            UnprocessedData.arg.Add(SpriteAnimate);
                        }
                    }

                    if (Operation == 5)
                    {
                        if (ProcessSection)
                        {
                            SP.PushTexture(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushTexture);
                        }
                    }

                    if (Operation == 6)
                    {
                        if (ProcessSection)
                        {
                            SP.Empty(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Empty);
                        }
                    }


                    if (Operation == 7)
                    {
                        if (ProcessSection)
                        {
                            SP.PushClear(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushClear);
                        }
                    }

                    if (Operation == 8)
                    {
                        if (ProcessSection)
                        {
                            SP.ClearPalette(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.ClearPallet);
                        }
                    }


                    if (Operation == 9)
                    {
                        Color TheColour = reader.ReadColor();
                        if (ProcessSection)
                        {
                            if (SP)
                            {
                                //TODO: remove this check - registering arrives after the sprite update, all clients will disconnect after a runtime
                                //removing and readding a bodypart through surgery would cause it, since the network identity already exists unlike the creation of a new human
                                SP.SetColor(TheColour, false);
                            }
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.SetColour);
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.r * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.g * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.b * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.a * 255)));
                        }
                    }

                    if (Operation == 10)
                    {
                        int          paletteCount = reader.ReadByte();
                        List <Color> Colours      = new List <Color>();
                        for (int i = 0; i < paletteCount; i++)
                        {
                            Colours.Add(reader.ReadColor());
                        }

                        if (ProcessSection)
                        {
                            SP.SetPaletteOfCurrentSprite(Colours, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Pallet);
                            UnprocessedData.arg.Add(Convert.ToChar(paletteCount));
                            foreach (var color in Colours)
                            {
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.r * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.g * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.b * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.a * 255)));
                            }
                        }
                    }
                }
            }

            return(message);
        }
示例#24
0
        public bool Deserialize(byte[] _bytes)
        {
            using (MemoryStream ms = new MemoryStream(_bytes))
            {
                using (NetworkReader nr = new NetworkReader(ms))
                {
                    Type type = GetType();

                    FieldInfo[] allFields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

                    PropertyInfo[]          allProperties = type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                    IEnumerable <FieldInfo> fields        = allFields
                                                            .Where(o => o.GetCustomAttributes(typeof(SyncVar)).Count() > 0)
                                                            .OrderBy(o => o.Name);
                    IEnumerable <PropertyInfo> properties = allProperties
                                                            .Where(o => o.GetCustomAttributes(typeof(SyncVar)).Count() > 0)
                                                            .OrderBy(o => o.Name);

                    Type fieldType;

                    foreach (FieldInfo info in fields)
                    {
                        fieldType = info.FieldType;

                        string typeString = fieldType.Name;
                        object tmpValue   = null;

                        bool switchOnType = true;

                        if (fieldType.IsEnum)
                        {
                            tmpValue     = nr.ReadInt32();
                            switchOnType = false;
                        }
                        if (switchOnType)
                        {
                            switch (typeString)
                            {
                            case "Boolean":
                                tmpValue = nr.ReadBoolean();
                                break;

                            case "Byte":
                                tmpValue = nr.ReadByte();
                                break;

                            case "SByte":
                                tmpValue = nr.ReadSByte();
                                break;

                            case "Int16":
                                tmpValue = nr.ReadInt16();
                                break;

                            case "Int32":
                                tmpValue = nr.ReadInt32();
                                break;

                            case "Int64":
                                tmpValue = nr.ReadInt64();
                                break;

                            case "UInt16":
                                tmpValue = nr.ReadUInt16();
                                break;

                            case "UInt32":
                                tmpValue = nr.ReadUInt32();
                                break;

                            case "UInt64":
                                tmpValue = nr.ReadUInt64();
                                break;

                            case "Single":
                                tmpValue = nr.ReadSingle();
                                break;

                            case "Double":
                                tmpValue = nr.ReadDouble();
                                break;

                            case "Decimal":
                                tmpValue = nr.ReadDecimal();
                                break;

                            case "Char":
                                tmpValue = nr.ReadChar();
                                break;

                            case "String":
                                tmpValue = nr.ReadString();
                                break;

                            case "Byte[]":
                                int length = nr.ReadInt32();
                                tmpValue = nr.ReadBytes(length);
                                break;

                            case "Vector2":
                                tmpValue = nr.ReadVector2();
                                break;

                            case "Vector3":
                                tmpValue = nr.ReadVector3();
                                break;

                            case "Vector4":
                                tmpValue = nr.ReadVector4();
                                break;

                            case "GameObject":
                                tmpValue = nr.ReadGameObject();
                                break;

                            case "Transform":
                                tmpValue = nr.ReadTransform();
                                break;

                            case "Color":
                                tmpValue = nr.ReadColor();
                                break;

                            case "Color32":
                                tmpValue = nr.ReadColor32();
                                break;

                            default:
                                Debug.LogWarning("Could not serialize field! " + info.Name + "(" + info.FieldType.Name + ")", this);
                                break;
                            }
                        }
                        info.SetValue(this, tmpValue);
                        SyncVar syncVar = info.GetCustomAttribute <SyncVar>();
                        if (syncVar is object && syncVar.Hook is object)
                        {
                            SendMessage(syncVar.Hook, tmpValue, SendMessageOptions.RequireReceiver);
                        }
                    }

                    foreach (PropertyInfo info in properties)
                    {
                        fieldType = info.PropertyType;

                        string typeString = fieldType.Name;
                        object tmpValue   = null;

                        bool switchOnType = true;

                        if (fieldType.IsEnum)
                        {
                            tmpValue     = nr.ReadInt32();
                            switchOnType = false;
                        }
                        if (switchOnType)
                        {
                            switch (typeString)
                            {
                            case "Boolean":
                                tmpValue = nr.ReadBoolean();
                                break;

                            case "Byte":
                                tmpValue = nr.ReadByte();
                                break;

                            case "SByte":
                                tmpValue = nr.ReadSByte();
                                break;

                            case "Int16":
                                tmpValue = nr.ReadInt16();
                                break;

                            case "Int32":
                                tmpValue = nr.ReadInt32();
                                break;

                            case "Int64":
                                tmpValue = nr.ReadInt64();
                                break;

                            case "UInt16":
                                tmpValue = nr.ReadUInt16();
                                break;

                            case "UInt32":
                                tmpValue = nr.ReadUInt32();
                                break;

                            case "UInt64":
                                tmpValue = nr.ReadUInt64();
                                break;

                            case "Single":
                                tmpValue = nr.ReadSingle();
                                break;

                            case "Double":
                                tmpValue = nr.ReadDouble();
                                break;

                            case "Decimal":
                                tmpValue = nr.ReadDecimal();
                                break;

                            case "Char":
                                tmpValue = nr.ReadChar();
                                break;

                            case "String":
                                tmpValue = nr.ReadString();
                                break;

                            case "Byte[]":
                                int length = nr.ReadInt32();
                                tmpValue = nr.ReadBytes(length);
                                break;

                            case "Vector2":
                                tmpValue = nr.ReadVector2();
                                break;

                            case "Vector3":
                                tmpValue = nr.ReadVector3();
                                break;

                            case "Vector4":
                                tmpValue = nr.ReadVector4();
                                break;

                            case "GameObject":
                                tmpValue = nr.ReadGameObject();
                                break;

                            case "Transform":
                                tmpValue = nr.ReadTransform();
                                break;

                            case "Color":
                                tmpValue = nr.ReadColor();
                                break;

                            case "Color32":
                                tmpValue = nr.ReadColor32();
                                break;

                            default:
                                Debug.LogWarning("Could not serialize field! " + info.Name + "(" + info.PropertyType.Name + ")", this);
                                break;
                            }
                        }
                        info.SetValue(this, tmpValue);
                        SyncVar syncVar = info.GetCustomAttribute <SyncVar>();
                        if (syncVar is object && syncVar.Hook is object)
                        {
                            SendMessage(syncVar.Hook, tmpValue, SendMessageOptions.RequireReceiver);
                        }
                    }
                }

                return(true);
            }
        }
示例#25
0
 public override void Deserialize(NetworkReader reader, out Color value)
 {
     value = reader.ReadColor();
 }
    /// <summary>
    /// Reads the stream to fsm variables. The stream is composed with a string for the key followed by the related value.
    /// </summary>
    /// <returns><c>true</c> if all went fine.</returns>
    /// <param name="toFsm">To fsm.</param>
    /// <param name="vars">The key/Fsm variables</param>
    /// <param name="reader"> The NetworkReader</param>
    /// <param name="missingData"> if stream is missing datas, <c>false</c> otherwise which means all expected data was found</param>
    public static bool ReadStreamToFsmVars(NetworkBehaviour source, Fsm toFsm, Dictionary <string, NamedVariable> vars, NetworkReader reader, out bool missingData, bool debug)
    {
        missingData = false;

        if (vars == null || vars.Count == 0)
        {
            return(true);
        }

        if (toFsm == null)
        {
            Debug.LogError("fromFsm is null", source);
            return(false);
        }

        // meta info to double check all expected data was processed

        List <string> _processedKey = new List <string>();


        if (debug)
        {
            Debug.Log("reading stream:\n" + reader.ToString(), source);
        }

        try{
            int _pairCount = reader.ReadInt32();

            if (debug)
            {
                Debug.Log("reading " + _pairCount + " Key/value pairs", source);
            }

            for (int i = 0; i < _pairCount; i++)
            {
                string _key = reader.ReadString();


                if (debug)
                {
                    Debug.Log("reading for key " + _key, source);
                }

                if (string.IsNullOrEmpty(_key))
                {
                    reader.ReadBoolean();

                    if (debug)
                    {
                        Debug.LogWarning("Found null or empty Stream key property on " + toFsm.Owner.name, source);
                    }
                }
                else if (!vars.ContainsKey(_key))
                {
                    reader.ReadBoolean();

                    if (debug)
                    {
                        Debug.LogWarning("Stream property <" + _key + "> not found as a Fsmvariable on " + toFsm.Owner.name, source);
                    }
                    missingData = true;
                }
                else
                {
                    NamedVariable _NamedVariable = vars[_key];

                    if (debug)
                    {
                        Debug.Log("Variable for key of type " + _NamedVariable.VariableType, source);
                    }

                    _processedKey.Add(_key);

                    string _variableName = _NamedVariable.Name;
                    switch (_NamedVariable.VariableType)
                    {
                    case VariableType.Int:
                        toFsm.Variables.GetFsmInt(_variableName).Value = reader.ReadInt32();
                        break;

                    case VariableType.Float:
                        toFsm.Variables.GetFsmFloat(_variableName).Value = reader.ReadSingle();
                        break;

                    case VariableType.Bool:
                        toFsm.Variables.GetFsmBool(_variableName).Value = reader.ReadBoolean();
                        break;

                    case VariableType.Color:
                        toFsm.Variables.GetFsmColor(_variableName).Value = reader.ReadColor();
                        break;

                    case VariableType.Quaternion:
                        toFsm.Variables.GetFsmQuaternion(_variableName).Value = reader.ReadQuaternion();
                        break;

                    case VariableType.Rect:
                        toFsm.Variables.GetFsmRect(_variableName).Value = reader.ReadRect();
                        break;

                    case VariableType.Vector2:
                        toFsm.Variables.GetFsmVector2(_variableName).Value = reader.ReadVector2();
                        break;

                    case VariableType.Vector3:
                        toFsm.Variables.GetFsmVector3(_variableName).Value = reader.ReadVector3();
                        break;

                    case VariableType.Texture:
                        reader.ReadBoolean();                         // we must read it however to keep moving forward
                        //UnityEngine.Debug.LogWarning("Texture not supported in initial data");
                        break;

                    case VariableType.Material:
                        reader.ReadBoolean();                         // we must read it however to keep moving forward
                        //	UnityEngine.Debug.LogWarning("Material not supported in initial data");
                        break;

                    case VariableType.String:
                        toFsm.Variables.GetFsmString(_variableName).Value = reader.ReadString();
                        break;

                    case VariableType.GameObject:
                        toFsm.Variables.GetFsmGameObject(_variableName).Value = reader.ReadGameObject();
                        break;

                    case VariableType.Object:
                        reader.ReadBoolean();
                        //Debug.LogWarning("Object not supported in initial data",source);
                        break;
                    }
                }
            }

            if (vars.Count > _processedKey.Count)
            {
                string[] _unprocessedKeys = new string[vars.Count];
                //vars.Keys.CopyTo(_unprocessedKeys,0);

                UnityEngine.Debug.LogWarning("Stream data missing properties <" + String.Join(",", _unprocessedKeys) + "> on " + toFsm.Owner.name);
                missingData = true;
            }

            return(true);
        }catch (System.Exception e)
        {
            UnityEngine.Debug.LogWarning("Stream data stream error " + e.Message);
        }


        return(false);
    }
    private static object ReadData(NetworkReader reader)
    {
        object resultObj = null;

        byte dataType = reader.ReadByte();

        if (dataType == BYTE)
        {
            resultObj = reader.ReadByte();
        }
        else if (dataType == SBYTE)
        {
            resultObj = reader.ReadSByte();
        }
        else if (dataType == CHAR)
        {
            resultObj = reader.ReadChar();
        }
        else if (dataType == BOOL)
        {
            resultObj = reader.ReadBoolean();
        }
        else if (dataType == SHORT)
        {
            resultObj = reader.ReadInt16();
        }
        else if (dataType == USHORT)
        {
            resultObj = reader.ReadUInt16();
        }
        else if (dataType == INT)
        {
            resultObj = reader.ReadInt32();
        }
        else if (dataType == UINT)
        {
            resultObj = reader.ReadPackedUInt32();
        }
        else if (dataType == LONG)
        {
            resultObj = reader.ReadInt64();
        }
        else if (dataType == ULONG)
        {
            resultObj = reader.ReadPackedUInt64();
        }
        else if (dataType == FLOAT)
        {
            resultObj = reader.ReadSingle();
        }
        else if (dataType == DOUBLE)
        {
            resultObj = reader.ReadDouble();
        }
        else if (dataType == DECIMAL)
        {
            resultObj = reader.ReadDecimal();
        }
        else if (dataType == STRING)
        {
            resultObj = reader.ReadString();
        }
        else if (dataType == VECTOR2)
        {
            resultObj = reader.ReadVector2();
        }
        else if (dataType == VECTOR3)
        {
            resultObj = reader.ReadVector3();
        }
        else if (dataType == VECTOR4)
        {
            resultObj = reader.ReadVector4();
        }
        else if (dataType == COLOR)
        {
            resultObj = reader.ReadColor();
        }
        else if (dataType == COLOR32)
        {
            resultObj = reader.ReadColor32();
        }
        else if (dataType == QUATERNION)
        {
            resultObj = reader.ReadQuaternion();
        }
        else if (dataType == TRANSFORM)
        {
            resultObj = reader.ReadTransform();
        }
        else if (dataType == RECT)
        {
            resultObj = reader.ReadRect();
        }
        else if (dataType == PLANE)
        {
            resultObj = reader.ReadPlane();
        }
        else if (dataType == GAMEOBJECT)
        {
            resultObj = reader.ReadGameObject();
        }
        else if (dataType == RAY)
        {
            resultObj = reader.ReadRay();
        }
        else if (dataType == MATRIX4X4)
        {
            resultObj = reader.ReadMatrix4x4();
        }
        else if (dataType == NETWORKHASH128)
        {
            resultObj = reader.ReadNetworkHash128();
        }
        else if (dataType == NETWORKIDENTITY)
        {
            resultObj = reader.ReadNetworkIdentity();
        }
        else if (dataType == MESSAGEBASE)
        {
            //resultObj = reader.ReadMessage<MessageBase>();
            resultObj = null;
        }
        else if (dataType == NETWORKINSTANCEID)
        {
            resultObj = reader.ReadNetworkId();
        }
        else if (dataType == NETWORKSCENEID)
        {
            resultObj = reader.ReadSceneId();
        }
        //Debug.Log(resultObj);
        return(resultObj);
    }