Пример #1
0
    public static JobHandle Begin(NativeArray <float3> positions, int batchSize)
    {
        MoveJob job = new MoveJob()
        {
            Positions = positions,
            DeltaTime = Time.deltaTime
        };

        return(IJobParallelForExtensions.Schedule(job, positions.Length, batchSize));
    }
Пример #2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new MoveJob
        {
            Dt = Time.deltaTime,
            HorizontalLimit = Bootstrap.HorizontalLimit
        };

        return(job.Schedule(this, 1, inputDeps));
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        MoveJob tMoveJob = new MoveJob
        {
            m_TranslationChunk   = GetArchetypeChunkComponentType <Translation>(),
            m_MoveComponentChunk = GetArchetypeChunkComponentType <C_MoveComponent>()
        };

        return(tMoveJob.Schedule(m_EntityQuery, inputDeps));
    }
Пример #4
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new MoveJob()
        {
            AnimationType = GetArchetypeChunkComponentType <AnimatorComponent>(false),
            ElapsedTime   = Time.ElapsedTime
        };

        return(job.Schedule(m_Group, inputDeps));
    }
Пример #5
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        MoveJob job = new MoveJob {
            deltaTime = Time.fixedDeltaTime
        };

        JobHandle jobHandle = job.Schedule(this, inputDeps);

        return(jobHandle);
    }
Пример #6
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var moveJob = new MoveJob
        {
            target = targetPosition,
            speed  = Time.DeltaTime * 0.1f
        }.Schedule(this, inputDeps);

        return(moveJob);
    }
Пример #7
0
 protected override JobHandle OnUpdate(JobHandle inputDeps)
 {
     Entities.WithoutBurst().WithStructuralChanges().ForEach((Entity e, ref Ruler ruler, in Translation trans) => {
         if (!ruler.landed)
         {
             // NodeFinder is a helper class that does what it says on the tin.
             NodeInfo n = NodeFinder.FindClosestUnoccupiedNode(new Vector3(trans.Value.x, trans.Value.y, trans.Value.z));
             // Move to the chosen node.
             EntityManager.AddComponent(e, typeof(MoveJob));
             MoveJob moveHere = new MoveJob {
                 target  = new float3(n.x, n.y, n.z),
                 speed   = 0.1f,
                 arrived = false
             };
             EntityManager.SetComponentData(e, moveHere);
             Debug.Log("Ruler has been landed!");
             // Spawn in the flag and default elements of an Empire.
             // The flag serves as the 'capital city' and main entity of the Empire.
             Entity flag           = EntityManager.Instantiate(ruler.capitalCityObject);
             float3 flagPos        = new float3(n.x, n.y + ruler.capitalOffset, n.z);
             Translation flagTrans = new Translation {
                 Value = flagPos
             };
             EntityManager.SetComponentData(flag, flagTrans);
             Empire newEmpire = new Empire {
                 wealth   = ruler.wealth,
                 pawnType = ruler.pawnType,
                 size     = 10.0f
             };
             EmpireResources resources = new EmpireResources {
                 wood    = 0,
                 berries = 0
             };
             // Give the flag the elements it needs to run itself.
             EntityManager.AddComponent(flag, typeof(Empire));
             EntityManager.SetComponentData(flag, newEmpire);
             EntityManager.AddComponent(flag, typeof(EmpireResources));
             EntityManager.SetComponentData(flag, resources);
             EntityManager.AddComponent(flag, typeof(SpawnRandomPawnJob));
             SpawnRandomPawnJob spawnJob = new SpawnRandomPawnJob {
                 amount = ruler.startPawns
             };
             EntityManager.SetComponentData(flag, spawnJob);
             TakeoverNearbyLands takeOverNearbyLands = new TakeoverNearbyLands {
                 center = flagPos,
                 size   = newEmpire.size
             };
             EntityManager.AddComponent(flag, typeof(TakeoverNearbyLands));
             EntityManager.SetComponentData(flag, takeOverNearbyLands);
             // We are now landed and other systems should be in place to handle the
             // Rulers actions.
             ruler.landed = true;
         }
     }).Run();
     return(default);
Пример #8
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        var job = new MoveJob()
        {
            deltaTime = Time.deltaTime,
            wallMap   = new NativeArray <bool>(GameManager.wallMap, Allocator.TempJob),
            rand      = new Random((uint)UnityEngine.Random.Range(0, 10000000))
        };

        return(job.Schedule(this, inputDependencies));
    }
