Пример #1
0
    private void OnEnable()
    {
        if (this.skeletonRenderer == null)
        {
            this.skeletonRenderer = base.GetComponent <SkeletonRenderer>();
        }
        if (this.skeletonAnimation == null)
        {
            this.skeletonAnimation = base.GetComponent <SkeletonAnimation>();
            if (this.skeletonAnimation == null)
            {
                this.skeletonAnimation = base.GetComponent <SkeletonAnimator>();
            }
        }
        SkeletonRenderer expr_51 = this.skeletonRenderer;

        expr_51.OnReset = (SkeletonRenderer.SkeletonRendererDelegate)Delegate.Remove(expr_51.OnReset, new SkeletonRenderer.SkeletonRendererDelegate(this.HandleRendererReset));
        SkeletonRenderer expr_78 = this.skeletonRenderer;

        expr_78.OnReset = (SkeletonRenderer.SkeletonRendererDelegate)Delegate.Combine(expr_78.OnReset, new SkeletonRenderer.SkeletonRendererDelegate(this.HandleRendererReset));
        if (this.skeletonAnimation != null)
        {
            this.skeletonAnimation.UpdateLocal -= new UpdateBonesDelegate(this.UpdateLocal);
            this.skeletonAnimation.UpdateLocal += new UpdateBonesDelegate(this.UpdateLocal);
        }
        this.CollectBones();
    }
Пример #2
0
 private void UpdateLocal(ISkeletonAnimation animated)
 {
     hipRotationTarget   = planter.Balance * hipTiltScale;
     hipRotationSmoothed = Mathf.MoveTowards(hipRotationSmoothed, hipRotationTarget, Time.deltaTime * hipRotationMoveScale * Mathf.Abs(2f * planter.Balance / planter.offBalanceThreshold));
     hipBone.Rotation    = hipRotationSmoothed;
     headBone.Rotation   = baseHeadRotation + (-hipRotationSmoothed * headTiltScale);
 }
Пример #3
0
 private void UpdateLocal(ISkeletonAnimation animated)
 {
     this.hipRotationTarget   = this.planter.Balance * this.hipTiltScale;
     this.hipRotationSmoothed = Mathf.MoveTowards(this.hipRotationSmoothed, this.hipRotationTarget, (Time.deltaTime * this.hipRotationMoveScale) * Mathf.Abs((float)((2f * this.planter.Balance) / this.planter.offBalanceThreshold)));
     this.hipBone.Rotation    = this.hipRotationSmoothed;
     this.headBone.Rotation   = this.baseHeadRotation + (-this.hipRotationSmoothed * this.headTiltScale);
 }
Пример #4
0
    void ApplyRootMotion(ISkeletonAnimation skelAnim)
    {
        if (transTimeline == null)
        {
            return;
        }

        float   duration  = track.animation.Duration;
        int     loopCount = Mathf.FloorToInt(track.TrackTime / duration);
        float   time      = track.TrackTime - loopCount * duration;
        Vector2 pos       = GetXYAtTime(transTimeline, time);
        Vector2 delta     = pos - lastPos;

        delta += fullDelta * (loopCount - Mathf.FloorToInt(lastTime / duration));

        if (skelAnim.Skeleton.FlipX)
        {
            delta.x = -delta.x;
        }

        if (inverseX)
        {
            delta.x = -delta.x;
        }

        transform.Translate(new Vector3(delta.x, 0f, 0f));
        skeletonAnimation.transform.Translate(new Vector3(0f, delta.y, 0f));
        //transform.Translate(delta.x, delta.y, 0);
        lastTime = track.TrackTime;
        lastPos  = pos;
    }
