예제 #1
0
    public virtual void initModel()
    {
        mainMotionManager = new L2DMotionManager();
        expressionManager = new L2DMotionManager();

        motions     = new Dictionary <string, AMotion>();
        expressions = new Dictionary <string, AMotion>();
    }
예제 #2
0
    public L2DBaseModel()
    {
        //モーションマネージャーを作成
        mainMotionManager = new L2DMotionManager();        //MotionQueueManagerクラスからの継承なので、使い方は同一
        expressionManager = new L2DMotionManager();

        motions     = new Dictionary <string, AMotion>();
        expressions = new Dictionary <string, AMotion>();
    }
예제 #3
0
    void Start()
    {
        //初始化环境
        Live2D.init();
        //string path = Application.dataPath + "/Resources/Epsilon/runtime/Epsilon.moc";
        //Live2DModelUnity.loadModel(path);
        //加载模型文件
        live2dModel = Live2DModelUnity.loadModel(modelTxt.bytes);
        for (int i = 0; i < texture2d.Length; i++)
        {
            live2dModel.setTexture(i, texture2d[i]);
        }
        float modelWidth = live2dModel.getCanvasWidth();

        live2dCanvasPos = Matrix4x4.Ortho(0, modelWidth, modelWidth, 0, -50, 50);

        //加载模型动作文件
        motions = new Live2DMotion[motionTxt.Length];
        for (int i = 0; i < motions.Length; i++)
        {
            motions[i] = Live2DMotion.loadMotion(motionTxt[i].bytes);
        }
        l2dMotionManager = new L2DMotionManager();

        expressionMotions = new L2DExpressionMotion[expressionTxt.Length];
        for (int i = 0; i < expressionMotions.Length; i++)
        {
            expressionMotions[i] = L2DExpressionMotion.loadJson(expressionTxt[i].bytes);
        }

        eyeBlinkMotion = new EyeBlinkMotion();
        eyeBlinkMotion.setParam(live2dModel);
        drag           = new L2DTargetPoint();
        physicHairBack = new PhysicsHair();
        physicHairSide = new PhysicsHair();
        physicHairSide.setup(0.2f, 0.5f, 0.14f);
        PhysicsHair.Src srcX = PhysicsHair.Src.SRC_TO_X;                  //横向摇摆
        physicHairSide.addSrcParam(srcX, "PARAM_ANGLE_X", 0.005f, 1);
        PhysicsHair.Target target = PhysicsHair.Target.TARGET_FROM_ANGLE; //表现形式
        physicHairSide.addTargetParam(target, "PARAM_HAIR_SIDE_L", 0.005f, 1);

        //motions[0].setLoop(true);
        motionQueueManager = new MotionQueueManager();
        //motionQueueManager.startMotion(motions[0]);
    }
