// Update is called once per frame void Update() { model.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); motionQueueManager.updateParam(model); eyeBlinkMotion.setParam(model); model.update(); if (GameManager.Instance.isGameOver) { return; } if ((missCui.transform.position.x - transform.position.x) < 3) { GameManager.Instance.isGameOver = true; GameManager.Instance.isCatched = true; } if (isDefeat) { transform.position = Vector3.Lerp(transform.position, initPos, 0.1f); Destroy(gameObject); } else { transform.Translate(Vector3.right * moveSpeed * Time.deltaTime); } }
// 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); }
// Update is called once per frame void Update() { live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); motionQueueManager.updateParam(live2DModel); eyeBlinkMotion.setParam(live2DModel); live2DModel.update(); if (GameManager.Instance.gameOver) { return; } //判断当前Boss是否追赶上翠花 if ((missCui.transform.position.x - transform.position.x) < 3) { GameManager.Instance.gameOver = true; } if (isDefeat) { transform.position = Vector3.Lerp(transform.position, initPos, 0.2f); } else { transform.Translate(Vector3.right * moveSpeed * Time.deltaTime); } }
void Update() { if (live2DModel == null) { load(); } live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); if (!Application.isPlaying) { live2DModel.update(); //motionManager.updateParam (live2DModel); return; } /* * var pos = Input.mousePosition; * if (Input.GetMouseButtonDown(0)) * { * // * } * else if (Input.GetMouseButton(0)) * { * dragMgr.Set(pos.x / Screen.width * 2 - 1, pos.y / Screen.height * 2 - 1); * } * else if (Input.GetMouseButtonUp(0)) * { * dragMgr.Set(0, 0); * } */ dragMgr.update(); live2DModel.setParamFloat("PARAM_ANGLE_X", dragMgr.getX() * 30); live2DModel.setParamFloat("PARAM_ANGLE_Y", dragMgr.getY() * 30); live2DModel.setParamFloat("PARAM_BODY_ANGLE_X", dragMgr.getX() * 10); live2DModel.setParamFloat("PARAM_EYE_BALL_X", -dragMgr.getX()); live2DModel.setParamFloat("PARAM_EYE_BALL_Y", -dragMgr.getY()); double timeSec = UtSystem.getUserTimeMSec() / 1000.0; double t = timeSec * 2 * Math.PI; live2DModel.setParamFloat("PARAM_BREATH", (float)(0.5f + 0.5f * Math.Sin(t / 3.0))); eyeBlink.setParam(live2DModel); if (physics != null) { physics.updateParam(live2DModel); } if (motionManager.isFinished()) { StartCoroutine(FadeModel(0, 1)); } live2DModel.update(); motionManager.updateParam(live2DModel); }
void Update() { if (live2DModel == null) { load(); } live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); if (!Application.isPlaying) { live2DModel.update(); return; } var pos = Input.mousePosition; //滑鼠左鍵壓下事件 if (Input.GetMouseButtonDown(0)) { // } else if (Input.GetMouseButton(0)) { dragMgr.Set(pos.x / Screen.width * 2 - 1, pos.y / Screen.height * 2 - 1); } else if (Input.GetMouseButtonUp(0)) { dragMgr.Set(0, 0); } dragMgr.update(); //臉部方向的調整 live2DModel.setParamFloat("PARAM_ANGLE_X", dragMgr.getX() * 30); live2DModel.setParamFloat("PARAM_ANGLE_Y", dragMgr.getY() * 30); //身體方向調整 live2DModel.setParamFloat("PARAM_BODY_ANGLE_X", dragMgr.getX() * 10); //眼睛看的方向調整 live2DModel.setParamFloat("PARAM_EYE_BALL_X", -dragMgr.getX()); live2DModel.setParamFloat("PARAM_EYE_BALL_Y", -dragMgr.getY()); double timeSec = UtSystem.getUserTimeMSec() / 1000.0; double t = timeSec * 2 * Math.PI; live2DModel.setParamFloat("PARAM_BREATH", (float)(0.5f + 0.5f * Math.Sin(t / 3.0))); eyeBlink.setParam(live2DModel); if (physics != null) { physics.updateParam(live2DModel); } live2DModel.update(); }
public void Update() { float modelWidth = live2DModel.getCanvasWidth(); //モデルのキャンバスの横幅 Matrix4x4 m1 = Matrix4x4.Ortho(0, modelWidth, modelWidth, 0, -50.0f, 50.0f); Matrix4x4 m2 = transform.localToWorldMatrix; Matrix4x4 m3 = m2 * m1; live2DModel.setMatrix(m3); //まばたきの間隔とモーションにかかる時間を設定 eyeBlink.setInterval(6000); eyeBlink.setEyeMotion(100, 100, 100); eyeBlink.setParam(live2DModel); live2DModel.update(); }
void Update() { if (live2DModel == null) { return; } live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); if (!Application.isPlaying) { live2DModel.update(); return; } double t = (UtSystem.getUserTimeMSec() / 1000.0) * 2 * Math.PI; if (Input.GetMouseButtonUp(0)) { mouthcheck = !mouthcheck; } //テキストを読み上げているか判定 if (mouthcheck) { mouth = (float)Mathf.PingPong(time += mouthspeed, 1); //口動かす } else { //徐々に口を閉じる if (mouth > 0) { mouth -= 0.1f; } } live2DModel.setParamFloat("PARAM_MOUTH_OPEN_Y", mouth); //口 live2DModel.setParamFloat("PARAM_BREATH", (float)(0.5f + 0.5f * Math.Sin(t / 3.2345)), 1); //呼吸 eyeBlink.setParam(live2DModel); //目ぱち live2DModel.update(); }
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]); }
void OnRenderObject() { if (live2DModel == null) { load(); } live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); if (!Application.isPlaying) { live2DModel.update(); live2DModel.draw(); return; } dragMgr.update(); live2DModel.setParamFloat("PARAM_ANGLE_X", dragMgr.getX() * 30); live2DModel.setParamFloat("PARAM_ANGLE_Y", dragMgr.getY() * 30); live2DModel.setParamFloat("PARAM_BODY_ANGLE_X", dragMgr.getX() * 10); live2DModel.setParamFloat("PARAM_EYE_BALL_X", -dragMgr.getX()); live2DModel.setParamFloat("PARAM_EYE_BALL_Y", -dragMgr.getY()); double timeSec = UtSystem.getUserTimeMSec() / 1000.0; double t = timeSec * 2 * Math.PI; live2DModel.setParamFloat("PARAM_BREATH", (float)(0.5f + 0.5f * Math.Sin(t / 3.0))); eyeBlink.setParam(live2DModel); if (physics != null) { physics.updateParam(live2DModel); } live2DModel.update(); live2DModel.draw(); }
// 렌더링할 때 호출된다 void OnRenderObject() { // Live2D 모델이 없으면 읽어들인다 if (m_live2DModel == null) { load(); } m_live2DModel.setMatrix(transform.localToWorldMatrix * m_live2DCanvasPos); // 만일 애플리케이션이 동작 중이 아니라면 모델을 업데이트하여 렌더링하고 돌아온다 if (!Application.isPlaying) { m_live2DModel.update(); m_live2DModel.draw(); return; } Idle(); // 아래에 있는 Idle() 함수 내용을 실행하고 여기로 돌아온다 Drag(); // 아래에 있는 Drag() 함수 내용을 실행하고 여기로 돌아온다 ※이것은 Idle()을 실행한 수에 실행해야 한다 // 눈깜박임 처리 m_eyeBlink.setParam(m_live2DModel); // 물리 연산 업데이트 if (m_physics != null) { m_physics.updateParam(m_live2DModel); } // 모델 업데이트 m_live2DModel.update(); // 모델 렌더링 m_live2DModel.draw(); }
// Update is called once per frame void Update() { //设置矩阵 当前坐标转换为世界坐标 矩阵相乘 live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); //启动api自带的update live2DModel.update(); ////启动动画管理 告诉他启动哪一个角色的动画 //motionQueueManager.updateParam(live2DModel); ////多个动作同时播放会卡一下最好不要设置相同参数 一般模型师都K好整个动作 //motionQueueManagerA.updateParam(live2DModel); expressionMotionQueueManager.updateParam(live2DModel); ////控制动画切换动作 if (Input.GetKeyDown(KeyCode.M)) { motionIndex++; if (motionIndex >= expressions.Length) { motionIndex = 0; } expressionMotionQueueManager.startMotion(expressions[motionIndex]); } ////判断待机动作 当前动作进行完毕 true //if (l2DMotionManager.isFinished()) //{ // StartMotion(0, 1); //} // if (Input.GetKeyDown(KeyCode.M)) //{ // StartMotion(14, 2); //} ////启动l2DMotionManager里的Update //l2DMotionManager.updateParam(live2DModel); //设置参数 参数id(就live2d编辑器的那个) value就是该参数值 weight权重 影响度 //live2DModel.setParamFloat("PARAM_ANGLE_X",30,weight); //if (Input.GetKeyDown(KeyCode.A)) //{ // //往之前度数加上10度 // live2DModel.addToParamFloat("PARAM_ANGLE_X", 10); //} ////之前倍数乘上这个数值 也就是正值会向右边扭头 负值控制向左扭头 就可以控制数值了 //live2DModel.multParamFloat("PARAM_ANGLE_X", 10); ////也可以通过获取索引设置参数 //int paramAngleX; //paramAngleX = live2DModel.getParamIndex("PARAM_ANGLE_X"); //live2DModel.setParamFloat(paramAngleX,30); ////参数的保存与回复 //live2DModel.setParamFloat("PARAM_ANGLE_X", 30, weight); ////保存与回复的参数是整个模型的所有参数 并不是之前同方法里的设置的几个参数 //live2DModel.saveParam(); //live2DModel.loadParam(); ////设置某一部分的透明度 //live2DModel.setPartsOpacity("PARTS_01_CLOTHES",0); //眨眼 eyeBlinkMotion.setParam(live2DModel); //后面时间按创建时间计算 类似于计时器 long time = UtSystem.getUserTimeMSec();//获取执行时间 physicsHairSideLeft.update(live2DModel, time); physicsHairSideRight.update(live2DModel, time); physicsHairBackLeft.update(live2DModel, time); physicsHairBackRight.update(live2DModel, time); //模型跟随鼠标转向与看向 //参数及时更新,考虑加速度等自然因素 计算坐标 逐渐更新 drag.update(); //获取鼠标位置 Vector3 pos = Input.mousePosition; if (Input.GetMouseButton(0)) { //转化坐标 //得到Live2D鼠标监测点的比例值-1到1(对应Live2D拖拽 //管理坐标系,或者叫影响度) //然后我们通过这个值去设置我们的参数 比如旋转30*当前的到的值 //然后按这个值所带来的影响度去影响我们的动作 //从而达到看向某一点的位置 drag.Set(pos.x / Screen.width * 2 - 1, pos.y / Screen.height * 2 - 1); } else if (Input.GetMouseButtonUp(0)) { drag.Set(0, 0); } //模型转向 if (drag.getX() != 0) { live2DModel.setParamFloat("PARAM_ANGLE_X", 30 * drag.getX()); live2DModel.setParamFloat("PARAM_ANGLE_Y", 30 * drag.getY()); live2DModel.setParamFloat("PARAM_BODY_ANGLE_X", 10 * drag.getX()); //官方给出如果取-drag.getX() 人物就会一直看你 就是屏幕中间 live2DModel.setParamFloat("PARAM_EYE_BALL_X", drag.getX()); live2DModel.setParamFloat("PARAM_EYE_BALL_Y", drag.getY()); } }
void Update() { if (live2DModel == null) { load(); } live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); if (!Application.isPlaying) { live2DModel.update(); return; } if (motionMgr.isFinished()) { motionMgr.startMotion(Live2DMotion.loadMotion(motionFiles.bytes)); } motionMgr.updateParam(live2DModel); var pos = Input.mousePosition; if (Input.GetMouseButtonDown(0)) { // } else if (Input.GetMouseButton(0)) { dragMgr.Set(pos.x / Screen.width * 2 - 1, pos.y / Screen.height * 2 - 1); } else if (Input.GetMouseButtonUp(0)) { dragMgr.Set(0, 0); } dragMgr.update(); //Debug.Log(dragMgr.getX()+"-"+dragMgr.getY()); live2DModel.setParamFloat("PARAM_ANGLE_X", dragMgr.getX() * 30); live2DModel.setParamFloat("PARAM_ANGLE_Y", dragMgr.getY() * 30); live2DModel.setParamFloat("PARAM_BODY_ANGLE_X", dragMgr.getX() * 10); live2DModel.setParamFloat("PARAM_BODY_ANGLE_Y", dragMgr.getY() * 5); live2DModel.setParamFloat("PARAM_EYE_BALL_X", dragMgr.getX()); live2DModel.setParamFloat("PARAM_EYE_BALL_Y", dragMgr.getY()); double timeSec = UtSystem.getUserTimeMSec() / 1000.0; double t = timeSec * 2 * Math.PI; live2DModel.setParamFloat("PARAM_BREATH", (float)(0.1f + 0.9f * Math.Sin(t / 3.0))); eyeBlink.setParam(live2DModel); if (physics != null) { physics.updateParam(live2DModel); } live2DModel.update(); }
void Update() { //Debug.Log(DateTime.Now); Festival(); Timer(); //base Behavior & Motion Ctrl if (live2DModel == null) { load(); } live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); if (!Application.isPlaying) { live2DModel.update(); //live2DModel.draw(); return; } //if (ВерныйAS.isPlaying) //{ // audioPlayerAS.volume = 0.1f; // //audioPlayerAS.mute = true; //} //else //{ // audioPlayerAS.volume = 1.0f; // //audioPlayerAS.mute = false; //} //每隔一段时间随机播放动画 //playTime += Time.deltaTime; //if (playTime >= playRate) //{ //if (motionMgr.isFinished()) //{ // motionMgr.startMotion(Live2DMotion.loadMotion(motionFile[UnityEngine.Random.Range(0, 4)].bytes)); // playTime = 0; //} //} var pos = Input.mousePosition; if (playTime < playRate) //计时器逻辑 { playTime += Time.deltaTime; } if (Input.GetMouseButtonDown(0))//点击随机播放动画和对应语音 { if (playTime >= playRate) { if (motionMgr.isFinished()) { audioClipID = UnityEngine.Random.Range(0, ВерныйAudioClipRandomIdle.Length); ВерныйAS.clip = ВерныйAudioClipRandomIdle[audioClipID]; ВерныйAS.Play(); cuAudioClipID = audioClipID; //获取当前随机到的声音ID //Debug.Log(cuAudioClipID); motionMgr.startMotion(Live2DMotion.loadMotion(idleMotionFile[cuAudioClipID].bytes)); //播放对应的动画 playTime -= playRate; } } } //else if (Input.GetMouseButtonDown(1)) //{ // if (motionMgr.isFinished()) // { // motionMgr.startMotion(motionBattle); // } //} else if (Input.GetMouseButton(0)) { dragMgr.Set(pos.x / Screen.width * 2 - 1, pos.y / Screen.height * 2 - 1); } else if (Input.GetMouseButtonUp(0)) { dragMgr.Set(0, 0); } dragMgr.update(); live2DModel.setParamFloat("PARAM_ANGLE_X", dragMgr.getX() * 20); live2DModel.setParamFloat("PARAM_ANGLE_Y", dragMgr.getY() * 20); live2DModel.setParamFloat("PARAM_BODY_ANGLE_X", dragMgr.getX() * 10); live2DModel.setParamFloat("PARAM_EYE_BALL_X", dragMgr.getX() * 20); live2DModel.setParamFloat("PARAM_EYE_BALL_Y", dragMgr.getY() * 20); live2DModel.setParamFloat("PARAM_ikari", dragMgr.getX()); live2DModel.setParamFloat("PARAM_ikari", dragMgr.getY()); live2DModel.setParamFloat("PARAM_HAIR_FRONT", dragMgr.getX()); live2DModel.setParamFloat("PARAM_HAIR_SIDE", dragMgr.getX()); live2DModel.setParamFloat("PARAM_HAIR_BACK", dragMgr.getX()); double timeSec = UtSystem.getUserTimeMSec() / 1000.0; double t = timeSec * 2 * Math.PI; live2DModel.setParamFloat("PARAM_BREATH", (float)(0.5f + 0.5f * Math.Sin(t / 3.0))); eyeBlink.setParam(live2DModel); if (physics != null) { physics.updateParam(live2DModel); } live2DModel.update(); if (live2DModel == null) { return; } live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); if (!Application.isPlaying) { live2DModel.update(); return; } motionMgr.updateParam(live2DModel); live2DModel.update(); OnRenderObject(); }
void Update() { // timer += Time.deltaTime; if (live2DModel == null) { load(); } live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); if (!Application.isPlaying) { live2DModel.update(); return; } // LookPlayer(); var pos = Input.mousePosition; if (Input.GetMouseButtonDown(0)) { // } else if (Input.GetMouseButton(0)) { dragMgr.Set(pos.x / Screen.width * 2 - 1, pos.y / Screen.height * 2 - 1); } else if (Input.GetMouseButtonUp(0)) { dragMgr.Set(0, 0); } dragMgr.update(); live2DModel.setParamFloat("PARAM_ANGLE_X", dragMgr.getX() * 30); live2DModel.setParamFloat("PARAM_ANGLE_Y", dragMgr.getY() * 30); //live2DModel.setParamFloat("PARAM_BODY_ANGLE_X", dragMgr.getX() * 10); //live2DModel.setParamFloat("PARAM_EYE_BALL_X", -dragMgr.getX()); //live2DModel.setParamFloat("PARAM_EYE_BALL_Y", -dragMgr.getY()); //笑い値を入れる live2DModel.setParamFloat("PARAM_SMILE", humanLaught.laught); // live2DModel.setParamFloat("PARAM_SMILE", Mathf.Abs(Mathf.Sin(timer))); //live2DModel.setParamFloat("PARAM_CRY", Mathf.Abs(Mathf.Sin(timer))); double timeSec = UtSystem.getUserTimeMSec() / 1000.0; double t = timeSec * 2 * Math.PI; //live2DModel.setParamFloat("PARAM_BREATH", (float)(0.5f + 0.5f * Math.Sin(t / 3.0))); eyeBlink.setParam(live2DModel); if (physics != null) { physics.updateParam(live2DModel); } live2DModel.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(); }
void Update() { live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); #region //if (Input.GetMouseButtonDown(0)) //{ // motionIndex++; // if (motionIndex >= motions.Length) // { // motionIndex = 0; // } // motionQueueManager.startMotion(motions[motionIndex]); //} //motionQueueManager.updateParam(live2DModel); //motionQueueManagerB.updateParam(live2DModel); //判断待机动作 //if (motionManager.isFinished()) //{ // StartMotion(0, 1); //} //else if (Input.GetKeyDown(KeyCode.Space)) //{ // StartMotion(14, 2); //} //motionManager.updateParam(live2DModel); //设置参数 // live2DModel.setParamFloat(2, 30, 1); //参数的保存与回复 整个模型的参数 //live2DModel.saveParam(); //live2DModel.loadParam(); //设定模型某一部分的透明度 //live2DModel.setPartsOpacity("PARTS_01_EYE_BALL_001", 0); #endregion //眨眼 eyeBlinkMotion.setParam(live2DModel); //获取鼠标位置 Vector3 pos = Input.mousePosition; if (Input.GetMouseButton(0)) { //通过公式转换得到live2d鼠标检测点的比例值是-1到1 //通过这个值取设置我们的参数 //按照这个值带来的影响度来影响模型动作 drag.Set(pos.x / Screen.width * 2 - 1, pos.y / Screen.height * 2 - 1); } else { drag.Set(0, 0); } drag.update(); //模型转向 if (drag.getX() != 0) { live2DModel.setParamFloat("PARAM_ANGLE_X", 30 * drag.getX()); live2DModel.setParamFloat("PARAM_ANGLE_Y", 30 * drag.getY()); live2DModel.setParamFloat("PARAM_EYE_BALL_X", drag.getX()); //取-值眼睛只盯着玩家 live2DModel.setParamFloat("PARAM_EYE_BALL_Y", drag.getY()); live2DModel.setParamFloat("PARAM_BODY_ANGLE_X", 10 * drag.getX()); } long time = UtSystem.getUserTimeMSec(); sideHairLeft.update(live2DModel, time); sideHairRight.update(live2DModel, time); backHairLeft.update(live2DModel, time); backHairRight.update(live2DModel, time); //表情使用 if (Input.GetMouseButtonDown(0)) { motionIndex++; if (motionIndex >= expressions.Length) { motionIndex = 0; } expressionManager.startMotion(expressions[motionIndex]); } expressionManager.updateParam(live2DModel); //更新模型状态 live2DModel.update(); }
// Update is called once per frame void Update() { live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); //if (Input.GetKeyDown(KeyCode.M)) //{ // motionIndex++; // if (motionIndex>=motions.Length) // { // motionIndex = 0; // } // motionQueueManager.startMotion(motions[motionIndex]); //} //motionQueueManager.updateParam(live2DModel); //motionQueueManagerA.updateParam(live2DModel); if (Input.GetKeyDown(KeyCode.M)) { motionIndex++; if (motionIndex >= expressions.Length) { motionIndex = 0; } expresionMotionQueueManager.startMotion(expressions[motionIndex]); } expresionMotionQueueManager.updateParam(live2DModel); //判断待机动作 //if (l2DMotionManager.isFinished()) //{ // StartMotion(0,1); //} //else if (Input.GetKeyDown(KeyCode.M)) //{ // StartMotion(14,2); //} //l2DMotionManager.updateParam(live2DModel); //设置参数 //live2DModel.setParamFloat("PARAM_ANGLE_X",1); //if (Input.GetKeyDown(KeyCode.A)) //{ // live2DModel.addToParamFloat("PARAM_ANGLE_X", a); //} //live2DModel.multParamFloat("PARAM_ANGLE_X", a); ////也可以通过获取索引去设置参数 //int paramAngleX; //paramAngleX = live2DModel.getParamIndex("PARAM_ANGLE_X"); //live2DModel.setParamFloat(paramAngleX,30); ////参数的保存与回复 //live2DModel.setParamFloat("PARAM_ANGLE_X", 30); ////保存与回复的参数是整个模型的所有参数,并不只是之前同方法里设置的某几个参数 //live2DModel.saveParam(); //live2DModel.loadParam(); //设定模型某一部分的不透明度。 //live2DModel.setPartsOpacity("PARTS_01_FACE_001", 0); //模型跟随鼠标转向与看向 //得到的Live2d鼠标检测点的比例值是-1到1(对应一个live2d拖拽 //管理坐标系,或者叫做影响度。) //然后我们通过这个值去设置我们的参数,比如旋转30度*当前得到的值 //就会按照这个值所带来的影响度去影响我们的模型动作 //从而到达看向某一个点的位置 Vector3 pos = Input.mousePosition;//屏幕坐标 if (Input.GetMouseButton(0)) { drag.Set(pos.x / Screen.width * 2 - 1, pos.y / Screen.height * 2 - 1); } else if (Input.GetMouseButtonUp(0)) { drag.Set(0, 0); } //参数及时更新,考虑加速度等自然因素,计算坐标,进行逐帧更新。 drag.update(); //模型转向 if (drag.getX() != 0) { live2DModel.setParamFloat("PARAM_ANGLE_X", 30 * drag.getX()); live2DModel.setParamFloat("PARAM_ANGLE_Y", 30 * drag.getY()); 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()); } //眨眼 eyeBlinkMotion.setParam(live2DModel); long time = UtSystem.getUserTimeMSec();//执行时间 physicsHairSideLeft.update(live2DModel, time); physicsHairSideRight.update(live2DModel, time); physicsHairBackLeft.update(live2DModel, time); physicsHairBackRight.update(live2DModel, time); live2DModel.update(); }
void Update() { if (live2DModel == null) { load(); } live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos); if (!Application.isPlaying) { live2DModel.update(); return; } while (client.Count() > 0) { meanindex = (meanindex + 1) % mean_size; string jsonLine = client.Receive().Split('\n')[0]; var json = MiniJSON.Json.Deserialize(jsonLine) as Dictionary <string, object>; Debug.Log(jsonLine); if (json == null) { continue; } Debug.Log(json["AcX"].GetType() + "type of json"); Debug.Log(json["AcX"]); acX = (Int64)json["AcX"] / AccRatio; acY = (Int64)json["AcY"] / AccRatio; acZ = (Int64)json["AcZ"] / AccRatio; _lastGyX[meanindex] = ((Int64)json["GyX"]); _lastGyY[meanindex] = ((Int64)json["GyY"]); _lastGyZ[meanindex] = ((Int64)json["GyZ"]); gyX = gyY = gyZ = 0.0f; for (var i = 0; i < mean_size; i++) { gyX += _lastGyX[i]; gyY += _lastGyY[i]; gyY += _lastGyY[i]; } gyX = gyX / GyroRatio; gyY = gyY / GyroRatio; gyZ = gyZ / GyroRatio; Debug.LogFormat("{0} {1} {2} {3} {4} {5}", acX, acY, acZ, gyX, gyY, gyZ); break; } live2DModel.setParamFloat("PARAM_ANGLE_X", acX); // head panning : value range -30.0 to 30.0 (degree) live2DModel.setParamFloat("PARAM_ANGLE_Y", acY); // head banking back and forth : -30 to 30 live2DModel.setParamFloat("PARAM_BODY_ANGLE_X", acZ); // body angle sideway : -30.0 to 30.0 live2DModel.setParamFloat("PARAM_EYE_L_OPEN", gyX + 0.5f); // 0 to 1 live2DModel.setParamFloat("PARAM_EYE_R_OPEN", gyX + 0.5f); // live2DModel.setParamFloat("PARAM_BROW_L_Y", gyX); // -1.0 to 1.0 live2DModel.setParamFloat("PARAM_BROW_R_Y", gyX); // live2DModel.setParamFloat("PARAM_MOUTH_OPEN_Y", gyY + 0.5f); // 0 to 1.0 live2DModel.setParamFloat("PARAM_MOUTH_FORM", gyZ); // -1.0 to 1.0 live2DModel.setParamFloat("PARAM_BREATH", 1); eyeBlink.setParam(live2DModel); if (physics != null) { physics.updateParam(live2DModel); } live2DModel.update(); }