Exemplo n.º 1
0
        /// <summary>Within scope</summary>
        /// <param name="buffer">King Buffer</param>
        private void WithinScope(KingBuffer buffer)
        {
            // Sync id
            var syncId = buffer.ReadShort();

            // Has synchronizer
            if (_syncsById.ContainsKey(syncId))
            {
                return;
            }

            // Spawn sync
            var KingSync = Spawn(
                buffer.ReadString(),
                buffer.ReadVector3(),
                buffer.ReadQuaternion(),
                syncId
                );

            // Invoke on reading
            KingSync.InvokeOnReading(buffer);

            // Spawning
            OnSpawning.Invoke(KingSync);
        }
Exemplo n.º 2
0
        /// <summary>Out of scope</summary>
        /// <param name="buffer">King Buffer</param>
        private void OutOfScope(KingBuffer buffer)
        {
            // Sync id
            var syncId = buffer.ReadShort();

            // No synchronizer
            if (!_syncsById.ContainsKey(syncId))
            {
                return;
            }

            // Unspawning
            OnUnpawning.Invoke(_syncsById[syncId]);

            // Unspawn
            Unspawn(syncId);
        }
Exemplo n.º 3
0
        /// <summary>Sync update</summary>
        /// <param name="buffer">King buffer</param>
        public void SyncUpdate(KingBuffer buffer)
        {
            var packet = buffer.ReadMessagePacket <KingPacket>();

            // OUT OF SCOPE
            if (packet == KingPacket.OutOfScope)
            {
                OutOfScope(buffer);
            }

            // WITHIN SCOPE
            if (packet == KingPacket.WithinScope)
            {
                WithinScope(buffer);
            }

            // SYNC SCENE
            if (packet == KingPacket.SyncScene)
            {
                // As long as you can read
                while (buffer.CanRead())
                {
                    // sync id
                    var syncId = buffer.ReadShort();

                    // Has synchronizer
                    if (!_syncsById.ContainsKey(syncId))
                    {
                        break;
                    }

                    // Catching
                    _syncsById[syncId].Catching(buffer);
                }
            }
        }