/
HumanManager.cs
115 lines (93 loc) · 3.35 KB
/
HumanManager.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HumanManager : MonoBehaviour {
////=============================================================================
//// Local Field
////
////=============================================================================
private Animator humanAnimator;
private Scrollbar scrollBar;
private float CALL_TIME;
public Animator HumanAnimator {
get {
return humanAnimator;
}
set {
humanAnimator = value;
}
}
public Scrollbar ScrollBar {
get {
return scrollBar;
}
set {
scrollBar = value;
}
}
////=============================================================================
//// Animation Hash
//// These are for animation.Static and Read only.
////=============================================================================
readonly static int ANI_HASH_ANGRY = Animator.StringToHash("Base Layer.Angry");
readonly static int ANI_HASH_SMILE = Animator.StringToHash("Base Layer.Smile");
////=============================================================================
//// MonoBehaviour
//// Basic function.
////=============================================================================
private void Start() {
this.InitializeComponents();
this.InitializeLocalField();
}
private void InitializeComponents() {
HumanAnimator = GetComponent<Animator>();
ScrollBar = GameObject.Find("Scrollbar").GetComponent<Scrollbar>();
}
private void InitializeLocalField() {
CALL_TIME = 1.0f;//For coroutine.
}
////=============================================================================
//// Animation
//// Operate human by animation.
////=============================================================================
public void StartSmileAimation() {
if(this.IsAnimationSmile()) {
return;
}
HumanAnimator.SetTrigger("SmileTrigger");
StartCoroutine(CallStartAngryAnimation(CALL_TIME, ScrollBar.value));
}
public void StartAngryAnimation() {
if(this.IsAnimationAngry()) {
return;
}
HumanAnimator.SetTrigger("AngryTrigger");
}
private IEnumerator CallStartAngryAnimation(float waitTime, float prevValue) {
Debug.Log("Start: CallStartAngryAnimation");
yield return new WaitForSeconds(waitTime);
//Get currentValue
float currentValue = ScrollBar.value;
//Compare the current value with the previous value
if(currentValue == prevValue) {
StartAngryAnimation();
} else {
StartCoroutine(CallStartAngryAnimation(CALL_TIME, ScrollBar.value));
}
}
private bool IsAnimationSmile() {
AnimatorStateInfo stateInfo = HumanAnimator.GetCurrentAnimatorStateInfo(0);
if(stateInfo.fullPathHash == ANI_HASH_SMILE) {
return true;
}
return false;
}
private bool IsAnimationAngry() {
AnimatorStateInfo stateInfo = HumanAnimator.GetCurrentAnimatorStateInfo(0);
if(stateInfo.fullPathHash == ANI_HASH_ANGRY) {
return true;
}
return false;
}
}