Ejemplo n.º 1
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]);
    }
Ejemplo n.º 2
0
        public static L2DPhysics load(char[] buf)
        {
            L2DPhysics ret = new L2DPhysics();

            Value json = Json.parseFromBytes(buf);


            List <Value> params_  = json.get("physics_hair").getVector(null);
            int          paramNum = params_.Count;

            for (int i = 0; i < paramNum; i++)
            {
                Value param = params_[i];

                PhysicsHair physics = new PhysicsHair();

                Value setup = param.get("setup");

                float length = setup.get("length").toFloat();

                float resist = setup.get("regist").toFloat();

                float mass = setup.get("mass").toFloat();
                physics.setup(length, resist, mass);


                List <Value> srcList = param.get("src").getVector(null);
                int          srcNum  = srcList.Count;
                for (int j = 0; j < srcNum; j++)
                {
                    Value           src     = srcList[j];
                    string          id      = src.get("id").toString();//param ID
                    PhysicsHair.Src type    = PhysicsHair.Src.SRC_TO_X;
                    string          typeStr = src.get("ptype").toString();
                    if (typeStr == "x")
                    {
                        type = PhysicsHair.Src.SRC_TO_X;
                    }
                    else if (typeStr == "y")
                    {
                        type = PhysicsHair.Src.SRC_TO_Y;
                    }
                    else if (typeStr == "angle")
                    {
                        type = PhysicsHair.Src.SRC_TO_G_ANGLE;
                    }
                    else
                    {
                        UtDebug.error("live2d", "Invalid parameter:hysicsHair.Src");
                    }

                    float scale  = src.get("scale").toFloat();
                    float weight = src.get("weight").toFloat();
                    physics.addSrcParam(type, id, scale, weight);
                }


                List <Value> targetList = param.get("targets").getVector(null);
                int          targetNum  = targetList.Count;
                for (int j = 0; j < targetNum; j++)
                {
                    Value              target  = targetList[j];
                    string             id      = target.get("id").toString();//param ID
                    PhysicsHair.Target type    = PhysicsHair.Target.TARGET_FROM_ANGLE;
                    string             typeStr = target.get("ptype").toString();
                    if (typeStr == "angle")
                    {
                        type = PhysicsHair.Target.TARGET_FROM_ANGLE;
                    }
                    else if (typeStr == "angle_v")
                    {
                        type = PhysicsHair.Target.TARGET_FROM_ANGLE_V;
                    }
                    else
                    {
                        UtDebug.error("live2d", "Invalid parameter:PhysicsHair.Target");
                    }

                    float scale  = target.get("scale").toFloat();
                    float weight = target.get("weight").toFloat();
                    physics.addTargetParam(type, id, scale, weight);
                }
                ret.addParam(physics);
            }

            return(ret);
        }
Ejemplo n.º 3
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);
        }
    }
Ejemplo n.º 4
0
 void addParam(PhysicsHair phisics)
 {
     physicsList.Add(phisics);
 }
Ejemplo n.º 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);
        }
    }
