Exemplo n.º 1
0
    void Update()
    {
        // 마우스 커서 좌표 가져오기
        var pos = Input.mousePosition;

        if (Input.GetMouseButtonDown(0))
        {
            // 마우스 왼쪽 버튼이 눌린 순간에 실행할 처리를 여기에 기술한다
        }
        // 눌린 순간은 아니지만 마우스 왼쪽 버튼이 눌린 상태(드래그 중)
        else if (Input.GetMouseButton(0))
        {
            // 계산한 좌표를 드래그 관리용 변수에 넣는다
            m_dragMgr.Set(pos.x / Screen.width * 2 - 1, pos.y / Screen.height * 2 - 1);
        }
        // 마우스 왼쪽 버튼이 눌린 순간
        else if (Input.GetMouseButtonUp(0))
        {
            // 드래그 관리용 변수에 (0,0)을 넣는다
            m_dragMgr.Set(0, 0);
        }

        // 임의의 모션을 Z키로 재생한다
        if (Input.GetKeyDown(KeyCode.Z))
        {
            m_motionMgr.startMotion(m_motions[2]);
        }
    }
Exemplo n.º 2
0
    public void ani(int num)
    {
        switch (num)
        {
        case 0:    //대기
            motion = Live2DMotion.loadMotion(mtnFiles[num].bytes);
            motion.setLoop(true);
            motionManager.startMotion(motion, false);
            break;

        case 1:    //공격
            motion = Live2DMotion.loadMotion(mtnFiles[num].bytes);
            motionManager.startMotion(motion, false);
            break;

        case 2:    //죽음
            motion = Live2DMotion.loadMotion(mtnFiles[num].bytes);
            motionManager.startMotion(motion, false);
            break;

        case 3:    //방어
            motion = Live2DMotion.loadMotion(mtnFiles[num].bytes);
            motionManager.startMotion(motion, false);
            break;

        case 4:    //점프공격
            motion = Live2DMotion.loadMotion(mtnFiles[num].bytes);
            motionManager.startMotion(motion, false);
            break;
        }
    }
Exemplo n.º 3
0
    private IEnumerator Routine_Main()
    {
        while (true)
        {
            while (true)
            {
                if (live2DModel == null)
                {
                    break;
                }
                live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos);

                if (!Application.isPlaying)
                {
                    live2DModel.update();
                    break;
                }

                if (motionMgr.isFinished() || main != _State)
                {
                    //歩き
                    if (_State == EnemyState.Walk)
                    {
                        motionMgr.startMotion(motions[0]);
                    }
                }

                if (main != _State)
                {
                    //噛みつき
                    if (_State == EnemyState.Attack)
                    {
                        motionMgr.startMotion(motions[1]);
                    }
                    //怯み
                    else if (_State == EnemyState.Stop)
                    {
                        motionMgr.startMotion(motions[2]);
                    }
                    //停止
                    if (_State == EnemyState.Wait)
                    {
                        motionMgr.startMotion(motions[3]);
                    }
                }

                main = _State;

                motionMgr.updateParam(live2DModel);
                live2DModel.update();
                live2DModel.draw();

                yield return(null);
            }
            yield return(null);
        }
    }
Exemplo n.º 4
0
    IEnumerator Attack()
    {
        while (true)
        {
            yield return(new WaitForSeconds(2));

            motionMgr.startMotion(AtkMotion);
            if (!StatusManager.instance.DealHP(Damage))
            {
                break;
            }
        }
    }
