private void SetUpRotationLimits(Animator animator, Transform[] bones)
        {
            // All limits
            this.limitDefaultLocalRotationArray = new NativeArray <Quaternion>(bones.Length, Allocator.Persistent);
            this.limitAxisArray = new NativeArray <Vector3>(bones.Length, Allocator.Persistent);

            // Hinge
            this.hingeFlags          = new NativeArray <int>(bones.Length, Allocator.Persistent);
            this.hingeMinArray       = new NativeArray <UnityEngine.Animations.PropertySceneHandle>(bones.Length, Allocator.Persistent);
            this.hingeMaxArray       = new NativeArray <UnityEngine.Animations.PropertySceneHandle>(bones.Length, Allocator.Persistent);
            this.hingeUseLimitsArray = new NativeArray <UnityEngine.Animations.PropertySceneHandle>(bones.Length, Allocator.Persistent);
            this.hingeLastRotations  = new NativeArray <Quaternion>(bones.Length, Allocator.Persistent);
            this.hingeLastAngles     = new NativeArray <float>(bones.Length, Allocator.Persistent);

            // Angle
            this.angleFlags = new NativeArray <int>(bones.Length, Allocator.Persistent);
            this.angleSecondaryAxisArray = new NativeArray <Vector3>(bones.Length, Allocator.Persistent);
            this.angleLimitArray         = new NativeArray <UnityEngine.Animations.PropertySceneHandle>(bones.Length, Allocator.Persistent);
            this.angleTwistLimitArray    = new NativeArray <UnityEngine.Animations.PropertySceneHandle>(bones.Length, Allocator.Persistent);

            for (int i = 0; i < bones.Length - 1; i++)
            {
                this.hingeFlags[i] = 0;
                this.angleFlags[i] = 0;

                var limit = bones[i].GetComponent <RotationLimit>();
                if (limit != null)
                {
                    // All limits
                    this.limitDefaultLocalRotationArray[i] = bones[i].localRotation;
                    this.limitAxisArray[i] = limit.axis;

                    limit.Disable();

                    // Hinge
                    if (limit is RotationLimitHinge)
                    {
                        //var hinge = limit as RotationLimitHinge;

                        this.hingeFlags[i]          = 1;
                        this.hingeMinArray[i]       = animator.BindSceneProperty(bones[i].transform, typeof(RotationLimitHinge), "min");
                        this.hingeMaxArray[i]       = animator.BindSceneProperty(bones[i].transform, typeof(RotationLimitHinge), "max");
                        this.hingeUseLimitsArray[i] = animator.BindSceneProperty(bones[i].transform, typeof(RotationLimitHinge), "useLimits");
                        this.hingeLastRotations[i]  = bones[i].localRotation;
                        this.hingeLastAngles[i]     = 0f;
                    }

                    // Angle
                    if (limit is RotationLimitAngle)
                    {
                        var angle = limit as RotationLimitAngle;

                        this.angleFlags[i] = 1;
                        this.angleSecondaryAxisArray[i] = angle.secondaryAxis;
                        this.angleLimitArray[i]         = animator.BindSceneProperty(bones[i].transform, typeof(RotationLimitAngle), "limit");
                        this.angleTwistLimitArray[i]    = animator.BindSceneProperty(bones[i].transform, typeof(RotationLimitAngle), "twistLimit");
                    }
                }
            }
        }
    public bool Setup(Animator animator, IkChain chain, Type componentType, string weightProperty, string weightOffsetProperty, string targetOffsetProperty)
    {
        if (!chain.HasValidData())
        {
            return(false);
        }

        // Target
        m_TargetOffset = chain.target.offset;

        if (chain.target.readFrom == TargetType.Stream)
        {
            m_EffectorStreamHandle = animator.BindStreamTransform(chain.target.target);
            m_UseStreamEffector    = true;
        }
        else
        {
            m_EffectorSceneHandle = animator.BindSceneTransform(chain.target.target);
            m_UseStreamEffector   = false;
        }


        // Weight
        if (chain.weight.useAnimatorProperty && chain.weight.propertyName != "")
        {
            m_AnimatorWeight      = animator.BindStreamProperty(animator.transform, typeof(Animator), chain.weight.propertyName);
            m_UseAnimatorProperty = true;
        }

        m_WeightHandle         = animator.BindSceneProperty(animator.transform, componentType, weightProperty);
        m_AnimatorWeightOffset = animator.BindSceneProperty(animator.transform, componentType, weightOffsetProperty);


        // Driven
        m_IkType = chain.driven.type;

        if (m_IkType == IkType.Generic)
        {
            var end   = chain.driven.genericEndJoint;
            var mid   = end.parent;
            var start = mid.parent;

            m_StartHandle = animator.BindStreamTransform(start);
            m_MidHandle   = animator.BindStreamTransform(mid);
            m_EndHandle   = animator.BindStreamTransform(end);
        }
        else
        {
            m_HumanLimb = chain.driven.humanoidLimb;
        }

        return(true);
    }
            public void Setup(Animator animator, RotationConstraint[] constraints)
            {
                int count = constraints.Length;

                referenceTransforms = new NativeArray <TransformStreamHandle>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                currentTransforms   = new NativeArray <TransformStreamHandle>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

                minMaxSpeeds = new NativeArray <Vector2>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                minMaxAngles = new NativeArray <Vector2>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

                lastPositions    = new NativeArray <Vector3>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                initialRotations = new NativeArray <Quaternion>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                lastAngles       = new NativeArray <float>(count, Allocator.Persistent);

                for (int i = 0; i < count; ++i)
                {
                    Assert.IsTrue(constraints[i].referenceTransform != null);
                    Assert.IsTrue(constraints[i].transform != null);

                    referenceTransforms[i] = animator.BindStreamTransform(constraints[i].referenceTransform);
                    currentTransforms[i]   = animator.BindStreamTransform(constraints[i].transform);

                    minMaxSpeeds[i] = new Vector2(constraints[i].minimumSpeed, constraints[i].maximumSpeed);
                    minMaxAngles[i] = new Vector2(constraints[i].minimumAngle, constraints[i].maximumAngle);

                    lastPositions[i]    = constraints[i].referenceTransform.position;
                    initialRotations[i] = constraints[i].transform.localRotation;
                }

                deltaTime = animator.BindSceneProperty(animator.gameObject.transform, typeof(Unit), "m_deltaTime");
            }
    private GameObject SetupEffector(ref FullBodyIKJob.EffectorHandle handle, string name)
    {
        var go = CreateEffector(name);

        if (go != null)
        {
            go.AddComponent <Effector>();
            handle.effector       = m_Animator.BindSceneTransform(go.transform);
            handle.positionWeight = m_Animator.BindSceneProperty(go.transform, typeof(Effector), "positionWeight");
            handle.rotationWeight = m_Animator.BindSceneProperty(go.transform, typeof(Effector), "rotationWeight");
            handle.pullWeight     = m_Animator.BindSceneProperty(go.transform, typeof(Effector), "pullWeight");
        }
        return(go);
    }