Пример #5
0
 private void AnimationOverrideSpriteAttach(ISkeletonAnimation animated)
 {
     if (this.overrideAnimation && base.isActiveAndEnabled)
     {
         this.Attach();
     }
 }
    // Handles Arm Orientation based on aim
    private void SetAimOrientation(ISkeletonAnimation skeletonAnimator)
    {
        // If arms are not in use then return
        if (!bArmBusy)
        {
            return;
        }

        // If climbing corner then return
        if (playerController.Motor.motorState == PlatformerMotor2D.MotorState.ClimbingCorner)
        {
            return;
        }

        weaponAimIKBone.UpdateWorldTransform();

        // If not aiming, then set aiming for ready state
        if (!playerController.bAimingDownSights)
        {
            ResetAimIK();
            weaponAimIKBone.SetPosition(weaponPivotIKBone.GetSkeletonSpacePosition() + playerController.AimPoint);
        }
        else         // Otherwise set aim for both head and weapon
        {
            weaponAimIKBone.SetPosition(weaponPivotIKBone.GetSkeletonSpacePosition() + playerController.AimPoint);
            headAimIKBone.SetPosition(headPivotIKBone.GetSkeletonSpacePosition() + playerController.HeadAimPoint);
        }
    }
                private void Start()
                {
                    _spineAnimator = GetComponent <SpineAnimator>();

                    ISkeletonAnimation s = _spineAnimator.GetSkeletonAnimation() as ISkeletonAnimation;

                    if (s != null)
                    {
                        s.UpdateLocal += HandleUpdateLocal;
                    }

                    IAnimationStateComponent sa = _spineAnimator.GetSkeletonAnimation() as IAnimationStateComponent;

                    if (sa != null)
                    {
                        this._state = sa.AnimationState;
                    }

                    SetSourceBone(_sourceBoneName);

                    Skeleton skeleton = s.Skeleton;

                    _siblingBones.Clear();
                    foreach (string bn in _siblingBoneNames)
                    {
                        Bone b = skeleton.FindBone(bn);
                        if (b != null)
                        {
                            _siblingBones.Add(b);
                        }
                    }
                }
Пример #8
0
    void Awake()
    {
        var graphic = GetComponent <SkeletonGraphic>();

        if (graphic != null)
        {
            _animation = graphic;
        }
        else
        {
            var aimation = GetComponent <SkeletonAnimation>();
            if (aimation != null)
            {
                _animation = aimation;
            }
            else
            {
                Debug.LogErrorFormat("{0} can not find component SkeletonAnimation!", gameObject.name);
                return;
            }
        }


        var data = AnimationState.Data.skeletonData;

        for (int i = 0; i < data.animations.Count; i++)
        {
            var animation = data.animations.Items[i];
            animationList.Add(animation.name);
        }
        for (int i = 0; i < data.AnimationNames.Count; i++)
        {
            animationList.Add(data.AnimationNames.Items[i]);
        }
    }
Пример #9
0
    public static void SetAnimation(this ISkeletonAnimation anim, string nameAnim, List <string> skinMix, Color color,
                                    bool loop = false, Action onComplete = null)
    {
        anim.SetAnimation(nameAnim, skinMix, loop, onComplete);

        anim.SetColor(color);
    }
        void OverrideLocal(ISkeletonAnimation animated)
        {
            if (bone == null || bone.Data.Name != boneName)
            {
                if (string.IsNullOrEmpty(boneName))
                {
                    return;
                }
                bone = spineComponent.Skeleton.FindBone(boneName);
                if (bone == null)
                {
                    Debug.LogFormat("Cannot find bone: '{0}'", boneName);
                    return;
                }
            }

            if (overridePosition)
            {
                bone.X = Mathf.Lerp(bone.X, localPosition.x, alpha);
                bone.Y = Mathf.Lerp(bone.Y, localPosition.y, alpha);
            }

            if (overrideRotation)
            {
                bone.Rotation = Mathf.Lerp(bone.Rotation, rotation, alpha);
            }
        }
Пример #11
0
 private void OnUpdate(ISkeletonAnimation animated)
 {
     for (int i = 0; i < _sequence.Count; i++)
     {
         _sequence[i].Update(Time.deltaTime);
     }
 }
Пример #12
0
//		public Transform skeletonSpaceTransform;

        IEnumerator Start()
        {
            if (parentSpaceHelper == null)
            {
                parentSpaceHelper = (new GameObject("Parent Space Helper")).transform;
                                #if !FLIPDEBUG
                parentSpaceHelper.hideFlags = HideFlags.HideInHierarchy;
                                #endif
            }

            targetSkeletonComponent = GetComponent <SkeletonRenderer>() as ISkeletonAnimation;
            if (targetSkeletonComponent == null)
            {
                Debug.LogError("Attached Spine component does not implement ISkeletonAnimation. This script is not compatible.");
            }
            skeleton = targetSkeletonComponent.Skeleton;

                        #if FLIPDEBUG
            skeleton.flipX = flipXInitially;
            skeleton.flipY = flipYInitially;
                        #endif

            if (applyOnStart)
            {
                yield return(null);

                Apply();
            }
        }
Пример #13
0
 void AnimationOverrideSpriteAttach(ISkeletonAnimation animated)
 {
     if (overrideAnimation && isActiveAndEnabled)
     {
         Attach();
     }
 }
