Exemplo n.º 1
0
        public void load()
        {
            if (mocFile != null)
            {
                live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);

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

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

            if (physicsFile != null)
            {
                physics = L2DPhysics.load(physicsFile.bytes);
            }

            if (poseFile != null)
            {
                pose = L2DPose.load(poseFile.bytes);
            }
        }
Exemplo n.º 2
0
    void load()
    {
        // .moc.bytes 파일을 불러와서 설정한다
        m_live2DModel = Live2DModelUnity.loadModel(m_mocFile.bytes);

        // 텍스쳐 파일 수만큼 읽어들여 설정한다
        for (int i = 0; i < m_textureFiles.Length; i++)
        {
            m_live2DModel.setTexture(i, m_textureFiles[i]);
        }

        // 캔버스 준비
        float modelWidth = m_live2DModel.getCanvasWidth();

        m_live2DCanvasPos = Matrix4x4.Ortho(0, modelWidth, modelWidth, 0, -50.0f, 50.0f);

        // 물리 설정 파일이 비어 있으면 불러온다
        if (m_physicsFile != null)
        {
            m_physics = L2DPhysics.load(m_physicsFile.bytes);
        }

        // 모션 관리용 변수를 준비한다
        m_motionMgr = new MotionQueueManager();

        // 메션 파일 수만큼 모션 관리용 배열을 확보한다
        m_motions = new Live2DMotion[m_motionFiles.Length];
        // 모션 파일 수만큼 모션을 읽어들인다
        for (int i = 0; i < m_motionFiles.Length; i++)
        {
            m_motions[i] = Live2DMotion.loadMotion(m_motionFiles[i].bytes);
        }
    }
    void load()
    {
        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);

        if (physicsFile != null)
        {
            physics = L2DPhysics.load(physicsFile.bytes);
        }

        motionMgr    = new MotionQueueManager();
        motionBattle = Live2DMotion.loadMotion(idleMotionFile[0].bytes);
        motionPort   = Live2DMotion.loadMotion(idleMotionFile[1].bytes);
        motionSecret = Live2DMotion.loadMotion(idleMotionFile[2].bytes);
        //motionLoop = Live2DMotion.loadMotion(motionFile[3].bytes);
        //motionВерныйOne = Live2DMotion.loadMotion(motionFile[4].bytes);
        //motionВерныйNewYear = Live2DMotion.loadMotion(motionFile[5].bytes);
        //motionTwoHour = Live2DMotion.loadMotion(motionFile[6].bytes);
    }
Exemplo n.º 4
0
 public void setPhysicsFileFromBytes(byte[] bytes)
 {
     if (bytes.Length != 0)
     {
         physics = L2DPhysics.load(bytes);
     }
 }
Exemplo n.º 5
0
    void load()
    {
        live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);

        // モーションのインスタンスの作成(mtnの読み込み)と設定
        motionAppeal = Live2DMotion.loadMotion(mtnFiles[0].bytes);
        motionAppeal.setFadeOut(5000);
        motionAppeal.setLoop(this.isMotionLoop);

        motionManager = new MotionQueueManager();        //モーション管理クラスの作成.
        //play
        motionManager.startMotion(motionAppeal, true);

        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);

        if (physicsFile != null)
        {
            physics = L2DPhysics.load(physicsFile.bytes);
        }
    }
