Example #1
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);
        }
Example #2
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);
        }