Last active
September 12, 2021 16:28
-
-
Save heistak/6113350 to your computer and use it in GitHub Desktop.
MMD4Mecanimの表情制御をMMD for Unityと同じやり方(制御用GameObjectのZ位置を動かす)で出来るようにするスクリプト。
This file contains 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; | |
// Script to make MMD4Mecanim's expressions controllable like MMDforUnity's expressions. | |
// Move the Z localPosition of an expression GameObject from 0.0-1.0 to control that expression. | |
/* | |
* Instructions: | |
* 1. Copy the "Expression" GameObject (and its children) from inside a MMDforUnity-imported model to inside a MMD4Mecanim-imported model. | |
* 2. Select all the individual GameObjects for the expressions inside the "Expression" GameObject. | |
* 3. Remove the MMDSkinsScript script from all of them. | |
* 4. Apply the MMD4MecanimExpressionCompatibility script (this script) instead to all of them. | |
* 5. Run the game, and try moving the Z axis of the individual expression GameObjects. | |
* | |
* 使い方: | |
* 1. MMDforUnityでインポートしたモデルのGameObject内から、MMD4MecanimでインポートしたモデルのGameObject内へ、"Expression" GameObjectおよびその中身をコピー | |
* 2. "Expression" GameObjectの中に入っている個別の表情用GameObjectすべてをまとめて選択 | |
* 3. それらすべてにアタッチされているMMDSkinsScriptスクリプトを削除 | |
* 4. それらすべてにMMD4MecanimExpressionCompatibilityスクリプト(このスクリプト)を代わりにアタッチ | |
* 5. ゲームを実行し、表情用GameObjectのZ軸を動かしてみる | |
*/ | |
// TODO: Autogenerate the expression GameObjects in advance using Editor Scripts. | |
public class MMD4MecanimExpressionCompatibility : MonoBehaviour { | |
private MMD4MecanimExpression.Expression targetExpression = null; | |
private bool initialized = false; | |
// Initialization will run at first frame Update (after MMD4MecanimExpression's initialization and list population is done) | |
void InitExpression () { | |
initialized = true; | |
MMD4MecanimExpression expressionManager = transform.parent.parent.GetComponent<MMD4MecanimExpression>(); | |
if (expressionManager == null) { | |
return; | |
} | |
foreach (MMD4MecanimExpression.Expression activeExpression in expressionManager.expressions) { | |
if (gameObject.name == activeExpression.name) { | |
targetExpression = activeExpression; | |
break; | |
} | |
} | |
} | |
// Update is called once per frame | |
void Update () { | |
if (!initialized) { | |
InitExpression(); | |
} | |
if (targetExpression == null) { | |
return; | |
} | |
targetExpression.weight = transform.localPosition.z; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment