コード例 #1
0
 internal WorkerWriter(World world, Entity entity, EntityId entityId)
     : base(world, entity, entityId)
 {
 }
コード例 #2
0
 public IInjectable CreateInjectable(Entity entity, EntityManager entityManager, ILogDispatcher logDispatcher)
 {
     return(new ReaderWriterImpl(entity, entityManager, logDispatcher));
 }
コード例 #3
0
 public override void AddCommandComponents(Unity.Entities.Entity entity)
 {
 }
コード例 #4
0
 internal InterestWriter(World world, Entity entity, EntityId entityId)
     : base(world, entity, entityId)
 {
 }
コード例 #5
0
 public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentData(entity, new Player2Tag {
     });
 }
コード例 #6
0
 public override void AddCommandRequestSender(Unity.Entities.Entity entity, long entityId)
 {
 }
コード例 #7
0
 internal DependencyTestWriter(World world, Entity entity, EntityId entityId)
     : base(world, entity, entityId)
 {
 }
コード例 #8
0
 public unsafe void SetEntityMass(Unity.Entities.Entity _entity, BlobAssetReference <Unity.Physics.Collider> _collider, float _mass)
 {
     Unity.Physics.Collider *colliderPtr = (Unity.Physics.Collider *)_collider.GetUnsafePtr();
     entityManager.SetComponentData(_entity, PhysicsMass.CreateDynamic(colliderPtr->MassProperties, _mass));
 }
コード例 #9
0
 public static bool Raycast(UnityEngine.Ray ray, float distance, out Unity.Physics.RaycastHit outHit, out Unity.Entities.Entity entity)
 {
     return(Raycast(ray.origin, ray.origin + (ray.direction * distance), out outHit, out entity));
 }
コード例 #10
0
 public void SetReceivedEntity(Unity.Entities.Entity entity)
 {
     EntityToTrack = entity;
     GameMaster.Instance.entitiesToObjectMap.Add(entity, this.transform);
 }
コード例 #11
0
 public override void AddCommandComponents(Entity entity)
 {
     EntityManager.AddComponentData(entity, new CommandComponent());
 }
コード例 #12
0
 internal PositionWriter(World world, Entity entity, EntityId entityId)
     : base(world, entity, entityId)
 {
 }
コード例 #13
0
 protected override ExhaustiveMapValueWriter CreateWriter(Entity entity, EntityId entityId)
 {
     return(new ExhaustiveMapValueWriter(World, entity, entityId));
 }
コード例 #14
0
 internal ExhaustiveRepeatedWriter(World world, Entity entity, EntityId entityId)
     : base(world, entity, entityId)
 {
 }
 internal ExhaustiveOptionalWriter(World world, Entity entity, EntityId entityId)
     : base(world, entity, entityId)
 {
 }
コード例 #16
0
    public static bool Raycast(float3 RayFrom, float3 RayTo, out Unity.Physics.RaycastHit outHit, out Unity.Entities.Entity entity)
    {
        var          physicsWorldSystem = Unity.Entities.World.Active.GetExistingSystem <Unity.Physics.Systems.BuildPhysicsWorld>();
        var          collisionWorld     = physicsWorldSystem.PhysicsWorld.CollisionWorld;
        RaycastInput input = new RaycastInput()
        {
            Start  = RayFrom,
            End    = RayTo,
            Filter = new CollisionFilter()
            {
                BelongsTo    = ~0u,
                CollidesWith = ~0u,                 // all 1s, so all layers, collide with everything
                GroupIndex   = 0
            }
        };

        Unity.Physics.RaycastHit hit = new Unity.Physics.RaycastHit();
        bool haveHit = collisionWorld.CastRay(input, out hit);

        outHit = hit;
        entity = Unity.Entities.Entity.Null;

        if (haveHit)
        {
            // see hit.Position
            // see hit.SurfaceNormal
            entity = physicsWorldSystem.PhysicsWorld.Bodies[hit.RigidBodyIndex].Entity;
            return(true);
        }

        return(false);
    }
