Esempio n. 1
0
        /// <summary>
        /// Called when the tile has been send from the server to this client.
        /// Here the data needs to be read and immediately applied.
        /// Default implementation reads the <see cref="BaseSpriteTint"/>, and all components.
        /// </summary>
        /// <param name="msg">The message to read data from.</param>
        /// <param name="forSpawn">If <see langword="true"/>, then all required data should be read, since this client knows nothing about this tile. If <see langword="false"/>, then only data that might have changed since spawned needs to be read.</param>
        public virtual void ReadData(NetBuffer msg, bool forSpawn)
        {
            this.BaseSpriteTint = msg.ReadColor();

            byte compCount = msg.ReadByte();

            for (int i = 0; i < compCount; i++)
            {
                byte index = msg.ReadByte();

                if (forSpawn)
                {
                    ushort id      = msg.ReadUInt16();
                    var    newComp = TileComponent.Create(id);
                    RemoveComponent(index, false);
                    AddComponent(newComp, index, false);
                }

                var current = components[index];
                current.ReadData(msg, forSpawn);
            }
        }