add mini uma facial

This commit is contained in:
CroakFang
2023-01-15 20:30:53 +08:00
parent 213f438819
commit 6618795498
6 changed files with 1397 additions and 130 deletions
+36 -4
View File
@@ -15,29 +15,38 @@ public class PageManager : MonoBehaviour
{
public ScrollRect ScrollRect;
public InputField PageText;
public InputField SearchText;
public int ShowCount;
public GameObject ContainerPrefab;
private int totalPage;
private int currentPage = 0;
private List<Entry> Entries;
private List<Entry> SubEntries;
public void Initialize(List<Entry> entries, ScrollRect scrollRect)
{
ScrollRect = scrollRect;
Entries = entries;
if (SearchText)
SearchText.text = "";
ShowCount = Mathf.FloorToInt(ScrollRect.GetComponent<RectTransform>().rect.height / ContainerPrefab.GetComponent<RectTransform>().rect.height);
totalPage = Mathf.CeilToInt(entries.Count / (float)ShowCount);
if (totalPage > 0)
{
currentPage = 0;
LoadPage(currentPage);
SearchText.interactable = true;
}
}
public void ResetCtrl()
{
if(ScrollRect)Clear();
totalPage = 0;
currentPage = 0;
PageText.text = "";
if(SearchText)
SearchText.text = "";
SearchText.interactable = false;
SubEntries = null;
Entries = null;
((Text)PageText.placeholder).text = $"- / -";
}
@@ -45,14 +54,15 @@ public class PageManager : MonoBehaviour
private void LoadPage(int index)
{
if (totalPage == 0) return;
var entries = (SearchText && SearchText.text != "" ? SubEntries : Entries);
Clear();
PageText.text = "";
((Text)PageText.placeholder).text = $"{currentPage + 1} / {totalPage}";
var start = ShowCount * index;
for (int i = 0;i< ShowCount; i++)
{
if (start + i >= Entries.Count) break;
var entry = Entries[start + i];
if (start + i >= entries.Count) break;
var entry = entries[start + i];
var container = Instantiate(ContainerPrefab, ScrollRect.content).GetComponent<UmaUIContainer>();
container.Name = container.name = entry.Name;
if (entry.FontSize > 0)
@@ -76,8 +86,30 @@ public class PageManager : MonoBehaviour
LoadPage(currentPage);
}
private void Clear()
public void OnSearch(string val)
{
Clear();
if (Entries == null) return;
if(val == "")
{
Initialize(Entries, ScrollRect);
}
else
{
SubEntries = new List<Entry>(Entries.Where(a => a.Name.Contains(val)));
ShowCount = Mathf.FloorToInt(ScrollRect.GetComponent<RectTransform>().rect.height / ContainerPrefab.GetComponent<RectTransform>().rect.height);
totalPage = Mathf.CeilToInt(SubEntries.Count / (float)ShowCount);
if (totalPage > 0)
{
currentPage = 0;
LoadPage(currentPage);
}
}
}
public void Clear()
{
if (!ScrollRect) return;
for (int i = ScrollRect.content.childCount - 1; i >= 0; i--)
{
Destroy(ScrollRect.content.GetChild(i).gameObject);
+33 -13
View File
@@ -441,6 +441,13 @@ public class UmaViewerBuilder : MonoBehaviour
}
CurrentUMAContainer.MergeModel();
var matList = new List<MeshRenderer>(CurrentUMAContainer.GetComponentsInChildren<MeshRenderer>());
var eyemat = matList.FirstOrDefault(a => a.gameObject.name.Equals("M_Eye"));
var mouthmat = matList.FirstOrDefault(a => a.gameObject.name.Equals("M_Mouth"));
var eyebrowLmat = matList.FirstOrDefault(a => a.gameObject.name.Equals("M_Mayu_L"));
var eyebrowRmat = matList.FirstOrDefault(a => a.gameObject.name.Equals("M_Mayu_R"));
UI.LoadFacialPanelsMini(eyemat.material, eyebrowLmat.material, eyebrowRmat.material, mouthmat.material);
LoadAsset(UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"anm_min_eve_chr{id}_00_idle01_loop")));
}
public void LoadProp(UmaDatabaseEntry entry)
@@ -463,7 +470,6 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentLiveContainer = new GameObject(Path.GetFileName(asset.Name)).AddComponent<UmaContainer>();
RecursiveLoadAsset(asset);
RecursiveLoadAsset(BGasset);
}
//Use CriWare Library
@@ -511,19 +517,10 @@ public class UmaViewerBuilder : MonoBehaviour
//Use decrypt function
public void LoadLiveSound(int songid, UmaDatabaseEntry SongAwb)
{
if (CurrentAudioSources.Count > 0)
{
var tmp = CurrentAudioSources[0];
CurrentAudioSources.Clear();
Destroy(tmp.gameObject);
UI.ResetAudioPlayer();
}
foreach (AudioClip clip in LoadAudio(SongAwb))
{
AddAudioSource(clip);
}
//load character voice
PlaySound(SongAwb);
//load BG
string nameVar = $"snd_bgm_live_{songid}_oke";
UmaDatabaseEntry BGawb = Main.AbList.FirstOrDefault(a => a.Name.Contains(nameVar) && a.Name.EndsWith("awb"));
if (BGawb != null)
@@ -538,6 +535,29 @@ public class UmaViewerBuilder : MonoBehaviour
LoadLiveLyrics(songid);
}
public void PlaySound(UmaDatabaseEntry SongAwb, int subindex = -1)
{
if (CurrentAudioSources.Count > 0)
{
var tmp = CurrentAudioSources[0];
CurrentAudioSources.Clear();
Destroy(tmp.gameObject);
UI.ResetAudioPlayer();
}
if(subindex == -1)
{
foreach (AudioClip clip in LoadAudio(SongAwb))
{
AddAudioSource(clip);
}
}
else
{
AddAudioSource(LoadAudio(SongAwb)[subindex]);
}
}
private void AddAudioSource(AudioClip clip)
{
AudioSource source;
+129 -37
View File
@@ -1,4 +1,5 @@
using Gallop;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
@@ -44,6 +45,9 @@ public class UmaViewerUI : MonoBehaviour
public ScrollRect LiveList;
public ScrollRect LiveSoundList;
public ScrollRect LiveCharaSoundList;
public ScrollRect NormalSoundList;
public ScrollRect NormalSubSoundList;
public PageManager NormalSoundCtrl;
[Header("audio")]
public Slider AudioSlider;
@@ -158,10 +162,15 @@ public class UmaViewerUI : MonoBehaviour
public void LoadedAssetsAdd(UmaDatabaseEntry entry)
{
foreach (UmaUIContainer ui in LoadedAssetsPanel.GetComponentsInChildren<UmaUIContainer>())
{
if (ui.Name == Path.GetFileName(entry.Name)) return;
}
LoadedAssetCount++;
string filePath = entry.FilePath;
var container = Instantiate(UmaContainerAssetsPrefab, LoadedAssetsPanel).GetComponent<UmaUIContainer>();
container.Name = Path.GetFileName(entry.Name) + "\n" + entry.Url;
container.Name = Path.GetFileName(entry.Name);
container.Button.onClick.AddListener(() => {Process.Start("explorer.exe", "/select," + filePath);});
LoadedAssetsPanel.sizeDelta = new Vector2(0, LoadedAssetCount * 35);
}
@@ -224,6 +233,46 @@ public class UmaViewerUI : MonoBehaviour
}
}
public void LoadMiniModelPanels()
{
var container1 = Instantiate(UmaContainerPrefab, MiniAnimationSetList.content).GetComponent<UmaUIContainer>();
container1.Name = container1.name = "General";
container1.Button.onClick.AddListener(() => {
HighlightChildImage(MiniAnimationSetList.content, container1);
ListAnimations(-1, true);
});
foreach (var chara in Main.Characters.OrderBy(c => c.Id))
{
var charaInstance = chara;
var container2 = Instantiate(UmaContainerPrefab, MiniCharactersList.content).GetComponent<UmaUIContainer>();
container2.Name = container2.name = chara.Id + " " + chara.Name;
container2.Button.onClick.AddListener(() => {
HighlightChildImage(MiniCharactersList.content, container2);
ListCostumes(charaInstance.Id, true);
});
if (chara.Icon)
{
container2.Image.sprite = chara.Icon;
container2.Image.enabled = true;
}
var container3 = Instantiate(UmaContainerPrefab, MiniAnimationSetList.content).GetComponent<UmaUIContainer>();
container3.Name = container3.name = chara.Id + " " + chara.Name;
container3.Button.onClick.AddListener(() => {
HighlightChildImage(MiniAnimationSetList.content, container3);
ListAnimations(charaInstance.Id, true);
});
if (chara.Icon)
{
container3.Image.sprite = chara.Icon;
container3.Image.enabled = true;
}
}
}
public void InstantiateFacialPart(GameObject UmaContainerSliderPrefab, FaceDrivenKeyTarget target, List<FacialMorph> targetMorph, ScrollRect TargetList)
{
foreach (FacialMorph morph in targetMorph)
@@ -310,8 +359,53 @@ public class UmaViewerUI : MonoBehaviour
InstantiateFacialPart(UmaContainerSliderPrefab, target, targetMorph, OtherList);
}
public void LoadFacialPanelsMini(Material Eye, Material MayuL, Material MayuR, Material Mouth)
{
currentFaceDrivenKeyTarget = null;
foreach (UmaUIContainer ui in FacialList.GetComponentsInChildren<UmaUIContainer>(true))
{
Destroy(ui.gameObject);
}
var action = new Action<ScrollRect, string, Material, int>((list, name, mat, type) =>
{
if (mat == null) return;
var container = Instantiate(UmaContainerSliderPrefab, list.content).GetComponent<UmaUIContainer>();
container.Name = name;
container.Slider.wholeNumbers = true;
container.Slider.value = 0;
container.Slider.maxValue = 15;
container.Slider.minValue = 0;
container.Slider.onValueChanged.AddListener((a) =>
{
var val = Convert.ToInt32(a);
if (type == 0)
{
mat.mainTextureOffset = new Vector2(0.25f * (val % 4), -0.25f * (val / 4));
}
else if(type == 1)
{
var vector = mat.GetVector("_UVOffset");
mat.SetVector("_UVOffset", new Vector4(0.25f * (val % 4), -0.25f * (val / 4), vector.z, vector.w));
}
else if(type == 2)
{
var vector = mat.GetVector("_UVOffset");
mat.SetVector("_UVOffset", new Vector4(vector.x, vector.y, 0.25f * (val % 4), -0.25f * (val / 4)));
}
});
});
action(EyeList, "Eye_L_Select", Eye, 2);
action(EyeList, "Eye_R_Select", Eye, 1);
action(MouthList, "Mouth_Select", Mouth, 0);
action(EyeBrowList, "Mayu_L_Select", MayuL, 0);
action(EyeBrowList, "Mayu_R_Select", MayuR, 0);
}
public void UpdateFacialPanels()
{
if(currentFaceDrivenKeyTarget)
LoadFacialPanels(currentFaceDrivenKeyTarget);
}
@@ -364,46 +458,24 @@ public class UmaViewerUI : MonoBehaviour
}
}
public void LoadMiniModelPanels()
public void LoadNormalSoundPanels()
{
var container1 = Instantiate(UmaContainerPrefab, MiniAnimationSetList.content).GetComponent<UmaUIContainer>();
container1.Name = container1.name = "General";
container1.Button.onClick.AddListener(() => {
HighlightChildImage(MiniAnimationSetList.content, container1);
ListAnimations(-1, true);
});
foreach (var chara in Main.Characters.OrderBy(c => c.Id))
NormalSoundCtrl.Clear();
var pageentrys = new List<PageManager.Entry>();
foreach (var entry in Main.AbSounds.Where(a => (!a.Name.Contains("live")) && a.Name.EndsWith("awb")))
{
var charaInstance = chara;
var container2 = Instantiate(UmaContainerPrefab, MiniCharactersList.content).GetComponent<UmaUIContainer>();
container2.Name = container2.name = chara.Id + " " + chara.Name;
container2.Button.onClick.AddListener(() => {
HighlightChildImage(MiniCharactersList.content, container2);
ListCostumes(charaInstance.Id, true);
});
if (chara.Icon)
var pageentry = new PageManager.Entry();
pageentry.Name = Path.GetFileNameWithoutExtension(entry.Name);
pageentry.OnClick = (container) =>
{
container2.Image.sprite = chara.Icon;
container2.Image.enabled = true;
}
var container3 = Instantiate(UmaContainerPrefab, MiniAnimationSetList.content).GetComponent<UmaUIContainer>();
container3.Name = container3.name = chara.Id + " " + chara.Name;
container3.Button.onClick.AddListener(() => {
HighlightChildImage(MiniAnimationSetList.content, container3);
ListAnimations(charaInstance.Id, true);
});
if (chara.Icon)
{
container3.Image.sprite = chara.Icon;
container3.Image.enabled = true;
}
HighlightChildImage(NormalSoundList.content, container);
ListNormalSubSounds(entry);
};
pageentrys.Add(pageentry);
}
NormalSoundCtrl.Initialize(pageentrys, NormalSoundList);
}
public void LoadPropPanel()
{
var pageentrys = new List<PageManager.Entry>();
@@ -500,7 +572,7 @@ public class UmaViewerUI : MonoBehaviour
Destroy(LiveCharaSoundList.content.GetChild(i).gameObject);
}
string nameVar = $"snd_bgm_live_{songid}_chara";
foreach (var entry in Main.AbList.Where(a => a.Name.Contains(nameVar) && a.Name.EndsWith("awb")))
foreach (var entry in Main.AbSounds.Where(a => a.Name.Contains(nameVar) && a.Name.EndsWith("awb")))
{
var container = Instantiate(UmaContainerPrefab, LiveCharaSoundList.content).GetComponent<UmaUIContainer>();
string[] split = Path.GetFileNameWithoutExtension(entry.Name).Split('_');
@@ -529,6 +601,26 @@ public class UmaViewerUI : MonoBehaviour
}
void ListNormalSubSounds(UmaDatabaseEntry awb)
{
for (int i = NormalSubSoundList.content.childCount - 1; i >= 0; i--)
{
Destroy(NormalSubSoundList.content.GetChild(i).gameObject);
}
var subSounds = Builder.LoadAudio(awb);
foreach(var sound in subSounds)
{
var container = Instantiate(UmaContainerPrefab, NormalSubSoundList.content).GetComponent<UmaUIContainer>();
container.Name = $"Clip_{subSounds.IndexOf(sound)}";
container.Button.onClick.AddListener(() => {
HighlightChildImage(NormalSubSoundList.content, container);
Builder.PlaySound(awb, subSounds.IndexOf(sound));
});
}
}
void ListAnimations(int umaId, bool mini)
{
ScrollRect animationList = mini ? MiniAnimationList : AnimationList;