add 2D BackGround setting

This commit is contained in:
CroakFang
2023-01-15 04:47:22 +08:00
parent 7de1a338fb
commit 213f438819
13 changed files with 3504 additions and 178 deletions
+109
View File
@@ -0,0 +1,109 @@
using Gallop;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Debug = UnityEngine.Debug;
public class PageManager : MonoBehaviour
{
public ScrollRect ScrollRect;
public InputField PageText;
public int ShowCount;
public GameObject ContainerPrefab;
private int totalPage;
private int currentPage = 0;
private List<Entry> Entries;
public void Initialize(List<Entry> entries, ScrollRect scrollRect)
{
ScrollRect = scrollRect;
Entries = entries;
ShowCount = Mathf.FloorToInt(ScrollRect.GetComponent<RectTransform>().rect.height / ContainerPrefab.GetComponent<RectTransform>().rect.height);
totalPage = Mathf.CeilToInt(entries.Count / (float)ShowCount);
if (totalPage > 0)
{
LoadPage(currentPage);
}
}
public void ResetCtrl()
{
if(ScrollRect)Clear();
totalPage = 0;
currentPage = 0;
PageText.text = "";
Entries = null;
((Text)PageText.placeholder).text = $"- / -";
}
private void LoadPage(int index)
{
if (totalPage == 0) return;
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];
var container = Instantiate(ContainerPrefab, ScrollRect.content).GetComponent<UmaUIContainer>();
container.Name = container.name = entry.Name;
if (entry.FontSize > 0)
{
container.FontSize = entry.FontSize;
}
if(entry.Sprite != null)
{
container.Image.sprite = entry.Sprite;
container.Image.enabled = true;
}
container.Button.onClick.AddListener(()=> { entry.OnClick(container); });
}
}
public void JumpToPage(string index)
{
PageText.text = "";
if (totalPage == 0|| index == "") return;
currentPage = Mathf.Clamp(int.Parse(index) - 1, 0, totalPage - 1);
LoadPage(currentPage);
}
private void Clear()
{
for (int i = ScrollRect.content.childCount - 1; i >= 0; i--)
{
Destroy(ScrollRect.content.GetChild(i).gameObject);
}
}
public void NextPage()
{
if (totalPage == 0) return;
currentPage = Mathf.Clamp(currentPage + 1, 0, totalPage - 1);
LoadPage(currentPage);
}
public void PrevPage()
{
if (totalPage == 0) return;
currentPage = Mathf.Clamp(currentPage - 1, 0, totalPage - 1);
LoadPage(currentPage);
}
public class Entry
{
public string Name;
public int FontSize;
public Sprite Sprite;
public UnityEngine.Events.UnityAction<UmaUIContainer> OnClick;
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 74c8e9ce85fd19f4a897a5782348dd5b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+15 -7
View File
@@ -1,4 +1,5 @@
using Gallop;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
@@ -131,10 +132,21 @@ public class UmaContainer : MonoBehaviour
UmaAnimator.runtimeAnimatorController = OverrideController;
}
public void SetHeight(int scale)
public void SetHeight(int scale = 0)
{
BodyScale = (scale / 160f);
transform.Find("Position").localScale *= BodyScale;//WIP
if(scale == 0)
{
BodyScale = 1;
}
else if(scale == -1)
{
BodyScale = (Convert.ToInt32(CharaData["scale"]) / 160f);
}
else
{
BodyScale = (scale / 160f);
}
transform.Find("Position").localScale = new Vector3(BodyScale, BodyScale, BodyScale);
}
public Transform[] MergeBone(SkinnedMeshRenderer from, List<Transform> targetBones)
@@ -237,10 +249,6 @@ public class UmaContainer : MonoBehaviour
}
}
private void LateUpdate()
{
}
public void SetNextAnimationCut(string cutName)
{
+8 -3
View File
@@ -345,7 +345,7 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.EyeHeight = CurrentUMAContainer.Head.GetComponent<AssetHolder>()._assetTableValue["head_center_offset_y"];
CurrentUMAContainer.MergeModel();
CurrentUMAContainer.Initialize();
CurrentUMAContainer.SetHeight(Convert.ToInt32(CurrentUMAContainer.CharaData["scale"]));
CurrentUMAContainer.SetHeight(-1);
LoadAsset(UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"anm_eve_chr{id}_00_idle01_loop")));
}
@@ -1094,6 +1094,7 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.UmaAnimator.Play("motion_1", -1);
CurrentUMAContainer.UmaAnimator.SetTrigger(needTransit ? "next_s" : "next");
CurrentUMAContainer.isAnimatorControl = false;
CurrentUMAContainer.SetHeight(-1);
}
else if (clip.name.Contains("tail"))
{
@@ -1108,6 +1109,7 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
CurrentUMAContainer.FaceOverrideController["clip_1"] = clip;
CurrentUMAContainer.isAnimatorControl = true;
CurrentUMAContainer.SetHeight(0);
CurrentUMAContainer.UmaFaceAnimator.Play("motion_1", 0, 0);
}
else if (clip.name.Contains("ear"))
@@ -1192,6 +1194,7 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
}
CurrentUMAContainer.isAnimatorControl = false;
CurrentUMAContainer.SetHeight(-1);
SetPreviewCamera(null);
CurrentUMAContainer.UmaAnimator.Play("motion_1", 0, lastTime);
@@ -1257,13 +1260,14 @@ public class UmaViewerBuilder : MonoBehaviour
{
Texture2D texture = (Texture2D)assetBundle.LoadAsset($"chr_icon_{id}");
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
assetBundle.Unload(false);
return sprite;
}
}
return null;
}
public Sprite LoadCostumeIcon(UmaDatabaseEntry item)
public Sprite LoadSprite(UmaDatabaseEntry item)
{
string path = item.FilePath;
if (File.Exists(path))
@@ -1271,6 +1275,7 @@ public class UmaViewerBuilder : MonoBehaviour
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);
assetBundle.Unload(false);
return sprite;
}
return null;
@@ -1289,13 +1294,13 @@ public class UmaViewerBuilder : MonoBehaviour
{
Texture2D texture = (Texture2D)assetBundle.LoadAsset($"jacket_icon_l_{musicid}");
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
assetBundle.Unload(false);
return sprite;
}
}
return null;
}
public void UnloadProp()
{
if (CurrentOtherContainer != null)
+1 -1
View File
@@ -83,7 +83,7 @@ public class UmaViewerMain : MonoBehaviour
var costume = new CostumeEntry();
var name = Path.GetFileName(item.Name);
costume.Id = name.Replace("dress_","");
costume.Icon = Builder.LoadCostumeIcon(item);
costume.Icon = Builder.LoadSprite(item);
Costumes.Add(costume);
}
+173 -115
View File
@@ -1,15 +1,12 @@
using Gallop;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Debug = UnityEngine.Debug;
public class UmaViewerUI : MonoBehaviour
{
@@ -24,14 +21,18 @@ public class UmaViewerUI : MonoBehaviour
public ScrollRect CostumeList;
public ScrollRect AnimationSetList;
public ScrollRect AnimationList;
public PageManager AnimationPageCtrl;
[Header("mini models")]
public ScrollRect MiniCharactersList;
public ScrollRect MiniCostumeList;
public ScrollRect MiniAnimationSetList;
public ScrollRect MiniAnimationList;
public PageManager MiniAnimationPageCtrl;
[Header("other")]
public ScrollRect PropList;
public PageManager PropPageCtrl;
public ScrollRect SceneList;
public PageManager ScenePageCtrl;
public ScrollRect EmotionList;
public Transform FacialList;
@@ -59,6 +60,13 @@ public class UmaViewerUI : MonoBehaviour
public TextMeshProUGUI AnimationSpeedText;
public TextMeshProUGUI AnimationProgressText;
[Header("backgrounds")]
public ScrollRect BackGroundList;
public PageManager BackGroundPageCtrl;
public GameObject BackGroundCameraObj;
public GameObject BG_HSVPickerObj;
public Image BG_Image;
[Header("settings")]
public TMP_InputField SSWidth;
public TMP_InputField SSHeight;
@@ -398,31 +406,37 @@ public class UmaViewerUI : MonoBehaviour
public void LoadPropPanel()
{
var pageentrys = new List<PageManager.Entry>();
foreach (var prop in Main.AbList.Where(a=>a.Name.Contains("pfb_chr_prop") && !a.Name.Contains("clothes")))
{
var propInstance = prop;
var container = Instantiate(UmaContainerPrefab, PropList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(prop.Name);
container.Button.onClick.AddListener(() => {
var pageentry = new PageManager.Entry();
pageentry.Name = Path.GetFileName(prop.Name);
pageentry.OnClick = (container) =>
{
HighlightChildImage(PropList.content, container);
Builder.LoadProp(propInstance);
});
Builder.LoadProp(prop);
};
pageentrys.Add(pageentry);
}
PropPageCtrl.Initialize(pageentrys,PropList);
}
public void LoadMapPanel()
{
var pageentrys = new List<PageManager.Entry>();
foreach (var scene in Main.AbList.Where(a => a.Name.StartsWith("3d/env") && Path.GetFileName(a.Name).StartsWith("pfb_")))
{
var sceneInstance = scene;
var container = Instantiate(UmaContainerPrefab, SceneList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(scene.Name);
container.FontSize = 19;
container.Button.onClick.AddListener(() => {
var pageentry = new PageManager.Entry();
pageentry.Name = Path.GetFileName(scene.Name);
pageentry.FontSize = 19;
pageentry.OnClick = (container) =>
{
HighlightChildImage(SceneList.content, container);
Builder.LoadProp(sceneInstance);
});
Builder.LoadProp(scene);
};
pageentrys.Add(pageentry);
}
ScenePageCtrl.Initialize(pageentrys, SceneList);
}
void ListCostumes(int umaId, bool mini)
@@ -479,21 +493,6 @@ public class UmaViewerUI : MonoBehaviour
}
}
public void SetCriWare(bool value)
{
isCriware = value;
}
public void SetHeadFix(bool value)
{
isHeadFix = value;
}
public void UpdateGifQualityLabel(float value)
{
GifQualityLabel.text = $"Quality: {(int)value} (default: 10)";
}
void ListLiveSounds(int songid)
{
for (int i = LiveCharaSoundList.content.childCount - 1; i >= 0; i--)
@@ -530,6 +529,130 @@ public class UmaViewerUI : MonoBehaviour
}
void ListAnimations(int umaId, bool mini)
{
ScrollRect animationList = mini ? MiniAnimationList : AnimationList;
PageManager pageManager = mini ? MiniAnimationPageCtrl : AnimationPageCtrl;
for (int i = animationList.content.childCount - 1; i >= 0; i--)
{
Destroy(animationList.content.GetChild(i).gameObject);
}
var filteredList = Main.AbMotions.Where(a => !a.Name.Contains($"mirror")
&& (mini ? a.Name.Contains($"mini") : !a.Name.Contains($"mini"))
&& !a.Name.Contains($"facial")
&& !a.Name.Contains($"_cam")
&& !a.Name.EndsWith($"_s")
&& !a.Name.EndsWith($"_e")
);
if (umaId == -1)
{
var pageentrys = new List<PageManager.Entry>();
foreach (var entry in filteredList.Where(a => (a.Name.Contains($"/type0") || a.Name.Contains($"/type99") || a.Name.Contains($"anm_sty_")) && !a.Name.Contains($"/tail") && !a.Name.EndsWith($"_pos") && !a.Name.EndsWith($"_prop") && !a.Name.EndsWith($"_pose") && !a.Name.Contains($"_defaultmotion")))
{
var pageentry = new PageManager.Entry();
pageentry.Name = Path.GetFileName(entry.Name);
pageentry.FontSize = 20;
pageentry.OnClick = (container) => {
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entry);
LoadedAnimation();
};
pageentrys.Add(pageentry);
}
pageManager.Initialize(pageentrys, animationList);
}
else if (umaId == -2)
{
foreach (var entry in filteredList.Where(a => a.Name.Contains($"/tail")))
{
var entryInstance = entry;
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 20;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});
}
pageManager.ResetCtrl();
}
else
{
//Common animations
foreach (var entry in filteredList.Where(a => a.Name.Contains($"chara/chr{umaId}") && !a.Name.Contains("pose")))
{
var entryInstance = entry;
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 20;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});
}
//Skill animations
foreach (var entry in filteredList.Where(a => a.Name.Contains($"card/body/crd{umaId}")))
{
var entryInstance = entry;
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 20;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});
}
pageManager.ResetCtrl();
}
}
void ListBackgrounds()
{
var bglist = Main.AbList.Where(a => a.Name.StartsWith("bg/bg"));
var pageentrys = new List<PageManager.Entry>();
foreach (var entry in bglist)
{
var pageentry = new PageManager.Entry();
pageentry.Name = Path.GetFileName(entry.Name);
pageentry.Sprite = Builder.LoadSprite(entry);
if (pageentry.Sprite == null) continue;
pageentry.OnClick = (container) => {
HighlightChildImage(BackGroundList.content, container);
BG_Image.sprite = pageentry.Sprite;
BG_Image.SetVerticesDirty();
};
if(BG_Image.sprite == null)
{
BG_Image.sprite = pageentry.Sprite;
BG_Image.SetVerticesDirty();
}
pageentrys.Add(pageentry);
}
BackGroundPageCtrl.Initialize(pageentrys, BackGroundList);
}
public void SetCriWare(bool value)
{
isCriware = value;
}
public void SetHeadFix(bool value)
{
isHeadFix = value;
}
public void UpdateGifQualityLabel(float value)
{
GifQualityLabel.text = $"Quality: {(int)value} (default: 10)";
}
string getCharaName(string id)
{
var entry = Main.Characters.FirstOrDefault(a => a.Id.ToString().Equals(id));
@@ -573,84 +696,6 @@ public class UmaViewerUI : MonoBehaviour
}
}
void ListAnimations(int umaId, bool mini)
{
ScrollRect animationList = mini ? MiniAnimationList : AnimationList;
for (int i = animationList.content.childCount - 1; i >= 0; i--)
{
Destroy(animationList.content.GetChild(i).gameObject);
}
var filteredList = Main.AbMotions.Where(a => !a.Name.Contains($"mirror")
&& (mini ? a.Name.Contains($"mini") : !a.Name.Contains($"mini"))
&& !a.Name.Contains($"facial")
&& !a.Name.Contains($"_cam")
&& !a.Name.EndsWith($"_s")
&& !a.Name.EndsWith($"_e")
);
if (umaId == -1)
{
foreach (var entry in filteredList.Where(a=> (a.Name.Contains($"/type0") || a.Name.Contains($"/type99") || a.Name.Contains($"anm_sty_")) && !a.Name.Contains($"/tail") && !a.Name.EndsWith($"_pos") && !a.Name.EndsWith($"_prop") && !a.Name.EndsWith($"_pose") && !a.Name.Contains($"_defaultmotion")))
{
var entryInstance = entry;
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 19;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});
}
}
else if(umaId == -2)
{
foreach (var entry in filteredList.Where(a => a.Name.Contains($"/tail")))
{
var entryInstance = entry;
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 19;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});
}
}
else
{
//Common animations
foreach (var entry in filteredList.Where(a => a.Name.Contains($"chara/chr{umaId}") && !a.Name.Contains("pose")))
{
var entryInstance = entry;
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 19;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});
}
//Skill animations
foreach (var entry in filteredList.Where(a => a.Name.Contains($"card/body/crd{umaId}")))
{
var entryInstance = entry;
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
container.Name = container.name = Path.GetFileName(entry.Name);
container.FontSize = 19;
container.Button.onClick.AddListener(() => {
HighlightChildImage(animationList.content, container);
Builder.LoadAsset(entryInstance);
LoadedAnimation();
});
}
}
}
public void LoadedAnimation()
{
if (!Builder.CurrentUMAContainer || !Builder.CurrentUMAContainer.UmaAnimator) return;
@@ -693,14 +738,27 @@ public class UmaViewerUI : MonoBehaviour
public void ChangeBackground(int index)
{
if(index == 0)
BackGroundPageCtrl.ResetCtrl();
switch (index)
{
Camera.main.clearFlags = CameraClearFlags.Skybox;
}
else
{
Camera.main.clearFlags = CameraClearFlags.SolidColor;
case 0:
Camera.main.clearFlags = CameraClearFlags.Skybox;
break;
case 1:
Camera.main.clearFlags = CameraClearFlags.SolidColor;
break;
case 2:
Camera.main.clearFlags = CameraClearFlags.Depth;
ListBackgrounds();
break;
default:
Camera.main.clearFlags = CameraClearFlags.Skybox;
break;
}
BackGroundCameraObj.SetActive(index == 2);
BG_HSVPickerObj.SetActive(index != 2);
BackGroundPageCtrl.transform.parent.gameObject.SetActive(index == 2);
}
public void ChangeBackgroundColor(Color color)