Explorar el Código

提交剧情语音,CG

leiyasi hace 1 año
padre
commit
67d7f367fe

+ 78 - 0
GameClient/Assets/Game/HotUpdate/DressUp/SceneController.cs

@@ -2,6 +2,10 @@ using UnityEngine;
 
 using System.Collections;
 using YooAsset;
+using Live2D.Cubism.Rendering;
+//using System.Collections.Generic;
+using FairyGUI;
+//using DG.Tweening;
 
 namespace GFGGame
 {
@@ -121,6 +125,80 @@ namespace GFGGame
             }
         }
 
+        public static void UpdateDialogAnim(string value, ref GameObject animObj)
+        {
+            StoryDialogDataManager.Instance.waiting = false;
+            if (value == "0")
+            {
+                if(animObj != null)
+                {
+                    PrefabManager.Instance.Restore(animObj);
+                    animObj = null;
+                }
+            }
+            else
+            {
+                string res = value.Split('/')[1];
+                animObj = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetStoryDialogCGPath(value, res));
+                Timers.inst.StartCoroutine(InitModel(animObj));
+                StoryDialogDataManager.Instance.dialogShowDelay = 0.4f;
+            }
+        }
+
+        private static IEnumerator InitModel(GameObject obj)
+        {
+            // 未加载到live2D之前,不做显示
+            obj.transform.localScale = Vector3.zero;
+            StoryDialogDataManager.Instance.waiting = true;
+            CubismRenderController[] cubismModels;
+            cubismModels = obj.transform.GetComponentsInChildren<CubismRenderController>();
+            while (cubismModels.Length == 0)
+            {
+                yield return new WaitForEndOfFrame();
+                cubismModels = obj.transform.GetComponentsInChildren<CubismRenderController>();
+            }
+            //List<SpriteRenderer> spriteRenderers = new List<SpriteRenderer>(obj.transform.GetComponentsInChildren<SpriteRenderer>());
+            obj.transform.localScale = Vector3.one;
+            //Ease ease = Ease.Linear;
+            //DOTween.To(() => 0, (value) =>
+            //{
+            //    if (cubismModels == null)
+            //    {
+            //        return;
+            //    }
+
+            //    for (int j = 0; j < cubismModels.Length; j++)
+            //    {
+            //        cubismModels[j].Opacity = value;
+            //    }
+
+            //    for (int i = 0; i < spriteRenderers.Count; i++)
+            //    {
+            //        if (spriteRenderers[i] == null)
+            //        {
+            //            spriteRenderers.RemoveAt(i);
+            //            continue;
+            //        }
+            //        Color color = spriteRenderers[i].color;
+            //        color.a = value;
+            //        spriteRenderers[i].color = color;
+            //    }
+            //}, 1, 0.5f).SetEase(ease).OnComplete(() =>
+            //{
+            //    StoryDialogDataManager.Instance.waiting = false;
+            //}).SetAutoKill().SetId("fade");
+            StoryDialogDataManager.Instance.waiting = false;
+        }
+
+
+        public static void ControlBgVisible(GameObject sceneObj, bool isShow)
+        {
+            Transform bg = sceneObj.transform.Find("Bg");
+            Transform bgNext = sceneObj.transform.Find("BgNext");
+            bg.gameObject.SetActive(isShow);
+            bgNext.gameObject.SetActive(isShow);
+        }
+
         public static void SetSpriteRendererAlpha(SpriteRenderer spr, float a)
         {
             Color c = spr.color;

+ 2 - 0
GameClient/Assets/Game/HotUpdate/Sound/VoiceManager.cs

@@ -67,6 +67,8 @@ namespace GFGGame
         public void StopVoice()
         {
             player.Stop();
+            handle = null;
+            player.clip = null;
         }
 
         public int GetClipLength()

+ 2 - 2
GameClient/Assets/Game/HotUpdate/Utils/ResPathUtil.cs

@@ -271,9 +271,9 @@ namespace GFGGame
             return $"{STUDIO_FILING_DIR_PATH}{res}.{extName}";
         }
 
-        public static string GetStoryDialogCGPath(string res, string extName = "prefab")
+        public static string GetStoryDialogCGPath(string dir, string res, string extName = "prefab")
         {
-            return $"{ANIMATION_DIR_PATH}/CG/{res}/{res}.{extName}";
+            return $"{ANIMATION_DIR_PATH}/{dir}/{res}.{extName}";
         }
     }
 }

+ 54 - 9
GameClient/Assets/Game/HotUpdate/Views/MainStory/StoryDialogView.cs

@@ -14,6 +14,7 @@ namespace GFGGame
         private UI_StoryDialogUI _ui;
         private UI_CompArrow _arrow;
         private GameObject _sceneObject;