Exemplo n.º 6
0
        /// <summary>
        /// JSON 파일로 간편하게 물리를 불러옵니다.
        /// </summary>
        /// <param name="path">물리 구성을 포함한 JSON 파일입니다.</param>
        /// <returns></returns>
        public static L2DPhysics[] LoadPhysics(string path)
        {
            List <L2DPhysics> physicsList = new List <L2DPhysics>();
            JObject           jsonObject  = JObject.Parse(File.ReadAllText(path));

            foreach (JObject json in jsonObject["physics_hair"])
            {
                L2DPhysics physics = new L2DPhysics();
                L2DPhysics.PhysicsSetup physicsSetup = new L2DPhysics.PhysicsSetup
                {
                    length = json["setup"]["length"].Value <float>(),
                    regist = json["setup"]["regist"].Value <float>(),
                    mass   = json["setup"]["mass"].Value <float>()
                };
                physics.Setup = physicsSetup;

                List <L2DPhysics.PhysicsSource> sourceList = new List <L2DPhysics.PhysicsSource>();
                foreach (JObject source in json["src"])
                {
                    L2DPhysics.PhysicsSource physicsSource = new L2DPhysics.PhysicsSource
                    {
                        id     = source["id"].Value <string>(),
                        ptype  = source["ptype"].Value <string>(),
                        scale  = source["scale"].Value <float>(),
                        weight = source["weight"].Value <float>()
                    };
                    sourceList.Add(physicsSource);
                }
                physics.Sources = sourceList.ToArray();

                List <L2DPhysics.PhysicsTargets> targetList = new List <L2DPhysics.PhysicsTargets>();
                foreach (JObject target in json["targets"])
                {
                    L2DPhysics.PhysicsTargets physicsTargets = new L2DPhysics.PhysicsTargets
                    {
                        id     = target["id"].Value <string>(),
                        ptype  = target["ptype"].Value <string>(),
                        scale  = target["scale"].Value <float>(),
                        weight = target["weight"].Value <float>()
                    };
                    targetList.Add(physicsTargets);
                }
                physics.Targets = targetList.ToArray();

                physicsList.Add(physics);
            }

            return(physicsList.ToArray());
        }
Exemplo n.º 7
0
 public void loadPhysics(string fileName)
 {
     if (fileName == null)
     {
         return;
     }
     if (LAppDefine.DEBUG_LOG)
     {
         Debug.Log("Load json : " + fileName);
     }
     try
     {
         TextAsset ta    = (TextAsset)(FileManager.open(fileName) as TextAsset);
         byte[]    bytes = ta.bytes;
         char[]    buf   = System.Text.Encoding.GetEncoding("UTF-8").GetString(bytes).ToCharArray();
         physics = L2DPhysics.load(buf);
     }
     catch (IOException e)
     {
         Debug.Log(e.StackTrace);
     }
 }
Exemplo n.º 8
0
    void load()
    {
        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);

        if (physicsFile != null)
        {
            physics = L2DPhysics.load(physicsFile.bytes);
        }
        if (motionMgr == null)
        {
            motionMgr = new MotionQueueManager();
        }
    }
Exemplo n.º 9
0
    void load()
    {
        //讀取model資料
        live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);

        for (int i = 0; i < textureFiles.Length; i++)
        {
            //將texture與model關聯起來
            live2DModel.setTexture(i, textureFiles[i]);
        }

        //指定live2dmodel的描繪位置
        float modelWidth = live2DModel.getCanvasWidth();

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

        //載入物理運算檔
        if (physicsFile != null)
        {
            physics = L2DPhysics.load(physicsFile.bytes);
        }
    }
Exemplo n.º 10
0
 //加载物理文件
 private void LoadPhysics()
 {
     physics = L2DPhysics.load(physicsFile.bytes);
     print("物理文件加载成功!");
 }
    void Awake()
    {
        chVoice = GetComponent <AudioSource> ();
        //  myRender = gameObject.GetComponentInChildren<MeshRenderer> ();

        lipSyncValue = 0f;

        //초기화 페이즈//


        Live2D.init();

        //json 파일 불러와서 속성 값들 리스트로 뽑아 옴
        model = Live2DModelUnity.loadModel(mocData.bytes);

        //모션 데이터 할당
        motionDataManager = GetComponent <MotionDataManager> ();


        //만약 숨쉬는 모션이 있으면
        if (breathMotion != null)
        {
            breathMotion_ = Live2DMotion.loadMotion(breathMotion.bytes);
        }


        //텍스쳐 세팅
        for (int i = 0; i < textureList.Length; i++)
        {
            model.setTexture(i, textureList [i]);
        }


        // 포즈 파일은 필수적인 것은 아님.
        if (poseData)
        {
            l2dPose = L2DPose.load(poseData.bytes);
        }

        if (physicsData)
        {
            l2dPhysics = L2DPhysics.load(physicsData.bytes);
        }


        //모션을 식별할때 이 스크립트는 string을 사용했지만 enum을 쓰든 뭘 쓰든 모션 식별자로 뭘 써도 무방.



        //아까 초기화한 모델의 가로 사이즈 받아옴.
        var width = model.getCanvasWidth();


        //캔버스 지정
        canvasMatrix = Matrix4x4.Ortho(0.0f, width, width, 0.0f, -50.0f, 50.0f);


        //모션 매니저들 할당. 사실 얘들은 모션들의 우선순위를 정해주는 등의 역할이 있으나 복잡해서 거의 안쓴다.
        //주 역활은 자기가 가지고 있는 주모션 하나를 모델 인스턴스에 적용해주는 것.
        //얘들에게 모션을 주고 여러 설정자들로 모션의 속성들을 설정해줄 수 있다. 그외에 우선순위를 정해주고 등등 기능 있으나 자주 안쓰임.
        //모션 매니저에 현재 모션을 지정해준다고 모델의 모션이 업데이트되지 않는다.
        //반드시 L2D매니저.UpdateParam(모델 인스턴스) 를 호출해줘야 모델 인스턴스의 움직임이 갱신됨.


        l2dMotionManager           = new L2DMotionManager();
        l2dExpressioNMotionManager = new L2DMotionManager();

        //모션 재생 시작


        //모델의 모션 업데이트
        l2dPose.updateParam(model);

        transformCache = transform;
    }