Пример #9
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var neighbors = new NeighborsDetectionJob
            {
                prodThresh          = math.cos(math.radians(Bootstrap.Param.neighborFov)),
                distThresh          = Bootstrap.Param.neighborDistance,
                neighborsFromEntity = GetBufferFromEntity <NeighborsEntityBuffer>(false),
                positionFromEntity  = GetComponentDataFromEntity <Position>(true),
                entities            = group.GetEntityArray(),
            };

            var wall = new WallJob
            {
                scale  = Bootstrap.Param.wallScale * 0.5f,
                thresh = Bootstrap.Param.wallDistance,
                weight = Bootstrap.Param.wallWeight,
            };

            var separation = new SeparationJob
            {
                separationWeight    = Bootstrap.Param.separationWeight,
                neighborsFromEntity = GetBufferFromEntity <NeighborsEntityBuffer>(true),
                positionFromEntity  = GetComponentDataFromEntity <Position>(true),
            };

            var alignment = new AlignmentJob
            {
                alignmentWeight     = Bootstrap.Param.alignmentWeight,
                neighborsFromEntity = GetBufferFromEntity <NeighborsEntityBuffer>(true),
                velocityFromEntity  = GetComponentDataFromEntity <Velocity>(true),
            };

            var cohesion = new CohesionJob
            {
                cohesionWeight      = Bootstrap.Param.cohesionWeight,
                neighborsFromEntity = GetBufferFromEntity <NeighborsEntityBuffer>(true),
                positionFromEntity  = GetComponentDataFromEntity <Position>(true),
            };

            var move = new MoveJob
            {
                dt       = Time.deltaTime,
                minSpeed = Bootstrap.Param.minSpeed,
                maxSpeed = Bootstrap.Param.maxSpeed,
            };

            inputDeps = neighbors.Schedule(this, inputDeps);
            inputDeps = wall.Schedule(this, inputDeps);
            inputDeps = separation.Schedule(this, inputDeps);
            inputDeps = alignment.Schedule(this, inputDeps);
            inputDeps = cohesion.Schedule(this, inputDeps);
            inputDeps = move.Schedule(this, inputDeps);
            return(inputDeps);
        }
Пример #10
0
    public override void OnUpdate(float deltaTime)
    {
        var newJob = new MoveJob {
            moveVector = this.moveVector
        };

        var handle = newJob.Schedule(this.transforms);

        JobHandle.ScheduleBatchedJobs();
        handle.Complete();
    }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            MoveJob moveJob = new MoveJob
            {
                deltaTime = Time.deltaTime
            };

            JobHandle moveHandle = moveJob.Schedule(this, inputDeps);

            return(moveHandle);
        }
Пример #12
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        MoveJob moveJob = new MoveJob
        {
            vec3CometPosition = GameManager.instance.Comet.position,
            deltaTime         = Time.deltaTime,
        };

        JobHandle moveHandle = moveJob.Schedule(this, inputDeps);

        return(moveHandle);
    }
Пример #13
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new MoveJob()
        {
            TranslationType     = GetArchetypeChunkComponentType <Translation>(false),
            MoveBySpeedDataType = GetArchetypeChunkComponentType <MoveBySpeedData>(true),
            WaveDataType        = GetArchetypeChunkComponentType <WaveData>(true),
            ElapsedTime         = Time.ElapsedTime
        };

        return(job.Schedule(m_Group, inputDeps));
    }
Пример #14
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var job = new MoveJob()
            {
                time = Time.timeSinceLevelLoad
            };

            return(job.Schedule(this, inputDeps)); //schedules parallel for jobs

            //*****execute in a single job************
            //return job.ScheduleSingle(this, inputDeps);
        }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new MoveJob
        {
            CommandBuffer = _commandBufferSystem.CreateCommandBuffer().ToConcurrent(),
            Random        = new Random((uint)UnityEngine.Random.Range(1, 100000))
        }.Schedule(this, inputDeps);

        _commandBufferSystem.AddJobHandleForProducer(job);

        return(job);
    }
Пример #16
0
        protected override void OnUpdate()
        {
            var job = new MoveJob()
            {
                DeltaTime       = Time.DeltaTime,
                TranslationType = GetComponentTypeHandle <Translation>(),
                SpeedType       = GetComponentTypeHandle <Speed>(),
                DestinationType = GetComponentTypeHandle <Destination>()
            };

            Dependency = job.Schedule(_destinationQuery, Dependency);
        }
Пример #17
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (GetSingleton <GamePause>().IsOn)
        {
            return(inputDeps);
        }

        MoveJob job = new MoveJob {
            DeltaTime = Time.DeltaTime
        };

        return(job.Schedule(this, inputDeps));
    }