Пример #14
0
    void OnEnable()
    {
        if (skeletonRenderer == null)
        {
            skeletonRenderer = GetComponent <SkeletonRenderer>();
        }

        if (skeletonAnimation == null)
        {
            skeletonAnimation = GetComponent <SkeletonAnimation>();
            if (skeletonAnimation == null)
            {
                skeletonAnimation = GetComponent <SkeletonAnimator>();
            }
        }

        skeletonRenderer.OnReset -= HandleRendererReset;
        skeletonRenderer.OnReset += HandleRendererReset;

        if (skeletonAnimation != null)
        {
            skeletonAnimation.UpdateLocal -= UpdateLocal;
            skeletonAnimation.UpdateLocal += UpdateLocal;
        }


        CollectBones();
    }
Пример #15
0
 public void Initialize(bool overwrite = true)
 {
     if (overwrite || (this.attachment == null))
     {
         ISkeletonComponent component = base.GetComponent <ISkeletonComponent>();
         SkeletonRenderer   renderer  = component as SkeletonRenderer;
         if (renderer != null)
         {
             this.applyPMA = renderer.pmaVertexColors;
         }
         else
         {
             SkeletonGraphic graphic = component as SkeletonGraphic;
             if (graphic != null)
             {
                 this.applyPMA = graphic.MeshGenerator.settings.pmaVertexColors;
             }
         }
         if (this.overrideAnimation)
         {
             ISkeletonAnimation animation = component as ISkeletonAnimation;
             if (animation != null)
             {
                 animation.UpdateComplete -= new UpdateBonesDelegate(this.AnimationOverrideSpriteAttach);
                 animation.UpdateComplete += new UpdateBonesDelegate(this.AnimationOverrideSpriteAttach);
             }
         }
         if (this.spineSlot == null)
         {
         }
         this.spineSlot = component.Skeleton.FindSlot(this.slot);
         Shader shader = !this.applyPMA ? Shader.Find("Sprites/Default") : Shader.Find("Spine/Skeleton");
         this.attachment = !this.applyPMA ? this.sprite.ToRegionAttachment(GetPageFor(this.sprite.texture, shader), 0f) : this.sprite.ToRegionAttachmentPMAClone(shader, TextureFormat.RGBA32, false, null, 0f);
     }
 }
Пример #16
0
 private void OverrideLocal(ISkeletonAnimation animated)
 {
     if ((this.bone == null) || (this.bone.Data.Name != this.boneName))
     {
         if (string.IsNullOrEmpty(this.boneName))
         {
             return;
         }
         this.bone = this.spineComponent.Skeleton.FindBone(this.boneName);
         if (this.bone == null)
         {
             object[] args = new object[] { this.boneName };
             Debug.LogFormat("Cannot find bone: '{0}'", args);
             return;
         }
     }
     if (this.overridePosition)
     {
         this.bone.X = Mathf.Lerp(this.bone.X, this.localPosition.x, this.alpha);
         this.bone.Y = Mathf.Lerp(this.bone.Y, this.localPosition.y, this.alpha);
     }
     if (this.overrideRotation)
     {
         this.bone.Rotation = Mathf.Lerp(this.bone.Rotation, this.rotation, this.alpha);
     }
 }
Пример #17
0
    void UpdateBones(ISkeletonAnimation skelAnim)
    {
        //if (transTimeline == null)
        //return;

        skelAnim.Skeleton.RootBone.X = 0;
        skelAnim.Skeleton.RootBone.Y = 0;
    }
Пример #18
0
 void UpdateWorld(ISkeletonAnimation anim)
 {
     UpdateAllBones(SkeletonUtilityBone.UpdatePhase.World);
     for (int i = 0, n = constraintComponents.Count; i < n; i++)
     {
         constraintComponents[i].DoUpdate();
     }
 }
Пример #19
0
 void UpdateWorld(ISkeletonAnimation anim)
 {
     UpdateAllBones();
     for (int i = 0, n = utilityConstraints.Count; i < n; i++)
     {
         utilityConstraints[i].DoUpdate();
     }
 }
Пример #20
0
        private void OnDestroy()
        {
            ISkeletonAnimation component = base.GetComponent <ISkeletonAnimation>();

            if (component != null)
            {
                component.UpdateComplete -= new UpdateBonesDelegate(this.AnimationOverrideSpriteAttach);
            }
        }
Пример #21
0
        void UpdateWorld(ISkeletonAnimation anim)
        {
            UpdateAllBones();

            foreach (SkeletonUtilityConstraint c in utilityConstraints)
            {
                c.DoUpdate();
            }
        }
