- 最后登录
- 2021-7-6
- 注册时间
- 2012-12-27
- 阅读权限
- 90
- 积分
- 76145
- 纳金币
- 53488
- 精华
- 316
|
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- public class UMovie : MonoBehaviour
- {
- public int mFps = 5;//每秒多少帧
- private float mSec; //一帧所需要的时间
- private float mDelta = 0f;
- public List<Sprite> sprites = new List<Sprite>();
- private int curFrame = 0; // 当前帧
- private bool mLoop = true;
- private bool mPlay = false;
- private int mStartIndex;
- private int mEndIndex;
- private Image container;
- // Use this for initialization
- void Start ()
- {
- container = GetComponent<Image> ();
- }
- public void Play(bool IsLoop = true)
- {
- if (sprites.Count > 0)
- {
- Play (0,sprites.Count-1, IsLoop);
- }
- }
- public void Play(int Start, int EndIndex, bool IsLoop)
- {
- mStartIndex = Start;
- mEndIndex = EndIndex;
- mLoop = IsLoop;
- mSec = 1f / (mFps);
- if (container == null)
- {
- container = GetComponent<Image> ();
- }
- container.enabled = true;
- mPlay = true;
- }
- public void Stop()
- {
- mPlay = false;
- }
- // Update is called once per frame
- void Update ()
- {
- if (mPlay)
- {
- mDelta += Time.deltaTime;
- if(mDelta > mSec)
- {
- mDelta = (mSec > 0f )? mDelta - mSec: 0f;
- if(++curFrame > mEndIndex - mStartIndex)
- {
- curFrame = mStartIndex;
- mPlay = mLoop;
- }
- container.sprite = sprites[curFrame];
- }
- }
- }
- public void SetSprite(Sprite sp)
- {
- mPlay = false;
- container.sprite = sp;
- }
- public void SetEnable(bool isEnable)
- {
- container.enabled = isEnable;
- if (isEnable == false)
- mPlay = false;
- }
- }
复制代码 |
|