private static void CreateModelInfo() { L2DModelInfo info = new L2DModelInfo(); info._modelName = "Epsilon"; info._settingPath = "Epsilon_free/Epsilon_free.model.json"; info._planeSize = 2.0f; info._layout._scale = 1.0f; info._layout._y = 0.85f; string json = JsonUtility.ToJson(info, true); const string filename = "Epsilon"; string filepath = Define.L2D._modelInfoRoot + "/" + filename; System.IO.File.WriteAllText(Application.dataPath + "/Resources/" + filepath + ".json", json); AssetDatabase.Refresh(); // 테스트 TextAsset loadedJson = Resources.Load <TextAsset>(filepath); L2DModelInfo loadedInfo = JsonUtility.FromJson <L2DModelInfo>(loadedJson.text); if (info.IsSame(loadedInfo)) { Debug.Log("ModelInfo created successfully " + filepath); } else { Debug.LogError("ModelInfo created but not same " + filepath); } }
private Dictionary <string, L2DModel> _models = new Dictionary <string, L2DModel>(); // <모델정보명, 생성된 모델> public L2DModel LoadModel(string modelInfoName) { L2DModel model = null; if (_models.TryGetValue(modelInfoName, out model)) { return(model); } string filepath = Define.L2D._modelInfoRoot + "/" + modelInfoName; TextAsset infoText = Resources.Load <TextAsset>(filepath); if (infoText == null) { Debug.LogError("'" + modelInfoName + "' ModelInfo does not exist"); return(null); } int slotIdx = RegisterToSlot(modelInfoName); L2DModelInfo info = JsonUtility.FromJson <L2DModelInfo>(infoText.text); model = new L2DModel(); model.Initialize(info, slotIdx); model.SetActivate(false); _models.Add(modelInfoName, model); return(model); }
// 테스트용 public bool IsSame(L2DModelInfo other) { if (_modelName != other._modelName) { return(false); } if (_settingPath != other._settingPath) { return(false); } if (_planeSize != other._planeSize) { return(false); } if (_layout._scale != other._layout._scale) { return(false); } if (_layout._y != other._layout._y) { return(false); } return(true); }
public void Initialize(L2DModelInfo modelInfo, int modelSlotIdx) { setUpdating(true); // 모델 갱신중 setInitialized(false); _IsActivate = true; _modelHomeDir = FileManager.getDirName(modelInfo._SettingFullPath); _modelRenderPos = new Vector3(modelSlotIdx * 5.0f, 60.0f, 0.0f); GameObject proxyObj = new GameObject(modelInfo._modelName); _proxy = proxyObj.AddComponent <L2DModelProxy>(); _proxy.Initialize(this, modelInfo._planeSize, _modelRenderPos); string modelJson = Live2DFramework.getPlatformManager().loadString(modelInfo._SettingFullPath); _modelSetting = new ModelSettingJson(modelJson); startTimeMSec = UtSystem.getUserTimeMSec(); _updatedOnce = false; // 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)); } } // 모션은 미리 읽지 않고 각 모션 재생 시도 시 읽어들임 // 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()); } // 파라미터 초기값 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(); // 레이아웃. 적용 순서에 따라 결과 달라짐에 주의 getModelMatrix().multScale(modelInfo._layout._scale, modelInfo._layout._scale); getModelMatrix().setY(modelInfo._layout._y); setUpdating(false); // 갱신상태 완료 setInitialized(true); }