예제 #4
0
    void Start()
    {
        //初始化
        Live2D.init();

        //读取模型
        //Live2DModelUnity.loadModel(Application.dataPath+"/Resources/Epsilon/runtime/Epsilon.moc");

        //第二种读取形式
        //TextAsset mocFile = Resources.Load<TextAsset>("Epsilon/runtime/Epsilon.moc");
        live2DModel = Live2DModelUnity.loadModel(modelFile.bytes);
        #region
        //与贴图建立关联
        //Texture2D texture2D1 = Resources.Load<Texture2D>("Epsilon/runtime/Epsilon.1024/texture_00");
        //Texture2D texture2D2 = Resources.Load<Texture2D>("Epsilon/runtime/Epsilon.1024/texture_01");
        //Texture2D texture2D3 = Resources.Load<Texture2D>("Epsilon/runtime/Epsilon.1024/texture_02");

        //live2DModel.setTexture(0,texture2D1);
        //live2DModel.setTexture(1,texture2D2);
        //live2DModel.setTexture(2,texture2D3);
        #endregion
        for (int i = 0; i < textures.Length; i++)
        {
            live2DModel.setTexture(i, textures[i]);
        }

        //指定显示位置与尺寸
        float modelWidth = live2DModel.getCanvasWidth();

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

        //播放动作
        //实例化动作
        //live2DMotionIdle = Live2DMotion.loadMotion(Application.dataPath + "/Resources/Epsilon/runtime/motions/Epsilon_idle_01");
        motions = new Live2DMotion[motionFiles.Length];
        for (int i = 0; i < motionFiles.Length; i++)
        {
            motions[i] = Live2DMotion.loadMotion(motionFiles[i].bytes);
        }
        #region
        //设置某一动画的一些属性
        //重复播放不淡入
        motions[0].setLoopFadeIn(false);
        motions[0].setFadeOut(1000);//毫秒
        motions[0].setFadeIn(1000);
        motions[0].setLoop(true);

        //motionQueueManager = new MotionQueueManager();
        //motionQueueManager.startMotion(motions[motionIndex]);

        //motions[5].setLoop(true);
        //motionQueueManagerB = new MotionQueueManager();
        //motionQueueManagerB.startMotion(motions[5]);
        #endregion

        //动作优先级使用
        motionManager = new L2DMotionManager();

        //眨眼
        eyeBlinkMotion = new EyeBlinkMotion();

        drag = new L2DTargetPoint();
        #region 头发物理效果处理
        sideHairLeft  = new PhysicsHair();
        sideHairRight = new PhysicsHair();
        backHairLeft  = new PhysicsHair();
        backHairRight = new PhysicsHair();

        //套用物理运算
        sideHairLeft.setup(0.2f, 0.5f, 0.14f);
        sideHairRight.setup(0.2f, 0.5f, 0.14f);
        PhysicsHair.Src srcX = PhysicsHair.Src.SRC_TO_X;//横向摇摆
        PhysicsHair.Src srcZ = PhysicsHair.Src.SRC_TO_G_ANGLE;

        sideHairLeft.addSrcParam(srcX, "PARAM_ANGLE_X", 0.005f, 1);
        sideHairRight.addSrcParam(srcX, "PARAM_ANGLE_X", 0.005f, 1);

        backHairLeft.setup(0.24f, 0.5f, 0.18f);
        backHairRight.setup(0.24f, 0.5f, 0.18f);

        backHairLeft.addSrcParam(srcX, "PARAM_ANGLE_X", 0.005f, 1);
        backHairLeft.addSrcParam(srcZ, "PARAM_ANGLE_Z", 0.8f, 1);
        backHairRight.addSrcParam(srcX, "PARAM_ANGLE_X", 0.005f, 1);
        backHairRight.addSrcParam(srcZ, "PARAM_ANGLE_Z", 0.8f, 1);

        //设置输出表现
        PhysicsHair.Target target = PhysicsHair.Target.TARGET_FROM_ANGLE;
        sideHairLeft.addTargetParam(target, "PARAM_HAIR_SIDE_L", 0.005f, 1);
        sideHairRight.addTargetParam(target, "PARAM_HAIR_SIDE_R", 0.005f, 1);
        backHairLeft.addTargetParam(target, "PARAM_HAIR_BACK_L", 0.005f, 1);
        backHairRight.addTargetParam(target, "PARAM_HAIR_BACK_R", 0.005f, 1);
        #endregion

        //表情
        expressionManager = new MotionQueueManager();
        expressions       = new L2DExpressionMotion[expressionFiles.Length];
        for (int i = 0; i < expressionFiles.Length; i++)
        {
            expressions[i] = L2DExpressionMotion.loadJson(expressionFiles[i].bytes);
        }
    }