Exemplo n.º 5
0
 //全局监听(步骤函数)
 private void Motion()
 {
     /*******表情更新*******/
     if (Input.GetKeyDown(MTN_DW))
     {
         motionIndex++;
         if (motionIndex >= motions.Length)
         {
             motionIndex = 0;
         }                                                      //出顶反底
         else if (motionIndex < 0)
         {
             motionIndex = motions.Length - 1;
         }                                                     //触底反弹
         motionQueueManager.startMotion(motions[motionIndex]); //队列更新
     }//表情下翻
     if (Input.GetKeyDown(MTN_RESET))
     {
         motionIndex = 0;
         motionQueueManager.startMotion(motions[motionIndex]);
     }//表情重置
     if (Input.GetKeyDown(MTN_UP))
     {
         motionIndex--;
         if (motionIndex >= motions.Length)
         {
             motionIndex = 0;
         }                                                      //出顶反底
         else if (motionIndex < 0)
         {
             motionIndex = motions.Length - 1;
         }                                                     //触底反弹
         motionQueueManager.startMotion(motions[motionIndex]); //队列更新
     }//表情上翻
     if (Input.GetKeyDown(EyeballTraceMoveMent))
     {
         this.flag_Eyeball = !flag_Eyeball;
     }
     //眼球跟踪
     /*-*/
     motions[motionIndex].setLoopFadeIn(true);
     motions[motionIndex].setFadeOut(modelAnimationFadeOut);
     motions[motionIndex].setFadeIn(modelAnimationFadein);
     motions[motionIndex].setLoop(true);
     //以上动画的更换方式(*过渡)
     motionQueueManager.updateParam(live2DModel);
     //更新队列
     /*******表情更新*******/
 }
Exemplo n.º 6
0
    void Update()
    {
        if (modelUnity == null)
        {
            return;
        }
        modelUnity.setMatrix(transform.localToWorldMatrix * matrix4X4);

        if (queueManager.isFinished())
        {
            queueManager.startMotion(dMotion);
        }
        queueManager.updateParam(modelUnity);
        modelUnity.update();
    }
Exemplo n.º 7
0
    void Update()
    {
        if (live2DModel == null)
        {
            return;
        }
        live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos);

        if (!Application.isPlaying)
        {
            live2DModel.update();
            return;
        }


        if (motionMgr.isFinished() || main != _State2)
        {
            //歩き
            if (_State2 == Enemy2State.Walk)
            {
                motionMgr.startMotion(motions[0]);
            }
        }

        if (main != _State2)
        {
            //噛みつき
            if (_State2 == Enemy2State.Attack)
            {
                motionMgr.startMotion(motions[1]);
            }
            //怯み
            else if (_State2 == Enemy2State.Stop)
            {
                motionMgr.startMotion(motions[2]);
            }
            //停止
            if (_State2 == Enemy2State.Wait)
            {
                motionMgr.startMotion(motions[3]);
            }
        }


        motionMgr.updateParam(live2DModel);
        live2DModel.update();
        live2DModel.draw();
    }
        void Update()
        {
            if (live2DModel == null)
            {
                return;
            }
            live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos);

            if (!Application.isPlaying)
            {
                live2DModel.update();
                return;
            }


            if (motionMgr.isFinished() || main != _State)
            {
                //歩き
                if (_State == Main.CharaState.Walk)
                {
                    live2DModel.setParamFloat("Param3", -1);
                    live2DModel.setParamFloat("Param7", 0);

                    motionMgr.startMotion(motions[0]);
                }
                //走り
                else if (_State == Main.CharaState.Run)
                {
                    live2DModel.setParamFloat("Param3", -1);
                    live2DModel.setParamFloat("Param7", 0);

                    motionMgr.startMotion(motions[1]);
                }
                //停止
                if (_State == Main.CharaState.Wait)
                {
                    //live2DModel.setParamFloat("Param3", -1);
                    motionMgr.startMotion(motions[2]);
                    //motionMgr.stopAllMotions();
                }
            }

            main = _State;

            motionMgr.updateParam(live2DModel);
            live2DModel.update();
            live2DModel.draw();
        }