コード例 #17
0
            private void ApplyAuthorityChange(Unity.Entities.Entity entity, Authority authority, global::Improbable.Worker.EntityId entityId)
            {
                switch (authority)
                {
                case Authority.Authoritative:
                    if (!entityManager.HasComponent <NotAuthoritative <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >(entity))
                    {
                        LogInvalidAuthorityTransition(Authority.Authoritative, Authority.NotAuthoritative, entityId);
                        return;
                    }

                    entityManager.RemoveComponent <NotAuthoritative <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >(entity);
                    entityManager.AddComponent(entity, ComponentType.Create <Authoritative <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >());

                    // Add event senders
                    break;

                case Authority.AuthorityLossImminent:
                    if (!entityManager.HasComponent <Authoritative <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >(entity))
                    {
                        LogInvalidAuthorityTransition(Authority.AuthorityLossImminent, Authority.Authoritative, entityId);
                        return;
                    }

                    entityManager.AddComponent(entity, ComponentType.Create <AuthorityLossImminent <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >());
                    break;

                case Authority.NotAuthoritative:
                    if (!entityManager.HasComponent <Authoritative <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >(entity))
                    {
                        LogInvalidAuthorityTransition(Authority.NotAuthoritative, Authority.Authoritative, entityId);
                        return;
                    }

                    if (entityManager.HasComponent <AuthorityLossImminent <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >(entity))
                    {
                        entityManager.RemoveComponent <AuthorityLossImminent <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >(entity);
                    }

                    entityManager.RemoveComponent <Authoritative <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >(entity);
                    entityManager.AddComponent(entity, ComponentType.Create <NotAuthoritative <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >());

                    // Remove event senders
                    break;
                }

                List <Authority> authorityChanges;

                if (entityManager.HasComponent <AuthorityChanges <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >(entity))
                {
                    authorityChanges = entityManager.GetComponentData <AuthorityChanges <Improbable.Gdk.Tests.ExhaustiveMapValue.Component> >(entity).Changes;
                }
                else
                {
                    var changes = new AuthorityChanges <Improbable.Gdk.Tests.ExhaustiveMapValue.Component>
                    {
                        Handle = AuthorityChangesProvider.Allocate(World)
                    };
                    AuthorityChangesProvider.Set(changes.Handle, new List <Authority>());
                    authorityChanges = changes.Changes;
                    entityManager.AddComponentData(entity, changes);
                }

                authorityChanges.Add(authority);
            }
コード例 #18
0
 protected abstract T CreateReceiver(World world, Entity entity, EntityId entityId);
コード例 #19
0
 protected override DependencyTestWriter CreateWriter(Entity entity, EntityId entityId)
 {
     return(new DependencyTestWriter(World, entity, entityId));
 }
コード例 #20
0
 protected abstract T CreateSender(Entity entity, World world);
コード例 #21
0
 protected override InterestWriter CreateWriter(Entity entity, EntityId entityId)
 {
     return(new InterestWriter(World, entity, entityId));
 }
コード例 #22
0
            private bool IsValidEntityId(global::Improbable.Worker.EntityId entityId, string opType, out Unity.Entities.Entity entity)
            {
                if (!Worker.TryGetEntity(entityId, out entity))
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent(EntityNotFound)
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, entityId.Id)
                                            .WithField("Op", opType)
                                            .WithField("Component", "Generated.Improbable.Gdk.Tests.ExhaustiveRepeated")
                                            );
                    return(false);
                }

                return(true);
            }
コード例 #23
0
 internal ExhaustiveMapValueWriter(World world, Entity entity, EntityId entityId)
     : base(world, entity, entityId)
 {
 }
コード例 #24
0
 public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentData(entity, new PlayerWeaponData {
         BulletType = BulletType, BulletTypePrefab = conversionSystem.GetPrimaryEntity(BulletTypePrefab)
     });
 }
コード例 #25
0
 public IInjectable CreateInjectable(Entity entity, EntityManager entityManager,
                                     ILogDispatcher logDispatcher)
 {
     return(new WorldCommandResponseHandler(logDispatcher));
 }
コード例 #26
0
 /// <summary>
 ///     Attempts to find an ECS entity associated with a SpatialOS entity ID.
 /// </summary>
 /// <param name="entityId">The SpatialOS entity ID.</param>
 /// <param name="entity">
 ///     When this method returns, contains the ECS entity associated with the SpatialOS entity ID if one was
 ///     found, else the default value for <see cref="Entity" />.
 /// </param>
 /// <returns>
 ///     True, if an ECS entity associated with the SpatialOS entity ID was found, false otherwise.
 /// </returns>
 public bool TryGetEntity(EntityId entityId, out Entity entity)
 {
     return(EntityIdToEntity.TryGetValue(entityId, out entity));
 }
コード例 #27
0
 public ReaderWriterImpl(Entity entity, EntityManager entityManager, ILogDispatcher logDispatcher)
     : base(entity, entityManager, logDispatcher)
 {
 }
コード例 #28
0
 internal ComponentWithNoFieldsWriter(World world, Entity entity, EntityId entityId)
     : base(world, entity, entityId)
 {
 }
