Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Please limit one question/topic per post.
Please provide the following details depending on types of question

▼ For question regarding Editor, please provide:
- Live2D Software Version: (e.g. Cubism Editor 3.1.02, Euclid Editor 1.2.02)
- OS & Version: (e.g. Windows 10, macOS HighSierra)
- PC Model: (e.g. MacBookPro 2017)
- Graphics Specifications: (e.g. GeForce GTX 950M)
- Memory: (e.g. 8GB)
- Illustration Software used: (e.g. Photoshop, ClipStudio, SAI)
- Attach screenshot or capture video to show your problem:
---------------------------
▼ For question regarding SDK, please provide:
- For us to reproduce the issue you wish to inquire about, please provide either a minimum project file which has the issue. or specific instructions on how to reproduce the issue.
- Types and version of Cubism SDK you are using.
---------------------------
▼ For question regarding Cubism Software License,
For issues related to purchasing, your order, license key, and subscription, please contact us via contact form:
https://www.live2d.jp/eng/contact/

How to apply motions

Hi, how can i apply the motions using unity? the idle, and the other motions. how to play it in unity? Thanks :)
Tagged:

Comments

  • Hi makeyerrmove,

    You can see this page on how to apply motions in general.
    http://sites.cybernoids.jp/cubism_e/sdk_tutorial/live2d_library/load_to_play_motion/set_motion

    As for instructions specific to Unity, see below SimpleModel.cs, and in here I put English translation in parentheses next to relevant Japanese instructions.


    -------------------------
    SimpleModel.cs

    using UnityEngine;
    using System;
    using System.IO;
    using System.Collections;
    using live2d;

    [ExecuteInEditMode]
    public class SimpleModel: MonoBehaviour
    {
    private Live2DModelUnity live2DModel;
    private Live2DMotion motion; // motion data
    private MotionQueueManager motionMgr; // モーションの再生を管理するクラス (class for running motions)

    private Matrix4x4 live2DCanvasPos;

    public TextAsset mocFile ;
    public Texture2D[] textureFiles ;
    public TextAsset motionFile; // .mtn file

    void Start ()
    {
    Live2D.init();

    live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);

    for (int i = 0; i < textureFiles.Length; i++)
    {
    live2DModel.setTexture(i, textureFiles[i]);
    }

    float modelWidth = live2DModel.getCanvasWidth();
    live2DCanvasPos = Matrix4x4.Ortho(0, modelWidth, modelWidth, 0, -50.0f, 50.0f);

    motionMgr = new MotionQueueManager(); // モーション管理クラスのインスタンスを作成
    motion = Live2DMotion.loadMotion(motionFile.bytes); // .mtnファイルからモーションの読み込み (Creates a new instance for motion control class.)
    }


    void OnRenderObject()
    {
    if (live2DModel == null) return;
    live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos);

    if ( ! Application.isPlaying)
    {
    live2DModel.update();
    live2DModel.draw();
    return;
    }

    if (motionMgr.isFinished())
    {
    // モーションの再生が終わっていれば(再生中でなければ)再生を開始する (Starts running a motion (unless the motion hasn’t finished playback).)
    motionMgr.startMotion(motion);
    }

    motionMgr.updateParam(live2DModel); // モーションによるパラメータの更新をモデルに反映(Feed back parameter updated by a motion to model.)

    live2DModel.update();
    live2DModel.draw();
    }
    }
Sign In or Register to comment.