Esempio n. 1
0
 public override void Reset()
 {
     owner            = null;
     targetGameObject = null;
     everyFrame       = false;
     constraint       = null;
 }
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha)
        {
            float[] array = this.frames;
            if (time < array[0])
            {
                return;
            }
            TransformConstraint transformConstraint = skeleton.transformConstraints.Items[this.transformConstraintIndex];

            if (time >= array[array.Length - 5])
            {
                int num = array.Length;
                transformConstraint.rotateMix    += (array[num + -4] - transformConstraint.rotateMix) * alpha;
                transformConstraint.translateMix += (array[num + -3] - transformConstraint.translateMix) * alpha;
                transformConstraint.scaleMix     += (array[num + -2] - transformConstraint.scaleMix) * alpha;
                transformConstraint.shearMix     += (array[num + -1] - transformConstraint.shearMix) * alpha;
                return;
            }
            int   num2         = Animation.binarySearch(array, time, 5);
            float num3         = array[num2];
            float curvePercent = base.GetCurvePercent(num2 / 5 - 1, 1f - (time - num3) / (array[num2 + -5] - num3));
            float num4         = array[num2 + -4];
            float num5         = array[num2 + -3];
            float num6         = array[num2 + -2];
            float num7         = array[num2 + -1];

            transformConstraint.rotateMix    += (num4 + (array[num2 + 1] - num4) * curvePercent - transformConstraint.rotateMix) * alpha;
            transformConstraint.translateMix += (num5 + (array[num2 + 2] - num5) * curvePercent - transformConstraint.translateMix) * alpha;
            transformConstraint.scaleMix     += (num6 + (array[num2 + 3] - num6) * curvePercent - transformConstraint.scaleMix) * alpha;
            transformConstraint.shearMix     += (num7 + (array[num2 + 4] - num7) * curvePercent - transformConstraint.shearMix) * alpha;
        }
Esempio n. 3
0
        public void TransformConstraintTests(string parameterValue, bool expected)
        {
            var constraint = new TransformConstraint();
            var actual     = TestValue(constraint, parameterValue);

            Assert.AreEqual(expected, actual);
        }
        private void AttachConstraint(TransformConstraint constraint)
        {
            int newElementIndex = selectedConstraints.arraySize;

            selectedConstraints.InsertArrayElementAtIndex(newElementIndex);
            selectedConstraints.GetArrayElementAtIndex(newElementIndex).objectReferenceValue = constraint;
            serializedObject.ApplyModifiedProperties();
        }
Esempio n. 5
0
 private void Awake()
 {
     this.xform    = base.transform;
     this.xformCns = base.gameObject.AddComponent <TransformConstraint>();
     this.xformCns.noTargetMode      = UnityConstraints.NO_TARGET_OPTIONS.SetByScript;
     this.xformCns.constrainRotation = false;
     this.lookCns = base.gameObject.AddComponent <SmoothLookAtConstraint>();
     this.lookCns.noTargetMode = UnityConstraints.NO_TARGET_OPTIONS.SetByScript;
     this.lookCns.pointAxis    = Vector3.up;
     this.lookCns.upAxis       = Vector3.forward;
     this.lookCns.speed        = this.turnSpeed;
     base.StartCoroutine(this.LookAtRandom());
     base.StartCoroutine(this.MoveRandom());
 }
Esempio n. 6
0
 private void Awake()
 {
     this.xform = base.transform;
     this.xformCns = base.gameObject.AddComponent<TransformConstraint>();
     this.xformCns.noTargetMode = UnityConstraints.NO_TARGET_OPTIONS.SetByScript;
     this.xformCns.constrainRotation = false;
     this.lookCns = base.gameObject.AddComponent<SmoothLookAtConstraint>();
     this.lookCns.noTargetMode = UnityConstraints.NO_TARGET_OPTIONS.SetByScript;
     this.lookCns.pointAxis = Vector3.up;
     this.lookCns.upAxis = Vector3.forward;
     this.lookCns.speed = this.turnSpeed;
     base.StartCoroutine(this.LookAtRandom());
     base.StartCoroutine(this.MoveRandom());
 }
    private void Awake()
    {
        this.xform = this.transform;  // Cache
    
        // Add a transform constraint
        this.xformCns = this.gameObject.AddComponent<TransformConstraint>();
        this.xformCns.noTargetMode = UnityConstraints.NO_TARGET_OPTIONS.SetByScript;
        this.xformCns.constrainRotation = false;

        // Add a smooth lookAt constraint
        this.lookCns = this.gameObject.AddComponent<SmoothLookAtConstraint>();
        this.lookCns.noTargetMode = UnityConstraints.NO_TARGET_OPTIONS.SetByScript;
        this.lookCns.pointAxis = Vector3.up;
        this.lookCns.upAxis = Vector3.forward;
        this.lookCns.speed = this.turnSpeed;

        // Start some co-routines to illustrate SetByScript
        this.StartCoroutine(this.LookAtRandom());
        this.StartCoroutine(this.MoveRandom());
    }