Пример #22
0
        private void UpdateLocal(ISkeletonAnimation animated)
        {
            Transform thisTransform = transform;

            Vector2 thisTransformPosition = thisTransform.position;
            float   centerOfGravityX      = thisTransformPosition.x + centerOfGravityXOffset;

            nearFoot.UpdateDistance(centerOfGravityX);
            farFoot.UpdateDistance(centerOfGravityX);
            balance             = nearFoot.displacementFromCenter + farFoot.displacementFromCenter;
            distanceBetweenFeet = Mathf.Abs(nearFoot.worldPos.x - farFoot.worldPos.x);

            // Detect time to make a new step
            bool isTooOffBalance   = Mathf.Abs(balance) > offBalanceThreshold;
            bool isFeetTooFarApart = distanceBetweenFeet > feetTooFarApartThreshold;
            bool timeForNewStep    = isFeetTooFarApart || isTooOffBalance;

            if (timeForNewStep)
            {
                // Choose which foot to use for next step.
                Foot stepFoot, otherFoot;
                bool stepLegIsNearLeg = nearFoot.distanceFromCenter > farFoot.distanceFromCenter;
                if (stepLegIsNearLeg)
                {
                    stepFoot  = nearFoot;
                    otherFoot = farFoot;
                }
                else
                {
                    stepFoot  = farFoot;
                    otherFoot = nearFoot;
                }

                // Start a new step.
                if (!stepFoot.IsStepInProgress && otherFoot.IsPrettyMuchDoneStepping)
                {
                    float newDisplacement = Foot.GetNewDisplacement(otherFoot.displacementFromCenter, comfyDistance, minimumSpaceBetweenFeet, maxNewStepDisplacement, forward, backward);
                    stepFoot.StartNewStep(newDisplacement, centerOfGravityX, thisTransformPosition.y, footRayRaise, hits, footSize);
                }
            }


            float deltaTime = Time.deltaTime;
            float stepSpeed = baseLerpSpeed;

            stepSpeed += (Mathf.Abs(balance) - 0.6f) * 2.5f;

            // Animate steps that are in progress.
            nearFoot.UpdateStepProgress(deltaTime, stepSpeed, shuffleDistance, forward, backward);
            farFoot.UpdateStepProgress(deltaTime, stepSpeed, shuffleDistance, forward, backward);

            nearFootBone.SetLocalPosition(thisTransform.InverseTransformPoint(nearFoot.worldPos));
            farFootBone.SetLocalPosition(thisTransform.InverseTransformPoint(farFoot.worldPos));
        }
Пример #23
0
        void HandleUpdateLocal(ISkeletonAnimation animatedSkeletonComponent)
        {
            if (!this.isActiveAndEnabled)
            {
                return;                 // Root motion is only applied when component is enabled.
            }
            var movementDelta = CalculateAnimationsMovementDelta();

            AdjustMovementDeltaToConfiguration(ref movementDelta, animatedSkeletonComponent.Skeleton);
            ApplyRootMotion(movementDelta);
        }
Пример #24
0
        void HandleUpdateLocal(ISkeletonAnimation animatedSkeletonComponent)
        {
            if (!this.isActiveAndEnabled)
            {
                return;                 // Root motion is only applied when component is enabled.
            }
            var     boneLocalDelta = CalculateAnimationsMovementDelta();
            Vector2 parentBoneScale;
            Vector2 skeletonDelta = GetSkeletonSpaceMovementDelta(boneLocalDelta, out parentBoneScale);

            ApplyRootMotion(skeletonDelta, parentBoneScale);
        }
Пример #25
0
        private void UpdateWorld(ISkeletonAnimation anim)
        {
            this.UpdateAllBones(SkeletonUtilityBone.UpdatePhase.World);
            int num   = 0;
            int count = this.utilityConstraints.Count;

            while (num < count)
            {
                this.utilityConstraints[num].DoUpdate();
                num++;
            }
        }
Пример #26
0
        private void UpdateSpineSkeleton(ISkeletonAnimation animatedSkeleton)
        {
            bool flipX        = this.skeleton.flipX;
            bool flipY        = this.skeleton.flipY;
            bool flag         = flipX ^ flipY;
            bool flag2        = flipX || flipY;
            Bone startingBone = this.StartingBone;

            foreach (KeyValuePair <Bone, Transform> keyValuePair in this.boneTable)
            {
                Bone       key       = keyValuePair.Key;
                Transform  value     = keyValuePair.Value;
                bool       flag3     = key == startingBone;
                Transform  transform = (!flag3) ? this.boneTable[key.Parent] : this.ragdollRoot;
                Vector3    position  = transform.position;
                Quaternion rotation  = transform.rotation;
                SkeletonRagdoll2D.parentSpaceHelper.position   = position;
                SkeletonRagdoll2D.parentSpaceHelper.rotation   = rotation;
                SkeletonRagdoll2D.parentSpaceHelper.localScale = transform.localScale;
                Vector3 position2 = value.position;
                Vector3 vector    = SkeletonRagdoll2D.parentSpaceHelper.InverseTransformDirection(value.right);
                Vector3 vector2   = SkeletonRagdoll2D.parentSpaceHelper.InverseTransformPoint(position2);
                float   num       = Mathf.Atan2(vector.y, vector.x) * 57.29578f;
                if (flag2)
                {
                    if (flag3)
                    {
                        if (flipX)
                        {
                            vector2.x *= -1f;
                        }
                        if (flipY)
                        {
                            vector2.y *= -1f;
                        }
                        num *= ((!flag) ? 1f : -1f);
                        if (flipX)
                        {
                            num += 180f;
                        }
                    }
                    else if (flag)
                    {
                        num       *= -1f;
                        vector2.y *= -1f;
                    }
                }
                key.x               = Mathf.Lerp(key.x, vector2.x, this.mix);
                key.y               = Mathf.Lerp(key.y, vector2.y, this.mix);
                key.rotation        = Mathf.Lerp(key.rotation, num, this.mix);
                key.appliedRotation = Mathf.Lerp(key.appliedRotation, num, this.mix);
            }
        }