Пример #18
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new MoveJob {
            randomSeed    = new Unity.Mathematics.Random((uint)UnityEngine.Random.Range(1, 100000)),
            deltaTime     = Time.deltaTime,
            commandBuffer = m_EndFrameBarrier.CreateCommandBuffer()
        }.ScheduleSingle(this, inputDeps);

        // We need to tell the barrier system which job it needs to complete before it can play back the commands.
        m_EndFrameBarrier.AddJobHandleForProducer(job);

        return(job);
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new MoveJob
        {
            query        = NavMeshQuery,
            navAgent     = AgentsGroup.ToComponentDataArray <NavAgent>(Allocator.TempJob),
            localToWorld = AgentsGroup.ToComponentDataArray <LocalToWorld>(Allocator.TempJob)
                           //Translations = AgentsGroup.ToComponentDataArray<Translation>(Allocator.TempJob),
                           //PathStatus =new NativeArray<PathQueryStatus>(1, Allocator.TempJob)
        };
        var hand = job.Schedule(inputDeps);

        return(hand);
    }
Пример #20
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var translationType = GetComponentTypeHandle <Translation>();
        var moveDataType    = GetComponentTypeHandle <MoveData_Job>();

        JobHandle jobHandle = new MoveJob()
        {
            deltaTime       = Time.DeltaTime,
            translationType = translationType,
            moveDataType    = moveDataType,
        }.Schedule(entityQuery, inputDeps);

        return(jobHandle);
    }
Пример #21
0
    protected override void OnUpdate()
    {
        _query.SetChangedVersionFilter(typeof(MoveStats));

        MoveJob _moveJob = new MoveJob();

        _moveJob._deltaTime         = Time.DeltaTime;
        _moveJob._moveStatsHandle   = GetComponentTypeHandle <MoveStats>(false);
        _moveJob._translationHandle = GetComponentTypeHandle <Translation>(false);
        _moveJob._entityTypeHandle  = GetEntityTypeHandle();
        _moveJob._ecb = m_EndSimulationEcbSystem.CreateCommandBuffer().AsParallelWriter();
        _moveJob.ScheduleParallel(_query, Dependency);

        m_EndSimulationEcbSystem.AddJobHandleForProducer(this.Dependency);
    }
Пример #22
0
    protected override void OnUpdate()
    {
        var updateTranslationJob = new MoveJob();

        updateTranslationJob.moveDataTypeHandle = this.
                                                  GetComponentTypeHandle <MoveData>(false);
        updateTranslationJob.translationTypeHandle = this.
                                                     GetComponentTypeHandle <Translation>(false);

        updateTranslationJob.DeltaTime = World.Time.DeltaTime;


        this.Dependency = updateTranslationJob.
                          ScheduleParallel(query, 1, this.Dependency);
    }
Пример #23
0
    private void Update()
    {
        moveJob    = new MoveJob {
        };
        moveHandle = moveJob.Schedule(transforms);


        //for (int i = 0; i < numSheep; i++)
        //{
        //    allSheep[i].transform.Translate(0, 0, 0.1f);
        //    if (allSheep[i].transform.position.z > 50)
        //    {
        //        allSheep[i].transform.position = new Vector3(allSheep[i].transform.position.x, 0, -50);
        //    }
        //}
    }
Пример #24
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var moveJob = new MoveJob
            {
                deltaTime           = Time.deltaTime,
                commandBuffer       = _endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(),
                targets             = _targets.ToEntityArray(Allocator.TempJob),
                targetsTranslations = _targets.ToComponentDataArray <Translation>(Allocator.TempJob)
            };

            var jobHandle = moveJob.Schedule(this, inputDeps);

            _endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);

            return(jobHandle);
        }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //Setup job
        MoveJob job = new MoveJob
        {
            physVType    = GetArchetypeChunkComponentType <PhysicsVelocity>(false),
            physMassType = GetArchetypeChunkComponentType <PhysicsMass>(false),
            inputType    = GetArchetypeChunkComponentType <InputStruct>(true),
            pControlType = GetArchetypeChunkComponentType <PhysicsControllerStruct>(false),
            toWorldType  = GetArchetypeChunkComponentType <LocalToWorld>(true),
            rotType      = GetArchetypeChunkComponentType <Rotation>(false),
            transType    = GetArchetypeChunkComponentType <Translation>(false),
            deltaTime    = Time.DeltaTime,
        };

        return(job.Schedule(q, inputDeps));
    }
