Exemple #1
0
        // ----------------------------------------------------

        #region // Private Methods

        void ExecuteJobs()
        {
            if (this._springBoneJobData.Length <= 0)
            {
                return;
            }

            if (!this._colliderHashMap.IsCreated)
            {
                // コライダーの初期化
                this._colliderHashMap = new NativeMultiHashMap <int, SphereCollider>(
                    this._colliderHashMapLength, Allocator.Persistent);
            }
            else
            {
                this._colliderHashMap.Clear();
            }

            if (this._colliderHashMap.Capacity != this._colliderHashMapLength)
            {
                this._colliderHashMap.Dispose();
                // コライダーの初期化
                this._colliderHashMap = new NativeMultiHashMap <int, SphereCollider>(
                    this._colliderHashMapLength, Allocator.Persistent);
            }


            var updateColliderHashJobHandle = new UpdateColliderHashJob
            {
                GroupParams     = this._colliderGroupJobData.GroupParams,
                ColliderHashMap = this._colliderHashMap.ToConcurrent(),
            }.Schedule(this._colliderGroupJobData.TransformAccessArray);

            // 親の回転の取得
            var updateParentRotationJobHandle = new UpdateParentRotationJob
            {
                ParentRotations = this._parentRotations,
            }.Schedule(this._springBoneJobData.ParentTransformAccessArray);

            // 物理演算
            this._jobHandle = new LogicJob
            {
                ImmutableNodeParams = this._springBoneJobData.ImmutableNodeParams,
                ParentRotations     = this._parentRotations,
                DeltaTime           = Time.deltaTime,
                ColliderHashMap     = this._colliderHashMap,
                VariableNodeParams  = this._springBoneJobData.VariableNodeParams,
            }.Schedule(this._springBoneJobData.TransformAccessArray,
                       JobHandle.CombineDependencies(updateColliderHashJobHandle, updateParentRotationJobHandle));

            JobHandle.ScheduleBatchedJobs();
        }
        // ----------------------------------------------------

        #region // Private Methods

        void ExecuteJobs()
        {
            var handles = new NativeArray <JobHandle>(this._currentBuffers.Count, Allocator.TempJob);

            for (var i = 0; i < this._currentBuffers.Count; ++i)
            {
                var buff = this._currentBuffers[i];
                if (buff.ColliderHashMap.IsCreated)
                {
                    buff.ColliderHashMap.Dispose();
                }

                // コライダーの更新
                buff.ColliderHashMap = new NativeMultiHashMap <int, SphereCollider>(
                    buff.ColliderHashMapLength, Allocator.TempJob);

                var handle = new UpdateColliderHashJob
                {
                    GroupParams     = buff.ColliderGroupJobDataValue.GroupParams,
                    ColliderHashMap = buff.ColliderHashMap.ToConcurrent(),
                }.Schedule(buff.ColliderGroupJobDataValue.TransformAccessArray);

                // 親の回転の取得
                handle = new UpdateParentRotationJob
                {
                    ParentRotations = buff.ParentRotations,
                }.Schedule(buff.SpringBoneJobDataValue.ParentTransformAccessArray, handle);

                // 物理演算
                handles[i] = new LogicJob
                {
                    ImmutableNodeParams = buff.SpringBoneJobDataValue.ImmutableNodeParams,
                    ParentRotations     = buff.ParentRotations,
                    DeltaTime           = Time.deltaTime,
                    ColliderHashMap     = buff.ColliderHashMap,
                    VariableNodeParams  = buff.SpringBoneJobDataValue.VariableNodeParams,
                }.Schedule(buff.SpringBoneJobDataValue.TransformAccessArray, handle);
            }

            this._jobHandle = JobHandle.CombineDependencies(handles);
            handles.Dispose();
            JobHandle.ScheduleBatchedJobs();
        }