• 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);
        }
  • 相关阅读:
    线段拟合(带拉格朗日乘子,HGL)
    工作到位的标准
    Git的简单使用
    位移
    java日期格式化(util包下转成sql包下)
    java中继承的概念
    工作流驳回到指定连线节点上
    年终个人总结
    实现多条件查询 匹配数据库字段中多个数据
    activiti和SSH项目做整合
  • 原文地址:https://www.cnblogs.com/llstart-new0201/p/8258429.html
Copyright © 2020-2023  润新知