Пример #27
0
	IEnumerator Start () {
		skeletonAnim = (ISkeletonAnimation)GetComponent<SkeletonRenderer>();
		if (helper == null) {
			helper = (Transform)(new GameObject("Helper")).transform;
			helper.hideFlags = HideFlags.HideInHierarchy;
		}

		if (applyOnStart) {
			yield return null;
			Apply();
		}
	}
Пример #28
0
        private void UpdateWorld(ISkeletonAnimation anim)
        {
            this.UpdateAllBones();
            int i     = 0;
            int count = this.utilityConstraints.Count;

            while (i < count)
            {
                this.utilityConstraints[i].DoUpdate();
                i++;
            }
        }
Пример #29
0
	IEnumerator Start () {
		skeletonAnim = (ISkeletonAnimation)GetComponent<SkeletonRenderer>();
		if (helper == null) {
			helper = (Transform)(new GameObject("Helper")).transform;
			helper.hideFlags = HideFlags.HideInHierarchy;
		}

		if (applyOnStart) {
			yield return null;
			Apply();
		}
	}
Пример #30
0
    static void SetColor(this ISkeletonAnimation anim, Color color)
    {
        var skeleton = anim.Skeleton;

        foreach (var slot in skeleton.Slots.Where(s => s.Data.Name.StartsWith("Stickman/")))
        {
            slot.SetColor(color);
        }
        foreach (var slot in skeleton.Slots.Where(s => s.Data.Name.StartsWith("swordsman/stickman")))
        {
            slot.SetColor(color);
        }
    }
Пример #31
0
        void OnEnable()
        {
            if (skeletonRenderer == null)
            {
                skeletonRenderer = GetComponent <SkeletonRenderer>();
            }
            if (skeletonGraphic == null)
            {
                skeletonGraphic = GetComponent <SkeletonGraphic>();
            }
            if (skeletonAnimation == null)
            {
                skeletonAnimation = skeletonRenderer != null?skeletonRenderer.GetComponent <ISkeletonAnimation>() :
                                        skeletonGraphic != null?skeletonGraphic.GetComponent <ISkeletonAnimation>() :
                                            GetComponent <ISkeletonAnimation>();
            }
            if (skeletonComponent == null)
            {
                skeletonComponent = skeletonRenderer != null?skeletonRenderer.GetComponent <ISkeletonComponent>() :
                                        skeletonGraphic != null?skeletonGraphic.GetComponent <ISkeletonComponent>() :
                                            GetComponent <ISkeletonComponent>();
            }

            if (skeletonRenderer != null)
            {
                skeletonRenderer.OnRebuild -= HandleRendererReset;
                skeletonRenderer.OnRebuild += HandleRendererReset;
            }
            else if (skeletonGraphic != null)
            {
                skeletonGraphic.OnRebuild -= HandleRendererReset;
                skeletonGraphic.OnRebuild += HandleRendererReset;
                canvas = skeletonGraphic.canvas;
                if (canvas == null)
                {
                    canvas = skeletonGraphic.GetComponentInParent <Canvas>();
                }
                if (canvas == null)
                {
                    positionScale = 100.0f;
                }
            }

            if (skeletonAnimation != null)
            {
                skeletonAnimation.UpdateLocal -= UpdateLocal;
                skeletonAnimation.UpdateLocal += UpdateLocal;
            }

            CollectBones();
        }
