From de0c02e755d262cab112fdeefebcfdca72954180 Mon Sep 17 00:00:00 2001 From: CroakFang <1605296300@qq.com> Date: Sun, 20 Nov 2022 17:57:09 +0800 Subject: [PATCH] Add other facial morph support ,bug fix --- Assets/Scenes/Version2.unity | 6 +- Assets/Scripts/UmaContainer.cs | 61 ++++---- Assets/Scripts/UmaViewerBuilder.cs | 96 ++++++------ Assets/Scripts/UmaViewerUI.cs | 16 +- .../umamusume/Gallop/FaceDrivenKeyTarget.cs | 68 +++++++- .../Scripts/umamusume/Gallop/FacialMorph.cs | 7 +- .../umamusume/Gallop/TearController.cs | 148 ++++++++++++++++++ .../umamusume/Gallop/TearController.cs.meta | 11 ++ 8 files changed, 324 insertions(+), 89 deletions(-) create mode 100644 Assets/Scripts/umamusume/Gallop/TearController.cs create mode 100644 Assets/Scripts/umamusume/Gallop/TearController.cs.meta diff --git a/Assets/Scenes/Version2.unity b/Assets/Scenes/Version2.unity index 9701489..119b79b 100644 --- a/Assets/Scenes/Version2.unity +++ b/Assets/Scenes/Version2.unity @@ -23405,8 +23405,8 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1882365343} m_HandleRect: {fileID: 1882365342} m_Direction: 2 - m_Value: 0.9999985 - m_Size: 0.9257714 + m_Value: 1 + m_Size: 0.92577153 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -36794,7 +36794,7 @@ MonoBehaviour: m_StringArgument: m_BoolArgument: 0 m_CallState: 2 - - m_Target: {fileID: 1923521930} + - m_Target: {fileID: 1443017299} m_TargetAssemblyTypeName: UnityEngine.UI.Selectable, UnityEngine.UI m_MethodName: set_interactable m_Mode: 6 diff --git a/Assets/Scripts/UmaContainer.cs b/Assets/Scripts/UmaContainer.cs index 80bd51d..bbbe169 100644 --- a/Assets/Scripts/UmaContainer.cs +++ b/Assets/Scripts/UmaContainer.cs @@ -45,8 +45,9 @@ public class UmaContainer : MonoBehaviour public List RightMangaObject = new List(); [Header("Tear")] - public List TearObjects_0 = new List(); - public List TearObjects_1 = new List(); + public GameObject TearPrefab_0; + public GameObject TearPrefab_1; + public List TearControllers = new List(); [Header("Generic")] public bool IsGeneric = false; @@ -192,39 +193,45 @@ public class UmaContainer : MonoBehaviour private void FixedUpdate() { - if (TrackTarget && EnableEyeTracking && !isAnimatorControl && !IsMini) + if (!IsMini) { - var targetPosotion = TrackTarget.transform.position - HeadBone.transform.up*EyeHeight; - var deltaPos = HeadBone.transform.InverseTransformPoint(targetPosotion); - var deltaRotation = Quaternion.LookRotation(deltaPos.normalized, HeadBone.transform.up).eulerAngles; - if (deltaRotation.x > 180) deltaRotation.x -= 360; - if (deltaRotation.y > 180) deltaRotation.y -= 360; + if (TrackTarget && EnableEyeTracking && !isAnimatorControl) + { + var targetPosotion = TrackTarget.transform.position - HeadBone.transform.up * EyeHeight; + var deltaPos = HeadBone.transform.InverseTransformPoint(targetPosotion); + var deltaRotation = Quaternion.LookRotation(deltaPos.normalized, HeadBone.transform.up).eulerAngles; + if (deltaRotation.x > 180) deltaRotation.x -= 360; + if (deltaRotation.y > 180) deltaRotation.y -= 360; - var finalRotation = new Vector2(Mathf.Clamp(deltaRotation.y / 35,-1,1), Mathf.Clamp(-deltaRotation.x / 25, -1, 1));//Limited to the angle of view - FaceDrivenKeyTarget.SetEyeRange(finalRotation.x, finalRotation.y, finalRotation.x, -finalRotation.y); - } + var finalRotation = new Vector2(Mathf.Clamp(deltaRotation.y / 35, -1, 1), Mathf.Clamp(-deltaRotation.x / 25, -1, 1));//Limited to the angle of view + FaceDrivenKeyTarget.SetEyeRange(finalRotation.x, finalRotation.y, finalRotation.x, -finalRotation.y); + } - if (isAnimatorControl && !IsMini) - { - FaceDrivenKeyTarget.ProcessLocator(); - } - - if (!IsMini && FaceMaterial) - { if (isAnimatorControl) { - FaceMaterial.SetVector("_FaceForward", Vector3.zero); - FaceMaterial.SetVector("_FaceUp", Vector3.zero); - FaceMaterial.SetVector("_FaceCenterPos", Vector3.zero); - + FaceDrivenKeyTarget.ProcessLocator(); } - else + + if (FaceMaterial) { - //Used to calculate facial shadows - FaceMaterial.SetVector("_FaceForward", HeadBone.transform.forward); - FaceMaterial.SetVector("_FaceUp", HeadBone.transform.up); - FaceMaterial.SetVector("_FaceCenterPos", HeadBone.transform.position); + if (isAnimatorControl) + { + FaceMaterial.SetVector("_FaceForward", Vector3.zero); + FaceMaterial.SetVector("_FaceUp", Vector3.zero); + FaceMaterial.SetVector("_FaceCenterPos", Vector3.zero); + + } + else + { + //Used to calculate facial shadows + FaceMaterial.SetVector("_FaceForward", HeadBone.transform.forward); + FaceMaterial.SetVector("_FaceUp", HeadBone.transform.up); + FaceMaterial.SetVector("_FaceCenterPos", HeadBone.transform.position); + } + FaceMaterial.SetFloat("_faceShadowEndY", HeadBone.transform.position.y); } + + TearControllers.ForEach(a => a.UpdateOffset()); } } diff --git a/Assets/Scripts/UmaViewerBuilder.cs b/Assets/Scripts/UmaViewerBuilder.cs index df01963..c06ac82 100644 --- a/Assets/Scripts/UmaViewerBuilder.cs +++ b/Assets/Scripts/UmaViewerBuilder.cs @@ -298,24 +298,30 @@ public class UmaViewerBuilder : MonoBehaviour CurrentUMAContainer.LeftMangaObject.Add(leftObj); var RightObj = Instantiate(obj, eyeLocator_R.transform); - bool invert = false; if (RightObj.TryGetComponent(out var holder)) { if (holder._assetTableValue["invert"] > 0) - invert = true; + RightObj.transform.localScale = new Vector3(-1, 1, 1); } - new List(RightObj.GetComponentsInChildren()).ForEach(a => { - a.material.renderQueue = -1; - if (invert) a.material.mainTextureScale = new Vector2(-1, 1); - }); + new List(RightObj.GetComponentsInChildren()).ForEach(a => { a.material.renderQueue = -1; }); CurrentUMAContainer.RightMangaObject.Add(RightObj); }); - var tearEntry = Main.AbChara.FindAll(a => a.Name.StartsWith("3d/chara/common/tear/")&& a.Name.Contains("pfb_chr_tear")); + var tearEntry = Main.AbChara.FindAll(a => a.Name.StartsWith("3d/chara/common/tear/") && a.Name.Contains("pfb_chr_tear")); if (tearEntry.Count > 0) { tearEntry.ForEach(a => RecursiveLoadAsset(a)); } + if (CurrentUMAContainer.TearPrefab_0 && CurrentUMAContainer.TearPrefab_1) + { + var p0 = CurrentUMAContainer.TearPrefab_0; + var p1 = CurrentUMAContainer.TearPrefab_1; + var t = headBone.transform; + CurrentUMAContainer.TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 0, 1)); + CurrentUMAContainer.TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 0, 0)); + CurrentUMAContainer.TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 1, 1)); + CurrentUMAContainer.TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 1, 0)); + } var firsehead = CurrentUMAContainer.Head; var faceDriven = firsehead.GetComponent()._assetTable["facial_target"] as FaceDrivenKeyTarget; @@ -338,7 +344,7 @@ public class UmaViewerBuilder : MonoBehaviour CurrentUMAContainer.EyeHeight = CurrentUMAContainer.Head.GetComponent()._assetTableValue["head_center_offset_y"]; CurrentUMAContainer.MergeModel(); CurrentUMAContainer.Initialize(); - + CurrentUMAContainer.SetHeight(Convert.ToInt32(CurrentUMAContainer.CharaData["scale"])); LoadAsset(UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"anm_eve_chr{id}_00_idle01_loop"))); } @@ -713,7 +719,7 @@ public class UmaViewerBuilder : MonoBehaviour LoadAnimation(aClip); } - if (CurrentLiveContainer|| aClip.name.Contains("tear")) + if (CurrentLiveContainer || aClip.name.Contains("tear")) { break; } @@ -1027,57 +1033,52 @@ public class UmaViewerBuilder : MonoBehaviour private void LoadTear(GameObject go) { - //WIP - //if (CurrentUMAContainer) - //{ - // var headBone = (GameObject)CurrentUMAContainer.Head.GetComponent()._assetTable["head"]; - // var attachBone_2_L = headBone.transform.Find("Eye_tear_attach_02_L"); - // var attachBone_2_R = headBone.transform.Find("Eye_tear_attach_02_R"); - // var attachBone_3_L = headBone.transform.Find("Eye_tear_attach_03_L"); - // var attachBone_3_R = headBone.transform.Find("Eye_tear_attach_03_R"); - // var ani = go.GetComponent(); - // var controller = new AnimatorOverrideController(ani.runtimeAnimatorController); - // controller["anm_tear000_00"] = go.GetComponent()._assetTable["default_animation"] as AnimationClip; - // ani.runtimeAnimatorController = controller; - // if (go.name.EndsWith("000")) - // { - // for(int i = 0; i < 4; i++) - // { - // var obj = Instantiate(go, headBone.transform); - // var attachBone = (i % 2 == 0 ? attachBone_3_L : attachBone_3_R); - // obj.transform.SetPositionAndRotation(attachBone.TransformPoint(Vector3.zero), attachBone.transform.rotation); - // CurrentUMAContainer.TearObjects_0.Add(obj); - // } - // } - // else if(go.name.EndsWith("001")) - // { - // for (int i = 0; i < 4; i++) - // { - // var obj = Instantiate(go, headBone.transform); - // var attachBone = (i % 2 == 0 ? attachBone_2_L : attachBone_2_R); - // obj.transform.SetPositionAndRotation(attachBone.TransformPoint(Vector3.zero), attachBone.transform.rotation); - // CurrentUMAContainer.TearObjects_1.Add(obj); - // } - // } - //} + if (CurrentUMAContainer) + { + if (go.name.EndsWith("000")) + { + CurrentUMAContainer.TearPrefab_0 = go; + } + else if (go.name.EndsWith("001")) + { + CurrentUMAContainer.TearPrefab_1 = go; + } + } } private void LoadAnimation(AnimationClip clip) { - bool needTransit = false; if (clip.name.EndsWith("_S")) { + CurrentUMAContainer.UpBodyReset(); CurrentUMAContainer.OverrideController["clip_s"] = clip; } else if (clip.name.EndsWith("_E")) { + CurrentUMAContainer.UpBodyReset(); CurrentUMAContainer.OverrideController["clip_e"] = clip; } else if (clip.name.EndsWith("_loop")) { - var motion_s = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name.Replace("_loop", "_s"))); - var motion_e = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(CurrentUMAContainer.OverrideController["clip_2"].name.Replace("_loop", "_e"))); + CurrentUMAContainer.UpBodyReset(); + UmaDatabaseEntry motion_e = null, motion_s = null; + if (clip.name.EndsWith("_loop")) + { + motion_s = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name.Replace("_loop", "_s"))); + } + + if (CurrentUMAContainer.OverrideController["clip_2"].name.EndsWith("_loop")) + { + motion_e = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(CurrentUMAContainer.OverrideController["clip_2"].name.Replace("_loop", "_e"))); + } + + if (CurrentUMAContainer.isAnimatorControl && CurrentUMAContainer.FaceDrivenKeyTarget) + { + CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator(); + } + + bool needTransit = false; needTransit = (motion_s != null && motion_e != null); if (needTransit) { @@ -1097,6 +1098,7 @@ public class UmaViewerBuilder : MonoBehaviour else if (clip.name.Contains("tail")) { if (CurrentUMAContainer.IsMini) return; + CurrentUMAContainer.UpBodyReset(); CurrentUMAContainer.OverrideController["clip_t"] = clip; CurrentUMAContainer.UmaAnimator.Play("motion_t", 1, 0); } @@ -1175,7 +1177,7 @@ public class UmaViewerBuilder : MonoBehaviour var nextMotion = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"{param[0]}_{param[1]}_{param[2]}_{param[3]}_0{index}")); var aevent = new AnimationEvent { - time = clip.length*0.99f, + time = clip.length * 0.99f, stringParameter = (nextMotion != null ? nextMotion.Name : null), functionName = (nextMotion != null ? "SetNextAnimationCut" : "SetEndAnimationCut") }; @@ -1193,7 +1195,7 @@ public class UmaViewerBuilder : MonoBehaviour SetPreviewCamera(null); CurrentUMAContainer.UmaAnimator.Play("motion_1", 0, lastTime); - CurrentUMAContainer.UmaAnimator.SetTrigger(needTransit ? "next_s" : "next"); + CurrentUMAContainer.UmaAnimator.SetTrigger("next"); } } } diff --git a/Assets/Scripts/UmaViewerUI.cs b/Assets/Scripts/UmaViewerUI.cs index bcc3241..f093fb2 100644 --- a/Assets/Scripts/UmaViewerUI.cs +++ b/Assets/Scripts/UmaViewerUI.cs @@ -224,7 +224,7 @@ public class UmaViewerUI : MonoBehaviour foreach(var prop in extraMorph.BindProperties) { var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent(); - container.Name = $"{morph.name}_{extraMorph.BindProperties.IndexOf(prop)}_{prop.Type}"; + container.Name = $"{morph.locator.name}({prop.Type})"; container.Slider.value = prop.Value; switch (prop.Type) { @@ -243,15 +243,25 @@ public class UmaViewerUI : MonoBehaviour container.Slider.maxValue = prop.BindPrefab.Count/2 - 1; container.Slider.minValue = 0; break; - case BindProperty.BindType.Bool: + case BindProperty.BindType.Enable: + case BindProperty.BindType.TearSelect: + case BindProperty.BindType.TearSide: container.Slider.wholeNumbers = true; container.Slider.maxValue = 1; container.Slider.minValue = 0; break; + case BindProperty.BindType.TearWeight: + container.Slider.maxValue = 1; + container.Slider.minValue = 0; + break; + case BindProperty.BindType.TearSpeed: + container.Slider.maxValue = 2; + container.Slider.minValue = 0; + break; } container.Slider.onValueChanged.AddListener((a) => { target.ChangeMorphWeight(prop, a); - if(prop.Type == BindProperty.BindType.Bool&& morph.name.Contains("Manga")) + if(prop.Type == BindProperty.BindType.Enable&& morph.name.Contains("Manga")) { target.ChangeMorphWeight(target.EyeMorphs[42], container.Slider.value > 0 ? 1 : 0); target.ChangeMorphWeight(target.EyeMorphs[43], container.Slider.value > 0 ? 1 : 0); diff --git a/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs b/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs index 747507b..f08b77b 100644 --- a/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs +++ b/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs @@ -258,10 +258,49 @@ namespace Gallop FaceMangaMorph.BindProperties.Add(new BindProperty() { Part = BindProperty.LocatorPart.ScaX, - Type = BindProperty.BindType.Bool, + Type = BindProperty.BindType.Enable, BindPrefab = mangaObjects }); OtherMorphs.Add(FaceMangaMorph); + + foreach(var tear in Container.TearControllers) + { + var index = Container.TearControllers.IndexOf(tear); + FacialExtraMorph FaceTearMorph = new FacialExtraMorph() + { + name = $"Tear{index}_Ctrl", + locator = DrivenKeyLocator.Find($"Tear{index}_Ctrl") + }; + FaceTearMorph.BindProperties.Add(new BindProperty() + { + Part = BindProperty.LocatorPart.ScaX, + Type = BindProperty.BindType.TearWeight, + BindTearController = tear, + Value = tear.Weight + }); + FaceTearMorph.BindProperties.Add(new BindProperty() + { + Part = BindProperty.LocatorPart.PosY, + Type = BindProperty.BindType.TearSide, + BindTearController = tear, + Value = tear.CurrentDir + }); + FaceTearMorph.BindProperties.Add(new BindProperty() + { + Part = BindProperty.LocatorPart.ScaY, + Type = BindProperty.BindType.TearSelect, + BindTearController = tear, + Value = tear.CurrenObject + }); + FaceTearMorph.BindProperties.Add(new BindProperty() + { + Part = BindProperty.LocatorPart.ScaZ, + Type = BindProperty.BindType.TearSpeed, + BindTearController = tear, + Value = tear.Speed + }); + OtherMorphs.Add(FaceTearMorph); + } } public void SetupAnimator() @@ -380,12 +419,24 @@ namespace Gallop property.BindPrefab.ForEach(a => a.SetActive(val + count < property.BindPrefab.Count && (val == property.BindPrefab.IndexOf(a) || val + count == property.BindPrefab.IndexOf(a)))); break; - case BindProperty.BindType.Bool: + case BindProperty.BindType.Enable: if (property.Value <= 0) { property.BindPrefab.ForEach(a =>a.SetActive(false)); } break; + case BindProperty.BindType.TearSide: + property.BindTearController.SetDir((int)property.Value); + break; + case BindProperty.BindType.TearWeight: + property.BindTearController.SetWegiht(property.Value); + break; + case BindProperty.BindType.TearSelect: + property.BindTearController.SetObject((int)property.Value); + break; + case BindProperty.BindType.TearSpeed: + property.BindTearController.SetSpeed(property.Value); + break; } } } @@ -491,12 +542,6 @@ namespace Gallop } }); - LeftEyeXrange.weight = -(EyeballCtrl_L_Locator.transform.localPosition.x * -100 + EyeballCtrl_All_Locator.transform.localPosition.x * -100); - RightEyeXrange.weight = -(EyeballCtrl_R_Locator.transform.localPosition.x * -100 + EyeballCtrl_All_Locator.transform.localPosition.x * -100); - - LeftEyeYrange.weight = -(EyeballCtrl_L_Locator.transform.localPosition.y * -100 + EyeballCtrl_All_Locator.transform.localPosition.y * -100); - RightEyeYrange.weight = (EyeballCtrl_R_Locator.transform.localPosition.y * -100 + EyeballCtrl_All_Locator.transform.localPosition.y * -100); - OtherMorphs.ForEach(morph => { morph.BindProperties.ForEach(property => @@ -505,12 +550,19 @@ namespace Gallop }); }); + LeftEyeXrange.weight = -(EyeballCtrl_L_Locator.transform.localPosition.x * -100 + EyeballCtrl_All_Locator.transform.localPosition.x * -100); + RightEyeXrange.weight = -(EyeballCtrl_R_Locator.transform.localPosition.x * -100 + EyeballCtrl_All_Locator.transform.localPosition.x * -100); + + LeftEyeYrange.weight = -(EyeballCtrl_L_Locator.transform.localPosition.y * -100 + EyeballCtrl_All_Locator.transform.localPosition.y * -100); + RightEyeYrange.weight = (EyeballCtrl_R_Locator.transform.localPosition.y * -100 + EyeballCtrl_All_Locator.transform.localPosition.y * -100); + ChangeMorph(); } public void ResetLocator() { Container.UmaFaceAnimator.Rebind(); + ProcessLocator(); ChangeMorph(); } } diff --git a/Assets/Scripts/umamusume/Gallop/FacialMorph.cs b/Assets/Scripts/umamusume/Gallop/FacialMorph.cs index 6ac414d..a548c8e 100644 --- a/Assets/Scripts/umamusume/Gallop/FacialMorph.cs +++ b/Assets/Scripts/umamusume/Gallop/FacialMorph.cs @@ -57,10 +57,15 @@ namespace Gallop Select, EyeSelect, Texture, - Bool + Enable, + TearSide, + TearWeight, + TearSelect, + TearSpeed } public Material BindMaterial; public Texture BindTexture; + public TearController BindTearController; public List BindPrefab = new List(); public string PropertyName; public LocatorPart Part; diff --git a/Assets/Scripts/umamusume/Gallop/TearController.cs b/Assets/Scripts/umamusume/Gallop/TearController.cs new file mode 100644 index 0000000..15d08fe --- /dev/null +++ b/Assets/Scripts/umamusume/Gallop/TearController.cs @@ -0,0 +1,148 @@ +using Gallop; +using UnityEngine; + +public class TearController +{ + public GameObject TearObject_0; + public GameObject TearObject_1; + + public Material CurrentMaterial; + public Material TearMaterial_0; + public Material TearMaterial_1; + + public int CurrenObject; + public int CurrentDir; + public float Weight; + public float Speed = 1; + + private Animator CurrentAnimator; + private Animator Animator_0; + private Animator Animator_1; + + private Transform AttachBone_2_L; + private Transform AttachBone_2_R; + private Transform AttachBone_3_L; + private Transform AttachBone_3_R; + + private AssetHolder CurrentAssetHolder; + private AssetHolder AssetHolder0; + private AssetHolder AssetHolder1; + + bool intialized; + public TearController(Transform headBone, GameObject tearPrefab_0, GameObject tearPrefab_1, int dir, int currentObject) + { + AttachBone_2_L = headBone.transform.Find("Eye_tear_attach_02_L"); + AttachBone_2_R = headBone.transform.Find("Eye_tear_attach_02_R"); + AttachBone_3_L = headBone.transform.Find("Eye_tear_attach_03_L"); + AttachBone_3_R = headBone.transform.Find("Eye_tear_attach_03_R"); + + TearObject_0 = tearPrefab_0; + AssetHolder0 = TearObject_0.GetComponent(); + TearMaterial_0 = TearObject_0.GetComponentInChildren().material; + Animator_0 = TearObject_0.GetComponent(); + var clip = AssetHolder0._assetTable["default_animation"] as AnimationClip; + var controller = new AnimatorOverrideController(Animator_0.runtimeAnimatorController); + controller["anm_tear000_00"] = clip; + Animator_0.runtimeAnimatorController = controller; + + TearObject_1 = tearPrefab_1; + AssetHolder1 = TearObject_1.GetComponent(); + TearMaterial_1 = TearObject_1.GetComponentInChildren().material; + Animator_1 = TearObject_1.GetComponent(); + clip = AssetHolder1._assetTable["default_animation"] as AnimationClip; + controller = new AnimatorOverrideController(Animator_1.runtimeAnimatorController); + controller["anm_tear000_00"] = clip; + Animator_1.runtimeAnimatorController = controller; + + SetWegiht(0); + SetDir(dir); + SetObject(currentObject); + + intialized = true; + } + + public void SetDir(int dir) + { + if (intialized && ((dir > 0 && CurrentDir > 0) || (dir <= 0 && CurrentDir <= 0))) return; + + CurrentDir = dir; + if (dir > 0)//RightEye + { + TearObject_0.transform.position = AttachBone_3_R.position + AttachBone_3_R.forward * 0.004f; + TearObject_1.transform.position = AttachBone_2_R.position + AttachBone_2_R.forward * 0.004f; + TearObject_0.transform.localScale = new Vector3(-1, 1, 1); + TearObject_1.transform.localScale = new Vector3(-1, 1, 1); + } + else//LeftEye + { + TearObject_0.transform.position = AttachBone_3_L.position + AttachBone_3_L.forward * 0.004f; + TearObject_1.transform.position = AttachBone_2_L.position + AttachBone_2_L.forward * 0.004f; + TearObject_0.transform.localScale = new Vector3(1, 1, 1); + TearObject_1.transform.localScale = new Vector3(1, 1, 1); + } + } + + public void SetObject(int curObject) + { + if (intialized && ((curObject < 1 && CurrenObject < 1) || (curObject >= 1 && CurrenObject >= 1))) return; + + CurrenObject = curObject; + CurrentAnimator = (curObject < 1) ? Animator_0 : Animator_1; + CurrentMaterial = (curObject < 1) ? TearMaterial_0 : TearMaterial_1; + CurrentAssetHolder = (curObject < 1) ? AssetHolder0 : AssetHolder1; + if (Weight > 0) + { + TearObject_0.SetActive(curObject < 1); + TearObject_1.SetActive(curObject >= 1); + } + } + + public void SetWegiht(float weight) + { + if (intialized && (weight <= 0 && Weight <= 0)) return; + + Weight = weight; + if (weight <= 0) + { + TearObject_0.SetActive(false); + TearObject_1.SetActive(false); + } + else + { + TearObject_0.SetActive(CurrenObject < 1); + TearObject_1.SetActive(CurrenObject >= 1); + } + } + + public void SetSpeed(float speed) + { + if (speed == Speed) return; + Speed = speed; + Animator_0.speed = speed; + Animator_1.speed = speed; + } + + public void UpdateOffset() + { + if (Weight <= 0) return; + + var time = Mathf.Repeat(CurrentAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime,1); + var width = (int)CurrentAssetHolder._assetTableValue["texture_width"]; + var height = (int)CurrentAssetHolder._assetTableValue["texture_height"]; + var partWidth = (int)CurrentAssetHolder._assetTableValue["texture_part_width"]; + var partHeight = (int)CurrentAssetHolder._assetTableValue["texture_part_height"]; + var offset = GetTextureOffset(time, width, height, partWidth, partHeight); + CurrentMaterial.SetColor("_TexScrollParam", new Color(offset.x, -offset.y, 0, Weight)); + } + + private Vector2 GetTextureOffset(float time,int w,int h,int pw ,int ph) + { + int wCount = w / pw; + int hCount = h / ph; + int index = (int)(time * (wCount * hCount)); + return new Vector2((index % wCount) / (float)wCount,(index/wCount)/(float)hCount); + } + + +} + diff --git a/Assets/Scripts/umamusume/Gallop/TearController.cs.meta b/Assets/Scripts/umamusume/Gallop/TearController.cs.meta new file mode 100644 index 0000000..06832f7 --- /dev/null +++ b/Assets/Scripts/umamusume/Gallop/TearController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 52416b72680489b4a9a3b590b739e09a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: