// Use this for initialization void Start() { Live2D.init(); //Live2DModelUnity asset = Live2DModelUnity.loadModel(Application.dataPath + "/Resources/Epsilon/runtime/Epsilon.moc"); live2DMode = Live2DModelUnity.loadModel(textAst.bytes); for (int i = 0; i < textures.Length; i++) { live2DMode.setTexture(i, textures[i]); } float canvasWidth = live2DMode.getCanvasWidth(); transformMar = Matrix4x4.Ortho(0, canvasWidth, canvasWidth, 0, -50, 50); motions = new Live2DMotion[motionFile.Length]; for (int i = 0; i < motions.Length; i++) { motions[i] = Live2DMotion.loadMotion(motionFile[i].bytes); } motions[0].setLoopFadeIn(true); motions[0].setLoop(true); motionManager.startMotion(motions[0]); //眨眼 eyeBlink.setParam(live2DMode); }
private void StartMotion(int index, int priority) { if (l2dMotionManager.getCurrentPriority() >= priority) { return; } l2dMotionManager.startMotion(motions[index]); }
void StartMotion(int motionIndex, int priority) { //当前优先级 如果当前优先级比较大就不播放了 if (l2DMotionManager.getCurrentPriority() >= priority) { return; } l2DMotionManager.startMotion(motions[motionIndex]); }
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(); }
// 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(); }
public void SetExpression(L2DExpressionMotion rawExpressionData) { rawExpressionData.setFadeIn(motionFadeSpeed); rawExpressionData.setFadeOut(motionFadeSpeed); l2dExpressioNMotionManager.startMotion(rawExpressionData, false); }