-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimationHandler.cs
71 lines (62 loc) · 1.88 KB
/
AnimationHandler.cs
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
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Assets.Scripts
{
public class AnimationHandler
{
private int[][] animationArray;
private int[] frameCounts;
private double frame;
public float frameRate = 9;
public AnimationHandler(params int[] frameCounts)
{
frame = 0.0;
this.frameCounts = frameCounts;
generateAnimationArray();
}
private void generateAnimationArray()
{
animationArray = new int[frameCounts.Length][];
int flag = 0;
for (int i = 0; i < frameCounts.Length; i++)
{
animationArray[i] = new int[frameCounts[i]];
for (int j = 0; j < animationArray[i].Length; j++)
animationArray[i][j] = flag++;
}
}
public double stepAnimation(int currState, UnityEngine.Animator anim)
{
anim.speed = frameRate * UnityEngine.Time.deltaTime;
if (Data.Paused)
anim.speed = 0;
checkFrameOverFlow(currState);
setAnimationFrame(anim, currState);
incrementFrame();
return frame;
}
private void checkFrameOverFlow(int currState)
{
if (frame >= frameCounts[currState])
frame = 0;
}
private void incrementFrame()
{
frame += UnityEngine.Time.deltaTime * frameRate;
}
private void setAnimationFrame(UnityEngine.Animator anim, int currState)
{
anim.SetInteger("frame", animationArray[currState][(int)frame]);
}
public double resetFrame()
{
return frame = 0;
}
public bool isDone(int state)
{
return frame >= frameCounts[state];
}
}
}