Optimize UI

This commit is contained in:
CroakFang
2023-01-14 21:27:34 +08:00
parent 19b3880f74
commit 0aead696b4
19 changed files with 1786 additions and 145 deletions
+10
View File
@@ -0,0 +1,10 @@
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI
{
class ScrollViewManager
{
}
}
+1 -3
View File
@@ -1,9 +1,6 @@
using UnityEngine;
using UnityEngine.UI;
public class UmaUIContainer : MonoBehaviour
{
enum TextType
@@ -67,5 +64,6 @@ public class UmaUIContainer : MonoBehaviour
public Button Button;
public Slider Slider;
public Image Image;
public Image ToggleImage;
}
-2
View File
@@ -62,7 +62,6 @@ public class UmaContainer : MonoBehaviour
public bool EnablePhysics = true;
public List<CySpringDataContainer> cySpringDataContainers;
public GameObject PhysicsContainer;
public ClothController ClothController;
public float BodyScale = 1;
public void Initialize()
{
@@ -235,7 +234,6 @@ public class UmaContainer : MonoBehaviour
TearControllers.ForEach(a => a.UpdateOffset());
ClothController?.Update(true);
}
}
@@ -80,6 +80,7 @@ public class LiveEntry
public int MusicId;
public string SongName;
public string BackGroundId;
public Sprite Icon;
public List<string[]> LiveSettings = new List<string[]>();
public LiveEntry(string data)
@@ -93,6 +94,17 @@ public class LiveEntry
}
}
[System.Serializable]
public class CostumeEntry
{
public string Id;
public int CharaId;
public int BodyType;
public int BodyTypeSub;
public Sprite Icon;
}
public enum UmaFileType
{
_3d_cutt,
@@ -39,11 +39,14 @@ public class UmaDatabaseController
public static string CharaPath = "3d/chara/";
/// <summary> 3d/effect/ </summary>
public static string EffectPath = "3d/effect/";
/// <summary> outgame/dress/ </summary>
public static string CostumePath = "outgame/dress/";
public IEnumerable<UmaDatabaseEntry> MetaEntries;
public IEnumerable<DataRow> CharaData;
public IEnumerable<FaceTypeData> FaceTypeData;
public IEnumerable<DataRow> LiveData;
public IEnumerable<DataRow> DressData;
/// <summary> Meta Database Connection </summary>
private SqliteConnection metaDb;
@@ -64,6 +67,7 @@ public class UmaDatabaseController
CharaData = ReadMaster(masterDb);
FaceTypeData = ReadFaceTypeData(masterDb);
LiveData = ReadAllLiveData(masterDb);
DressData = ReadAllDressData(masterDb);
}
catch
{
@@ -151,6 +155,21 @@ public class UmaDatabaseController
}
}
static IEnumerable<DataRow> ReadAllDressData(SqliteConnection conn)
{
SqliteCommand sqlite_cmd = conn.CreateCommand();
sqlite_cmd.CommandText =
$"SELECT * FROM dress_data";
SqliteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
var result = new DataTable();
result.Load(sqlite_datareader);
var temp = result.Rows.GetEnumerator();
while (temp.MoveNext())
{
yield return (DataRow)temp.Current;
}
}
public static DataRow ReadCharaData(int id)
{
SqliteCommand sqlite_cmd = instance.masterDb.CreateCommand();
+33
View File
@@ -1263,6 +1263,39 @@ public class UmaViewerBuilder : MonoBehaviour
return null;
}
public Sprite LoadCostumeIcon(UmaDatabaseEntry item)
{
string path = item.FilePath;
if (File.Exists(path))
{
AssetBundle assetBundle = AssetBundle.LoadFromFile(path);
Texture2D texture = (Texture2D)assetBundle.LoadAsset(assetBundle.GetAllAssetNames()[0]);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
return sprite;
}
return null;
}
public Sprite LoadLiveIcon(int musicid)
{
string value = $"live/jacket/jacket_icon_l_{musicid}";
var entry = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.Equals(value));
if(entry == null) return null;
string path = entry.FilePath;
if (File.Exists(path))
{
AssetBundle assetBundle = AssetBundle.LoadFromFile(path);
if (assetBundle.Contains($"jacket_icon_l_{musicid}"))
{
Texture2D texture = (Texture2D)assetBundle.LoadAsset($"jacket_icon_l_{musicid}");
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
return sprite;
}
}
return null;
}
public void UnloadProp()
{
if (CurrentOtherContainer != null)
+28 -3
View File
@@ -17,11 +17,13 @@ public class UmaViewerMain : MonoBehaviour
public List<CharaEntry> Characters = new List<CharaEntry>();
public List<LiveEntry> Lives = new List<LiveEntry>();
public List<CostumeEntry> Costumes = new List<CostumeEntry>();
public List<UmaDatabaseEntry> AbList = new List<UmaDatabaseEntry>();
public List<UmaDatabaseEntry> AbMotions = new List<UmaDatabaseEntry>();
public List<UmaDatabaseEntry> AbSounds = new List<UmaDatabaseEntry>();
public List<UmaDatabaseEntry> AbChara = new List<UmaDatabaseEntry>();
public List<UmaDatabaseEntry> AbEffect = new List<UmaDatabaseEntry>();
public List<UmaDatabaseEntry> CostumeList = new List<UmaDatabaseEntry>();
[Header("Asset Memory")]
public bool ShadersLoaded = false;
@@ -37,13 +39,14 @@ public class UmaViewerMain : MonoBehaviour
AbMotions = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.MotionPath)).ToList();
AbEffect = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.EffectPath)).ToList();
AbSounds = AbList.Where(ab => ab.Name.EndsWith(".awb") || ab.Name.EndsWith(".acb")).ToList();
CostumeList = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.CostumePath)).ToList();
}
private IEnumerator Start()
{
Dictionary<int, string> enNames = new Dictionary<int, string>();
if(Config.Instance.Language == Language.En)
if (Config.Instance.Language == Language.En)
{
yield return UmaViewerDownload.DownloadText("https://www.tracenacademy.com/api/BasicCharaDataInfo", txt =>
{
@@ -70,11 +73,32 @@ public class UmaViewerMain : MonoBehaviour
Name = enNames.ContainsKey(id) ? enNames[id] : item["charaname"].ToString(),
Icon = UmaViewerBuilder.Instance.LoadCharaIcon(id.ToString()),
Id = id,
ThemeColor = "#"+item["ui_nameplate_color_1"].ToString()
ThemeColor = "#" + item["ui_nameplate_color_1"].ToString()
});
}
}
foreach (var item in CostumeList)
{
var costume = new CostumeEntry();
var name = Path.GetFileName(item.Name);
costume.Id = name.Replace("dress_","");
costume.Icon = Builder.LoadCostumeIcon(item);
Costumes.Add(costume);
}
var DressData = UmaDatabaseController.Instance.DressData;
foreach (var data in DressData)
{
var costume = Costumes.FirstOrDefault(a => a.Id.Split('_')[0].Contains(data["id"].ToString()) );
if (costume != null)
{
costume.CharaId = Convert.ToInt32(data["chara_id"]);
costume.BodyType = Convert.ToInt32(data["body_type"]);
costume.BodyTypeSub = Convert.ToInt32(data["body_type_sub"]);
}
}
UI.LoadModelPanels();
UI.LoadMiniModelPanels();
UI.LoadPropPanel();
@@ -101,7 +125,8 @@ public class UmaViewerMain : MonoBehaviour
Lives.Add(new LiveEntry(liveData.text)
{
MusicId = musicId,
SongName = songName
SongName = songName,
Icon = UmaViewerBuilder.Instance.LoadLiveIcon(musicId)
});
}
}
+75 -65
View File
@@ -9,6 +9,7 @@ using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Debug = UnityEngine.Debug;
public class UmaViewerUI : MonoBehaviour
{
@@ -75,6 +76,8 @@ public class UmaViewerUI : MonoBehaviour
public List<GameObject> TogglableFacials = new List<GameObject>();
public GameObject UmaContainerPrefab;
public GameObject UmaContainerCostumePrefab;
public GameObject UmaContainerLivePrefab;
public GameObject UmaContainerSliderPrefab;
public GameObject UmaContainerAssetsPrefab;
private int LoadedAssetCount = 0;
@@ -136,12 +139,12 @@ public class UmaViewerUI : MonoBehaviour
}
}
public void HighlightChildImage(Transform mainObject, Image child)
public void HighlightChildImage(Transform mainObject, UmaUIContainer child)
{
foreach(var t in mainObject.GetComponentsInChildren<Image>())
foreach(var t in mainObject.GetComponentsInChildren<UmaUIContainer>())
{
if (t.transform.parent != mainObject) continue;
t.color = t == child ? UIColor2 : UIColor1;
t.ToggleImage.enabled = (t == child);
}
}
@@ -167,19 +170,17 @@ public class UmaViewerUI : MonoBehaviour
public void LoadModelPanels()
{
var container = Instantiate(UmaContainerPrefab, AnimationSetList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = "Generic";
var imageInstance = container.GetComponent<Image>();
container.Button.onClick.AddListener(() => {
HighlightChildImage(AnimationSetList.content, imageInstance);
var container1 = Instantiate(UmaContainerPrefab, AnimationSetList.content).GetComponent<UmaUIContainer>();
container1.Name = container1.name = "Generic";
container1.Button.onClick.AddListener(() => {
HighlightChildImage(AnimationSetList.content, container1);
ListAnimations(-1, false);
});
container = Instantiate(UmaContainerPrefab, AnimationSetList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = "Tail";
imageInstance = container.GetComponent<Image>();
container.Button.onClick.AddListener(() => {
HighlightChildImage(AnimationSetList.content, imageInstance);
var container2 = Instantiate(UmaContainerPrefab, AnimationSetList.content).GetComponent<UmaUIContainer>();
container2.Name = container2.name = "Tail";
container2.Button.onClick.AddListener(() => {
HighlightChildImage(AnimationSetList.content, container2);
ListAnimations(-2, false);
});
@@ -187,32 +188,30 @@ public class UmaViewerUI : MonoBehaviour
{
var charaInstance = chara;
container = Instantiate(UmaContainerPrefab, CharactersList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = chara.Id + " " + chara.Name;
var imageInstance1 = container.GetComponent<Image>();
container.Button.onClick.AddListener(() => {
HighlightChildImage(CharactersList.content, imageInstance1);
var container3 = Instantiate(UmaContainerPrefab, CharactersList.content).GetComponent<UmaUIContainer>();
container3.Name = container3.name = chara.Id + " " + chara.Name;
container3.Button.onClick.AddListener(() => {
HighlightChildImage(CharactersList.content, container3);
ListCostumes(charaInstance.Id, false);
});
if (chara.Icon)
{
container.Image.sprite = chara.Icon;
container.Image.enabled = true;
container3.Image.sprite = chara.Icon;
container3.Image.enabled = true;
}
container = Instantiate(UmaContainerPrefab, AnimationSetList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = chara.Id + " " + chara.Name;
var imageInstance2 = container.GetComponent<Image>();
container.Button.onClick.AddListener(() => {
HighlightChildImage(AnimationSetList.content, imageInstance2);
var container4 = Instantiate(UmaContainerPrefab, AnimationSetList.content).GetComponent<UmaUIContainer>();
container4.Name = container4.name = chara.Id + " " + chara.Name;
container4.Button.onClick.AddListener(() => {
HighlightChildImage(AnimationSetList.content, container4);
ListAnimations(charaInstance.Id, false);
});
if (chara.Icon)
{
container.Image.sprite = chara.Icon;
container.Image.enabled = true;
container4.Image.sprite = chara.Icon;
container4.Image.enabled = true;
}
}
}
@@ -337,19 +336,21 @@ public class UmaViewerUI : MonoBehaviour
foreach (var live in Main.Lives.OrderBy(c => c.MusicId))
{
var liveInstance = live;
var container = Instantiate(UmaContainerPrefab, LiveList.content).GetComponent<UmaUIContainer>();
var container = Instantiate(UmaContainerLivePrefab, LiveList.content).GetComponent<UmaUIContainer>();
container.Name = " "+ live.MusicId + " " + live.SongName;
var imageInstance1 = container.GetComponent<Image>();
container.Image.sprite = live.Icon;
container.Image.enabled = container.Image.sprite;
container.Button.onClick.AddListener(() => {
HighlightChildImage(LiveList.content, imageInstance1);
HighlightChildImage(LiveList.content, container);
Builder.LoadLive(live);
});
var CharaContainer = Instantiate(UmaContainerPrefab, LiveSoundList.content).GetComponent<UmaUIContainer>();
var CharaContainer = Instantiate(UmaContainerLivePrefab, LiveSoundList.content).GetComponent<UmaUIContainer>();
CharaContainer.Name = " " + live.MusicId + " " + live.SongName;
var CharaimageInstance1 = CharaContainer.GetComponent<Image>();
CharaContainer.Image.sprite = live.Icon;
CharaContainer.Image.enabled = CharaContainer.Image.sprite;
CharaContainer.Button.onClick.AddListener(() => {
HighlightChildImage(LiveSoundList.content, CharaimageInstance1);
HighlightChildImage(LiveSoundList.content, container);
ListLiveSounds(live.MusicId);
});
}
@@ -357,43 +358,40 @@ public class UmaViewerUI : MonoBehaviour
public void LoadMiniModelPanels()
{
var container = Instantiate(UmaContainerPrefab, MiniAnimationSetList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = "General";
var imageInstance = container.GetComponent<Image>();
container.Button.onClick.AddListener(() => {
HighlightChildImage(MiniAnimationSetList.content, imageInstance);
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;
container = Instantiate(UmaContainerPrefab, MiniCharactersList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = chara.Id + " " + chara.Name;
var imageInstance1 = container.GetComponent<Image>();
container.Button.onClick.AddListener(() => {
HighlightChildImage(MiniCharactersList.content, imageInstance1);
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)
{
container.Image.sprite = chara.Icon;
container.Image.enabled = true;
container2.Image.sprite = chara.Icon;
container2.Image.enabled = true;
}
container = Instantiate(UmaContainerPrefab, MiniAnimationSetList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = chara.Id + " " + chara.Name;
var imageInstance2 = container.GetComponent<Image>();
container.Button.onClick.AddListener(() => {
HighlightChildImage(MiniAnimationSetList.content, imageInstance2);
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)
{
container.Image.sprite = chara.Icon;
container.Image.enabled = true;
container3.Image.sprite = chara.Icon;
container3.Image.enabled = true;
}
}
}
@@ -405,9 +403,8 @@ public class UmaViewerUI : MonoBehaviour
var propInstance = prop;
var container = Instantiate(UmaContainerPrefab, PropList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(prop.Name);
var imageInstance1 = container.GetComponent<Image>();
container.Button.onClick.AddListener(() => {
HighlightChildImage(PropList.content, imageInstance1);
HighlightChildImage(PropList.content, container);
Builder.LoadProp(propInstance);
});
}
@@ -421,9 +418,8 @@ public class UmaViewerUI : MonoBehaviour
var container = Instantiate(UmaContainerPrefab, SceneList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(scene.Name);
container.FontSize = 19;
var imageInstance1 = container.GetComponent<Image>();
container.Button.onClick.AddListener(() => {
HighlightChildImage(SceneList.content, imageInstance1);
HighlightChildImage(SceneList.content, container);
Builder.LoadProp(sceneInstance);
});
}
@@ -439,14 +435,20 @@ public class UmaViewerUI : MonoBehaviour
string nameVar = mini ? $"pfb_mbdy{umaId}" : $"pfb_bdy{umaId}";
foreach (var entry in Main.AbList.Where(a => !a.Name.Contains("clothes") && a.Name.Contains(nameVar)))
{
var container = Instantiate(UmaContainerPrefab, costumeList.content).GetComponent<UmaUIContainer>();
var container = Instantiate(UmaContainerCostumePrefab, costumeList.content).GetComponent<UmaUIContainer>();
string[] split = entry.Name.Split('_');
string costumeId = split[split.Length - 1];
container.Name = container.name = GetCostumeName(costumeId);
container.Button.onClick.AddListener(() => {
HighlightChildImage(costumeList.content, container.GetComponent<Image>());
HighlightChildImage(costumeList.content, container);
StartCoroutine(Builder.LoadUma(umaId, costumeId, mini));
});
var icon = Main.Costumes.FirstOrDefault(a => (a.CharaId == umaId&&a.BodyTypeSub == int.Parse(costumeId)));
if (icon == null) icon = Main.Costumes[0];
container.Image.sprite = icon.Icon;
container.Image.enabled = true;
}
//Common costumes
List<string> costumes = new List<string>();
@@ -459,12 +461,20 @@ public class UmaViewerUI : MonoBehaviour
{
costumes.Add(id);
string costumeId = id;
var container = Instantiate(UmaContainerPrefab, costumeList.content).GetComponent<UmaUIContainer>();
var container = Instantiate(UmaContainerCostumePrefab, costumeList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = GetCostumeName(id);
container.Button.onClick.AddListener(() => {
HighlightChildImage(costumeList.content, container.GetComponent<Image>());
HighlightChildImage(costumeList.content, container);
StartCoroutine(Builder.LoadUma(umaId, costumeId, mini));
});
var data = costumeId.Split('_');
var bodytype = int.Parse(data[0]);
var bodysub = int.Parse(data[1]);
var icon = Main.Costumes.FirstOrDefault(a => a.BodyType == bodytype&& a.BodyTypeSub == bodysub);
if (icon == null) icon = Main.Costumes[0];
container.Image.sprite = icon.Icon;
container.Image.enabled = true;
}
}
}
@@ -506,7 +516,7 @@ public class UmaViewerUI : MonoBehaviour
}
container.Button.onClick.AddListener(() => {
HighlightChildImage(LiveCharaSoundList.content, container.GetComponent<Image>());
HighlightChildImage(LiveCharaSoundList.content, container);
if (isCriware)
{
Builder.LoadLiveSoundCri(songid, entry);
@@ -588,7 +598,7 @@ public class UmaViewerUI : MonoBehaviour
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 19;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container.GetComponent<Image>());
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});
@@ -603,7 +613,7 @@ public class UmaViewerUI : MonoBehaviour
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 19;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container.GetComponent<Image>());
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});
@@ -619,7 +629,7 @@ public class UmaViewerUI : MonoBehaviour
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 19;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container.GetComponent<Image>());
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});
@@ -633,7 +643,7 @@ public class UmaViewerUI : MonoBehaviour
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 19;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container.GetComponent<Image>());
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});