unity 序列帧播放

Posted 81192

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity 序列帧播放相关的知识,希望对你有一定的参考价值。

    [SerializeField]
    private Image m_ScreenImage;             //序列帧播放的image
    [SerializeField]
    private int m_FrameRate = 30;                  // 一秒播放的帧数
    [SerializeField]
    private string m_strFolder= "";       // 序列帧通过Resource.load的加载,所以序列帧文件要放在Resource目录下,此变量为Resource下序列帧的存放目录
    [SerializeField]
    private string m_strPreName= "";    //每一序列帧文件名字相同部分,如第四十帧文件全名为9_Bumper_00040,则此处应为9_Bumper_000
    [SerializeField]
    private int m_nFromNo=0;  //开始播放帧
    [SerializeField]
    private int m_nEndNo=244;//结束帧
    [SerializeField]
    private int m_nFixLen = -1; //序列帧名字补全位数,-1为不补全,如第四十帧文件全名为9_Bumper_00040,m_strPreName为9_Bumper_000,则补全位数为2

    public void StartPlay(string id)
    {
        StartCoroutine(Play());
    }

   private IEnumerator Play()
    {int nCurrentTextureIndex = m_nFromNo;
        while (true)
        {
            // So long as the textures should be playing...
            Sprite t;
            //
            string strImagePath = "";
            string strNum = "";
            if (m_nFixLen == -1)
            {
                strNum = nCurrentTextureIndex.ToString();
            }
            else
            {
                string strFormat = "{0:";
                for (int i = 0; i < m_nFixLen; ++i)
                {
                    strFormat += "0";
                }
                strFormat += "}";
                strNum = string.Format(strFormat, nCurrentTextureIndex);
            }

            strImagePath = m_strFolder + "/" + m_strPreName + strNum;
            t = Resources.Load<Sprite>(strImagePath);
            m_ScreenImage.sprite = t;// Then increment the texture index (looping once it reaches the length of the textures array.
            //nCurrentTextureIndex = m_nFromNo + (nCurrentTextureIndex - m_nFromNo + 1) % (m_nEndNo - m_nFromNo + 1);//m_AnimTextures.Length;
            nCurrentTextureIndex++;
// Wait for the next frame.
            yield return m_FrameRateWait;
        }
    }

    void Start()
    {
        m_FrameRateWait = new WaitForSeconds(1f / m_FrameRate);
    }

 

以上是关于unity 序列帧播放的主要内容,如果未能解决你的问题,请参考以下文章

Unity 播放序列帧

unity怎么让贴图序列播放

Unity Shader播放序列帧动画

转UNITY3D 游戏开发之四有关实现2D帧序列帧播放相关—Animating Tiledtexture

跟我一起学Unity3D代码中分割图片而且载入帧序列动画

Unity 2D:创建序列帧动画