Exemplo n.º 9
0
        /// <summary>
        /// 外部初始化入口
        /// </summary>
        public void InitModel(byte[] modelDatas, byte[] animationDatas, Texture2D[] textures)
        {
            enabled = true;
            //载入模型
            live2DModel = Live2DModelUnity.loadModel(modelDatas);

            //载入贴图
            Texture2D texture2D = Resources.Load <Texture2D>("");

            live2DModel.setTexture(0, texture2D);
            for (int i = 0; i < textures.Length; i++)
            {
                live2DModel.setTexture(i, textures[i]);
            }
            float modelWidth = live2DModel.getCanvasWidth();

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

            //载入动作
            motions = new Live2DMotion[1];
            for (int i = 0; i < motions.Length; i++)
            {
                motions[i] = Live2DMotion.loadMotion(animationDatas);
            }
            motions[0].setLoopFadeIn(true);
            motions[0].setFadeOut(FadeOutTime);
            motions[0].setFadeIn(FadeInTime);
            motions[0].setLoop(true);

            //播放第一个动作
            motionQueueManager.startMotion(motions[0]);
        }
Exemplo n.º 10
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.º 11
0
    void OnRenderObject()
    {
        if (live2DModel == null)
        {
            return;
        }
        live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos);

        if (!Application.isPlaying)
        {
            live2DModel.update();
            live2DModel.draw();
            return;
        }

        if (motionMgr.isFinished())
        {
            motionMgr.startMotion(motion);
        }

        motionMgr.updateParam(live2DModel);

        live2DModel.update();
        live2DModel.draw();
    }
Exemplo n.º 12
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();
    }
Exemplo n.º 13
0
    void OnRenderObject()
    {
        if (live2DModel == null)
        {
            return;
        }
        live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos);

        if (!Application.isPlaying)
        {
            live2DModel.update();
            live2DModel.draw();
            return;
        }

        // motion播完或是flag改變
        if (motionMgr.isFinished() || mtnBehaviour.changeflg == true)
        {
            // load motion
            motion = Live2DMotion.loadMotion(motionFile.bytes);
            // 播放motion
            motionMgr.startMotion(motion);
            // 設置flag為off
            mtnBehaviour.changeflg = false;
        }

        motionMgr.updateParam(live2DModel);

        live2DModel.update();
        live2DModel.draw();
    }
Exemplo n.º 14
0
    // Use this for initialization
    void Start()
    {
        Live2D.init();

        motion = Live2DMotion.loadMotion(mtnFiles[0].bytes);

        motion.setLoop(true);

        live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);
        for (int i = 0; i < textures.Length; i++)
        {
            live2DModel.setTexture(i, textures[i]);
        }

        motionManager = new MotionQueueManager();

        motionManager.startMotion(motion, false);

        live2DModel.setPartsOpacity("PARTS_WEAPON01", 0);
        live2DModel.setPartsOpacity("PARTS_WEAPON02", 0);
        live2DModel.setPartsOpacity("PARTS_WEAPON03", 0);
        live2DModel.setPartsOpacity("PARTS_WEAPON04", 0);
        live2DModel.setPartsOpacity("PARTS_WEAPON05", 0);
        live2DModel.setPartsOpacity("PARTS_WEAPON06", 0);
    }
Exemplo n.º 15
0
 // @Brief : Set motion
 // @Param : pMotionName => Motion name
 //        : bIsLoop     => Is loop motion
 public void SetMotion(string pMotionName, bool bIsLoop)
 {
     KrDebug.Assert(m_pMotionDatas.ContainsKey(pMotionName), "Motion is not registered. key = " + pMotionName, typeof(KrLive2DModel));
     byte[] pMotionData = m_pMotionDatas[pMotionName];
     m_pMotion = Live2DMotion.loadMotion(pMotionData);
     m_pMotion.setLoop(bIsLoop);
     m_pMotionManager.startMotion(m_pMotion, false);
 }
Exemplo n.º 16
0
 public void Play()
 {
     myCamera.enabled = true;
     FinishCoroutineStop();
     motionMgr.startMotion(motion);
     IsStop = false;
     if (live2DModelUnity != null)
     {
         motionMgr.updateParam(live2DModelUnity);
         live2DModelUnity.update();
     }
     if (!motion.isLoop())
     {
         IEnum_MotionFinish = MotionFinishedStop(motion);
         StartCoroutine(IEnum_MotionFinish);
     }
 }
    public void NextMotion()
    {
        if (motions == null || motions.Length == 0)
        {
            return;
        }

        currentMotionIndex++;
        if (currentMotionIndex >= motions.Length)
        {
            currentMotionIndex = 0;
        }
        var motion = motions[currentMotionIndex];

        motionMgr.stopAllMotions();
        motionMgr.startMotion(motion);
        running = true;
    }
