Last active
August 29, 2015 14:01
-
-
Save hecomi/38968c5b2934eb5fa103 to your computer and use it in GitHub Desktop.
まばたきとかする MMD4M 用のヤツ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class MMD4M_Blink : MonoBehaviour | |
{ | |
private MMD4MecanimMorphHelper eyeMorph_; | |
enum BlinkState { | |
None, | |
Closing, | |
Opening | |
}; | |
private BlinkState state_ = BlinkState.None; | |
private int waitCnt_ = 0; | |
public float frequency = 0.8f; | |
public float morphSpeed = 0.1f; | |
public float maxWeight = 1.0f; | |
public string morphName = "まばたき"; | |
void Start() | |
{ | |
eyeMorph_ = gameObject.AddComponent<MMD4MecanimMorphHelper>(); | |
} | |
void Update() | |
{ | |
eyeMorph_.morphSpeed = morphSpeed; | |
eyeMorph_.morphName = morphName; | |
switch (state_) { | |
case BlinkState.None: | |
if (Random.value < frequency * Time.deltaTime) { | |
state_ = BlinkState.Closing; | |
eyeMorph_.morphWeight = maxWeight; | |
waitCnt_ = (int)(morphSpeed / Time.deltaTime);; | |
} | |
break; | |
case BlinkState.Closing: | |
if (waitCnt_ <= 0) { | |
state_ = BlinkState.Opening; | |
eyeMorph_.morphWeight = 0.0f; | |
waitCnt_ = (int)(morphSpeed / Time.deltaTime); | |
}; | |
break; | |
case BlinkState.Opening: | |
if (waitCnt_ <= 0) { | |
state_ = BlinkState.None; | |
waitCnt_ = (int)(morphSpeed / Time.deltaTime); | |
}; | |
break; | |
} | |
--waitCnt_; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment