示例#1
0
    void Update()
    {
        live2dModel.setMatrix(transform.localToWorldMatrix * live2dCanvasPos);
        if (l2dMotionManager.isFinished())
        {
            StartMotion(0, 1);
        }
        else if (Input.GetKeyDown(KeyCode.Space))
        {
            StartMotion(14, 2);
        }
        l2dMotionManager.updateParam(live2dModel);

        Vector3 pos = Input.mousePosition;

        drag.Set(pos.x / Screen.width * 2 - 1, pos.y / Screen.height * 2 - 1);
        live2dModel.setParamFloat("PARAM_ANGLE_X", 30 * drag.getX());
        live2dModel.setParamFloat("PARAM_BODY_ANGLE_X", 10 * drag.getX());
        live2dModel.setParamFloat("PARAM_EYE_BALL_X", -drag.getX());
        live2dModel.setParamFloat("PARAM_EYE_BALL_Y", -drag.getY());
        drag.update();

        long time = UtSystem.getUserTimeMSec();

        physicHairSide.update(live2dModel, time);
        if (Input.GetKeyDown(KeyCode.Space))
        {
            motionIndex = (motionIndex + 1 >= expressionMotions.Length ? 0 : motionIndex + 1);
            //expressionMotions[motionIndex].setLoop(true);
            motionQueueManager.startMotion(expressionMotions[motionIndex]);
        }
        motionQueueManager.updateParam(live2dModel);
        live2dModel.update();
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        live2DMode.setMatrix(transform.localToWorldMatrix * transformMar);
        motionManager.updateParam(live2DMode);

        Vector3 mousePos = Input.mousePosition;

        if (Input.GetMouseButton(0))
        {
            dragEff.Set(mousePos.x / Screen.width * 2 - 1, mousePos.y / Screen.height * 2 - 1);
        }

        if (Input.GetMouseButtonUp(0))
        {
            dragEff.Set(0, 0);
        }
        dragEff.update();
        if (dragEff.getX() != 0 && dragEff.getY() != 0)
        {
            live2DMode.setParamFloat("PARAM_ANGLE_X", dragEff.getX() * 30);
            live2DMode.setParamFloat("PARAM_ANGLE_Y", dragEff.getY() * 30);
            live2DMode.setParamFloat("PARAM_EYE_BALL_X", -dragEff.getX());
            live2DMode.setParamFloat("PARAM_EYE_BALL_Y", -dragEff.getY());
            live2DMode.setParamFloat("PARAM_BODY_ANGLE_X", 10 * dragEff.getX());
            live2DMode.setParamFloat("PARAM_BODY_ANGLE_Y", 10 * dragEff.getY());
        }
        live2DMode.update();
    }
    void LateUpdate()
    {
        //모션이 끝남
        //모션을 1회 재생했을 때 해당 모션이 완전이 재생되고 종료되었는지는 isFinished 메소드로 체크 가능.
        if (l2dMotionManager.isFinished())
        {
            if (enableAnimationForIdle)
            {
                //idle 애니메이션을 재생하길 원하는 경우
                //기본 모션으로 바꿔준다.
                //l2dMotionManager.startMotion(motionDataManager.GetLiveMotion("IDLE"));
                StartIdleMotion();
                //isBreath = false;
            }
            else
            {
                //모션이 끝나긴 했는데, IDLE 애니메이션을 루프재생 하길 원치 않은 경우
                if (breathMotion != null)
                {
                    //숨쉬기 모션이 있으면 모션이 끝났을때, 모션의 마지막 프레임 자세를 간직한체 그 위에 숨쉬는 모습을 덧칠해줌.
                    l2dMotionManager.startMotion(breathMotion_, false);
                    isBreath = true;
                }
            }
        }


        if (isBreath)
        {
            l2dEyeBlink.updateParam(model);
        }


        //모션 매니저들이 자신들이 가진 모션의 속성들로 모델을 갱신
        l2dMotionManager.updateParam(model);
        l2dExpressioNMotionManager.updateParam(model);

        //만약 캐릭터가 말하는 중이면 입모양 움직여 주세요. 먼저 립싱크값 갱신
        SetLipSync();
        //그 다음에 갱신된 립싱크 값으로 입에 해당하는 속성의 값을 갱신합니다.
        model.setParamFloat(L2DStandardID.PARAM_MOUTH_OPEN_Y, lipSyncValue, 0.7f);


        l2dPhysics.updateParam(model);
        //포즈 업데이트
        l2dPose.updateParam(model);

        //그리고 최종 갱신.
        model.update();
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        int motionIndex = 0;

        // 根据返回的情感指数,在对应情感动作中随机选取
        if (ChatWithTuling.flag == true)
        {
            rate = ChatWithTuling.rate;
            // 积极动作
            if (rate > 0.5)
            {
                motionIndex = optimisticIndex[getRandomIndex(optimisticIndex.Length)];
            }
            // 消极动作
            else if (rate < 0)
            {
                motionIndex = pessimisticIndex[getRandomIndex(pessimisticIndex.Length)];
            }
            // 中立动作
            else
            {
                motionIndex = neutralIndex[getRandomIndex(neutralIndex.Length)];
            }

            print("rate: " + rate + ", motionIndex: " + motionIndex);

            ChatWithTuling.flag = false;
        }


        //为模型设置用于显示的画布,后面是2个矩阵相乘
        live2DModel.setMatrix(transform.localToWorldMatrix * live2DCancasPos);

        //设置物理过程,更新模型的参数
        physics.updateParam(live2DModel);

        //设置眨眼动作,设置模型的参数
        eyeBlinkMotion.setParam(live2DModel);

        //按M键切换动作并播放声音
        if (motionManager.isFinished())                         //动作完成,切换到默认的动作
        {
            motionManager.startMotionPrio(motions[0], 1);       //默认的动作的优先级为1,数值较高,优先级较大
        }
        // 展示特定情绪的动作
        else if (motionIndex != 0)
        {
            motionManager.startMotionPrio(motions[motionIndex], 2);     //新动作的优先级为2
        }

        ////按M键切换动作并播放声音
        //if (motionManager.isFinished())                         //动作完成,切换到默认的动作
        //{
        //    motionManager.startMotionPrio(motions[0], 1);       //默认的动作的优先级为1,数值较高,优先级较大
        //}
        //else if (Input.GetKeyDown(KeyCode.M))
        //{
        //    motionManager.startMotionPrio(motions[motionIndex], 2);     //新动作的优先级为2
        //    //motionIndex++;

        //    print("motion index: " + motionIndex + "\n");

        //    if (motionIndex >= motions.Length)
        //    {
        //        motionIndex = 0;
        //    }


        //    //播放声音
        //    audioSource.clip = audioClips[audioIndex];
        //    audioSource.Play();

        //    audioIndex++;
        //    if (audioIndex >= audioClips.Length)
        //    {
        //        audioIndex = 0;
        //    }

        //}
        motionManager.updateParam(live2DModel);             //设置了动作后,更新模型的参数

        //表情的动作是一直保持的
        if (Input.GetKeyDown(KeyCode.E))
        {
            expressionManager.startMotion(expressions[expressionIndex]);

            print("expression index: " + expressionIndex + "\n");

            expressionIndex++;
            if (expressionIndex >= expressionFiles.Length)
            {
                expressionIndex = 0;
            }
        }
        expressionManager.updateParam(live2DModel);

        Vector3 mousePos = Input.mousePosition;         //获得鼠标的坐标

        //更新模型参数,使模型随着鼠标运动
        l2DTargetPoint.Set(mousePos.x / Screen.width * 2 - 1, mousePos.y / Screen.height * 2 - 1);      //将鼠标坐标缩放到[-1, 1],然后存储到l2DTargetPoint中
        l2DTargetPoint.update();

        //从l2DTargetPoint中取出坐标,用于更新模型的参数
        live2DModel.setParamFloat("PARAM_ANGLE_X", l2DTargetPoint.getX() * 30);
        live2DModel.setParamFloat("PARAM_ANGLE_Y", l2DTargetPoint.getY() * 30);
        live2DModel.setParamFloat("PARAM_BODY_ANGLE_X", l2DTargetPoint.getX() * 10);
        //live2DModel.setParamFloat("PARAM_BODY_ANGLE_Y", l2DTargetPoint.getY() * 10);
        live2DModel.setParamFloat("PARAM_EYE_BALL_X", l2DTargetPoint.getX());
        live2DModel.setParamFloat("PARAM_EYE_BALL_Y", l2DTargetPoint.getY());

        //更新模型的参数,放在Updat()函数后面
        live2DModel.update();
    }