public void Init(String modelJson) { updating = true; initialized = false; modelSetting = new ModelSettingJson(modelJson); if (LAppDefine.DEBUG_LOG) { Debug.Log("Start to load model"); } // Live2D Model if (modelSetting.GetModelFile() != null) { loadModelData(modelHomeDir + modelSetting.GetModelFile()); var len = modelSetting.GetTextureNum(); for (int i = 0; i < len; i++) { loadTexture(i, modelHomeDir + modelSetting.GetTextureFile(i)); } } for (int i = 0; i < modelSetting.GetInitParamNum(); i++) { string id = modelSetting.GetInitParamID(i); float value = modelSetting.GetInitParamValue(i); live2DModel.setParamFloat(id, value); } for (int i = 0; i < modelSetting.GetInitPartsVisibleNum(); i++) { string id = modelSetting.GetInitPartsVisibleID(i); float value = modelSetting.GetInitPartsVisibleValue(i); live2DModel.setPartsOpacity(id, value); } view.SetupView( live2DModel.getCanvasWidth(), live2DModel.getCanvasHeight()); updating = false; initialized = true; }
/* * 初始化模型 * @throws Exception */ public void Init(String modelJson) { updating = true; initialized = false; modelSetting = new ModelSettingJson(modelJson); if (LAppDefine.DEBUG_LOG) { Debug.Log("Start to load model"); } // Live2D Model if (modelSetting.GetModelFile() != null) { loadModelData(modelHomeDir + modelSetting.GetModelFile()); var len = modelSetting.GetTextureNum(); Debug.Log(len); for (int i = 0; i < len; i++) { loadTexture(i, modelHomeDir + modelSetting.GetTextureFile(i)); } } // Expression if (modelSetting.GetExpressionNum() != 0) { var len = modelSetting.GetExpressionNum(); for (int i = 0; i < len; i++) { loadExpression(modelSetting.GetExpressionName(i), modelHomeDir + modelSetting.GetExpressionFile(i)); } } // Physics if (modelSetting.GetPhysicsFile() != null) { loadPhysics(modelHomeDir + modelSetting.GetPhysicsFile()); } // Pose if (modelSetting.GetPoseFile() != null) { loadPose(modelHomeDir + modelSetting.GetPoseFile()); } // 由于布局可以在Unity上设置,因此不会从JSON中读取 //Dictionary<string, float> layout = new Dictionary<string, float>(); //if (modelSetting.GetLayout(layout)) //{ // if (layout.ContainsKey("width")) modelMatrix.setWidth(layout["width"]); // if (layout.ContainsKey("height")) modelMatrix.setHeight(layout["height"]); // if (layout.ContainsKey("x")) modelMatrix.setX(layout["x"]); // if (layout.ContainsKey("y")) modelMatrix.setY(layout["y"]); // if (layout.ContainsKey("center_x")) modelMatrix.centerX(layout["center_x"]); // if (layout.ContainsKey("center_y")) modelMatrix.centerY(layout["center_y"]); // if (layout.ContainsKey("top")) modelMatrix.top(layout["top"]); // if (layout.ContainsKey("bottom")) modelMatrix.bottom(layout["bottom"]); // if (layout.ContainsKey("left")) modelMatrix.left(layout["left"]); // if (layout.ContainsKey("right")) modelMatrix.right(layout["right"]); //} // 初始参数 for (int i = 0; i < modelSetting.GetInitParamNum(); i++) { string id = modelSetting.GetInitParamID(i); float value = modelSetting.GetInitParamValue(i); live2DModel.setParamFloat(id, value); } for (int i = 0; i < modelSetting.GetInitPartsVisibleNum(); i++) { string id = modelSetting.GetInitPartsVisibleID(i); float value = modelSetting.GetInitPartsVisibleValue(i); live2DModel.setPartsOpacity(id, value); } // 自动捕眼器 eyeBlink = new L2DEyeBlink(); view.SetupView( live2DModel.getCanvasWidth(), live2DModel.getCanvasHeight()); updating = false; // 更新状態の完了 initialized = true; // 初期化完了 }