コード例 #29
0
            private void ApplyAuthorityChange(Unity.Entities.Entity entity, Authority authority, global::Improbable.Worker.EntityId entityId)
            {
                switch (authority)
                {
                case Authority.Authoritative:
                    if (!entityManager.HasComponent <NotAuthoritative <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity))
                    {
                        LogInvalidAuthorityTransition(Authority.Authoritative, Authority.NotAuthoritative, entityId);
                        return;
                    }

                    entityManager.RemoveComponent <NotAuthoritative <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity);
                    entityManager.AddComponent(entity, ComponentType.Create <Authoritative <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >());

                    // Add event senders
                    {
                        var eventSender = new EventSender.MyEvent()
                        {
                            handle = ReferenceTypeProviders.MyEventProvider.Allocate(World)
                        };
                        ReferenceTypeProviders.MyEventProvider.Set(eventSender.handle, new List <global::Improbable.Gdk.Tests.AlternateSchemaSyntax.RandomDataType>());
                        entityManager.AddComponentData(entity, eventSender);
                    }
                    break;

                case Authority.AuthorityLossImminent:
                    if (!entityManager.HasComponent <Authoritative <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity))
                    {
                        LogInvalidAuthorityTransition(Authority.AuthorityLossImminent, Authority.Authoritative, entityId);
                        return;
                    }

                    entityManager.AddComponent(entity, ComponentType.Create <AuthorityLossImminent <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >());
                    break;

                case Authority.NotAuthoritative:
                    if (!entityManager.HasComponent <Authoritative <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity))
                    {
                        LogInvalidAuthorityTransition(Authority.NotAuthoritative, Authority.Authoritative, entityId);
                        return;
                    }

                    if (entityManager.HasComponent <AuthorityLossImminent <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity))
                    {
                        entityManager.RemoveComponent <AuthorityLossImminent <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity);
                    }

                    entityManager.RemoveComponent <Authoritative <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity);
                    entityManager.AddComponent(entity, ComponentType.Create <NotAuthoritative <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >());

                    // Remove event senders
                    {
                        var eventSender = entityManager.GetComponentData <EventSender.MyEvent>(entity);
                        ReferenceTypeProviders.MyEventProvider.Free(eventSender.handle);
                        entityManager.RemoveComponent <EventSender.MyEvent>(entity);
                    }
                    break;
                }

                List <Authority> authorityChanges;

                if (entityManager.HasComponent <AuthorityChanges <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity))
                {
                    authorityChanges = entityManager.GetComponentData <AuthorityChanges <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity).Changes;
                }
                else
                {
                    var changes = new AuthorityChanges <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component>
                    {
                        Handle = AuthorityChangesProvider.Allocate(World)
                    };
                    AuthorityChangesProvider.Set(changes.Handle, new List <Authority>());
                    authorityChanges = changes.Changes;
                    entityManager.AddComponentData(entity, changes);
                }

                authorityChanges.Add(authority);
            }
