Ejemplo n.º 1
0
    override public void PlayAnimation(string animName, bool loop = false, int layerIndex = 0)
    {
        Spine.Animation animation = _skeletonData.FindAnimation(animName);
        if (animation == null)
        {
            Debug.LogErrorFormat("'{0}' anim invalid in '{1}'", animName, gameObject.name);
            return;
        }

        _skeletonState.SetAnimation(layerIndex, animation, loop);
    }
Ejemplo n.º 2
0
    public bool DoAddQueue_AnimationContinuedly <ENUM_ANIMATION_NAME>(ENUM_ANIMATION_NAME eAnimName)
    {
        string strAnimName = eAnimName.ToString();
        bool   bSuccess    = _pSkeletonData.FindAnimation(strAnimName) != null;

        if (bSuccess)
        {
            _queueAnimationWait.Enqueue(strAnimName);
        }

        return(bSuccess);
    }
        public void PlayPauseAnimation(string animationName, bool loop)
        {
            if (skeletonAnimation == null)
            {
                Debug.LogWarning("Animation was stopped but preview doesn't exist. It's possible that the Preview Panel is closed.");
            }

            var targetAnimation = skeletonData.FindAnimation(animationName);

            if (targetAnimation != null)
            {
                var  currentTrack   = skeletonAnimation.AnimationState.GetCurrent(0);
                bool isEmpty        = (currentTrack == null);
                bool isNewAnimation = isEmpty || currentTrack.Animation != targetAnimation;

                var skeleton       = skeletonAnimation.Skeleton;
                var animationState = skeletonAnimation.AnimationState;

                if (isEmpty)
                {
                    skeleton.SetToSetupPose();
                    animationState.SetAnimation(0, targetAnimation, loop);
                }
                else
                {
                    var sameAnimation = (currentTrack.Animation == targetAnimation);
                    if (sameAnimation)
                    {
                        currentTrack.TimeScale = (currentTrack.TimeScale == 0) ? 1f : 0f;                         // pause/play
                    }
                    else
                    {
                        currentTrack.TimeScale = 1f;
                        animationState.SetAnimation(0, targetAnimation, loop);
                    }
                }

                if (isNewAnimation)
                {
                    currentAnimationEvents.Clear();
                    currentAnimationEventTimes.Clear();
                    foreach (Timeline timeline in targetAnimation.Timelines)
                    {
                        var eventTimeline = timeline as EventTimeline;
                        if (eventTimeline != null)
                        {
                            for (int i = 0; i < eventTimeline.Events.Length; i++)
                            {
                                currentAnimationEvents.Add(eventTimeline.Events[i]);
                                currentAnimationEventTimes.Add(eventTimeline.Frames[i]);
                            }
                        }
                    }
                }
            }
            else
            {
                Debug.LogFormat("Something went wrong. The Spine.Animation named '{0}' was not found.", animationName);
            }
        }
 public void EnsureInitialize(SkeletonData data)
 {
     if (animation == null && !string.IsNullOrEmpty(animationName))
     {
         animation = data.FindAnimation(animationName);
     }
 }
        //internal SpineAnimationBehaviour previous;

//		internal readonly ExposedList<int> timelineData = new ExposedList<int>();
//		internal readonly ExposedList<SpineAnimationBehaviour> timelineDipMix = new ExposedList<SpineAnimationBehaviour>();
//		internal readonly ExposedList<float> timelinesRotation = new ExposedList<float>();
//
//		internal bool HasTimeline (int id) {
//			var timelines = animation.timelines.Items;
//			for (int i = 0, n = animation.timelines.Count; i < n; i++)
//				if (timelines[i].PropertyId == id) return true;
//			return false;
//		}

        public void EnsureInitialize(SkeletonData data)
        {
            if (animation == null)
            {
                animation = data.FindAnimation(animationName);
                //this.previous = previous;
            }
        }
Ejemplo n.º 6
0
    /// <summary>
    /// 현재 플레이하는 애니메이션 이름과 재생하고자 할 애니메이션 이름이 같을 경우 안될 수 있음
    /// </summary>
    /// <typeparam name="ENUM_ANIM_NAME"></typeparam>
    /// <param name="eAnimName"></param>
    /// <returns></returns>
    public bool DoPlayAnimation <ENUM_ANIMATION_NAME>(ENUM_ANIMATION_NAME eAnimName)
    {
        string strAnimName = eAnimName.ToString();
        bool   bSuccess    = _pSkeletonData.FindAnimation(strAnimName) != null;

        if (bSuccess)
        {
            _pAnimation.AnimationName = "";
            _pAnimation.AnimationName = strAnimName;
            _pAnimation.state.Event  += State_Event;
        }

        return(bSuccess);
    }
        public void Initialize()
        {
            if (skeletonDataAsset == null)
            {
                return;
            }
            SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(AnimationReferenceAsset.QuietSkeletonData);

            this.animation = skeletonData != null?skeletonData.FindAnimation(animationName) : null;

            if (this.animation == null)
            {
                Debug.LogWarningFormat("Animation '{0}' not found in SkeletonData : {1}.", animationName, skeletonDataAsset.name);
            }
        }
