Optimize the code

This commit is contained in:
CroakFang
2023-07-08 22:41:47 +08:00
parent 5ce66189ee
commit 30a6e8d5f7
4 changed files with 146 additions and 146 deletions
+1
View File
@@ -66,3 +66,4 @@ crashlytics-build.properties
/umamusume /umamusume
Config.json Config.json
/gltf /gltf
/Assets/Plugins/RootMotion/FinalIK/_Integration
+2 -2
View File
@@ -44,13 +44,13 @@ public class UmaSceneController:MonoBehaviour
// Wait until the last operation fully loads to return anything // Wait until the last operation fully loads to return anything
yield return new WaitUntil(()=> asyncLoad.isDone); yield return new WaitUntil(()=> asyncLoad.isDone);
OnSceneloaded.Invoke(); OnSceneloaded();
// Unload the previous Scene // Unload the previous Scene
AsyncOperation asyncUnLoad = SceneManager.UnloadSceneAsync(currentScene); AsyncOperation asyncUnLoad = SceneManager.UnloadSceneAsync(currentScene);
yield return new WaitUntil(() => asyncUnLoad.isDone); yield return new WaitUntil(() => asyncUnLoad.isDone);
OnLastSceneUnloaded.Invoke(); OnLastSceneUnloaded();
animation.Play("SceneTransition_e"); animation.Play("SceneTransition_e");
yield return new WaitUntil(() => !animation.isPlaying); yield return new WaitUntil(() => !animation.isPlaying);
+142 -143
View File
@@ -8,6 +8,7 @@ using System.IO;
using System.Linq; using System.Linq;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI; using UnityEngine.UI;
using Debug = UnityEngine.Debug; using Debug = UnityEngine.Debug;
@@ -345,69 +346,6 @@ public class UmaViewerUI : MonoBehaviour
} }
} }
public void InstantiateFacialPart(GameObject UmaContainerSliderPrefab, FaceDrivenKeyTarget target, List<FacialMorph> targetMorph, ScrollRect TargetList)
{
foreach (FacialMorph morph in targetMorph)
{
if (morph is FacialOtherMorph extraMorph)
{
foreach (var prop in extraMorph.BindProperties)
{
var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent<UmaUIContainer>();
Debug.Log(morph.name);
container.Name = $"{morph.locator.name}({prop.Type})";
container.Slider.value = prop.Value;
switch (prop.Type)
{
case BindProperty.BindType.Shader:
case BindProperty.BindType.Texture:
container.Slider.maxValue = 1;
container.Slider.minValue = 0;
break;
case BindProperty.BindType.Select:
container.Slider.wholeNumbers = true;
container.Slider.maxValue = prop.BindPrefab.Count - 1;
container.Slider.minValue = 0;
break;
case BindProperty.BindType.EyeSelect:
container.Slider.wholeNumbers = true;
container.Slider.maxValue = prop.BindPrefab.Count / 2 - 1;
container.Slider.minValue = 0;
break;
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, morph);
});
}
}
else
{
var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent<UmaUIContainer>();
container.Name = $"{morph.name}({morph.tag})";
container.Slider.value = morph.weight;
container.Slider.maxValue = 1;
container.Slider.minValue = morph.tag.Contains("Range") ? -1 : 0;
container.Slider.onValueChanged.AddListener((a) => { target.ChangeMorphWeight(morph, a); });
}
}
}
public void LoadFacialPanels(FaceDrivenKeyTarget target) public void LoadFacialPanels(FaceDrivenKeyTarget target)
{ {
currentFaceDrivenKeyTarget = target; currentFaceDrivenKeyTarget = target;
@@ -418,14 +356,74 @@ public class UmaViewerUI : MonoBehaviour
} }
if (target == null) return; if (target == null) return;
InstantiateFacialPart(UmaContainerSliderPrefab, target, target.EarMorphs, EarList);
InstantiateFacialPart(UmaContainerSliderPrefab, target, target.EyeBrowMorphs, EyeBrowList);
InstantiateFacialPart(UmaContainerSliderPrefab, target, target.EyeMorphs, EyeList);
InstantiateFacialPart(UmaContainerSliderPrefab, target, target.MouthMorphs, MouthList);
List<FacialMorph> targetMorph = new List<FacialMorph>(target.OtherMorphs); List<FacialMorph> targetMorph = new List<FacialMorph>(target.OtherMorphs);
InstantiateFacialPart(UmaContainerSliderPrefab, target, targetMorph, OtherList); Action<GameObject, FaceDrivenKeyTarget, List<FacialMorph>, ScrollRect> action = (UmaContainerSliderPrefab, target, targetMorph, TargetList) =>
{
foreach (FacialMorph morph in targetMorph)
{
if (morph is FacialOtherMorph extraMorph)
{
foreach (var prop in extraMorph.BindProperties)
{
var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent<UmaUIContainer>();
Debug.Log(morph.name);
container.Name = $"{morph.locator.name}({prop.Type})";
container.Slider.value = prop.Value;
switch (prop.Type)
{
case BindProperty.BindType.Shader:
case BindProperty.BindType.Texture:
container.Slider.maxValue = 1;
container.Slider.minValue = 0;
break;
case BindProperty.BindType.Select:
container.Slider.wholeNumbers = true;
container.Slider.maxValue = prop.BindPrefab.Count - 1;
container.Slider.minValue = 0;
break;
case BindProperty.BindType.EyeSelect:
container.Slider.wholeNumbers = true;
container.Slider.maxValue = prop.BindPrefab.Count / 2 - 1;
container.Slider.minValue = 0;
break;
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, morph);
});
}
}
else
{
var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent<UmaUIContainer>();
container.Name = $"{morph.name}({morph.tag})";
container.Slider.value = morph.weight;
container.Slider.maxValue = 1;
container.Slider.minValue = morph.tag.Contains("Range") ? -1 : 0;
container.Slider.onValueChanged.AddListener((a) => { target.ChangeMorphWeight(morph, a); });
}
}
};
action(UmaContainerSliderPrefab, target, target.EarMorphs, EarList);
action(UmaContainerSliderPrefab, target, target.EyeBrowMorphs, EyeBrowList);
action(UmaContainerSliderPrefab, target, target.EyeMorphs, EyeList);
action(UmaContainerSliderPrefab, target, target.MouthMorphs, MouthList);
action(UmaContainerSliderPrefab, target, targetMorph, OtherList);
} }
public void LoadFacialPanelsMini(Material Eye, Material MayuL, Material MayuR, Material Mouth) public void LoadFacialPanelsMini(Material Eye, Material MayuL, Material MayuR, Material Mouth)
@@ -504,31 +502,27 @@ public class UmaViewerUI : MonoBehaviour
public void LoadLivePanels() public void LoadLivePanels()
{ {
foreach (var live in Main.Lives.OrderBy(c => c.MusicId)) Action<LiveEntry, GameObject, ScrollRect, UnityAction> createContainer = (live, containerPrefab, parent, onClickAction) =>
{ {
var liveInstance = live; var container = Instantiate(containerPrefab, parent.content).GetComponent<UmaUIContainer>();
var container = Instantiate(UmaContainerLivePrefab, LiveList.content).GetComponent<UmaUIContainer>();
container.Name = " " + live.MusicId + " " + live.SongName; container.Name = " " + live.MusicId + " " + live.SongName;
container.Image.sprite = live.Icon; container.Image.sprite = live.Icon;
container.Image.enabled = container.Image.sprite; container.Image.enabled = container.Image.sprite;
container.Button.onClick.AddListener(() => container.Button.onClick.AddListener(() =>
{ {
HighlightChildImage(LiveList.content, container); HighlightChildImage(parent.content, container);
ShowLiveSelectPannel(live); onClickAction.Invoke();
}); });
};
var CharaContainer = Instantiate(UmaContainerLivePrefab, LiveSoundList.content).GetComponent<UmaUIContainer>(); foreach (var live in Main.Lives.OrderBy(c => c.MusicId))
CharaContainer.Name = " " + live.MusicId + " " + live.SongName; {
CharaContainer.Image.sprite = live.Icon; createContainer(live, UmaContainerLivePrefab, LiveList, () => ShowLiveSelectPannel(live));
CharaContainer.Image.enabled = CharaContainer.Image.sprite; createContainer(live, UmaContainerLivePrefab, LiveSoundList, () => ListLiveSounds(live.MusicId));
CharaContainer.Button.onClick.AddListener(() =>
{
HighlightChildImage(LiveSoundList.content, container);
ListLiveSounds(live.MusicId);
});
} }
} }
public void LoadNormalSoundPanels() public void LoadNormalSoundPanels()
{ {
NormalSoundCtrl.Clear(); NormalSoundCtrl.Clear();
@@ -950,13 +944,14 @@ public class UmaViewerUI : MonoBehaviour
public void LoadedAnimation() public void LoadedAnimation()
{ {
if (!Builder.CurrentUMAContainer || !Builder.CurrentUMAContainer.UmaAnimator) return; var container = Builder.CurrentUMAContainer;
if (!container || !container.UmaAnimator) return;
AnimationSlider.SetValueWithoutNotify(0); AnimationSlider.SetValueWithoutNotify(0);
// Reset settings by Panel // Reset settings by Panel
Builder.CurrentUMAContainer.UmaAnimator.speed = AnimationSpeedSlider.value; container.UmaAnimator.speed = AnimationSpeedSlider.value;
Builder.AnimationCameraAnimator.speed = AnimationSpeedSlider.value; Builder.AnimationCameraAnimator.speed = AnimationSpeedSlider.value;
if (Builder.CurrentUMAContainer.UmaFaceAnimator) if (container.UmaFaceAnimator)
Builder.CurrentUMAContainer.UmaFaceAnimator.speed = AnimationSpeedSlider.value; container.UmaFaceAnimator.speed = AnimationSpeedSlider.value;
} }
/// <summary> Toggles one object ON and all others from UI.TogglablePanels list OFF </summary> /// <summary> Toggles one object ON and all others from UI.TogglablePanels list OFF </summary>
@@ -1040,19 +1035,21 @@ public class UmaViewerUI : MonoBehaviour
public void SetFaceOverrideEnable(bool isOn) public void SetFaceOverrideEnable(bool isOn)
{ {
EnableFaceOverride = isOn; EnableFaceOverride = isOn;
if (Builder.CurrentUMAContainer && Builder.CurrentUMAContainer.FaceOverrideData) var container = Builder.CurrentUMAContainer;
if (container && container.FaceOverrideData)
{ {
Builder.CurrentUMAContainer.FaceOverrideData.Enable = isOn; container.FaceOverrideData.Enable = isOn;
} }
} }
public void AudioPause() public void AudioPause()
{ {
if (Builder.CurrentAudioSources.Count > 0) var sources = Builder.CurrentAudioSources;
if (sources.Count > 0)
{ {
AudioSource MainSource = Builder.CurrentAudioSources[0]; AudioSource MainSource = sources[0];
var state = MainSource.isPlaying; var state = MainSource.isPlaying;
foreach (AudioSource source in Builder.CurrentAudioSources) foreach (AudioSource source in sources)
{ {
if (state) if (state)
{ {
@@ -1086,51 +1083,51 @@ public class UmaViewerUI : MonoBehaviour
public void AnimationPause() public void AnimationPause()
{ {
if (!Builder.CurrentUMAContainer || !Builder.CurrentUMAContainer.UmaAnimator) return; var container = Builder.CurrentUMAContainer;
if (Builder.OverrideController.animationClips.Length > 0) if (!container || !container.UmaAnimator) return;
{ if (Builder.OverrideController.animationClips.Length == 0) return;
var animator = Builder.CurrentUMAContainer.UmaAnimator;
var animator_face = Builder.CurrentUMAContainer.UmaFaceAnimator;
var animator_cam = Builder.AnimationCameraAnimator;
var AnimeState = animator.GetCurrentAnimatorStateInfo(0);
var state = animator.speed > 0f;
if (state)
{
animator.speed = 0;
if (animator_face)
animator_face.speed = 0;
animator_cam.speed = 0;
}
else if (AnimeState.normalizedTime < 1f)
{
animator.speed = AnimationSpeedSlider.value;
animator_cam.speed = AnimationSpeedSlider.value;
if (animator_face)
animator_face.speed = AnimationSpeedSlider.value;
}
else
{
animator.speed = AnimationSpeedSlider.value;
animator.Play(0, 0, 0);
animator.Play(0, 2, 0);
animator_cam.speed = AnimationSpeedSlider.value;
animator_cam.Play(0, -1, 0);
if (animator_face)
{
animator_face.speed = AnimationSpeedSlider.value;
animator_face.Play(0, 0, 0);
animator_face.Play(0, 1, 0);
}
}
var animator = container.UmaAnimator;
var animator_face = container.UmaFaceAnimator;
var animator_cam = Builder.AnimationCameraAnimator;
var AnimeState = animator.GetCurrentAnimatorStateInfo(0);
var state = animator.speed > 0f;
if (state)
{
animator.speed = 0;
if (animator_face)
animator_face.speed = 0;
animator_cam.speed = 0;
}
else if (AnimeState.normalizedTime < 1f)
{
animator.speed = AnimationSpeedSlider.value;
animator_cam.speed = AnimationSpeedSlider.value;
if (animator_face)
animator_face.speed = AnimationSpeedSlider.value;
}
else
{
animator.speed = AnimationSpeedSlider.value;
animator.Play(0, 0, 0);
animator.Play(0, 2, 0);
animator_cam.speed = AnimationSpeedSlider.value;
animator_cam.Play(0, -1, 0);
if (animator_face)
{
animator_face.speed = AnimationSpeedSlider.value;
animator_face.Play(0, 0, 0);
animator_face.Play(0, 1, 0);
}
} }
} }
public void AnimationProgressChange(float val) public void AnimationProgressChange(float val)
{ {
if (!Builder.CurrentUMAContainer) return; var container = Builder.CurrentUMAContainer;
var animator = Builder.CurrentUMAContainer.UmaAnimator; if (!container) return;
var animator_face = Builder.CurrentUMAContainer.UmaFaceAnimator; var animator = container.UmaAnimator;
var animator_face = container.UmaFaceAnimator;
var animator_cam = Builder.AnimationCameraAnimator; var animator_cam = Builder.AnimationCameraAnimator;
if (animator != null) if (animator != null)
{ {
@@ -1158,13 +1155,16 @@ public class UmaViewerUI : MonoBehaviour
public void AnimationSpeedChange(float val) public void AnimationSpeedChange(float val)
{ {
var container = Builder.CurrentUMAContainer;
AnimationSpeedText.text = string.Format("Speed: {0:F2}", val); AnimationSpeedText.text = string.Format("Speed: {0:F2}", val);
if (!Builder.CurrentUMAContainer || !Builder.CurrentUMAContainer.UmaAnimator) return;
Builder.CurrentUMAContainer.UmaAnimator.speed = val; if (!container || !container.UmaAnimator) return;
container.UmaAnimator.speed = val;
Builder.AnimationCameraAnimator.speed = val; Builder.AnimationCameraAnimator.speed = val;
if (Builder.CurrentUMAContainer.UmaFaceAnimator) if (container.UmaFaceAnimator)
{ {
Builder.CurrentUMAContainer.UmaFaceAnimator.speed = val; container.UmaFaceAnimator.speed = val;
} }
} }
@@ -1178,7 +1178,6 @@ public class UmaViewerUI : MonoBehaviour
public static string ToTimeFormat(float time) public static string ToTimeFormat(float time)
{ {
int seconds = (int)time; int seconds = (int)time;
int hour = seconds / 3600; int hour = seconds / 3600;
int minute = seconds % 3600 / 60; int minute = seconds % 3600 / 60;
@@ -1209,16 +1208,16 @@ public class UmaViewerUI : MonoBehaviour
public void RecordVMD() public void RecordVMD()
{ {
var container = Builder.CurrentUMAContainer;
var camera = Builder.AnimationCamera;
var buttonText = VMDButton.GetComponentInChildren<TextMeshProUGUI>(); var buttonText = VMDButton.GetComponentInChildren<TextMeshProUGUI>();
if (!UmaViewerBuilder.Instance.CurrentUMAContainer || UmaViewerBuilder.Instance.CurrentUMAContainer.IsMini)
if (!container || container.IsMini)
{ {
buttonText.text = string.Format("<color=#FF0000>{0}</color>", "Need Normal UMA"); buttonText.text = string.Format("<color=#FF0000>{0}</color>", "Need Normal UMA");
return; return;
} }
var container = UmaViewerBuilder.Instance.CurrentUMAContainer;
var camera = UmaViewerBuilder.Instance.AnimationCamera;
var rootbone = container.transform.Find("Position"); var rootbone = container.transform.Find("Position");
if (rootbone.gameObject.TryGetComponent(out UnityHumanoidVMDRecorder recorder)) if (rootbone.gameObject.TryGetComponent(out UnityHumanoidVMDRecorder recorder))
{ {
@@ -1315,9 +1314,9 @@ public class UmaViewerUI : MonoBehaviour
public void ExportModel() public void ExportModel()
{ {
if (Builder.CurrentUMAContainer) var container = Builder.CurrentUMAContainer;
if (container)
{ {
var container = Builder.CurrentUMAContainer;
var path = StandaloneFileBrowser.SaveFilePanel("Save PMX File", Config.Instance.MainPath, container.gameObject.name, "pmx"); var path = StandaloneFileBrowser.SaveFilePanel("Save PMX File", Config.Instance.MainPath, container.gameObject.name, "pmx");
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))
{ {
@@ -789,7 +789,7 @@ namespace Gallop
srcmorph.weight = 0; srcmorph.weight = 0;
} }
} }
targetMorph.ForEach(a => a.Invoke()); targetMorph.ForEach(a => a());
} }
} }
}; };