Пример #32
0
		IEnumerator Start () {
			if (parentSpaceHelper == null) {
				parentSpaceHelper = (new GameObject("Parent Space Helper")).transform;
				parentSpaceHelper.hideFlags = HideFlags.HideInHierarchy;
			}

			targetSkeletonComponent = GetComponent<SkeletonRenderer>() as ISkeletonAnimation;
			if (targetSkeletonComponent == null) Debug.LogError("Attached Spine component does not implement ISkeletonAnimation. This script is not compatible.");
			skeleton = targetSkeletonComponent.Skeleton;

			if (applyOnStart) {
				yield return null;
				Apply();
			}
		}
		void OnEnable () {
			if (skeletonRenderer == null) {
				skeletonRenderer = GetComponent<SkeletonRenderer>();
			}

			if (skeletonAnimation == null) {
				skeletonAnimation = GetComponent<SkeletonAnimation>();
				if (skeletonAnimation == null)
					skeletonAnimation = GetComponent<SkeletonAnimator>();
			}

			skeletonRenderer.OnRebuild -= HandleRendererReset;
			skeletonRenderer.OnRebuild += HandleRendererReset;

			if (skeletonAnimation != null) {
				skeletonAnimation.UpdateLocal -= UpdateLocal;
				skeletonAnimation.UpdateLocal += UpdateLocal;
			}

			CollectBones();
		}
		void UpdateLocal (ISkeletonAnimation anim) {
			if (needToReprocessBones)
				CollectBones();

			var utilityBones = this.utilityBones;
			if (utilityBones == null) return;
			for (int i = 0, n = utilityBones.Count; i < n; i++)
				utilityBones[i].transformLerpComplete = false;

			UpdateAllBones();
		}
		void UpdateWorld (ISkeletonAnimation anim) {
			UpdateAllBones();
			for (int i = 0, n = utilityConstraints.Count; i < n; i++)
				utilityConstraints[i].DoUpdate();
		}
Пример #36
0
		void UpdateSpineSkeleton (ISkeletonAnimation skeletonRenderer) {
			bool flipX = skeleton.flipX;
			bool flipY = skeleton.flipY;
			bool flipXOR = flipX ^ flipY;
			bool flipOR = flipX || flipY;

			foreach (var pair in boneTable) {
				var b = pair.Key;
				var t = pair.Value;
				bool isStartingBone = b == StartingBone;
				Transform parentTransform = isStartingBone ? ragdollRoot : boneTable[b.Parent];
				Vector3 parentTransformWorldPosition = parentTransform.position;
				Quaternion parentTransformWorldRotation = parentTransform.rotation;

				parentSpaceHelper.position = parentTransformWorldPosition;
				parentSpaceHelper.rotation = parentTransformWorldRotation;
				parentSpaceHelper.localScale = parentTransform.localScale;

				Vector3 boneWorldPosition = t.position;
				Vector3 right = parentSpaceHelper.InverseTransformDirection(t.right);

				Vector3 boneLocalPosition = parentSpaceHelper.InverseTransformPoint(boneWorldPosition);
				float boneLocalRotation = Mathf.Atan2(right.y, right.x) * Mathf.Rad2Deg;

				if (flipOR) {
					if (isStartingBone) {
						if (flipX) boneLocalPosition.x *= -1f;
						if (flipY) boneLocalPosition.y *= -1f;

						boneLocalRotation = boneLocalRotation * (flipXOR ? -1f : 1f);
						if (flipX) boneLocalRotation += 180;
					} else {
						if (flipXOR) {
							boneLocalRotation *= -1f;
							boneLocalPosition.y *= -1f; // wtf??
						}
					}
				}

				b.x = Mathf.Lerp(b.x, boneLocalPosition.x, mix);
				b.y = Mathf.Lerp(b.y, boneLocalPosition.y, mix);
				b.rotation = Mathf.Lerp(b.rotation, boneLocalRotation, mix);
				b.appliedRotation = Mathf.Lerp(b.appliedRotation, boneLocalRotation, mix);
			}
		}
Пример #37
0
		// This is called after the animation is applied to the skeleton and can be used to adjust the bones dynamically.
		public void UpdateLocal (ISkeletonAnimation skeletonRenderer) {
			headBone.Rotation += extraRotation;
		}
