Esempio n. 1
0
        // On the updating of the tex animator
        protected override JobHandle OnUpdate(JobHandle dependancies)
        {
            // initialise the system for the first ime
            InitializeTextureAnimator();
            if (!bInit)
            {
                return(dependancies);
            }

            // flush the job system
            previousFrameJob.Complete();
            previousFrameJob = dependancies;

            // Draw the instanced meshes
            Drawer.DrawMeshes();

            // Set the animator job attributes
            PrepareAnimatorDataJob prepareAnimatorJob = new PrepareAnimatorDataJob();

            prepareAnimatorJob.animationClips = animationClipBakedData;
            prepareAnimatorJob.deltaTime      = Time.deltaTime;
            prepareAnimatorJob.texAnimData    = characters.animationData;

            // Schedule this job dependant on the previous job
            JobHandle prepareAnimator = prepareAnimatorJob.Schedule(characters.Length, BatchSize, previousFrameJob);

            // Create a tempory job handle array
            NativeArray <JobHandle> jobHandles = new NativeArray <JobHandle>(50, Allocator.Temp);

            // set the firs t job handle to the prepaer animator job
            jobHandles[0] = prepareAnimator;

            ComputeJobs(prepareAnimator, jobHandles);
            previousFrameJob = JobHandle.CombineDependencies(jobHandles);

            // dispose of the jobs
            jobHandles.Dispose();
            return(previousFrameJob);
        }
Esempio n. 2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        Initialize();

        if (!initialized)
        {
            return(inputDeps);
        }

        if (SimulationSettings.Instance.DisableRendering)
        {
            return(inputDeps);
        }

        float dt = Time.deltaTime;

        if (perUnitTypeDataHolder != null)
        {
            previousFrameFence.Complete();
            previousFrameFence = inputDeps;

            lod0Count = lod1Count = lod2Count = lod3Count = 0;

            foreach (var data in perUnitTypeDataHolder)
            {
                data.Value.Drawer.Draw();
                data.Value.Lod1Drawer.Draw();
                data.Value.Lod2Drawer.Draw();
                data.Value.Lod3Drawer.Draw();

                lod0Count       += data.Value.Drawer.UnitToDrawCount;
                lod1Count       += data.Value.Lod1Drawer.UnitToDrawCount;
                lod2Count       += data.Value.Lod2Drawer.UnitToDrawCount;
                lod3Count       += data.Value.Lod3Drawer.UnitToDrawCount;
                data.Value.Count = lod0Count + lod1Count + lod2Count + lod3Count;
            }

            var prepareAnimatorJob = new PrepareAnimatorDataJob()
            {
                animationClips      = animationClipData,
                dt                  = dt,
                textureAnimatorData = units.animationData,
            };

            var prepareAnimatorFence = prepareAnimatorJob.Schedule(units.Length, SimulationState.BigBatchSize, previousFrameFence);

            NativeArray <JobHandle> jobHandles = new NativeArray <JobHandle>(4, Allocator.Temp);
            jobHandles[0] = prepareAnimatorFence;

            foreach (var data in perUnitTypeDataHolder)
            {
                switch (data.Key)
                {
                case UnitType.Melee:
                    ComputeFences(meleeUnits.animationData, dt, meleeUnits.transforms, data, prepareAnimatorFence, jobHandles, 0);
                    data.Value.Count = meleeUnits.Length;
                    break;

                case UnitType.Skeleton:
                    ComputeFences(skeletonUnits.animationData, dt, skeletonUnits.transforms, data, prepareAnimatorFence, jobHandles, 3);
                    data.Value.Count = skeletonUnits.Length;
                    break;
                }
            }

            Profiler.BeginSample("Combine all dependencies");
            previousFrameFence = JobHandle.CombineDependencies(jobHandles);
            Profiler.EndSample();

            jobHandles.Dispose();
            return(previousFrameFence);
        }
        return(inputDeps);
    }