qtp test Codejock Xtreme Suite control

2023-01-21   ES  

Saying a guide, in fact, I want to vomit. Essence Essence
The official library document is really spicy chicken. Its explanation documents look at the writing well, and the results are outdated. Most of the API mentioned in it can not be found at all!

official document:http://zh.esotericsoftware.com/spine-unity

But we have to use it, so we need to turn it over it and find the API that can really be called. It is recommended to see it here, so that we can at least have a certain understanding of its architectural ideas. Convenient to quickly analyze itZhen.apiWhat is used to do ~

below a single -channel animation control script. People can wave their hands, or turn their heads, and cover the low -level animation with high -level channels)

using UnityEngine;
using Spine.Unity;
using Spine;

/// <summary>
///Single channel spine assistant
/// </summary>
public class SingleTrackSpineHelper
{
    public GameObject gameObject;
    public Transform transform;

    /// <summary>
    ///Current channel
    /// </summary>
    public int currentTrack = 0;

    // Bone animation objects
    private SkeletonAnimation _skeletonAnimation;
    // channel entity
    private TrackEntry _trackEntry;

    /// <summary>
    ///Construction
    /// </summary>
    public SingleTrackSpineHelper(GameObject gameObject)
    {
        this.gameObject = gameObject;
        this.transform = this.gameObject.transform;

        _skeletonAnimation = this.gameObject.GetComponent<SkeletonAnimation>();
    }

    /// <summary>
    ///stop
    /// </summary>
    public void Stop()
    {
        _skeletonAnimation.state.ClearTrack(currentTrack);
    }

    /// <summary>
    ///Play according to time
    /// </summary>
    /// <param name="animationName">Animation name</param>
    /// <param name="loop">true = cycle, false = single</param>
    /// <param name="fromTime">Start time (unit seconds)</param>
    /// <param name="toTime">End time (unit seconds)</param>
    public TrackEntry PlayByTime(string animationName, bool loop = false, float fromTime = -1, float toTime = -1)
    {
        this.Stop();

        _trackEntry = _skeletonAnimation.state.SetAnimation(currentTrack, animationName, loop);

        if (fromTime >= 0)
        {
            _trackEntry.TrackTime = fromTime;
        }
        if (toTime >= 0)
        {
            _trackEntry.TrackEnd = toTime;
        }

        return _trackEntry;
    }
    /// <summary>
    ///Play according to the number of frames
    /// </summary>
    /// <param name="animationName">Animation name</param>
    /// <param name="loop">true = cycle, false = single</param>
    /// <param name="fromFrame">Start frame</param>
    /// <param name="toFrame">Ending frame</param>
    public TrackEntry PlayByFrame(string animationName, bool loop = false, int fromFrame = -1, int toFrame = -1)
    {
        float fromTime = -1;
        if (fromFrame >= 0)
        {
            fromTime = (float)fromFrame / SpineConst.FRAME_UNIT;
        }

        float toTime = -1;
        if (toFrame >= 0)
        {
            toTime = (float)toFrame / SpineConst.FRAME_UNIT;
        }

        return this.PlayByTime(animationName, loop, fromTime, toTime);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="animationName"></param>
    /// <param name="loop"></param>
    /// <returns></returns>
    public TrackEntry Play(string animationName, bool loop = false)
    {
        return this.PlayByTime(animationName, loop, -1, -1);
    }
}

If we just broadcast simple animations, this small control script for packaging is enough.
_skeletonAnimation.stateThis is the main method for us to get the current animation and play animation. If there is a document, it will not be cumbersome.

When we interrupted an animation in the middle and let it start, we must think of this as soon as possible:
_skeletonAnimation.state.SetAnimation(currentTrack, animationName, loop);
Ran Goose, it is not used for eggs. Simply adjust it like this, you will find that the animation will pull back from the current place, and the animation will not play it at all. This is not the result we want.

The correct approach should be used first
_skeletonAnimation.state.ClearTrack(currentTrack);
to stop the currently running channel, and then play this animation again. At this time, you find that the animation really starts, instead of pulling it back. Essence Essence

and when we only need to play a certain animation on the timeline, it is not the official method at all, but we need to use it
_trackEntry.TrackTimeand_trackEntry.TrackEndThese two methods, they control the start and end of the animation under the current channel!

These methods are actually methods we often need in the project, but the goose official has a lot of useless API descriptions. Essence Essence

PS:
I hope this article is helpful to you without being blindfolded by Spine’s official documentation.
The official is really big. Is it really okay to write such a document?

source

Related Posts

qt Multi -thread programming object thread and function execution thread

Elgamal encryption algorithm

H5 Implementation picture upload case

$ .ajax 2.0 Error “Uncaught Typerror: Illegal Invocation” Calla

qtp test Codejock Xtreme Suite control

Random Posts

Use spark, ANSJ segmentation to perform frequent statistics

[HDU 1269] Lysaka Castle Strong Connect

Maven project uses log4j configuration output log pengyao

IOS development III controller use and custom label barbar The concept of

MySQL8.0.26 Installation Tutorial (Super Simple)