Exemplo n.º 18
0
 /// <summary>
 /// 更新処理
 /// </summary>
 void Update()
 {
     // モーション再生が終了した場合
     if (motionManager != null && motionManager.isFinished())
     {
         // モーションをロードする
         motion = Live2DMotion.loadMotion(mtnFiles[motioncnt].bytes);
         // フェードインの設定
         motion.setFadeIn(mtnFadeines[motioncnt]);
         // フェードアウトの設定
         motion.setFadeOut(mtnFadeoutes[motioncnt]);
         // モーション再生
         motionManager.startMotion(motion, false);
         // 音声再生
         if (soundFiles[motioncnt] != null)
         {
             GetComponent <AudioSource>().clip = soundFiles[motioncnt];
             GetComponent <AudioSource>().Play();
         }
     }
 }
Exemplo n.º 19
0
    public void ani(int num)
    {
        switch (num)
        {
        case 0:
            motion = Live2DMotion.loadMotion(mtnFiles[num].bytes);
            motion.setLoop(true);
            motionManager.startMotion(motion, false);
            break;

        case 1:
            motion = Live2DMotion.loadMotion(mtnFiles[num].bytes);
            motion.setLoop(true);
            motionManager.startMotion(motion, false);

            break;

        case 2:
            motion = Live2DMotion.loadMotion(mtnFiles[num].bytes);
            motionManager.startMotion(motion, false);
            break;
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        Live2D.init();
        live2DModel = Live2DModelUnity.loadModel(modelFile.bytes);
        live2DModel.setTexture(0, texture);
        float modelWidth = live2DModel.getCanvasWidth();

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

        live2DmotionIdle = Live2DMotion.loadMotion(idleMotionFile.bytes);

        live2DmotionIdle.setLoop(true);

        motionQueueManager.startMotion(live2DmotionIdle);
        initPos = transform.position;
    }
Exemplo n.º 21
0
    // Use this for initialization
    void OnEnable()
    {
        Live2D.init();

        live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);

        for (int i = 0; i < textures.Length; i++)
        {
            live2DModel.setTexture(i, textures[i]);
        }
        motion = Live2DMotion.loadMotion(mtnFiles[0].bytes);
        motion.setLoop(true);

        motionManager = new MotionQueueManager();

        motionManager.startMotion(motion, false);
    }
Exemplo n.º 22
0
    private int motioncnt = 0;                                          // ファイル項番


    /// <summary>
    /// 初期化処理
    /// </summary>
    void Start()
    {
        // JSONを読込
        Json_Read();
        // Live2D初期化
        Live2D.init();
        // モーション管理クラスのインスタンス
        motionManager = new MotionQueueManager();
        // モーションのインスタンス
        motion = Live2DMotion.loadMotion(mtnFiles[0].bytes);
        // モーションの再生
        motionManager.startMotion(motion, false);
        // 表示位置
        float modelWidth = live2DModel.getCanvasWidth();

        live2DCanvasPos = Matrix4x4.Ortho(0, modelWidth, modelWidth, 0, -50.0f, 50.0f);
    }
Exemplo n.º 23
0
    void Update()
    {
        if (motionMgr.isFinished())
        {
            motionMgr.startMotion(motion);
        }

        for (int i = 0; i < NUM_MODELS; i++)
        {
            var live2DModel = models[i];
            if (live2DModel == null)
            {
                continue;
            }

            motionMgr.updateParam(live2DModel);

            live2DModel.update();
        }
    }
