Exemple #1
0
        /// <summary>Unspawn</summary>
        /// <param name="sync">sync</param>
        public void Unspawn(KingSync sync)
        {
            // Remove sync
            _syncsById.Remove(sync.SyncId);
            _syncs.Remove(sync);

            // Remove from the scope of all
            foreach (KingSync kingSync in _syncs)
            {
                kingSync.OutOfScope(sync);
            }

            // Destroy
            Destroy(sync.gameObject);
        }
Exemple #2
0
        /// <summary>Within scope</summary>
        /// <param name="sync">King Sync</param>
        internal void WithinScope(KingSync sync)
        {
            // Ignore if there is no owner
            if (Owner == null)
            {
                return;
            }

            // Ignore if in scope
            if (_syncsById.ContainsKey(sync.SyncId))
            {
                return;
            }

            // Add to indexed sync
            _syncsById.Add(sync.SyncId, sync);

            // WITHIN SCOPE
            var buffer = new KingBuffer();

            buffer.WriteMessagePacket(KingPacket.WithinScope);

            // Write node identifier
            // Owner always receives ID 0
            if (sync == this)
            {
                buffer.WriteShort(OWNER_ID);
            }
            else
            {
                buffer.WriteShort(sync.SyncId);
            }

            // Write prefab
            buffer.WriteString(Prefab);

            // Write full data
            InvokeOnWriting(buffer, true);

            // Send
            Owner.Send(buffer);
        }
Exemple #3
0
        /// <summary>Out of scope</summary>
        /// <param name="sync">King Sync</param>
        internal void OutOfScope(KingSync sync)
        {
            // Ignore if there is no owner
            if (Owner == null)
            {
                return;
            }

            // Ignore if not in scope
            if (!_syncsById.ContainsKey(sync.SyncId))
            {
                return;
            }

            // Remove from indexed sync
            _syncsById.Remove(sync.SyncId);

            // OUT OF SCOPE
            var buffer = new KingBuffer();;

            buffer.WriteMessagePacket(KingPacket.OutOfScope);

            // Write node identifier
            // Owner always receives ID 0
            if (sync == this)
            {
                buffer.WriteShort(OWNER_ID);
            }
            else
            {
                buffer.WriteShort(sync.SyncId);
            }

            // Send
            Owner.Send(buffer);
        }