码迷,mamicode.com
首页 > 编程语言 > 详细

unity 序列帧播放

时间:2018-01-10 14:49:43      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:tco   long   loop   next   tor   trim   ima   length   tar   

    [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 序列帧播放

标签:tco   long   loop   next   tor   trim   ima   length   tar   

原文地址:https://www.cnblogs.com/llstart-new0201/p/8258429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!