コード例 #30
0
        protected override void OnUpdate()
        {
            Entity cameraEntity   = default;
            float3 cameraPosition = default;

            if (m_CameraQuery.CalculateEntityCount() > 0)
            {
                cameraEntity = m_CameraQuery.GetSingletonEntity();
                var cameraObject = EntityManager.GetComponentObject <UnityEngine.Camera>(cameraEntity);
                cameraPosition = cameraObject.transform.position;
            }

            var player = this.GetFirstSelfGamePlayer();

            if (!EntityManager.TryGetComponentData(player, out GameRhythmInputComponent playerCommand))
            {
                Destroy();
                return;
            }

            var cameraState = this.GetComputedCameraState();

            var isWorldSpace = cameraState.StateData.Target != default;

            if (!EntityManager.HasComponent <UnitDescription>(cameraState.StateData.Target))
            {
                isWorldSpace = false;
            }

            var canvasRect = m_Canvas.pixelRect;

            if (isWorldSpace && cameraEntity != default)
            {
                var translation = EntityManager.GetComponentData <Translation>(cameraState.StateData.Target);
                m_Canvas.renderMode           = RenderMode.WorldSpace;
                m_Canvas.transform.position   = new Vector3(translation.Value.x, translation.Value.y + 25 * 0.05f, cameraPosition.z + 10);
                m_Canvas.transform.localScale = Vector3.one * 0.05f;

                var rectTransform = m_Canvas.GetComponent <RectTransform>();
                rectTransform.sizeDelta = new Vector2(100, 100);

                canvasRect.width  = 90;
                canvasRect.height = 105;
            }
            else
            {
                m_Canvas.transform.position = Vector3.zero;
                m_Canvas.renderMode         = RenderMode.ScreenSpaceCamera;
                m_Canvas.worldCamera        = EntityManager.GetComponentObject <UnityEngine.Camera>(cameraEntity);
            }

            var pixelRange = new float2(canvasRect.width, canvasRect.height);

            Entity engine = default;

            if (cameraState.StateData.Target != default)
            {
                engine = PlayerComponentFinder.GetRelativeChild <RhythmEngineDescription>(EntityManager, m_EngineQuery, cameraState.StateData.Target, player);
            }
            else
            {
                engine = PlayerComponentFinder.FromQueryFindPlayerChild(m_EngineQuery, player);
            }

            if (engine == default)
            {
                Destroy();
                return;
            }

            var process  = EntityManager.GetComponentData <RhythmEngineLocalState>(engine);
            var settings = EntityManager.GetComponentData <RhythmEngineSettings>(engine);

            if (!EntityManager.HasComponent <RhythmEngineIsPlaying>(engine) || RhythmEngineUtility.GetFlowBeat(process.Elapsed, settings.BeatInterval) < 0)
            {
                Destroy();
                return;
            }

            var key = 1;

            foreach (var ac in playerCommand.Actions)
            {
                if (!ac.InterFrame.HasBeenPressed(timeSystem.GetReport(player).Active))
                {
                    key++;
                    continue;
                }

                var keyRange = new float2();
                if (key <= 2)
                {
                    if (key == 1)
                    {
                        keyRange.x = -0.35f;
                    }
                    else
                    {
                        keyRange.x = 0.35f;
                    }

                    keyRange.x += Random.Range(-0.025f, 0.025f);
                    keyRange.y  = Random.Range(-0.1f, 0.1f);
                }
                else
                {
                    if (key == 3)
                    {
                        keyRange.y = -0.375f;
                    }
                    else
                    {
                        keyRange.y = 0.375f;
                    }

                    keyRange.y += Random.Range(-0.025f, 0.025f);
                    keyRange.x  = Random.Range(-0.1f, 0.1f);
                }

                keyRange += 0.5f;

                var width  = pixelRange.x * 0.5f;
                var height = pixelRange.y * 0.5f;
                var keyPos = new float2(math.lerp(-width, width, keyRange.x), math.lerp(-height, height, keyRange.y));

                var beGameObject = DrumBackendPools[key].Dequeue();
                using (new SetTemporaryInjectionWorld(World))
                {
                    beGameObject.name = $"BackendPressure (Key: {key})";
                    beGameObject.SetActive(true);
                    beGameObject.transform.SetParent(m_Canvas.transform, false);
                    beGameObject.transform.localScale = m_Canvas.renderMode == RenderMode.WorldSpace
                                                ? Vector3.one * 0.7f
                                                : 0.008f * math.min(width, height) * Vector3.one;
                    beGameObject.transform.localPosition = new Vector3(keyPos.x, keyPos.y, 0);
                    beGameObject.transform.rotation      = Quaternion.Euler(0, 0, Random.Range(-12.5f, 12.5f));
                }

                var backend = beGameObject.GetComponent <UIDrumPressureBackend>();
                backend.OnReset();
                backend.SetTarget(EntityManager);
                backend.SetPresentationFromPool(DrumPresentationPools[key]);

                var prevRand     = backend.rand;
                var absRealScore = math.abs(RhythmEngineUtility.GetScore(process.Elapsed, settings.BeatInterval));

                backend.play    = true;
                backend.key     = key;
                backend.rand    = DrumVariantCount[key];
                backend.perfect = absRealScore <= FlowPressure.Perfect;
                backend.endTime = Time.ElapsedTime + 1;

                var i = 0;
                while (prevRand == DrumVariantCount[key] && i < 3)
                {
                    DrumVariantCount[key] = Random.Range(0, 2);
                    i++;
                }

                key++;
            }

            Entities.ForEach((UIDrumPressureBackend backend) =>
            {
                var presentation = backend.Presentation;
                if (presentation != null)
                {
                    if (backend.play)
                    {
                        var color = presentation.colors[backend.key - 1];
                        color.a   = 1;
                        foreach (var effectImage in presentation.effectImages)
                        {
                            effectImage.color = color;
                        }

                        presentation.drumImage.sprite = presentation.sprites[backend.key - 1];

                        backend.play = false;

                        presentation.animator.SetBool(StrHashPerfect, backend.perfect);
                        presentation.animator.SetInteger(StrHashKey, backend.key);
                        presentation.animator.SetFloat(StrHashVariant, backend.rand);
                        presentation.animator.SetTrigger(StrHashPlay);
                    }

                    presentation.animator.Update(Time.DeltaTime);
                }

                if (backend.endTime > Time.ElapsedTime)
                {
                    return;
                }

                backend.Return(true, true);
            }).WithStructuralChanges().Run();

            return;
        }