Esempio n. 8
0
    private void Awake()
    {
        this.xform = this.transform;  // Cache

        // Add a transform constraint
        this.xformCns = this.gameObject.AddComponent <TransformConstraint>();
        this.xformCns.noTargetMode      = UnityConstraints.NO_TARGET_OPTIONS.SetByScript;
        this.xformCns.constrainRotation = false;

        // Add a smooth lookAt constraint
        this.lookCns = this.gameObject.AddComponent <SmoothLookAtConstraint>();
        this.lookCns.noTargetMode = UnityConstraints.NO_TARGET_OPTIONS.SetByScript;
        this.lookCns.pointAxis    = Vector3.up;
        this.lookCns.upAxis       = Vector3.forward;
        this.lookCns.speed        = this.turnSpeed;

        // Start some co-routines to illustrate SetByScript
        this.StartCoroutine(this.LookAtRandom());
        this.StartCoroutine(this.MoveRandom());
    }
Esempio n. 9
0
        void DoSetConstraintTarget()
        {
            var go = Fsm.GetOwnerDefaultTarget(owner);

            if (go == null)
            {
                return;
            }

            if (go != previousGo)
            {
                constraint = go.GetComponent <TransformConstraint>();
                previousGo = go;
            }

            if (constraint == null)
            {
                return;
            }

            constraint.target = targetGameObject.Value.transform;
        }
Esempio n. 10
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            TransformConstraint transformConstraint = skeleton.transformConstraints.Items[transformConstraintIndex];

            float[] array = frames;
            if (time < array[0])
            {
                TransformConstraintData data = transformConstraint.data;
                switch (pose)
                {
                case MixPose.Setup:
                    transformConstraint.rotateMix    = data.rotateMix;
                    transformConstraint.translateMix = data.translateMix;
                    transformConstraint.scaleMix     = data.scaleMix;
                    transformConstraint.shearMix     = data.shearMix;
                    break;

                case MixPose.Current:
                    transformConstraint.rotateMix    += (data.rotateMix - transformConstraint.rotateMix) * alpha;
                    transformConstraint.translateMix += (data.translateMix - transformConstraint.translateMix) * alpha;
                    transformConstraint.scaleMix     += (data.scaleMix - transformConstraint.scaleMix) * alpha;
                    transformConstraint.shearMix     += (data.shearMix - transformConstraint.shearMix) * alpha;
                    break;
                }
                return;
            }
            float num2;
            float num3;
            float num4;
            float num5;

            if (time >= array[array.Length - 5])
            {
                int num = array.Length;
                num2 = array[num + -4];
                num3 = array[num + -3];
                num4 = array[num + -2];
                num5 = array[num + -1];
            }
            else
            {
                int num6 = Animation.BinarySearch(array, time, 5);
                num2 = array[num6 + -4];
                num3 = array[num6 + -3];
                num4 = array[num6 + -2];
                num5 = array[num6 + -1];
                float num7         = array[num6];
                float curvePercent = GetCurvePercent(num6 / 5 - 1, 1f - (time - num7) / (array[num6 + -5] - num7));
                num2 += (array[num6 + 1] - num2) * curvePercent;
                num3 += (array[num6 + 2] - num3) * curvePercent;
                num4 += (array[num6 + 3] - num4) * curvePercent;
                num5 += (array[num6 + 4] - num5) * curvePercent;
            }
            if (pose == MixPose.Setup)
            {
                TransformConstraintData data2 = transformConstraint.data;
                transformConstraint.rotateMix    = data2.rotateMix + (num2 - data2.rotateMix) * alpha;
                transformConstraint.translateMix = data2.translateMix + (num3 - data2.translateMix) * alpha;
                transformConstraint.scaleMix     = data2.scaleMix + (num4 - data2.scaleMix) * alpha;
                transformConstraint.shearMix     = data2.shearMix + (num5 - data2.shearMix) * alpha;
            }
            else
            {
                transformConstraint.rotateMix    += (num2 - transformConstraint.rotateMix) * alpha;
                transformConstraint.translateMix += (num3 - transformConstraint.translateMix) * alpha;
                transformConstraint.scaleMix     += (num4 - transformConstraint.scaleMix) * alpha;
                transformConstraint.shearMix     += (num5 - transformConstraint.shearMix) * alpha;
            }
        }
        /// <summary>
        /// Adds a constraint to the specified already-sorted list of constraints, maintaining
        /// execution priority order. SortedSet is not used, as equal priorities
        /// break duplicate-checking with SortedSet, as well as SortedSet not being
        /// able to handle runtime-changing exec priorities.
        /// </summary>
        /// <param name="constraintList">Sorted list of existing priorites</param>
        /// <param name="constraint">Constraint to add</param>
        /// <param name="comparer">ConstraintExecOrderComparer for comparing two constraint priorities</param>
        internal static void AddWithPriority(ref List <TransformConstraint> constraintList, TransformConstraint constraint, ConstraintExecOrderComparer comparer)
        {
            if (constraintList.Contains(constraint))
            {
                return;
            }

            if (constraintList.Count == 0 || comparer.Compare(constraintList[constraintList.Count - 1], constraint) < 0)
            {
                constraintList.Add(constraint);
                return;
            }
            else if (comparer.Compare(constraintList[0], constraint) > 0)
            {
                constraintList.Insert(0, constraint);
                return;
            }
            else
            {
                int idx = constraintList.BinarySearch(constraint, comparer);
                if (idx < 0)
                {
                    // idx will be the two's complement of the index of the
                    // next element that is "larger" than the given constraint.
                    idx = ~idx;
                }
                constraintList.Insert(idx, constraint);
            }
        }