blob: e2c4495dfd30db6b3d06faf38fe842f6c1e920ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// by chai
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace TweenAnimation
{
public class TweenController : MonoBehaviour
{
public bool autoPlayOnEnable;
public string defaultAnimation;
public List<TweenAnimation> animations;
private string m_Current;
private TweenAnimation m_CurrentAnimation;
private float m_StartTime;
public void OnEnable()
{
if(autoPlayOnEnable)
{
PlayAnimation(defaultAnimation);
}
}
public void PlayAnimation(string name)
{
m_Current = name;
m_CurrentAnimation = null;
for (int i = 0; i < animations.Count; ++i)
{
if(animations[i].name == name)
{
m_CurrentAnimation = animations[i];
break;
}
}
if(m_CurrentAnimation == null)
{
Debug.LogError("No such animation'" + name + "'");
}
else
{
m_CurrentAnimation.BeforePlay();
}
m_StartTime = Time.time;
}
private void Update()
{
if (m_CurrentAnimation == null)
return;
float t = Time.time;
m_CurrentAnimation.Process(t - m_StartTime);
}
}
}
|