Пример #26
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        /*
         * Entities.ForEach((ref Translation translation, ref MotionProperties motionProperties) =>
         *  {
         *      translation.Value += motionProperties.direction * motionProperties.moveSpeed * Time.deltaTime;
         *  });
         */

        //EntityQuery entityQuery = GetEntityQuery(typeof(Translation), typeof(MotionProperties));
        MoveJob moveJob = new MoveJob
        {
            deltaTime = Time.deltaTime
        };

        return(moveJob.Schedule(this, inputDeps));
    }
Пример #27
0
    private IEnumerator PlayTurnCoroutine(BoardData board)
    {
#if UNITY_EDITOR
        float time = Time.timeSinceLevelLoad;
#endif
        MoveJob moveJob = new MoveJob()
        {
            move    = Vector3Int.zero,
            board   = board,
            myToken = myToken,
            depth   = depth,
            jobID   = 10101
        };

        JobMonitor jobMonitor = new JobMonitor();

        if (onStartPlanning != null)
        {
            onStartPlanning.Invoke();
        }

        //start the job
        StartCoroutine(GetMove(moveJob, jobMonitor));

#if UNITY_EDITOR
        Debug.Log("Working");
#endif

        //wait for it to complete
        yield return(new WaitUntil(() => jobMonitor.complete));

        if (onStopPlanning != null)
        {
            onStopPlanning.Invoke();
        }

        //place the token based on selected move
        PlaceToken(moveJob.move);

#if UNITY_EDITOR
        Debug.Log("Completed in " + (Time.timeSinceLevelLoad - time) + " seconds.");
        Debug.Log("Placed token at " + moveJob.move + ".");
#endif
    }
Пример #28
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var pArrrayHastargetMove = new NativeArray <Entity>(m_Group.CalculateEntityCount(), Allocator.TempJob);
            var pJob = new MoveJob()
            {
                completeJob = pArrrayHastargetMove,
                deltaTime   = Time.deltaTime
            };
            var pJobEventHandle = new HandleEventJob()
            {
                completeJob = pArrrayHastargetMove,
                ecb         = ecb.CreateCommandBuffer().ToConcurrent()
            };
            var pJobHandle = pJob.Schedule(this, inputDeps);

            pJobHandle = pJobEventHandle.Schedule(this, pJobHandle);
            ecb.AddJobHandleForProducer(pJobHandle);
            return(pJobHandle);
        }
Пример #29
0
    private IEnumerator MoveAction(Vector3 position)
    {
        Vector3 startPosition = transform.position;

        for (float time = 0f; time < 0.25f; time += Time.deltaTime)
        {
            MoveJob moveJob = new MoveJob();
            moveJob.startPosition = startPosition;
            moveJob.position      = position;
            moveJob.time          = time;
            moveJob.deltaTime     = Time.deltaTime;

            moveJobHandle = moveJob.Schedule(transforms);
            yield return(null);
        }

        transform.position = position;
        spriteRenderer.transform.localPosition = Vector3.zero;
    }
Пример #30
0
    //private void OnTriggerEnter2D(Collider2D collision)
    //{
    //    if (collision.gameObject.tag == "Asteroid")
    //    {
    //        SpriteRenderer sp = collision.gameObject.GetComponent<SpriteRenderer>();
    //        sp.enabled = !sp.enabled;

    //    }
    //}
    //private void OnTriggerExit2D(Collider2D collision)
    //
    //    if (collision.gameObject.tag == "Asteroid")
    //    {
    //        SpriteRenderer sp = collision.gameObject.GetComponent<SpriteRenderer>();
    //        sp.enabled = !sp.enabled;

    //    }
    //}
    private void Update()
    {
        jobHandle.Complete();

        TransformAccessArray  transformAccessArray     = new TransformAccessArray(asteroidTransforms);
        NativeArray <float>   nativeAsteroidSpeeds     = new NativeArray <float>(asteroidSpeeds, Allocator.Persistent);
        NativeArray <Vector3> nativeAsteroidDirections = new NativeArray <Vector3>(asteroidDirections, Allocator.Persistent);

        MoveJob moveJob = new MoveJob();

        moveJob.speeds     = nativeAsteroidSpeeds;
        moveJob.directions = nativeAsteroidDirections;

        jobHandle = moveJob.Schedule(transformAccessArray);

        transformAccessArray.Dispose();
        nativeAsteroidSpeeds.Dispose();
        nativeAsteroidDirections.Dispose();
    }