Ejemplo n.º 6
0
        public static L2DPhysics load(char[] buf)
        {
            L2DPhysics ret = new L2DPhysics();

            Value json = Json.parseFromBytes(buf);

            List<Value> params_ = json.get("physics_hair").getVector(null);
            int paramNum = params_.Count;

            for (int i = 0; i < paramNum; i++)
            {
                Value param = params_[i];

                PhysicsHair physics = new PhysicsHair();

                Value setup = param.get("setup");

                float length = setup.get("length").toFloat();

                float resist = setup.get("regist").toFloat();

                float mass = setup.get("mass").toFloat();
                physics.setup(length, resist, mass);

                List<Value> srcList = param.get("src").getVector(null);
                int srcNum = srcList.Count;
                for (int j = 0; j < srcNum; j++)
                {
                    Value src = srcList[j];
                    string id = src.get("id").toString();//param ID
                    PhysicsHair.Src type = PhysicsHair.Src.SRC_TO_X;
                    string typeStr = src.get("ptype").toString();
                    if (typeStr == "x")
                    {
                        type = PhysicsHair.Src.SRC_TO_X;
                    }
                    else if (typeStr == "y")
                    {
                        type = PhysicsHair.Src.SRC_TO_Y;
                    }
                    else if (typeStr == "angle")
                    {
                        type = PhysicsHair.Src.SRC_TO_G_ANGLE;
                    }
                    else
                    {
                        UtDebug.error("live2d", "Invalid value. PhysicsHair.Src");
                    }

                    float scale = src.get("scale").toFloat();
                    float weight = src.get("weight").toFloat();
                    physics.addSrcParam(type, id, scale, weight);
                }

                List<Value> targetList = param.get("targets").getVector(null);
                int targetNum = targetList.Count;
                for (int j = 0; j < targetNum; j++)
                {
                    Value target = targetList[j];
                    string id = target.get("id").toString();//param ID
                    PhysicsHair.Target type = PhysicsHair.Target.TARGET_FROM_ANGLE;
                    string typeStr = target.get("ptype").toString();
                    if (typeStr == "angle")
                    {
                        type = PhysicsHair.Target.TARGET_FROM_ANGLE;
                    }
                    else if (typeStr == "angle_v")
                    {
                        type = PhysicsHair.Target.TARGET_FROM_ANGLE_V;
                    }
                    else
                    {
                        UtDebug.error("live2d", "Invalid value. PhysicsHair.Target");
                    }

                    float scale = target.get("scale").toFloat();
                    float weight = target.get("weight").toFloat();
                    physics.addTargetParam(type, id, scale, weight);

                }
                ret.addParam(physics);
            }

            return ret;
        }
Ejemplo n.º 7
0
 void addParam(PhysicsHair phisics)
 {
     physicsList.Add(phisics);
 }
 public static L2DPhysics load(char[] buf)
 {
     L2DPhysics physics = new L2DPhysics();
     List<Value> list = Json.parseFromBytes(buf).get("physics_hair").getVector(null);
     int count = list.Count;
     for (int i = 0; i < count; i++)
     {
         Value value3 = list[i];
         PhysicsHair phisics = new PhysicsHair();
         Value value4 = value3.get("setup");
         float num3 = value4.get("length").toFloat();
         float num4 = value4.get("regist").toFloat();
         float num5 = value4.get("mass").toFloat();
         phisics.setup(num3, num4, num5);
         List<Value> list2 = value3.get("src").getVector(null);
         int num6 = list2.Count;
         for (int j = 0; j < num6; j++)
         {
             Value value5 = list2[j];
             string paramID = value5.get("id").toString();
             PhysicsHair.Src srcType = PhysicsHair.Src.SRC_TO_X;
             string str2 = value5.get("ptype").toString();
             if (str2 == "x")
             {
                 srcType = PhysicsHair.Src.SRC_TO_X;
             }
             else if (str2 == "y")
             {
                 srcType = PhysicsHair.Src.SRC_TO_Y;
             }
             else if (str2 == "angle")
             {
                 srcType = PhysicsHair.Src.SRC_TO_G_ANGLE;
             }
             else
             {
                 object[] args = new object[] { "Invalid value. PhysicsHair.Src" };
                 UtDebug.error("live2d", args);
             }
             float scale = value5.get("scale").toFloat();
             float weight = value5.get("weight").toFloat();
             phisics.addSrcParam(srcType, paramID, scale, weight);
         }
         List<Value> list3 = value3.get("targets").getVector(null);
         int num10 = list3.Count;
         for (int k = 0; k < num10; k++)
         {
             Value value6 = list3[k];
             string str3 = value6.get("id").toString();
             PhysicsHair.Target targetType = PhysicsHair.Target.TARGET_FROM_ANGLE;
             string str4 = value6.get("ptype").toString();
             if (str4 == "angle")
             {
                 targetType = PhysicsHair.Target.TARGET_FROM_ANGLE;
             }
             else if (str4 == "angle_v")
             {
                 targetType = PhysicsHair.Target.TARGET_FROM_ANGLE_V;
             }
             else
             {
                 object[] objArray2 = new object[] { "Invalid value. PhysicsHair.Target" };
                 UtDebug.error("live2d", objArray2);
             }
             float num12 = value6.get("scale").toFloat();
             float num13 = value6.get("weight").toFloat();
             phisics.addTargetParam(targetType, str3, num12, num13);
         }
         physics.addParam(phisics);
     }
     return physics;
 }
 private void addParam(PhysicsHair phisics)
 {
     this.physicsList.Add(phisics);
 }