+        private GameObject _animObject;
         private EffectUI _effectUI1;
         private DressUpObjUI _dressUpObjUI;
         private GTextField _wordTextField;
@@ -51,6 +52,12 @@ namespace GFGGame
                 _sceneObject = null;
             }
 
+            if(_animObject != null)
+            {
+                PrefabManager.Instance.Restore(_animObject);
+                _animObject = null;
+            }
+
             _dressUpObjUI?.Dispose();
             _dressUpObjUI = null;
 
@@ -98,9 +105,11 @@ namespace GFGGame
         protected override void OnShown()
         {
             base.OnShown();
+
             if (_sceneObject == null)
             {
                 _sceneObject = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("SceneStoryDialog"));
+
             }
             if (_dressUpObjUI == null)
             {
@@ -165,11 +174,20 @@ namespace GFGGame
             Timers.inst.Remove(ShowNextWords);
             ScreenBlackController.Instance.HideBlack();
             StopAutoPlay();
+            VoiceManager.Instance.StopVoice();
+
             if (_sceneObject != null)
             {
                 PrefabManager.Instance.Restore(_sceneObject);
                 _sceneObject = null;
             }
+
+            if (_animObject != null)
+            {
+                PrefabManager.Instance.Restore(_animObject);
+                _animObject = null;
+            }
+
             _dressUpObjUI.dressUpObj.TakeOffAll();
             MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
             _onCompleteStoryDialogCall = null;
@@ -309,6 +327,7 @@ namespace GFGGame
                 {
                     delay = _currentStepCfg.blankScreenDur;
                     UpdatePic("0");
+                    UpdateAnim("0");
                 }
             }
             if (delay > 0)
@@ -349,6 +368,7 @@ namespace GFGGame
             UpdateMusic(storyDialogCfg.musicRes);
             UpdateBg(storyDialogCfg.bgRes);
             UpdatePic(storyDialogCfg.picRes);
+            UpdateAnim(storyDialogCfg.aniRes);
             UpdateRoleObj(storyDialogCfg.name);
             PlayEffect(storyDialogCfg.effectInfoArr);
             PlayShake(storyDialogCfg.shakeInfoArr);
@@ -441,17 +461,11 @@ namespace GFGGame
 
             VoiceManager.Instance.StopVoice();
             // 如果配置了语音,读取语音
-            VoiceManager.Instance.LoadRes(ResPathUtil.GetCardSoundPath("test", "wav"));
+            VoiceManager.Instance.LoadRes(ResPathUtil.GetVoicePath(storyDialogCfg.voiceRes));
             _wordList = Regex.Split(words, "&&");
 
-            if (effectInfo.Length > 0)
-            {
-                // 等待CG播放完毕直接进入下一段
-                Timers.inst.StartCoroutine(WaitCGAnimFinish(effectInfo[0], int.Parse(effectInfo[1])));
-            }
-
             // 有对话
-            if (_wordList.Length > 0)
+            if (_wordList.Length > 0 && !_wordList[0].Equals(""))
             {
                 if (roleName == "self")
                 {
@@ -582,6 +596,20 @@ namespace GFGGame
 
                 ShowNextDialog();
             }
+            else
+            {
+                OnStepComplete();
+                //if (effectInfo.Length > 0)
+                //{
+                //    // 等待CG播放完毕直接进入下一段
+                //    Timers.inst.StartCoroutine(WaitCGAnimFinish(effectInfo[0], int.Parse(effectInfo[1])));
+                //}
+                //// 播放效果等
+                //else
+                //{
+                //    OnStepComplete();
+                //}
+            }
 
         }
 
@@ -701,6 +729,23 @@ namespace GFGGame
             }
         }
 
+        private void UpdateAnim(string value)
+        {
+            if (value.Length > 0 && !IsTeaParty)
+            {
+                if (value == "0")
+                {
+                    SceneController.ControlBgVisible(_sceneObject, true);
+                }
+                else
+                {
+                    SceneController.ControlBgVisible(_sceneObject, false);
+
+                }
+                SceneController.UpdateDialogAnim(value, ref _animObject);
+            }
+        }
+
         private void UpdateRoleObj(string value)
         {
             if (IsTeaParty)
@@ -828,7 +873,7 @@ namespace GFGGame
 
         private IEnumerator WaitCGAnimFinish(string resName, int times = 1)
         {
-            GameObject cg = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetStoryDialogCGPath(resName));
+            GameObject cg = PrefabManager.Instance.InstantiateSync("test");
             Animator animator = cg.GetComponentInChildren<Animator>();
             AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
 

BIN
GameClient/Assets/ResIn/UI/Main/Main_fui.bytes