Пример #38
0
    public void Apply()
    {
        skeletonAnim = (ISkeletonAnimation)GetComponent<SkeletonRenderer>();
        if (helper == null)
        {
            helper = (Transform)(new GameObject("Helper")).transform;
            helper.hideFlags = HideFlags.HideInHierarchy;
        }
        isActive = true;
        skeleton = skeletonAnim.Skeleton;

        var ragdollRootBone = skeleton.FindBone(startingBoneName);
        startingBone = ragdollRootBone;
        RecursivelyCreateBoneProxies(ragdollRootBone);

        rootRigidbody = boneTable[ragdollRootBone].GetComponent<Rigidbody2D>();
        rootRigidbody.isKinematic = pinStartBone;
        rootRigidbody.mass = rootMass;

        List<Collider2D> boneColliders = new List<Collider2D>();

        foreach (var pair in boneTable)
        {
            var b = pair.Key;
            var t = pair.Value;
            Bone parentBone = null;
            Transform parentTransform = transform;

            boneColliders.Add(t.GetComponent<Collider2D>());

            if (b != startingBone)
            {
                parentBone = b.Parent;
                parentTransform = boneTable[parentBone];
            }
            else {
                ragdollRoot = new GameObject("RagdollRoot").transform;
                ragdollRoot.parent = transform;

                if (b == skeleton.RootBone)
                {
                    ragdollRoot.localPosition = new Vector3(b.WorldX, b.WorldY, 0);
                    ragdollRoot.localRotation = Quaternion.Euler(0, 0, GetCompensatedRotationIK(b));
                    parentTransform = ragdollRoot;
                }
                else {
                    ragdollRoot.localPosition = new Vector3(b.Parent.WorldX, b.Parent.WorldY, 0);
                    ragdollRoot.localRotation = Quaternion.Euler(0, 0, GetCompensatedRotationIK(b.Parent));
                    parentTransform = ragdollRoot;
                }

                rootOffset = t.position - transform.position;
            }

            var rbParent = parentTransform.GetComponent<Rigidbody2D>();

            if (rbParent != null)
            {
                var joint = t.gameObject.AddComponent<HingeJoint2D>();
                joint.connectedBody = rbParent;
                Vector3 localPos = parentTransform.InverseTransformPoint(t.position);
                localPos.x *= 1;
                joint.connectedAnchor = localPos;
                joint.GetComponent<Rigidbody2D>().mass = joint.connectedBody.mass * massFalloffFactor;
                JointAngleLimits2D limits = new JointAngleLimits2D();
                joint.GetComponent<Rigidbody2D>().angularDrag = 10;

                limits.min = 0;
                limits.max = 0;

                joint.limits = limits;
                joint.useLimits = true;
                joints.Add(b.data.name, joint);
                StaminaBody script = joint.gameObject.AddComponent<StaminaBody>();
                if(b.data.name == "LeftHand")
                {
                    script.isLeftHand = true;
                }
                else if(b.data.name == "RightHand")
                {
                    script.isRightHand = true;
                }
                else if (b.data.name == "RightFoot")
                {
                    script.isRightFoot = true;
                }
                else if (b.data.name == "LeftFoot")
                {
                    script.isLeftFoot = true;
                }
                script.player = gameObject.GetComponent<RagDollSpine>();
                joint.gameObject.tag = "Player" + (int)script.player.player;
            }
        }

        for (int x = 0; x < boneColliders.Count; x++)
        {
            for (int y = 0; y < boneColliders.Count; y++)
            {
                if (x == y) continue;
                Physics2D.IgnoreCollision(boneColliders[x], boneColliders[y]);
            }
        }

        var utilityBones = GetComponentsInChildren<SkeletonUtilityBone>();
        if (utilityBones.Length > 0)
        {
            List<string> destroyedUtilityBoneNames = new List<string>();
            foreach (var ub in utilityBones)
            {
                if (ub.mode == SkeletonUtilityBone.Mode.Override)
                {
                    destroyedUtilityBoneNames.Add(ub.gameObject.name);
                    Destroy(ub.gameObject);
                }
            }

            if (destroyedUtilityBoneNames.Count > 0)
            {
                string msg = "Destroyed Utility Bones: ";
                for (int i = 0; i < destroyedUtilityBoneNames.Count; i++)
                {
                    msg += destroyedUtilityBoneNames[i];
                    if (i != destroyedUtilityBoneNames.Count - 1)
                    {
                        msg += ",";
                    }
                }
                Debug.LogWarning(msg);
            }
        }

        if (disableIK)
        {
            foreach (IkConstraint ik in skeleton.IkConstraints)
            {
                ik.Mix = 0;
            }
        }

        skeletonAnim.UpdateWorld += UpdateWorld;
    }