예제 #5
0
    // Use this for initialization
    void Start()
    {
        //初始化
        Live2D.init();

        //释放
        //Live2D.dispose();

        //读取模型
        //Live2DModelUnity.loadModel(Application.dataPath+ "/Resources/Epsilon/runtime/Epsilon.moc");
        //TextAsset mocFile = Resources.Load<TextAsset>("Epsilon/runtime/Epsilon.moc");

        live2DModel = Live2DModelUnity.loadModel(modelFile.bytes);

        //与贴图建立关联
        //Texture2D texture2D1 = Resources.Load<Texture2D>("Epsilon/runtime/Epsilon.1024/texture_00");
        //Texture2D texture2D2 = Resources.Load<Texture2D>("Epsilon/runtime/Epsilon.1024/texture_01");
        //Texture2D texture2D3 = Resources.Load<Texture2D>("Epsilon/runtime/Epsilon.1024/texture_02");
        //live2DModel.setTexture(0,texture2D1);
        //live2DModel.setTexture(1, texture2D2);
        //live2DModel.setTexture(2, texture2D3);
        for (int i = 0; i < textures.Length; i++)
        {
            live2DModel.setTexture(i, textures[i]);
        }

        //指定显示位置与尺寸(使用正交矩阵与相关API显示图像,再由游戏物体的位置和摄像机的size调整图像到合适的位置)
        float modelWidth = live2DModel.getCanvasWidth();

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

        //播放动作
        //实例化动作对象
        //live2DMontionIdle = Live2DMotion.loadMotion(Application.dataPath+"");
        //TextAsset mtnFile = Resources.Load<TextAsset>("");
        //live2DMontionIdle= Live2DMotion.loadMotion(mtnFile.bytes);
        motions = new Live2DMotion[motionFiles.Length];
        for (int i = 0; i < motions.Length; i++)
        {
            motions[i] = Live2DMotion.loadMotion(motionFiles[i].bytes);
        }
        //设置某一个动画的一些属性
        //重复播放不淡入。
        motions[0].setLoopFadeIn(false);
        //设置淡入淡出时间,参数单位为毫秒
        motions[0].setFadeOut(1000);
        motions[0].setFadeIn(1000);
        //动画是否循环播放
        //motions[0].setLoop(true);

        //motionQueueManager = new MotionQueueManager();
        //motionQueueManager.startMotion(motions[0]);

        ////播放多个动作
        //motions[5].setLoop(true);

        //motionQueueManagerA = new MotionQueueManager();
        //motionQueueManagerA.startMotion(motions[5]);

        //动作的优先级使用
        l2DMotionManager = new L2DMotionManager();

        //眨眼
        eyeBlinkMotion = new EyeBlinkMotion();

        //鼠标拖拽
        drag = new L2DTargetPoint();


        #region 左右两侧头发的摇摆
        //左测旁边的头发
        physicsHairSideLeft = new PhysicsHair();
        //套用物理运算
        physicsHairSideLeft.setup(0.2f,   // 长度 : 单位是公尺 影响摇摆周期(快慢)
                                  0.5f,   // 空气阻力 : 可设定0~1的值、预设值是0.5 影响摇摆衰減的速度
                                  0.14f); // 质量 : 单位是kg 
        //设置输入参数
        //设置哪一个部分变动时进行哪一种物理运算
        PhysicsHair.Src srcXLeft = PhysicsHair.Src.SRC_TO_X;//横向摇摆

        //第三个参数,"PARAM_ANGLE_X"变动时头发受到0.005倍的影响度的输入参数
        physicsHairSideLeft.addSrcParam(srcXLeft, "PARAM_ANGLE_X", 0.005f, 1);

        //设置输出表现
        PhysicsHair.Target target = PhysicsHair.Target.TARGET_FROM_ANGLE;//表现形式

        physicsHairSideLeft.addTargetParam(target, "PARAM_HAIR_SIDE_L", 0.005f, 1);


        //右侧旁边的头发
        physicsHairSideRight = new PhysicsHair();
        //套用物理运算
        physicsHairSideRight.setup(0.2f,   // 长度 : 单位是公尺 影响摇摆周期(快慢)
                                   0.5f,   // 空气阻力 : 可设定0~1的值、预设值是0.5 影响摇摆衰減的速度
                                   0.14f); // 质量 : 单位是kg 
        //设置输入参数
        //设置哪一个部分变动时进行哪一种物理运算
        PhysicsHair.Src srcXRight = PhysicsHair.Src.SRC_TO_X;//横向摇摆
        //PhysicsHair.Src srcXRight = PhysicsHair.Src.SRC_TO_Y;

        //第三个参数,"PARAM_ANGLE_X"变动时头发受到0.005倍的影响度的输入参数
        physicsHairSideRight.addSrcParam(srcXRight, "PARAM_ANGLE_X", 0.005f, 1);

        //设置输出表现
        PhysicsHair.Target targetRight = PhysicsHair.Target.TARGET_FROM_ANGLE;//表现形式

        physicsHairSideRight.addTargetParam(targetRight, "PARAM_HAIR_SIDE_R", 0.005f, 1);

        #endregion

        #region 左右后边头发的摇摆
        //左边
        physicsHairBackLeft = new PhysicsHair();
        physicsHairBackLeft.setup(0.24f, 0.5f, 0.18f);

        PhysicsHair.Src srcXBackLeft = PhysicsHair.Src.SRC_TO_X;
        PhysicsHair.Src srcZBackLeft = PhysicsHair.Src.SRC_TO_G_ANGLE;

        physicsHairBackLeft.addSrcParam(srcXBackLeft, "PARAM_ANGLE_X", 0.005f, 1);
        physicsHairBackLeft.addSrcParam(srcZBackLeft, "PARAM_ANGLE_Z", 0.8f, 1);

        PhysicsHair.Target targetBackLeft = PhysicsHair.Target.TARGET_FROM_ANGLE;

        physicsHairBackLeft.addTargetParam(targetBackLeft, "PARAM_HAIR_BACK_L", 0.005f, 1);

        //右边
        physicsHairBackRight = new PhysicsHair();
        physicsHairBackRight.setup(0.24f, 0.5f, 0.18f);

        PhysicsHair.Src srcXBackRight = PhysicsHair.Src.SRC_TO_X;
        PhysicsHair.Src srcZBackRight = PhysicsHair.Src.SRC_TO_G_ANGLE;

        physicsHairBackRight.addSrcParam(srcXBackRight, "PARAM_ANGLE_X", 0.005f, 1);
        physicsHairBackRight.addSrcParam(srcZBackRight, "PARAM_ANGLE_Z", 0.8f, 1);

        PhysicsHair.Target targetBackRight = PhysicsHair.Target.TARGET_FROM_ANGLE;

        physicsHairBackRight.addTargetParam(targetBackRight, "PARAM_HAIR_BACK_R", 0.005f, 1);

        #endregion

        //表情
        expresionMotionQueueManager = new MotionQueueManager();
        expressions = new L2DExpressionMotion[expressionFiles.Length];
        for (int i = 0; i < expressions.Length; i++)
        {
            expressions[i] = L2DExpressionMotion.loadJson(expressionFiles[i].bytes);
        }
    }
    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;
    }