Unityにて実行時のモーション再生につきまして
はじめて質問させていただきます。
Unity実行時(そして実行中のモーションの切替時)に、モーションが1フレーム目からではなく、デフォルトの状態(モデラーで設定したモデルの初期状態)からモーションの1フレーム目に遷移してからモーションの再生がはじまってしまいます。
実行時即モーションの1フレーム目から開始する方法はないでしょうか。
ちなみに、コードは下記です。
こちらで実行すると、実行時にモデルの初期状態→モーションの1フレーム目から再生となり、またクリック毎に「前モーション→デフォルトの状態→次のモーション」というふうに遷移してしまいます(この間にあるデフォルトの状態をなくしたい)。
コードに何か問題がありますでしょうか?(mtnファイルが問題?)
public class main : MonoBehaviour {
public TextAsset mocFile;
public Texture2D[] textures;
public TextAsset[] mtnFiles; // mtnファイル
private Live2DModelUnity live2DModel;
private Live2DMotion motion; // Live2Dモーションクラス
private MotionQueueManager motionManager; // モーション管理クラス
int suuti;
void Start () {
Live2D.init ();
live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);
live2DModel.setTexture(0, textures[0]);
motion = Live2DMotion.loadMotion( mtnFiles[ 0 ].bytes );
motion.setLoop( true );
motionManager = new MotionQueueManager();
motionManager.startMotion( motion, false );
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonUp(0)){
suuti++;
if(suuti>=4){
suuti=0;
}
live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);
live2DModel.setTexture(0, textures[0]);
motion = Live2DMotion.loadMotion( mtnFiles[suuti].bytes );
motion.setLoop( true );
motionManager = new MotionQueueManager();
motionManager.startMotion( motion, false );
}
}
void OnRenderObject()
{
Matrix4x4 m1=Matrix4x4.Ortho(-200.0f, 200.0f,200.0f,-200.0f,-0.5f,0.5f);
Matrix4x4 m2 = transform.localToWorldMatrix;
Matrix4x4 m3 = m2*m1;
live2DModel.setMatrix(m3);
motionManager.updateParam( live2DModel );
live2DModel.update();
live2DModel.draw();
}
}
以上、よろしくお願い致します。
Unity実行時(そして実行中のモーションの切替時)に、モーションが1フレーム目からではなく、デフォルトの状態(モデラーで設定したモデルの初期状態)からモーションの1フレーム目に遷移してからモーションの再生がはじまってしまいます。
実行時即モーションの1フレーム目から開始する方法はないでしょうか。
ちなみに、コードは下記です。
こちらで実行すると、実行時にモデルの初期状態→モーションの1フレーム目から再生となり、またクリック毎に「前モーション→デフォルトの状態→次のモーション」というふうに遷移してしまいます(この間にあるデフォルトの状態をなくしたい)。
コードに何か問題がありますでしょうか?(mtnファイルが問題?)
public class main : MonoBehaviour {
public TextAsset mocFile;
public Texture2D[] textures;
public TextAsset[] mtnFiles; // mtnファイル
private Live2DModelUnity live2DModel;
private Live2DMotion motion; // Live2Dモーションクラス
private MotionQueueManager motionManager; // モーション管理クラス
int suuti;
void Start () {
Live2D.init ();
live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);
live2DModel.setTexture(0, textures[0]);
motion = Live2DMotion.loadMotion( mtnFiles[ 0 ].bytes );
motion.setLoop( true );
motionManager = new MotionQueueManager();
motionManager.startMotion( motion, false );
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonUp(0)){
suuti++;
if(suuti>=4){
suuti=0;
}
live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);
live2DModel.setTexture(0, textures[0]);
motion = Live2DMotion.loadMotion( mtnFiles[suuti].bytes );
motion.setLoop( true );
motionManager = new MotionQueueManager();
motionManager.startMotion( motion, false );
}
}
void OnRenderObject()
{
Matrix4x4 m1=Matrix4x4.Ortho(-200.0f, 200.0f,200.0f,-200.0f,-0.5f,0.5f);
Matrix4x4 m2 = transform.localToWorldMatrix;
Matrix4x4 m3 = m2*m1;
live2DModel.setMatrix(m3);
motionManager.updateParam( live2DModel );
live2DModel.update();
live2DModel.draw();
}
}
以上、よろしくお願い致します。
0
コメント
>motion.setLoop( true );
のすぐ下で、
motion.setFadeIn (0);
motion.setFadeOut (0);
を設定してみてください。
setFadeIn()、setFadeOut()でゆるやかに移り変わる時間を0にしてやることで、最初から最後まで再生しているモーションの値に設定されるようになります。
既に回答がありますが前にブログに書いたので参考にどうぞ!
Live2DMotionクラスのフェードアウト初期値