public override void Destroy(MultiAimConstraintJob job)
 {
     job.sourceTransforms.Dispose();
     job.sourceWeights.Dispose();
     job.sourceOffsets.Dispose();
     job.weightBuffer.Dispose();
 }
        /// <inheritdoc />
        public override MultiAimConstraintJob Create(Animator animator, ref T data, Component component)
        {
            var job = new MultiAimConstraintJob();

            job.driven       = ReadWriteTransformHandle.Bind(animator, data.constrainedObject);
            job.drivenParent = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject.parent);
            job.aimAxis      = data.aimAxis;
            job.upAxis       = data.upAxis;

            job.worldUpType   = (MultiAimConstraintJob.WorldUpType)data.worldUpType;
            job.worldUpAxis   = data.worldUpAxis;
            job.worldUpObject = ReadOnlyTransformHandle.Bind(animator, data.worldUpObject);

            WeightedTransformArray sourceObjects = data.sourceObjects;

            WeightedTransformArrayBinder.BindReadOnlyTransforms(animator, component, sourceObjects, out job.sourceTransforms);
            WeightedTransformArrayBinder.BindWeights(animator, component, sourceObjects, data.sourceObjectsProperty, out job.sourceWeights);

            job.sourceOffsets = new NativeArray <Quaternion>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            job.weightBuffer = new NativeArray <float>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            for (int i = 0; i < sourceObjects.Count; ++i)
            {
                if (data.maintainOffset)
                {
                    var constrainedAim = data.constrainedObject.rotation * data.aimAxis;
                    job.sourceOffsets[i] = QuaternionExt.FromToRotation(
                        sourceObjects[i].transform.position - data.constrainedObject.position,
                        constrainedAim
                        );
                }
                else
                {
                    job.sourceOffsets[i] = Quaternion.identity;
                }
            }

            job.minLimit     = FloatProperty.Bind(animator, component, data.minLimitFloatProperty);
            job.maxLimit     = FloatProperty.Bind(animator, component, data.maxLimitFloatProperty);
            job.drivenOffset = Vector3Property.Bind(animator, component, data.offsetVector3Property);

            job.axesMask = new Vector3(
                System.Convert.ToSingle(data.constrainedXAxis),
                System.Convert.ToSingle(data.constrainedYAxis),
                System.Convert.ToSingle(data.constrainedZAxis)
                );

            return(job);
        }
Beispiel #3
0
        public override MultiAimConstraintJob Create(Animator animator, ref T data)
        {
            var job          = new MultiAimConstraintJob();
            var cacheBuilder = new AnimationJobCacheBuilder();

            job.driven       = TransformHandle.Bind(animator, data.constrainedObject);
            job.drivenParent = TransformHandle.Bind(animator, data.constrainedObject.parent);
            job.drivenOffset = cacheBuilder.Add(data.offset);
            job.limitsIdx    = cacheBuilder.Add(data.limits);
            job.aimAxis      = data.aimAxis;

            var src        = data.sourceObjects;
            var srcWeights = data.sourceWeights;

            job.sources              = new NativeArray <TransformHandle>(src.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            job.sourceOffsets        = new NativeArray <Quaternion>(src.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            job.sourceWeightStartIdx = cacheBuilder.AllocateChunk(src.Length);

            for (int i = 0; i < src.Length; ++i)
            {
                job.sources[i] = TransformHandle.Bind(animator, src[i]);
                cacheBuilder.SetValue(job.sourceWeightStartIdx, i, srcWeights[i]);
                if (data.maintainOffset)
                {
                    var constrainedAim = data.constrainedObject.rotation * data.aimAxis;
                    job.sourceOffsets[i] = QuaternionExt.FromToRotation(
                        src[i].position - data.constrainedObject.position,
                        constrainedAim
                        );
                }
                else
                {
                    job.sourceOffsets[i] = Quaternion.identity;
                }
            }

            job.axesMask = new Vector3(
                System.Convert.ToSingle(data.constrainedXAxis),
                System.Convert.ToSingle(data.constrainedYAxis),
                System.Convert.ToSingle(data.constrainedZAxis)
                );
            job.cache = cacheBuilder.Build();

            return(job);
        }
Beispiel #4
0
 public override void Update(MultiAimConstraintJob job, ref T data)
 {
     job.cache.Set(data.offset, job.drivenOffset);
     job.cache.SetArray(data.sourceWeights, job.sourceWeightStartIdx);
     job.cache.Set(data.limits, job.limitsIdx);
 }
Beispiel #5
0
 public override void Destroy(MultiAimConstraintJob job)
 {
     job.sources.Dispose();
     job.sourceOffsets.Dispose();
     job.cache.Dispose();
 }