Ejemplo n.º 8
0
                public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
                {
                    ScriptPlayable <SpineAnimatorPlayableBehaviour> playable = ScriptPlayable <SpineAnimatorPlayableBehaviour> .Create(graph, new SpineAnimatorPlayableBehaviour());

                    SpineAnimatorPlayableBehaviour clone = playable.GetBehaviour();

                    clone._clipAsset = this;

                    if (_animationSource != null && !string.IsNullOrEmpty(_animationId))
                    {
                        SkeletonData skeletonData = _animationSource.GetSkeletonData(false);
                        Animation    animation    = skeletonData.FindAnimation(_animationId);
                        clone._animation = animation;
                    }

                    return(playable);
                }
    private void MakeEventList()
    {
        m_eventList = new List <string>();
        if (animationName.stringValue == noneName)
        {
            eventName.stringValue            = noneName;
            targetEffectController.eventName = eventName.stringValue;
            m_eventList.Add(noneName);
            serializedObject.ApplyModifiedProperties();
            return;
        }
        Spine.Animation anim      = animationData.FindAnimation(animationName.stringValue);
        Timeline[]      timelines = anim.Timelines.Items;
        m_eventList.Add(noneName);
        for (int i = 0; i < timelines.Length; i++)
        {
            EventTimeline eventTimeline = timelines[i] as EventTimeline;

            if (eventTimeline != null)
            {
                Spine.Event[] events = eventTimeline.Events;
                for (int k = 0; k < events.Length; k++)
                {
                    string eventName = events[k].ToString();
                    if (m_eventList.Contains(eventName))
                    {
                        continue;
                    }
                    else
                    {
                        m_eventList.Add(eventName);
                    }
                    // Debug.Log(events[k].ToString());
                }
            }
        }
        if (m_eventList.Contains(eventName.stringValue))
        {
            return;
        }

        eventName.stringValue = noneName;
        serializedObject.ApplyModifiedProperties();
    }
                public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
                {
                    ScriptPlayable <Spine3DAnimatorPlayableBehaviour> playable = ScriptPlayable <Spine3DAnimatorPlayableBehaviour> .Create(graph, new Spine3DAnimatorPlayableBehaviour());

                    Spine3DAnimatorPlayableBehaviour clone = playable.GetBehaviour();

                    Spine3DAnimatorTrackMixer trackMixer = TimelineUtils.GetTrackMixer <Spine3DAnimatorTrackMixer>(graph, _parentAnimatorTrack);

                    clone._clipAsset = this;

                    if (_animationSource != null && !string.IsNullOrEmpty(_animationId))
                    {
                        SkeletonData skeletonData = _animationSource.GetSkeletonData(false);
                        Animation    animation    = skeletonData.FindAnimation(_animationId);

                        clone._animationDuration = animation != null ? animation.Duration : (float)PlayableBinding.DefaultDuration;
                        clone._animationSpeed    = _animationSpeed;

                        clone._proxyAnimation             = animation;
                        clone._proxyAnimationOrientations = _validOrientations;
                    }

                    return(playable);
                }
Ejemplo n.º 11
0
		static AnimationClip ExtractAnimation (string name, SkeletonData skeletonData, Dictionary<int, List<string>> slotLookup, bool bakeIK, SendMessageOptions eventOptions, AnimationClip clip = null) {
			var animation = skeletonData.FindAnimation(name);

			var timelines = animation.Timelines;

			if (clip == null) {
				clip = new AnimationClip();
			} else {
				clip.ClearCurves();
				AnimationUtility.SetAnimationEvents(clip, new AnimationEvent[0]);
			}

			clip.name = name;

			Skeleton skeleton = new Skeleton(skeletonData);

			List<int> ignoreRotateTimelineIndexes = new List<int>();

			if (bakeIK) {
				foreach (IkConstraint i in skeleton.IkConstraints) {
					foreach (Bone b in i.Bones) {
						int index = skeleton.FindBoneIndex(b.Data.Name);
						ignoreRotateTimelineIndexes.Add(index);
						BakeBoneConstraints(b, animation, clip);
					}
				}
			}

			foreach (Bone b in skeleton.Bones) {
				if (!b.Data.TransformMode.InheritsRotation()) {
					int index = skeleton.FindBoneIndex(b.Data.Name);

					if (ignoreRotateTimelineIndexes.Contains(index) == false) {
						ignoreRotateTimelineIndexes.Add(index);
						BakeBoneConstraints(b, animation, clip);
					}
				}
			}

			foreach (Timeline t in timelines) {
				skeleton.SetToSetupPose();

				if (t is ScaleTimeline) {
					ParseScaleTimeline(skeleton, (ScaleTimeline)t, clip);
				} else if (t is TranslateTimeline) {
					ParseTranslateTimeline(skeleton, (TranslateTimeline)t, clip);
				} else if (t is RotateTimeline) {
					//bypass any rotation keys if they're going to get baked anyway to prevent localEulerAngles vs Baked collision
					if (ignoreRotateTimelineIndexes.Contains(((RotateTimeline)t).BoneIndex) == false)
						ParseRotateTimeline(skeleton, (RotateTimeline)t, clip);
				} else if (t is AttachmentTimeline) {
					ParseAttachmentTimeline(skeleton, (AttachmentTimeline)t, slotLookup, clip);
				} else if (t is EventTimeline) {
					ParseEventTimeline((EventTimeline)t, clip, eventOptions);
				}

			}

			var settings = AnimationUtility.GetAnimationClipSettings(clip);
			settings.loopTime = true;
			settings.stopTime = Mathf.Max(clip.length, 0.001f);

			SetAnimationSettings(clip, settings);

			clip.EnsureQuaternionContinuity();

			EditorUtility.SetDirty(clip);

			return clip;
		}