From 63a3bbcc7ab01c395f0d522fa3d171ba83ab6d89 Mon Sep 17 00:00:00 2001 From: CroakFang <1605296300@qq.com> Date: Thu, 3 Nov 2022 23:55:36 +0800 Subject: [PATCH] bug fix --- Assets/Scripts/UmaContainer.cs | 6 ++---- Assets/Scripts/UmaViewerBuilder.cs | 21 ++++++++++++++++----- Assets/Scripts/UmaViewerUI.cs | 26 +++++++++++++++++++------- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/UmaContainer.cs b/Assets/Scripts/UmaContainer.cs index f51f687..3f92981 100644 --- a/Assets/Scripts/UmaContainer.cs +++ b/Assets/Scripts/UmaContainer.cs @@ -40,8 +40,6 @@ public class UmaContainer : MonoBehaviour public void MergeModel() { if (!Body) return; - - HeadBone = (GameObject)Body.GetComponent()._assetTable.list.FindLast(a => a.Key == "head").Value; EyeHeight = 0.1f; TrackTarget = Camera.main.gameObject; @@ -137,7 +135,7 @@ public class UmaContainer : MonoBehaviour private void FixedUpdate() { - if (TrackTarget&&!isAnimatorControl) + if (TrackTarget&&!isAnimatorControl&&!IsMini) { var targetPosotion = TrackTarget.transform.position - HeadBone.transform.up*EyeHeight; var deltaPos = HeadBone.transform.InverseTransformPoint(targetPosotion); @@ -146,7 +144,7 @@ public class UmaContainer : MonoBehaviour FaceDrivenKeyTarget.SetEyeRange(finalRotation.x, finalRotation.y, finalRotation.x, -finalRotation.y); } - if (isAnimatorControl) + if (isAnimatorControl && !IsMini) { FaceDrivenKeyTarget.ProcessLocator(); } diff --git a/Assets/Scripts/UmaViewerBuilder.cs b/Assets/Scripts/UmaViewerBuilder.cs index 03ead08..332bed5 100644 --- a/Assets/Scripts/UmaViewerBuilder.cs +++ b/Assets/Scripts/UmaViewerBuilder.cs @@ -286,8 +286,11 @@ public class UmaViewerBuilder : MonoBehaviour emotionDriven.FaceDrivenKeyTarget = FaceDriven; emotionDriven.FaceEmotionKey = UmaDatabaseController.Instance.FaceTypeData.ToList(); emotionDriven.Initialize(); + + CurrentUMAContainer.HeadBone = (GameObject)CurrentUMAContainer.Body.GetComponent()._assetTable.list.FindLast(a => a.Key == "head").Value; } + CurrentUMAContainer.MergeModel(); CurrentUMAContainer.LoadPhysics(); LoadAsset(UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"anm_eve_chr{id}_00_idle01_loop"))); @@ -956,8 +959,12 @@ public class UmaViewerBuilder : MonoBehaviour } else if (clip.name.Contains("face")) { - CurrentUMAContainer.FaceOverrideController["clip_1"] = clip; - CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator(); + if (CurrentUMAContainer.FaceDrivenKeyTarget) + { + CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator(); + CurrentUMAContainer.FaceOverrideController["clip_1"] = clip; + } + CurrentUMAContainer.isAnimatorControl = true; CurrentUMAContainer.UmaFaceAnimator.Play("motion_1", 0, 0); } @@ -996,7 +1003,8 @@ public class UmaViewerBuilder : MonoBehaviour else { CurrentUMAContainer.isAnimatorControl = false; - CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator(); + if (CurrentUMAContainer.FaceDrivenKeyTarget) + CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator(); PreviewCamera.enabled = false; if (CurrentCameraAnimator) @@ -1095,8 +1103,11 @@ public class UmaViewerBuilder : MonoBehaviour if (container.Slider != null) container.Slider.SetValueWithoutNotify(0); } - CurrentUMAContainer.FaceDrivenKeyTarget.ClearMorph(); - CurrentUMAContainer.FaceDrivenKeyTarget.ChangeMorph(); + if (CurrentUMAContainer.FaceDrivenKeyTarget) + { + CurrentUMAContainer.FaceDrivenKeyTarget.ClearMorph(); + CurrentUMAContainer.FaceDrivenKeyTarget.ChangeMorph(); + } } } diff --git a/Assets/Scripts/UmaViewerUI.cs b/Assets/Scripts/UmaViewerUI.cs index 8f1e703..0da6609 100644 --- a/Assets/Scripts/UmaViewerUI.cs +++ b/Assets/Scripts/UmaViewerUI.cs @@ -565,6 +565,7 @@ public class UmaViewerUI : MonoBehaviour AnimationSlider.SetValueWithoutNotify(0); // Reset settings by Panel Builder.CurrentUMAContainer.UmaAnimator.speed = AnimationSpeedSlider.value; + if(Builder.CurrentUMAContainer.UmaFaceAnimator) Builder.CurrentUMAContainer.UmaFaceAnimator.speed = AnimationSpeedSlider.value; } @@ -668,23 +669,28 @@ public class UmaViewerUI : MonoBehaviour if (state) { animator.speed = 0; - animator_face.speed = 0; + if (animator_face) + animator_face.speed = 0; animator_cam.speed = 0; } else if (AnimeState.normalizedTime < 1f) { animator.speed = AnimationSpeedSlider.value; - animator_face.speed = AnimationSpeedSlider.value; animator_cam.speed = AnimationSpeedSlider.value; + if (animator_face) + animator_face.speed = AnimationSpeedSlider.value; } else { animator.speed = AnimationSpeedSlider.value; animator.Play(0, -1, 0); - animator_face.speed = AnimationSpeedSlider.value; - animator_face.Play(0, -1, 0); animator_cam.speed = AnimationSpeedSlider.value; animator_cam.Play(0, -1, 0); + if (animator_face) + { + animator_face.speed = AnimationSpeedSlider.value; + animator_face.Play(0, -1, 0); + } } } @@ -703,10 +709,13 @@ public class UmaViewerUI : MonoBehaviour // Pause and Seek; animator.speed = 0; animator.Play(0, -1, val); - animator_face.speed = 0; - animator_face.Play(0, -1, val); animator_cam.speed = 0; animator_cam.Play(0, -1, val); + if (animator_face) + { + animator_face.speed = 0; + animator_face.Play(0, -1, val); + } AnimationProgressText.text = string.Format("{0} / {1}", ToFrameFormat(val * AnimeClip.length, AnimeClip.frameRate), ToFrameFormat(AnimeClip.length, AnimeClip.frameRate)); } @@ -717,8 +726,11 @@ public class UmaViewerUI : MonoBehaviour AnimationSpeedText.text = string.Format("Animation Speed: {0:F2}", val); if (!Builder.CurrentUMAContainer || !Builder.CurrentUMAContainer.UmaAnimator) return; Builder.CurrentUMAContainer.UmaAnimator.speed = val; - Builder.CurrentUMAContainer.UmaFaceAnimator.speed = val; Builder.CurrentCameraAnimator.speed = val; + if (Builder.CurrentUMAContainer.UmaFaceAnimator) + { + Builder.CurrentUMAContainer.UmaFaceAnimator.speed = val; + } } public void ResetAudioPlayer()