-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathAnimationControl.cs
More file actions
99 lines (83 loc) · 2.4 KB
/
AnimationControl.cs
File metadata and controls
99 lines (83 loc) · 2.4 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using UnityEngine;
using UnityEngine.UI;
using System.Text.RegularExpressions;
using System.Collections.Generic;
public class AnimationControl : MonoBehaviour
{
[SerializeField]
string[] animationNames;
[SerializeField]
Text animationNameText;
[SerializeField]
RuntimeAnimatorController[] animationContoller;
int animationNumber = 0;
int playingAnimationNumber = 0;
void Start()
{
SetText();
SetAnimator();
PlayAnimation();
}
void SetText()
{
animationNameText.text = animationNames[animationNumber];
}
void SetAnimator()
{
List<Transform> lists = new List<Transform>();
for (int i = 0; i < transform.childCount; i++)
{
lists.Add(transform.GetChild(i));
}
for (int j = 0; j < lists.Count; j++)
{
for (int i = 0; i < lists.Count - 1; i++)
{
Transform temp = null;
int num1 = GetNumFromText(lists[i].name);
int num2 = GetNumFromText(lists[i + 1].name);
if (num1 > num2)
{
temp = lists[i];
lists[i] = lists[i + 1];
lists[i + 1] = temp;
}
}
}
for (int i = 0; i < lists.Count; i++)
{
lists[i].GetComponent<Animator>().runtimeAnimatorController = animationContoller[i];
}
Debug.Log(lists[0].name);
}
void PlayAnimation()
{
Animator[] animators = GetComponentsInChildren<Animator>();
foreach (Animator anim in animators)
{
anim.SetBool(animationNames[playingAnimationNumber], false);
anim.SetBool(animationNames[animationNumber], true);
}
Debug.Log(animationNames[playingAnimationNumber]);
playingAnimationNumber = animationNumber;
}
public void OnButtonNext()
{
animationNumber++;
if (animationNumber > animationNames.Length - 1) animationNumber = 0;
SetText();
PlayAnimation();
}
public void OnButtonBack()
{
animationNumber--;
if (animationNumber < 0) animationNumber = animationNames.Length - 1;
SetText();
PlayAnimation();
}
int GetNumFromText(string text)
{
Regex re = new Regex(@"[^0-9]");
return int.Parse(re.Replace(text, ""));
}
}