Exemplo n.º 12
0
    /// <summary>
    /// JSONを読み込む
    /// </summary>
    void Json_Read()
    {
        // model.jsonを読み込む
        char[] buf  = modelJson.text.ToCharArray();
        Value  json = Json.parseFromBytes(buf);


        // モデルを読み込む
        mocFile = new TextAsset();
        string live2Dpath = "Live2D/";

        mocFile = (Resources.Load(live2Dpath + json.get("model").toString(), typeof(TextAsset)) as TextAsset);
        Debug.Log(live2Dpath + json.get("model").toString());
        live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);

        // テクスチャを読み込む
        int texture_num = json.get("textures").getVector(null).Count;

        textures = new Texture2D[texture_num];

        for (int i = 0; i < texture_num; i++)
        {
            // 不要な拡張子を削除
            string texturenm = Regex.Replace(json.get("textures").get(i).toString(), ".png$", "");
            textures[i] = (Resources.Load(live2Dpath + texturenm, typeof(Texture2D)) as Texture2D);
            live2DModel.setTexture(i, textures[i]);
        }

        // モーションの配下のキーを取得
        Dictionary <string, Value> motion_keys = json.get("motions").getMap(null);
        int mtn_tag = 0;
        int mtn_num = 0;

        string[] motion_tags = new string[motion_keys.Count];

        // 読込モーションファイル数カウント用
        foreach (var mtnkey in motion_keys)
        {
            // motions配下のキーを取得
            motion_tags[mtn_tag] = mtnkey.Key.ToString();
            // 読み込むモーションファイル数を取得
            mtn_num += json.get("motions").get(motion_tags[mtn_tag]).getVector(null).Count;
            mtn_tag++;
        }
        // インスタンス化
        mtnFiles     = new TextAsset[mtn_num];
        soundFiles   = new AudioClip[mtn_num];
        mtnFadeines  = new int[mtn_num];
        mtnFadeoutes = new int[mtn_num];

        mtn_tag = 0;
        mtn_num = 0;
        // モーションファイル数分JSON読込
        foreach (var mtnkey in motion_keys)
        {
            // モーションとサウンドを読み込む(motions配下のタグを読み込む)
            Value motionPaths = json.get("motions").get(motion_tags[mtn_tag]);
            int   motionNum   = motionPaths.getVector(null).Count;

            for (int m = 0; m < motionNum; m++)
            {
                mtnFiles[mtn_num] = (Resources.Load(live2Dpath + motionPaths.get(m).get("file").toString()) as TextAsset);
                // サウンドファイルがあれば入れる
                if (motionPaths.get(m).getMap(null).ContainsKey("sound"))
                {
                    // 不要な拡張子を削除
                    string soundnm = Regex.Replace(Regex.Replace(motionPaths.get(m).get("sound").toString(), ".mp3$", ""), ".wav$", "");
                    soundFiles[mtn_num] = (Resources.Load(live2Dpath + soundnm, typeof(AudioClip)) as AudioClip);
                }
                //フェードイン
                if (motionPaths.get(m).getMap(null).ContainsKey("fade_in"))
                {
                    mtnFadeines[mtn_num] = int.Parse(motionPaths.get(m).get("fade_in").toString());
                }
                //フェードアウト
                if (motionPaths.get(m).getMap(null).ContainsKey("fade_out"))
                {
                    mtnFadeoutes[mtn_num] = int.Parse(motionPaths.get(m).get("fade_out").toString());
                }
                mtn_num++;
            }
            mtn_tag++;
        }

        // ポーズファイルを読み込む
        if (json.getMap(null).ContainsKey("pose"))
        {
            Value posepath = json.get("pose");
            poseFile = new TextAsset();
            poseFile = (Resources.Load(live2Dpath + posepath.toString(), typeof(TextAsset)) as TextAsset);
            // pose.jsonを読み込む
            char[] posebuf = poseFile.text.ToCharArray();
            // パーツ切り替えクラスへ渡す
            pose = L2DPose.load(posebuf);
        }

        // 物理演算ファイルを読み込む
        if (json.getMap(null).ContainsKey("physics"))
        {
            Value physicpath = json.get("physics");
            physicsFile = new TextAsset();
            physicsFile = (Resources.Load(live2Dpath + physicpath.toString(), typeof(TextAsset)) as TextAsset);
            // physics.jsonを読み込む
            char[] physicsbuf = physicsFile.text.ToCharArray();
            // 物理演算クラスへ渡す
            physics = L2DPhysics.load(physicsbuf);
        }
    }
