Exemple #1
0
        public void Publish([NotNull] NetworkEntityNowVisibleEventArgs eventArgs)
        {
            if (eventArgs == null)
            {
                throw new ArgumentNullException(nameof(eventArgs));
            }

            //Just forward the publishing
            OnNetworkEntityNowVisible?.Invoke(this, eventArgs);
        }
Exemple #2
0
        /// <inheritdoc />
        public override async Task HandleMessage(IPeerMessageContext <GameClientPacketPayload> context, NetworkObjectVisibilityChangeEventPayload payload)
        {
            foreach (var entity in payload.EntitiesToCreate)
            {
                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug($"Encountered new entity: {entity.EntityGuid}");
                }
            }

            foreach (var entity in payload.OutOfRangeEntities)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Debug($"Leaving entity: {entity}");
                }
            }

            //Assume it's a player for now
            foreach (var creationData in payload.EntitiesToCreate)
            {
                //TODO: Right now we're creating a temporary entity data collection.
                EntityFieldDataCollection <EntityDataFieldType> testData = new EntityFieldDataCollection <EntityDataFieldType>();

                //We set the initial values off the main thread, it is much better that way.
                //However, that means initial values won't dispatch OnChange stuff.
                SetInitialFieldValues(creationData, testData);

                OnNetworkEntityNowVisible?.Invoke(this, new NetworkEntityNowVisibleEventArgs(creationData.EntityGuid, creationData, testData));
            }

            foreach (var destroyData in payload.OutOfRangeEntities)
            {
                OnNetworkEntityVisibilityLost?.Invoke(this, new NetworkEntityVisibilityLostEventArgs(destroyData));
            }

            //TODO: We should not waste 2, maybe even more, frames to prevent the race condition for spawn/despawn and other packets.
            //We SHOULD actually only call these awaits in other handlers where we realize we MAY not have spawned the entity yet.
            //This should yield better-case throughput because MANY packets could be handled unrelated inbetween these awaits.
            //Two tickable frames is long enough for all spawn/despawn logic to have run.
            await UnityExtended.AwaitNextTickableFrameAsync()
            .ConfigureAwait(false);

            await UnityExtended.AwaitNextTickableFrameAsync()
            .ConfigureAwait(false);
        }