Esempio n. 1
0
        void OnEnable()
        {
            skeletonUtility  = (SkeletonUtility)target;
            skeletonRenderer = skeletonUtility.skeletonRenderer;
            skeletonGraphic  = skeletonUtility.skeletonGraphic;
            skeleton         = skeletonUtility.Skeleton;

            if (skeleton == null)
            {
                if (skeletonRenderer != null)
                {
                    skeletonRenderer.Initialize(false);
                    skeletonRenderer.LateUpdate();
                }
                else if (skeletonGraphic != null)
                {
                    skeletonGraphic.Initialize(false);
                    skeletonGraphic.LateUpdate();
                }
                skeleton = skeletonUtility.Skeleton;
            }

            if ((skeletonRenderer != null && !skeletonRenderer.valid) ||
                (skeletonGraphic != null && !skeletonGraphic.IsValid))
            {
                return;
            }

#if !NEW_PREFAB_SYSTEM
            isPrefab |= PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab;
#endif
        }
Esempio n. 2
0
 public static void ReinitializeComponent(SkeletonGraphic component)
 {
     if (component == null)
     {
         return;
     }
     if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset))
     {
         return;
     }
     component.Initialize(true);
     component.LateUpdate();
 }
Esempio n. 3
0
    public void FillHeroData(int _hIndex)
    {
        for (int i = 0; i < imgAllStars.Length; i++)
        {
            if (i <= heroSelected.level)
            {
                imgAllStars[i].sprite = sprStar;
            }
            else
            {
                imgAllStars[i].sprite = sprStarUnlock;
            }
        }
        txtPlayerName.text = heroSelected.name;

        FillDataPlayer(_hIndex);
        if (p1Skeleton.Skeleton != null)
        {
            p1Skeleton.Skeleton.SetSkin("G" + curWeaponIndex);
            p1Skeleton.Skeleton.SetSlotsToSetupPose();
            p1Skeleton.LateUpdate();
        }
        if (p2Skeleton.Skeleton != null)
        {
            p2Skeleton.Skeleton.SetSkin("G" + curWeaponIndex);
            p2Skeleton.Skeleton.SetSlotsToSetupPose();
            p2Skeleton.LateUpdate();
        }

        if (heroSelected != null)
        {
            if (heroSelected.level + 1 >= 2)
            {
                //imgSkill2.color = clUnlock;
                imgLock.enabled = false;
            }
            else
            {
                //imgSkill2.color = clNotYetUnlock;
                imgLock.enabled = true;
            }
        }
        else
        {
            //imgSkill2.color = clNotYetUnlock;
            imgLock.enabled = true;
        }
    }
        public void PreviewEditModePose(Playable playable,
                                        ISkeletonComponent skeletonComponent, IAnimationStateComponent animationStateComponent,
                                        SkeletonAnimation skeletonAnimation, SkeletonGraphic skeletonGraphic)
        {
            if (Application.isPlaying)
            {
                return;
            }
            if (animationStateComponent.IsNullOrDestroyed() || skeletonComponent == null)
            {
                return;
            }

            int inputCount             = playable.GetInputCount();
            int lastNonZeroWeightTrack = -1;

            for (int i = 0; i < inputCount; i++)
            {
                float inputWeight = playable.GetInputWeight(i);
                if (inputWeight > 0)
                {
                    lastNonZeroWeightTrack = i;
                }
            }

            if (lastNonZeroWeightTrack != -1)
            {
                ScriptPlayable <SpineAnimationStateBehaviour> inputPlayableClip =
                    (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(lastNonZeroWeightTrack);
                SpineAnimationStateBehaviour clipData = inputPlayableClip.GetBehaviour();

                var skeleton = skeletonComponent.Skeleton;

                bool skeletonDataMismatch = clipData.animationReference != null && clipData.animationReference.SkeletonDataAsset &&
                                            skeletonComponent.SkeletonDataAsset.GetSkeletonData(true) != clipData.animationReference.SkeletonDataAsset.GetSkeletonData(true);
                if (skeletonDataMismatch)
                {
                    Debug.LogWarningFormat("SpineAnimationStateMixerBehaviour tried to apply an animation for the wrong skeleton. Expected {0}. Was {1}",
                                           skeletonComponent.SkeletonDataAsset, clipData.animationReference.SkeletonDataAsset);
                }

                // Getting the from-animation here because it's required to get the mix information from AnimationStateData.
                Animation fromAnimation = null;
                float     fromClipTime  = 0;
                bool      fromClipLoop  = false;
                if (lastNonZeroWeightTrack != 0 && inputCount > 1)
                {
                    var fromClip     = (ScriptPlayable <SpineAnimationStateBehaviour>)playable.GetInput(lastNonZeroWeightTrack - 1);
                    var fromClipData = fromClip.GetBehaviour();
                    fromAnimation = fromClipData.animationReference != null ? fromClipData.animationReference.Animation : null;
                    fromClipTime  = (float)fromClip.GetTime() * (float)fromClip.GetSpeed();
                    fromClipLoop  = fromClipData.loop;
                }

                Animation toAnimation = clipData.animationReference != null ? clipData.animationReference.Animation : null;
                float     toClipTime  = (float)inputPlayableClip.GetTime() * (float)inputPlayableClip.GetSpeed();
                float     mixDuration = clipData.mixDuration;

                if (!clipData.customDuration && fromAnimation != null && toAnimation != null)
                {
                    mixDuration = animationStateComponent.AnimationState.Data.GetMix(fromAnimation, toAnimation);
                }

                if (trackIndex == 0)
                {
                    skeleton.SetToSetupPose();
                }

                // Approximate what AnimationState might do at runtime.
                if (fromAnimation != null && mixDuration > 0 && toClipTime < mixDuration)
                {
                    dummyAnimationState = dummyAnimationState ?? new AnimationState(skeletonComponent.SkeletonDataAsset.GetAnimationStateData());

                    var  toEntry   = dummyAnimationState.GetCurrent(0);
                    var  fromEntry = toEntry != null ? toEntry.MixingFrom : null;
                    bool isAnimationTransitionMatch = (toEntry != null && toEntry.Animation == toAnimation && fromEntry != null && fromEntry.Animation == fromAnimation);

                    if (!isAnimationTransitionMatch)
                    {
                        dummyAnimationState.ClearTracks();
                        fromEntry = dummyAnimationState.SetAnimation(0, fromAnimation, fromClipLoop);
                        fromEntry.AllowImmediateQueue();
                        if (toAnimation != null)
                        {
                            toEntry = dummyAnimationState.SetAnimation(0, toAnimation, clipData.loop);
                            toEntry.HoldPrevious = clipData.holdPrevious;
                        }
                    }

                    // Update track times.
                    fromEntry.TrackTime = fromClipTime;
                    if (toEntry != null)
                    {
                        toEntry.TrackTime = toClipTime;
                        toEntry.MixTime   = toClipTime;
                    }

                    // Apply Pose
                    dummyAnimationState.Update(0);
                    dummyAnimationState.Apply(skeleton);
                }
                else
                {
                    if (toAnimation != null)
                    {
                        toAnimation.Apply(skeleton, 0, toClipTime, clipData.loop, null, 1f, MixBlend.Setup, MixDirection.In);
                    }
                }
                skeleton.UpdateWorldTransform();

                if (skeletonAnimation)
                {
                    skeletonAnimation.LateUpdate();
                }
                else if (skeletonGraphic)
                {
                    skeletonGraphic.LateUpdate();
                }
            }
            // Do nothing outside of the first clip and the last clip.
        }