Esempio n. 1
0
            public override void OnComponentUpdate(ComponentUpdateOp op)
            {
                if (!IsValidEntityId(op.EntityId, "OnComponentUpdate", out var entity))
                {
                    return;
                }

                if (entityManager.HasComponent <NotAuthoritative <Generated.Improbable.Gdk.Tests.NestedComponent.Component> >(entity))
                {
                    var data = entityManager.GetComponentData <Generated.Improbable.Gdk.Tests.NestedComponent.Component>(entity);

                    var update = Generated.Improbable.Gdk.Tests.NestedComponent.Serialization.GetAndApplyUpdate(op.Update.SchemaData.Value.GetFields(), ref data);

                    List <Generated.Improbable.Gdk.Tests.NestedComponent.Update> updates;
                    if (entityManager.HasComponent <Generated.Improbable.Gdk.Tests.NestedComponent.ReceivedUpdates>(entity))
                    {
                        updates = entityManager.GetComponentData <Generated.Improbable.Gdk.Tests.NestedComponent.ReceivedUpdates>(entity).Updates;
                    }
                    else
                    {
                        var updatesComponent = new Generated.Improbable.Gdk.Tests.NestedComponent.ReceivedUpdates
                        {
                            handle = ReferenceTypeProviders.UpdatesProvider.Allocate(World)
                        };
                        ReferenceTypeProviders.UpdatesProvider.Set(updatesComponent.handle, new List <Generated.Improbable.Gdk.Tests.NestedComponent.Update>());
                        updates = updatesComponent.Updates;
                        entityManager.AddComponentData(entity, updatesComponent);
                    }

                    updates.Add(update);

                    data.DirtyBit = false;
                    entityManager.SetComponentData(entity, data);
                }
            }
Esempio n. 2
0
            public override void OnAddComponent(AddComponentOp op)
            {
                if (!IsValidEntityId(op.EntityId, "AddComponentOp", out var entity))
                {
                    return;
                }

                var data = Generated.Improbable.Gdk.Tests.NestedComponent.Serialization.Deserialize(op.Data.SchemaData.Value.GetFields(), World);

                data.DirtyBit = false;
                entityManager.AddComponentData(entity, data);
                entityManager.AddComponentData(entity, new NotAuthoritative <Generated.Improbable.Gdk.Tests.NestedComponent.Component>());

                var update = new Generated.Improbable.Gdk.Tests.NestedComponent.Update
                {
                    NestedType = data.NestedType,
                };

                var updates = new List <Generated.Improbable.Gdk.Tests.NestedComponent.Update>
                {
                    update
                };

                var updatesComponent = new Generated.Improbable.Gdk.Tests.NestedComponent.ReceivedUpdates
                {
                    handle = ReferenceTypeProviders.UpdatesProvider.Allocate(World)
                };

                ReferenceTypeProviders.UpdatesProvider.Set(updatesComponent.handle, updates);
                entityManager.AddComponentData(entity, updatesComponent);

                if (entityManager.HasComponent <ComponentRemoved <Generated.Improbable.Gdk.Tests.NestedComponent.Component> >(entity))
                {
                    entityManager.RemoveComponent <ComponentRemoved <Generated.Improbable.Gdk.Tests.NestedComponent.Component> >(entity);
                }
                else if (!entityManager.HasComponent <ComponentAdded <Generated.Improbable.Gdk.Tests.NestedComponent.Component> >(entity))
                {
                    entityManager.AddComponentData(entity, new ComponentAdded <Generated.Improbable.Gdk.Tests.NestedComponent.Component>());
                }
                else
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent(ReceivedDuplicateComponentAdded)
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField("Component", "Generated.Improbable.Gdk.Tests.NestedComponent")
                                            );
                }
            }