示例#1
0
    void Update()
    {
        float startTime = Time.realtimeSinceStartup;

        //moveX = Random.Range(-1f, 1f);
        //moveY = Random.Range(-1f, 1f);

        if (useJob)
        {
            positions   = new NativeArray <float3>(humanList.Count, Allocator.TempJob);
            directionsX = new NativeArray <float>(humanList.Count, Allocator.TempJob);
            directionsY = new NativeArray <float>(humanList.Count, Allocator.TempJob);
            speeds      = new NativeArray <float>(humanList.Count, Allocator.TempJob);


            for (int i = 0; i < humanList.Count; ++i)
            {
                positions[i]   = humanList[i].transform.position;
                directionsX[i] = humanList[i].dirX;
                directionsY[i] = humanList[i].dirY;
                speeds[i]      = humanList[i].speed;
            }
            JobSystem moveJob = new JobSystem {
                deltaTime    = Time.deltaTime,
                topBounds    = topBounds,
                rightBounds  = rightBounds,
                leftBounds   = leftBounds,
                bottomBounds = bottomBounds,
                positions    = positions,
                directionsX  = directionsX,
                directionsY  = directionsY,
                speeds       = speeds
            };

            moveHandle = moveJob.Schedule(humanList.Count, innerLoopBatchCount);
            moveHandle.Complete();

            for (int i = 0; i < humanList.Count; ++i)
            {
                humanList[i].transform.position = positions[i];
                humanList[i].dirX  = directionsX[i];
                humanList[i].dirY  = directionsY[i];
                humanList[i].speed = speeds[i];
            }

            positions.Dispose();
            directionsX.Dispose();
            directionsY.Dispose();
            speeds.Dispose();

            //    // use job system
            //    moveHandle.Complete();

            //    moveJob = new JobSystem()
            //    {
            //        deltaTime = Time.deltaTime,
            //        top = topBounds,
            //        left = leftBounds,
            //        right = rightBounds,
            //        bottom = bottomBounds,
            //        minSpeed = minSpeed,
            //        maxSpeed = maxSpeed,
            //        moveX = moveX,
            //        moveY = moveY

            //    };

            //    moveHandle = moveJob.Schedule(transforms);

            //    JobHandle.ScheduleBatchedJobs();
        }
        else
        {
            foreach (Human human in humanList)
            {
                human.transform.position += new Vector3(human.dirX, human.dirY, 0f) * (human.speed * Time.deltaTime);

                if (human.transform.position.x <= leftBounds)
                {
                    // left wall
                    human.dirX = -human.dirX;
                }
                if (human.transform.position.x >= rightBounds)
                {
                    // right wall
                    human.dirX = -human.dirX;
                }
                if (human.transform.position.y <= bottomBounds)
                {
                    // bottom wall
                    human.dirY = -human.dirY;
                }
                if (human.transform.position.y >= topBounds)
                {
                    // top wall
                    human.dirY = -human.dirY;
                }
            }
        }

        Debug.Log(((Time.realtimeSinceStartup - startTime) * 1000f) + "ms");
    }
示例#2
0
 public void SheduleJobs(JobSystem jobSystem, ScheduleScope scope)
 {
     jobSystem.Schedule(PlatformUpdate, scope);
 }
示例#3
0
 public void SheduleJobs(JobSystem jobSystem, ScheduleScope scope)
 {
     jobSystem.Schedule(CollectJob, scope);
 }