-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoBlink.cs
More file actions
140 lines (120 loc) · 3.15 KB
/
Copy pathAutoBlink.cs
File metadata and controls
140 lines (120 loc) · 3.15 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
//AutoBlink.cs
//オート目パチスクリプト
//2014/06/23 N.Kobayashi
//
using UnityEngine;
using System.Collections;
namespace UnityChan
{
public class AutoBlink : MonoBehaviour
{
public bool isActive = true; //オート目パチ有効
public SkinnedMeshRenderer ref_SMR_EYE_DEF; //EYE_DEFへの参照
public SkinnedMeshRenderer ref_SMR_EL_DEF; //EL_DEFへの参照
public float ratio_Close = 85.0f; //閉じ目ブレンドシェイプ比率
public float ratio_HalfClose = 20.0f; //半閉じ目ブレンドシェイプ比率
[HideInInspector]
public float
ratio_Open = 0.0f;
private bool timerStarted = false; //タイマースタート管理用
private bool isBlink = false; //目パチ管理用
public float timeBlink = 0.4f; //目パチの時間
private float timeRemining = 0.0f; //タイマー残り時間
public float threshold = 0.3f; // ランダム判定の閾値
public float interval = 3.0f; // ランダム判定のインターバル
enum Status
{
Close,
HalfClose,
Open //目パチの状態
}
private Status eyeStatus; //現在の目パチステータス
void Awake ()
{
//ref_SMR_EYE_DEF = GameObject.Find("EYE_DEF").GetComponent<SkinnedMeshRenderer>();
//ref_SMR_EL_DEF = GameObject.Find("EL_DEF").GetComponent<SkinnedMeshRenderer>();
}
// Use this for initialization
void Start ()
{
ResetTimer ();
// ランダム判定用関数をスタートする
StartCoroutine ("RandomChange");
}
//タイマーリセット
void ResetTimer ()
{
timeRemining = timeBlink;
timerStarted = false;
}
// Update is called once per frame
void Update ()
{
if (!timerStarted) {
eyeStatus = Status.Close;
timerStarted = true;
}
if (timerStarted) {
timeRemining -= Time.deltaTime;
if (timeRemining <= 0.0f) {
eyeStatus = Status.Open;
ResetTimer ();
} else if (timeRemining <= timeBlink * 0.3f) {
eyeStatus = Status.HalfClose;
}
}
}
void LateUpdate ()
{
if (isActive) {
if (isBlink) {
switch (eyeStatus) {
case Status.Close:
SetCloseEyes ();
break;
case Status.HalfClose:
SetHalfCloseEyes ();
break;
case Status.Open:
SetOpenEyes ();
isBlink = false;
break;
}
//Debug.Log(eyeStatus);
}
}
}
void SetCloseEyes ()
{
ref_SMR_EYE_DEF.SetBlendShapeWeight (6, ratio_Close);
ref_SMR_EL_DEF.SetBlendShapeWeight (6, ratio_Close);
}
void SetHalfCloseEyes ()
{
ref_SMR_EYE_DEF.SetBlendShapeWeight (6, ratio_HalfClose);
ref_SMR_EL_DEF.SetBlendShapeWeight (6, ratio_HalfClose);
}
void SetOpenEyes ()
{
ref_SMR_EYE_DEF.SetBlendShapeWeight (6, ratio_Open);
ref_SMR_EL_DEF.SetBlendShapeWeight (6, ratio_Open);
}
// ランダム判定用関数
IEnumerator RandomChange ()
{
// 無限ループ開始
while (true) {
//ランダム判定用シード発生
float _seed = Random.Range (0.0f, 1.0f);
if (!isBlink) {
if (_seed > threshold) {
isBlink = true;
}
}
// 次の判定までインターバルを置く
yield return new WaitForSeconds (interval);
}
}
}
}