Example #1
0
        public override void UpdateSystem()
        {
            CollisionWorld            collisionWorld    = m_physicsWorldBuilder.PhysicsWorld.CollisionWorld;
            NativeArray <Translation> cameraTranslation = m_entityQuery.ToComponentDataArrayAsync <Translation>(Allocator.TempJob, out JobHandle cameraTranslationHandle);
            float3                      mousePos        = m_inputManagementSystem.InputData.mouseInput.mouseWorldPos;
            CollisionFilter             collisionFilter = m_collisionFilter;
            NativeArray <RaycastResult> raycastResult   = m_raycastResult;

            ComponentDataFromEntity <UnitTag> unitTagLookup = GetComponentDataFromEntity <UnitTag>();

            Dependency = JobHandle.CombineDependencies(Dependency, cameraTranslationHandle);

            Dependency = Job
                         .WithReadOnly(cameraTranslation)
                         .WithCode(() =>
            {
                float3 cameraPos = cameraTranslation[0].Value;
                RaycastResult result;
                if (InputManagementSystem.CastRayFromMouse(cameraPos, mousePos, 1000.0f, out Unity.Physics.RaycastHit closestHit, collisionFilter, collisionWorld))
                {
                    Entity hitEntity = closestHit.Entity;

                    if (HasComponent <EnemyTag>(hitEntity))
                    {
                        result = new RaycastResult
                        {
                            raycastTargetType   = RaycastTargetType.Enemy,
                            hitPosition         = closestHit.Position,
                            raycastTargetEntity = closestHit.Entity
                        };
                        raycastResult[0] = result;

                        return;
                    }

                    if (HasComponent <UnitTag>(hitEntity))
                    {
                        result = new RaycastResult
                        {
                            raycastTargetType   = RaycastTargetType.Unit,
                            hitPosition         = closestHit.Position,
                            raycastTargetEntity = closestHit.Entity
                        };
                        raycastResult[0] = result;

                        return;
                    }

                    if (HasComponent <ResourceNode>(hitEntity))
                    {
                        result = new RaycastResult
                        {
                            raycastTargetType   = RaycastTargetType.ResourceNode,
                            hitPosition         = closestHit.Position,
                            raycastTargetEntity = closestHit.Entity
                        };
                        raycastResult[0] = result;

                        return;
                    }
                    result = new RaycastResult
                    {
                        raycastTargetType   = RaycastTargetType.Ground,
                        hitPosition         = closestHit.Position,
                        raycastTargetEntity = closestHit.Entity
                    };
                    raycastResult[0] = result;
                }
 public override void GetBehaviourDependencies(Dependencies dependencies)
 {
     m_inputManagementSystem = dependencies.GetDependency <InputManagementSystem>();
 }
Example #3
0
 public override void GetSystemDependencies(Dependencies dependencies)
 {
     m_inputManagementSystem   = dependencies.GetDependency <InputManagementSystem>();
     endFrameJobCompleteSystem = dependencies.GetDependency <EndFrameJobCompleteSystem>();
 }
 public override void GetSystemDependencies(Dependencies dependencies)
 {
     m_inputManagementSystem = dependencies.GetDependency <InputManagementSystem>();
     m_raycastSystem         = dependencies.GetDependency <RaycastSystem>();
     m_gridManager           = dependencies.GetDependency <GridManager>();
 }