Exemplo n.º 13
0
    /**
     * JSONファイルから読み込み
     * 仕様についてはマニュアル参照。JSONスキーマの形式の仕様がある。
     * @param buf
     * @return
     */
    public static L2DPhysics load(char[] buf)
    {
        L2DPhysics ret = new L2DPhysics();

        Value json = Json.parseFromBytes(buf);

        //物理演算一覧
        List <Value> params_  = json.get("physics_hair").getVector(null);
        int          paramNum = params_.Count;

        for (int i = 0; i < paramNum; i++)
        {
            Value param = params_[i];

            PhysicsHair physics = new PhysicsHair();
            //計算の設定
            Value setup = param.get("setup");
            //長さ
            float length = setup.get("length").toFloat();
            //空気抵抗
            float resist = setup.get("regist").toFloat();
            //質量
            float mass = setup.get("mass").toFloat();
            physics.setup(length, resist, mass);

            //元パラメータの設定
            List <Value> srcList = param.get("src").getVector(null);
            int          srcNum  = srcList.Count;
            for (int j = 0; j < srcNum; j++)
            {
                Value           src     = srcList[j];
                string          id      = src.get("id").toString();  //param ID
                PhysicsHair.Src type    = PhysicsHair.Src.SRC_TO_X;
                string          typeStr = src.get("ptype").toString();
                if (typeStr == "x")
                {
                    type = PhysicsHair.Src.SRC_TO_X;
                }
                else if (typeStr == "y")
                {
                    type = PhysicsHair.Src.SRC_TO_Y;
                }
                else if (typeStr == "angle")
                {
                    type = PhysicsHair.Src.SRC_TO_G_ANGLE;
                }
                else
                {
                    UtDebug.error("live2d", "物理演算の設定で無効なパラメータが指定されました。PhysicsHair.Src");
                }

                float scale  = src.get("scale").toFloat();
                float weight = src.get("weight").toFloat();
                physics.addSrcParam(type, id, scale, weight);
            }

            //対象パラメータの設定
            List <Value> targetList = param.get("targets").getVector(null);
            int          targetNum  = targetList.Count;
            for (int j = 0; j < targetNum; j++)
            {
                Value              target  = targetList[j];
                string             id      = target.get("id").toString();//param ID
                PhysicsHair.Target type    = PhysicsHair.Target.TARGET_FROM_ANGLE;
                string             typeStr = target.get("ptype").toString();
                if (typeStr == "angle")
                {
                    type = PhysicsHair.Target.TARGET_FROM_ANGLE;
                }
                else if (typeStr == "angle_v")
                {
                    type = PhysicsHair.Target.TARGET_FROM_ANGLE_V;
                }
                else
                {
                    UtDebug.error("live2d", "物理演算の設定で無効なパラメータが指定されました。PhysicsHair.Target");
                }

                float scale  = target.get("scale").toFloat();
                float weight = target.get("weight").toFloat();
                physics.addTargetParam(type, id, scale, weight);
            }
            ret.addParam(physics);
        }

        return(ret);
    }