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); }
private IEnumerator ShowModelTask(string name, string motionName, bool motionLoop, string expressionName, Vector3 position, float duration) { L2DModel model = LoadModel(name); if (model == null) { yield break; } model.SetActivate(true); model.SetEyeBlinkEnabled(false); if (expressionName == "") { model.ClearExpression(true); } else { model.SetExpression(expressionName, true); } model.SetMotion(motionName, motionLoop, true); model.SetPosition(position); float startTime = Time.time; while (Time.time - (startTime + duration) < 0.0f) { float rate = (Time.time - startTime) / duration; model.SetAlpha(Mathf.Lerp(0.0f, 1.0f, rate)); yield return(null); } model.SetAlpha(1.0f); }
public void Dispose() { if (_model != null) { _model.UnloadAsset(); _model = null; } Destroy(this); }
/// <summary> /// 触发男主信息默认第一句语音 /// </summary> /// <param name="dialogId"></param> public void Live2DTiggerNpcInfoFirstVoice(string dialogId) { L2DModel model = _live2DGraphic.GetMainLive2DView.Model; _live2DGraphic.GetMainLive2DView.LipSync = true; new AssetLoader().LoadAudio( AssetLoader.GetMainPanleDialogById(dialogId), (clip, loader) => { AudioManager.Instance.PlayDubbing(clip); }); }
public override void Do() { L2DModel model = GameSystem._Instance._ModelManager.GetActiveModel(_ModelName); if (model == null) { Debug.LogError("[Command_Motion.NotExistActiveModel]" + _ModelName); return; } model.SetMotion(_MotionName, _MotionLoop, false); }
void PlayDialog(string musicId, int expressionId, L2DModel model) { new AssetLoader().LoadAudio(AssetLoader.GetMainPanleDialogById(musicId), //expressionInfo.Dialog), (clip, loader) => { AudioManager.Instance.PlayDubbing(clip); Debug.Log("AudioManager.Instance.PlayDubbing"); model.SetExpression(model.ExpressionList[expressionId], clip.length + 1); isClick = false; }); }
public void Initialize(L2DModel model, float planeSize, Vector3 modelRenderPos) { _model = model; _Trans.position = new Vector3(0.0f, -1.0f, 0.0f); _renderTex = RenderTexture.GetTemporary(Define.L2D._modelRenderTexSize, Define.L2D._modelRenderTexSize, 16, RenderTextureFormat.ARGB32); _plane = CreateModelPlane(planeSize); _plane.Initialize(_Trans, _renderTex); _modelCam = CreateModelCamera(); _modelCam.Initialize(gameObject.name, modelRenderPos, _renderTex); }
public override void Do() { L2DModel model = GameSystem._Instance._ModelManager.GetActiveModel(_Name); if (model == null) { Debug.LogError("modelpos/NoModel/" + _Name); return; } GameSystem._Instance.RegisterTask(ModelPositionTask(model)); }
public override void Do() { L2DModel model = GameSystem._Instance._ModelManager.GetActiveModel(_ModelName); if (model == null) { Debug.LogError("[Command_EyeBlink.NotExistActiveModel]" + _ModelName); return; } model.SetEyeBlinkEnabled(_Enable); }
public void LoadModel(string modelId, List <string> donotUnloadIds) { if (_model != null && modelId != ModelId) { _model.UnloadAsset(); } ModelId = modelId; _model = new L2DModel(); _model.LoadAssets(modelId, donotUnloadIds); }
private void LoadModelJSON_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog dialog = new OpenFileDialog { Filter = "JSON 모델 구성|*.json" }; bool?result = dialog.ShowDialog(); if (result == true) { // Live2D // 모델 불러오기 ReleaseCheck(); model = L2DFunctions.LoadModel(dialog.FileName); // 설정 업데이트 UpdateConfig(); // Application // 목록 초기화 ListMotion.Items.Clear(); ListExpression.Items.Clear(); // 모션 목록 갱신 if (model.Motion != null) { foreach (L2DMotion[] group in model.Motion.Values) { foreach (L2DMotion motion in group) { ListMotion.Items.Add(Path.GetFileName(motion.Path)); } } } // 표정 목록 갱신 if (model.Expression != null) { for (int i = 0; i < model.Expression.Count; i++) { ListExpression.Items.Add(model.Expression.Keys.ElementAt(i)); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error); } }
public L2DModel GetActiveModel(string name) { L2DModel model = null; if (_models.TryGetValue(name, out model) && model._IsActivate) { return(model); } else { return(null); } }
private IEnumerator ModelPositionTask(L2DModel model) { model.SetPosition(_Position); float startTime = Time.time; while (Time.time - (startTime + _Duration) < 0.0f) { float rate = (Time.time - startTime) / _Duration; model.SetAlpha(Mathf.Lerp(0.0f, 1.0f, rate)); yield return(null); } model.SetAlpha(1.0f); }
public void RemoveModel(string modelInfoName) { L2DModel model = null; if (!_models.TryGetValue(modelInfoName, out model)) { Debug.LogError("[ModelManager.RemoveModel.CannotFindModel]" + modelInfoName); return; } RemoveFromSlot(modelInfoName); _models.Remove(modelInfoName); model.OnRemove(); }
public void SetMainLive2d(PlayerVo vo) { if (vo.Apparel[0] <= 0 || !L2DModel.HasResource(vo.Apparel[0].ToString())) { _isShowLive2d = false; _live2dGraphic.Hide(); return; } ChangeRole(vo.Apparel[0]); if (GuideManager.CurStage() != GuideStage.MainLine1_1Level_1_3Level_Stage) { Live2dTigger(EXPRESSIONTRIGERTYPE.LOGIN, -1, false); } }
/// <summary> /// 触发语音Item语音 /// </summary> /// <param name="info"></param> public void Live2dTiggerVoice(CardAwardPreInfo info) { L2DModel model = _live2DGraphic.GetMainLive2DView.Model; _live2DGraphic.GetMainLive2DView.LipSync = true; if (info.dialogId == "") { model.SetExpression(model.ExpressionList[info.expressionId], 2); return; } new AssetLoader().LoadAudio( AssetLoader.GetMainPanleDialogById(info.dialogId), //expressionInfo.Dialog), (clip, loader) => { model.SetExpression(model.ExpressionList[info.expressionId], clip.length + 1); AudioManager.Instance.PlayDubbing(clip); }); }
public override void Do() { L2DModel model = GameSystem._Instance._ModelManager.GetActiveModel(_ModelName); if (model == null) { Debug.LogError("[Command_Expression.NotExistActiveModel]" + _ModelName); return; } if (_ExpressionName == "") { model.ClearExpression(false); } else { model.SetExpression(_ExpressionName, false); } }
/// <summary> /// 触发送礼语音 /// </summary> /// <param name="pbId"></param> /// <param name="itemId"></param> public void Live2dTiggerGiftVoice(int pbId, int itemId) { L2DModel model = _live2DGraphic.GetMainLive2DView.Model; ExpressionInfo expressionInfo = ClientData.GetRandomGiftExpression(pbId, itemId); if (expressionInfo == null) { return; } _live2DGraphic.GetMainLive2DView.LipSync = true; model.SetExpression(model.ExpressionList[expressionInfo.Id]); if (expressionInfo.Dialog == "") { return; } new AssetLoader().LoadAudio( AssetLoader.GetMainPanleDialogById(expressionInfo.Dialog), //expressionInfo.Dialog), (clip, loader) => { AudioManager.Instance.PlayDubbing(clip); }); }
private void LoadModel_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog dialog = new OpenFileDialog { Filter = "MOC 모델|*.moc" }; bool?result = dialog.ShowDialog(); if (result == true) { // 모델 초기화 if (model != null) { model.Dispose(); } // 모델 불러오기 ReleaseCheck(); model = new L2DModel(dialog.FileName); // 텍스처 불러오기 string texruePath = string.Format("{0}\\{1}.1024", new FileInfo(dialog.FileName).Directory.FullName, Path.GetFileNameWithoutExtension(dialog.FileName)); if (Directory.Exists(texruePath)) { model.SetTexture(Directory.GetFiles(texruePath)); } // 설정 업데이트 UpdateConfig(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error); } }
private IEnumerator HideModelTask(string name, float duration) { L2DModel model = GetActiveModel(name); if (model == null) { Debug.LogError("Not exist activated model " + name); yield break; } float startTime = Time.time; while (Time.time - (startTime + duration) < 0.0f) { float rate = (Time.time - startTime) / duration; model.SetAlpha(Mathf.Lerp(1.0f, 0.0f, rate)); yield return(null); } model.SetActivate(false); }
/// <summary> /// 触发好感度主机界面摸摸乐语音 /// </summary> /// <param name="eType"></param> /// <param name="labelId"></param> /// <param name="isSendClick"></param> private void Live2dTigger(EXPRESSIONTRIGERTYPE eType, int labelId = -1, bool isSendClick = true) { L2DModel model = _live2DGraphic.GetMainLive2DView.Model; ExpressionInfo expressionInfo = ClientData.GetRandomExpression(_npcId, eType, labelId); if (expressionInfo == null) { Debug.Log("expressionInfo == null"); _isClick = false; return; } if (!model.IsIdle) { _isClick = false; Debug.LogError("model is busy "); return; } _live2DGraphic.GetMainLive2DView.LipSync = true; if (expressionInfo.Dialog == "") { Debug.Log("expressionInfo.Dialog == null"); model.SetExpression(model.ExpressionList[expressionInfo.Id], 2); _isClick = false; return; } new AssetLoader().LoadAudio(AssetLoader.GetMainPanleDialogById(expressionInfo.Dialog), //expressionInfo.Dialog), (clip, loader) => { AudioManager.Instance.PlayDubbing(clip); Debug.Log("AudioManager.Instance.PlayDubbing"); model.SetExpression(model.ExpressionList[expressionInfo.Id], clip.length + 1); _isClick = false; }); }
private void ChangeRole(int id) { _isShowLive2d = true; _live2dGraphic.Show(); var live2dName = id.ToString(); if (_extendCacheVo != null && _extendCacheVo.needDownload) { var curStep = GuideManager.GetRemoteGuideStep(GuideTypePB.MainGuide); if (curStep >= GuideConst.MainLineStep_OnClick_FavorabilityShowMainViewBtn) { //老号,要读取默认的! _live2dGraphic.Hide(); _live2dGraphic.LoadAnimationById(GlobalData.PlayerModel.PlayerVo.Apparel[0].ToString()); } else { _live2dGraphic.LoadAnimationById(live2dName); } } else { //_cacheVo = CacheManager.CheckExtendCache(); _live2dGraphic.LoadAnimationById(live2dName); } // Debug.LogError("load!"); L2DModel model = _live2dGraphic.GetMainLive2DView.Model; model.StartMotion(L2DConst.MOTION_GROUP_IDLE, 0, L2DConst.PRIORITY_IDLE, true); model.SetExpression(model.ExpressionList[2]); model.StartEyeBlink(); SetLive2dClickSize(); SdkHelper.PushAgent.PushCreate30DaysNotice(); }
public void Live2dTigger(EXPRESSIONTRIGERTYPE eType, int labelId = -1, bool isSendClick = true) { //eType = EXPRESSIONTRIGERTYPE.LOVEDIARY; //labelId = 8004; L2DModel model = _live2dGraphic.GetMainLive2DView.Model; ExpressionInfo expressionInfo = ClientData.GetRandomExpression(GlobalData.PlayerModel.PlayerVo.NpcId, eType, labelId); if (expressionInfo == null) { Debug.Log("expressionInfo == null"); isClick = false; return; } if (!model.IsIdle) { isClick = false; Debug.LogError("model is busy "); return; } if (isSendClick) { SendMessage(new Message(MessageConst.CMD_MAIN_ON_LIVE2DCLICK)); } _live2dGraphic.GetMainLive2DView.LipSync = true; if (expressionInfo.Dialog == "") { Debug.Log("expressionInfo.Dialog == null"); model.SetExpression(model.ExpressionList[expressionInfo.Id], 2); isClick = false; return; } string musicId = expressionInfo.Dialog; if (labelId != -1) { if (CacheManager.IsLoveDiaryNeedDown(musicId)) { CacheManager.DownloadLoveDiaryCache(musicId, str => { Debug.LogError("DownloadLoveDiaryCache finish"); PlayDialog(musicId, expressionInfo.Id, model); }, () => { Debug.LogError("DownloadLoveDiaryCache error"); PlayDialog(musicId, expressionInfo.Id, model); }); } else { PlayDialog(musicId, expressionInfo.Id, model); } //CacheVo cacheVo= CacheManager.CheckLoveDiaryCache(musicId); //if (cacheVo != null && cacheVo.needDownload) //{ // CacheManager.DownloadLoveDiaryCache(musicId, str => // { // Debug.LogError("DownloadLoveDiaryCache finish"); // PlayDialog(musicId, expressionInfo.Id, model); // }, ()=>{ // Debug.LogError("DownloadLoveDiaryCache error"); // PlayDialog(musicId, expressionInfo.Id, model); // }); //} } else { //new AssetLoader().LoadAudio(AssetLoader.GetMainPanleDialogById(expressionInfo.Dialog), //expressionInfo.Dialog), //(clip, loader) => // { // AudioManager.Instance.PlayDubbing(clip); // Debug.Log("AudioManager.Instance.PlayDubbing"); // model.SetExpression(model.ExpressionList[expressionInfo.Id], clip.length + 1); // isClick = false; //}); PlayDialog(musicId, expressionInfo.Id, model); } }
/// <summary> /// JSON 파일로 간편하게 모델을 불러옵니다. /// </summary> /// <param name="path">모델 구성을 포함한 JSON 파일입니다.</param> public static L2DModel LoadModel(string path) { // JSON 분석 string modelPath; string[] texturePath; string physicsPath = null; string posePath = null; string parentPath = Directory.GetParent(path).FullName; Dictionary <string, L2DMotion[]> motionDictionary = new Dictionary <string, L2DMotion[]>(); Dictionary <string, L2DExpression> expressionDictionary = new Dictionary <string, L2DExpression>(); JObject jsonObject = JObject.Parse(File.ReadAllText(path)); // - model modelPath = FixPath(path, jsonObject.GetValue("model").Value <string>()); // - textures texturePath = jsonObject.GetValue("textures").Values <string>().ToArray(); for (int i = 0; i < texturePath.Length; i++) { texturePath[i] = FixPath(path, texturePath[i]); } // - physics JToken resultPhysics; jsonObject.TryGetValue("physics", out resultPhysics); if (resultPhysics != null) { physicsPath = FixPath(path, resultPhysics.Value <string>()); } // - pose JToken resultPose; jsonObject.TryGetValue("pose", out resultPose); if (resultPose != null) { posePath = FixPath(path, resultPose.Value <string>()); } // - motions foreach (JProperty jsonMotion in jsonObject["motions"].Children()) { List <L2DMotion> motionList = new List <L2DMotion>(); foreach (JArray jsonChildren in jsonMotion.Children().ToList()) { foreach (JObject result in jsonChildren) { L2DMotion motion = null; string motionFile = FixPath(path, result.GetValue("file").Value <string>()); JToken resultSound; result.TryGetValue("sound", out resultSound); if (resultSound == null) { motion = new L2DMotion(motionFile); } else { string soundFile = FixPath(path, resultSound.Value <string>()); motion = new L2DMotion(motionFile, soundFile); } JToken resultFadeIn; result.TryGetValue("fade_in", out resultFadeIn); JToken resultFadeOut; result.TryGetValue("fade_out", out resultFadeOut); if (resultFadeIn != null) { motion.SetFadeIn(resultFadeIn.Value <int>()); } if (resultFadeOut != null) { motion.SetFadeOut(resultFadeOut.Value <int>()); } if (motion != null) { motionList.Add(motion); } } } motionDictionary.Add(jsonMotion.Name, motionList.ToArray()); } // - expression JToken resultExpression; jsonObject.TryGetValue("expressions", out resultExpression); if (resultExpression != null) { foreach (JObject json in resultExpression) { string name = json["name"].Value <string>(); L2DExpression expression = LoadExpression(FixPath(path, json["file"].Value <string>())); expressionDictionary.Add(name, expression); } } // L2DModel 생성 L2DModel model = new L2DModel(modelPath); model.SetTexture(texturePath); model.Motion = motionDictionary; if (resultExpression != null) { model.Expression = expressionDictionary; } if (physicsPath != null) { model.Physics = LoadPhysics(physicsPath); } if (posePath != null) { model.Pose = LoadPose(posePath); } model.SaveParam(); return(model); }
public void InitializeIDX(L2DModel model) { _ParamIDX = model.GetParamIndex("VISIBLE:" + ID); _PartsIDX = model.GetPartsDataIndex(ID); model.SetParamFloat(ParamIDX, 1); }