Beispiel #5
0
        public void Setup(Animator animator, Transform[] bones, Transform target)
        {
            this.bones       = new NativeArray <UnityEngine.Animations.TransformStreamHandle>(bones.Length, Allocator.Persistent);
            this.boneWeights = new NativeArray <UnityEngine.Animations.PropertySceneHandle>(bones.Length - 1, Allocator.Persistent);
            this.boneSqrMags = new NativeArray <float>(bones.Length - 1, Allocator.Persistent);

            for (int i = 0; i < this.bones.Length; i++)
            {
                this.bones[i] = animator.BindStreamTransform(bones[i]);
            }

            for (int i = 0; i < this.bones.Length - 1; i++)
            {
                var boneParams = bones[i].gameObject.GetComponent <IKJBoneParams>();
                if (boneParams == null)
                {
                    boneParams = bones[i].gameObject.AddComponent <IKJBoneParams>();
                }

                this.boneWeights[i] = animator.BindSceneProperty(bones[i].transform, typeof(IKJBoneParams), "weight");
            }

            // Rotation Limits
            SetUpRotationLimits(animator, bones);

            _target           = animator.BindSceneTransform(target);
            _IKPositionWeight = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "weight");
            _maxIterations    = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "maxIterations");
            _tolerance        = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "tolerance");
            _XY = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "XY");
            _useRotationLimits = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "useRotationLimits");
        }
        public void Setup(Animator animator, Transform[] bones, Transform target, Transform poleTarget, Transform aimTransform)
        {
            this.bones       = new NativeArray <UnityEngine.Animations.TransformStreamHandle>(bones.Length, Allocator.Persistent);
            this.boneWeights = new NativeArray <UnityEngine.Animations.PropertySceneHandle>(bones.Length, Allocator.Persistent);

            for (int i = 0; i < this.bones.Length; i++)
            {
                this.bones[i] = animator.BindStreamTransform(bones[i]);
            }


            for (int i = 0; i < this.bones.Length; i++)
            {
                var boneParams = bones[i].gameObject.GetComponent <IKJBoneParams>();
                if (boneParams == null)
                {
                    boneParams = bones[i].gameObject.AddComponent <IKJBoneParams>();
                }

                this.boneWeights[i] = animator.BindSceneProperty(bones[i].transform, typeof(IKJBoneParams), "weight");
            }

            // Rotation Limits
            SetUpRotationLimits(animator, bones);

            _target           = animator.BindSceneTransform(target);
            _poleTarget       = animator.BindSceneTransform(poleTarget);
            _transform        = animator.BindStreamTransform(aimTransform);
            _IKPositionWeight = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "weight");
            _poleWeight       = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleWeight");
            _axisX            = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "axisX");
            _axisY            = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "axisY");
            _axisZ            = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "axisZ");
            _poleAxisX        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleAxisX");
            _poleAxisY        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleAxisY");
            _poleAxisZ        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleAxisZ");
            _clampWeight      = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "clampWeight");
            _clampSmoothing   = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "clampSmoothing");
            _maxIterations    = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "maxIterations");
            _tolerance        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "tolerance");
            _XY = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "XY");
            _useRotationLimits = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "useRotationLimits");

            step = 1f / (float)bones.Length;
        }
 public void BindAt(int index, Animator animator, Component component, string property)
 {
     sceneHandles[index]  = animator.BindSceneProperty(component.transform, component.GetType(), property);
     streamHandles[index] = animator.BindStreamProperty(component.transform, component.GetType(), property);
 }
 public static PropertySceneHandle BindSceneProperty(this Animator animator, Transform transform, Type type, string property)
 {
     return(animator.BindSceneProperty(transform, type, property, false));
 }