Exemplo n.º 24
0
    //程序入口点
    private void initModel()
    {
        Live2D.init();
        //初始化
        //Live2DModelUnity.loadModel(Application.dataPath + /*root*/"/Md/AyaX/aya_live_sr01_t03.moc");
        live2DModel = Live2DModelUnity.loadModel(modelFile.bytes);
        Texture2D texture2D = Resources.Load <Texture2D>("");

        //载入模型
        live2DModel.setTexture(0, texture2D);
        for (int i = 0; i < textures.Length; i++)
        {
            live2DModel.setTexture(i, textures[i]);
        }
        //循环取值贴图
        float modelWidth = live2DModel.getCanvasWidth();

        live2DCanvansPos = Matrix4x4.Ortho(0, modelWidth, modelWidth, 0, -50, 50);
        //加载贴图材质
        //live2DMotionIdle = Live2DMotion.loadMotion(Application.dataPath + "/Md/AyaX/idle01.mtn");
        //TextAsset mtnFile = Resources.Load<TextAsset>("");
        //live2DMotionIdle = Live2DMotion.loadMotion(mtnFile.bytes);
        //指定默认动作
        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].setFadeOut(2000);
        motions[0].setFadeIn(2000);
        motions[0].setLoop(true);
        //默认动作行为
        motionQueueManager = new MotionQueueManager();
        //新建动作队列
        motionQueueManager.startMotion(motions[0]);
        //加载动作队列第一个
        drag = new L2DTargetPoint();
        //定义拖拽
    }
Exemplo n.º 25
0
    // @Brief : Initialize
    // @Param : pMocFilePath        => Moc file path
    //        : pTexturePaths       => Texture paths
    //        : pMotionFilePaths    => Motion file paths
    //        : bFromResources      => From resources file
    public void Initialize(string pMocFilePath, string[] pTexturePaths, string[] pMotionFilePaths, bool bFromResources)
    {
        // Initialize live2d
        KrLive2DInitializer.Create();

        // Load model
        byte[] pMocFile = KrResources.LoadBytes(pMocFilePath, bFromResources);
        m_pLive2dModel = Live2DModelUnity.loadModel(pMocFile);

        // Set render mode
        // NOTE : 1. There are advantages and disadvantages depending on the type
        //        2. Each drawing timing is different
        // Ref : http://sites.cybernoids.jp/cubism2/sdk_tutorial/platform-setting/unity/csharp/render-mode
        m_pLive2dModel.setRenderMode(Live2D.L2D_RENDER_DRAW_MESH);

        for (int sIndex = 0; sIndex < pTexturePaths.Length; sIndex++)
        {
            Texture2D pTexture = KrResources.LoadTexture2D(pTexturePaths[sIndex], bFromResources);
            // Set Texture
            m_pLive2dModel.setTexture(sIndex, pTexture);
        }

        // Load Motion
        m_pMotionDatas = new Dictionary <string, byte[]>();
        for (int sIndex = 0; sIndex < pMotionFilePaths.Length; sIndex++)
        {
            m_pMotionDatas.Add(pMotionFilePaths[sIndex], KrResources.LoadBytes(pMotionFilePaths[sIndex], bFromResources));
        }
        m_pMotionManager = new MotionQueueManager();
        // Create idle motion
        m_pIdleMotionManager = new MotionQueueManager();
        // NOTE : Let the 0th position of the motion list be the idle motion
        m_pIdleMotion = Live2DMotion.loadMotion(pMotionFilePaths[0]);
        m_pIdleMotion.setLoop(true);
        m_pIdleMotionManager.startMotion(m_pIdleMotion, false);

        SetPosition(Vector3.zero);
    }
Exemplo n.º 26
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.º 27
0
 //默认表情
 private void SetMotion(Live2DMotion motion)
 {
     motion.setFadeIn(0);
     motion.setFadeOut(0);
     motionMgr.startMotion(motion);
 }
Exemplo n.º 28
0
    // 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());
        }
    }
Exemplo n.º 29
0
    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();

        if (Input.GetKeyDown(KeyCode.A))
        {// pressed "A" key.
            motionMgr.startMotion(motion);
        }

        motionMgr.updateParam(live2DModel);

        live2DModel.update();
    }
Exemplo n.º 30
0
    // 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();
    }
Exemplo n.º 31
0
    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();
    }