Пример #39
0
    void UpdateWorld(ISkeletonAnimation skeletonRenderer)
    {
        foreach (var pair in boneTable) {
            var b = pair.Key;
            var t = pair.Value;
            // bool flip = false;
            bool flipX = false;  //TODO:  deal with negative scale instead of Flip Key for Spine 3.0
            bool flipY = false;  //TODO:  deal with negative scale instead of Flip Key for Spine 3.0
            Bone parentBone = null;
            Transform parentTransform = transform;

            if (b != startingBone) {
                parentBone = b.Parent;
                parentTransform = boneTable[parentBone];
                // MITCH
                // flipX = parentBone.WorldFlipX;
                // flipY = parentBone.WorldFlipY;

            } else {
                parentBone = b.Parent;
                parentTransform = ragdollRoot;
                if (b.Parent != null) {
                    // MITCH
                    // flipX = b.worldFlipX;
                    // flipY = b.WorldFlipY;
                } else {
                    flipX = b.Skeleton.FlipX;
                    flipY = b.Skeleton.FlipY;
                }
            }

            //flip = flipX ^ flipY;

            helper.position = parentTransform.position;
            helper.rotation = parentTransform.rotation;
            helper.localScale = new Vector3(flipX ? -parentTransform.localScale.x : parentTransform.localScale.x, flipY ? -parentTransform.localScale.y : parentTransform.localScale.y, 1);

            Vector3 pos = t.position;
            pos = helper.InverseTransformPoint(pos);
            b.X = Mathf.Lerp(b.X, pos.x, mix);
            b.Y = Mathf.Lerp(b.Y, pos.y, mix);

            Vector3 right = helper.InverseTransformDirection(t.right);

            float a = Mathf.Atan2(right.y, right.x) * Mathf.Rad2Deg;

            // MITCH
            //if (b.WorldFlipX ^ b.WorldFlipY) {
            //	a *= -1;
            //}

            if (parentBone != null) {
                // MITCH
                //if ((b.WorldFlipX ^ b.WorldFlipY) != flip) {
                //	a -= GetCompensatedRotationIK(parentBone) * 2;
                //}
            }

            b.Rotation = Mathf.Lerp(b.Rotation, a, mix);
            // MITCH
            // b.RotationIK = Mathf.Lerp(b.rotationIK, a, mix);
        }
    }
		void UpdateComplete (ISkeletonAnimation anim) {
			UpdateAllBones();
		}
Пример #41
0
		/// <summary>Performed every skeleton animation update to translate Unity Transforms positions into Spine bone transforms.</summary>
		void UpdateSpineSkeleton (ISkeletonAnimation animatedSkeleton) {
			#if FLIPDEBUG
			if (disableUpdateBones) return;
			#endif

			bool flipX = skeleton.flipX;
			bool flipY = skeleton.flipY;
			bool flipXOR = flipX ^ flipY;
			bool flipOR = flipX || flipY;
			var startingBone = this.StartingBone;

			foreach (var pair in boneTable) {
				var b = pair.Key;
				var t = pair.Value;
				bool isStartingBone = (b == startingBone);
				Transform parentTransform = isStartingBone ? ragdollRoot : boneTable[b.Parent];
				Vector3 parentTransformWorldPosition = parentTransform.position;
				Quaternion parentTransformWorldRotation = parentTransform.rotation;

				parentSpaceHelper.position = parentTransformWorldPosition;
				parentSpaceHelper.rotation = parentTransformWorldRotation;
				parentSpaceHelper.localScale = parentTransform.localScale;

				Vector3 boneWorldPosition = t.position;
				Vector3 right = parentSpaceHelper.InverseTransformDirection(t.right);

				Vector3 boneLocalPosition = parentSpaceHelper.InverseTransformPoint(boneWorldPosition);
				float boneLocalRotation = Mathf.Atan2(right.y, right.x) * Mathf.Rad2Deg;
				if (flipOR) {
					if (isStartingBone) {
						if (flipX) boneLocalPosition.x *= -1f;
						if (flipY) boneLocalPosition.y *= -1f;

						boneLocalRotation = boneLocalRotation * (flipXOR ? -1f : 1f);
						if (flipX) boneLocalRotation += 180;
					} else {
						if (flipXOR) {
							boneLocalRotation *= -1f;
							boneLocalPosition.y *= -1f; // wtf??
						}
					}
				}

				b.x = Mathf.Lerp(b.x, boneLocalPosition.x, mix);
				b.y = Mathf.Lerp(b.y, boneLocalPosition.y, mix);
				b.rotation = Mathf.Lerp(b.rotation, boneLocalRotation, mix);
				b.appliedRotation = Mathf.Lerp(b.appliedRotation, boneLocalRotation, mix);

//				Mitch Original Code:
//				Vector3 right = parentSpaceHelper.InverseTransformDirection(t.right);
//				float a = Mathf.Atan2(right.y, right.x) * Mathf.Rad2Deg;
//				if (b.worldSignX ^ b.worldSignY) {
//					a *= -1;
//				}
//				if (parentBone != null) {
//					if ((b.WorldFlipX ^ b.WorldFlipY) != flip) {
//						a -= GetCompensatedRotationIK(parentBone) * 2;
//					}
//				}
//				b.Rotation = Mathf.Lerp(b.Rotation, a, mix);
			}
		}