You've already forked UniversalViewer
							
							DanMachi:
-compatibility improvements Core: -simplified object and keyframe serialization -complicated assetbundle loading
This commit is contained in:
		
							
								
								
									
										239
									
								
								Assets/KF3/Scripts/UI/SpawnPanel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										239
									
								
								Assets/KF3/Scripts/UI/SpawnPanel.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,239 @@ | ||||
| using System; | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| namespace KF3.UI.Panels | ||||
| { | ||||
|     public class SpawnPanel : MonoBehaviour | ||||
|     { | ||||
|         public void Open() { } | ||||
|         public void Close() { } | ||||
|  | ||||
|         public Button FriendSelectButton; | ||||
|         public ScrollRect FriendSelection; | ||||
|  | ||||
|         public Button CeruleanSelectButton; | ||||
|         public ScrollRect CeruleanSelection; | ||||
|  | ||||
|         public Button FurnitureSelectButton; | ||||
|         public ScrollRect FurnitureSelection; | ||||
|  | ||||
|         public Button MiscSelectButton; | ||||
|         public ScrollRect MiscSelection; | ||||
|  | ||||
|         public Button MiracleSelectButton; | ||||
|         public ScrollRect MiracleSelection; | ||||
|  | ||||
|         public List<GameObject> LoadedIcons = new List<GameObject>(); | ||||
|  | ||||
|         private KF3ModelViewerMain _main; | ||||
|  | ||||
|         public void SwitchSpawnerTab(Button button) | ||||
|         { | ||||
|             var buttons = new List<Button>() { FriendSelectButton, CeruleanSelectButton, FurnitureSelectButton, MiscSelectButton, MiracleSelectButton }; | ||||
|             var contents = new List<ScrollRect>() { FriendSelection, CeruleanSelection, FurnitureSelection, MiscSelection, MiracleSelection }; | ||||
|  | ||||
|             for(int i = 0; i < buttons.Count; i++) | ||||
|             { | ||||
|                 var value = buttons[i] == button; | ||||
|                 buttons[i].interactable = !value; | ||||
|                 contents[i].gameObject.SetActive(value); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public IEnumerator LoadAll(KF3ModelViewerMain main) | ||||
|         { | ||||
|             _main = main; | ||||
|             LoadCeruleanIcons(); | ||||
|             _main.StartCoroutine(LoadCharacterIcons()); | ||||
|             _main.StartCoroutine(LoadFurnitureIcons()); | ||||
|             LoadMiscIcons(_main.Assets.GetMisc(), MiscSelection.content); | ||||
|             LoadMiscIcons(_main.Assets.GetMiracles(), MiracleSelection.content); | ||||
|             yield break; | ||||
|         } | ||||
|  | ||||
|         public void FilterIcons(string value) | ||||
|         { | ||||
|             if (String.IsNullOrEmpty(value)) | ||||
|             { | ||||
|                 foreach (var icon in LoadedIcons) | ||||
|                 { | ||||
|                     icon.SetActive(true); | ||||
|                 } | ||||
|             } | ||||
|             else foreach (var icon in LoadedIcons) | ||||
|                 { | ||||
|                     icon.SetActive(icon.GetComponentInChildren<Text>().text.ToUpper().Contains(value.ToUpper())); | ||||
|                 } | ||||
|         } | ||||
|  | ||||
|         private IEnumerator LoadCharacterIcons() | ||||
|         { | ||||
|             var abIcons = _main.Assets.Icons.ToList(); | ||||
|             var abChara = _main.Assets.Characters.ToList(); | ||||
|             int total = abChara.Count; | ||||
|             var tex2D = Resources.Load(Strings.CharaErrorPrefab) as Texture2D; | ||||
|             Dictionary<GameObject, KF3AssetBundle> icons = new Dictionary<GameObject, KF3AssetBundle>(); | ||||
|  | ||||
|             foreach (var bundle in abChara) | ||||
|             { | ||||
|                 KF3AssetBundle b = bundle as KF3AssetBundle; | ||||
|                 string id = b.IdStr; | ||||
|                 int idNum = b.IdNum; | ||||
|                 string displayName = id + "_" + KF3Names.GetCharaName(idNum); | ||||
|  | ||||
|                 var icon = abIcons.FirstOrDefault(ab => ab.FileName == $"icon_chara_{id}.png"); | ||||
|                 if (icon == null) | ||||
|                 { | ||||
|                     icon = abIcons.FirstOrDefault(ab => ab.FileName == $"icon_chara_mini_{id}.png"); | ||||
|                 } | ||||
|  | ||||
|                 GameObject go = Instantiate(_main.Resources.ModelIcon, FriendSelection.content.transform); | ||||
|                 go.name = bundle.FileName; | ||||
|                 go.GetComponentInChildren<Text>().text = displayName; | ||||
|                 go.GetComponentInChildren<Button>().onClick.AddListener(() => | ||||
|                 { | ||||
|                     _main.StartCoroutine(_main.Builder.BuildCharacter(bundle.FileName, bundle.FileName)); | ||||
|                     Close(); | ||||
|                 }); | ||||
|  | ||||
|                 if (icon != null) | ||||
|                 { | ||||
|                     icons.Add(go, icon); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     go.GetComponentInChildren<RawImage>().texture = tex2D; | ||||
|                 } | ||||
|                 LoadedIcons.Add(go); | ||||
|             } | ||||
|  | ||||
|             foreach (var i in icons) | ||||
|             { | ||||
|                 var go = i.Key; | ||||
|                 var icon = i.Value; | ||||
|                 yield return _main.Assets.LoadAsset(icon, (ab) => { | ||||
|                     if (ab != null) | ||||
|                     { | ||||
|                         go.GetComponentInChildren<RawImage>().texture = ab.LoadAsset(ab.GetAllAssetNames()[0]) as Texture2D; | ||||
|                         ab.Unload(false); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         go.GetComponentInChildren<RawImage>().texture = tex2D; | ||||
|                     } | ||||
|                 }); | ||||
|             } | ||||
|  | ||||
|             //Error.Log(Color.green, $"Loaded {loaded}/{total} Character Icons"); | ||||
|         } | ||||
|  | ||||
|         private void LoadCeruleanIcons() | ||||
|         { | ||||
|             var abCell = _main.Assets.CeruleansD.Select(c => c.Value[0]).ToList(); | ||||
|             var tex2D = Resources.Load(Strings.CharaErrorPrefab) as Texture2D; | ||||
|             foreach (var bundle in abCell) | ||||
|             { | ||||
|                 KF3AssetBundle b = bundle; | ||||
|  | ||||
|                 GameObject go = Instantiate(_main.Resources.ModelIcon, CeruleanSelection.content.transform); | ||||
|                 go.name = bundle.FileName; | ||||
|                 go.GetComponentInChildren<Text>().text = bundle.DisplayName; | ||||
|                 go.GetComponentInChildren<Button>().onClick.AddListener(() => | ||||
|                 { | ||||
|                     _main.StartCoroutine(_main.Builder.BuildCerulean(bundle.FileName, bundle.FileName, null)); | ||||
|                     Close(); | ||||
|                 }); | ||||
|                 go.GetComponentInChildren<RawImage>().texture = tex2D; | ||||
|                 LoadedIcons.Add(go); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private void LoadMiscIcons(List<KF3AssetBundle> icons, Transform panel) | ||||
|         { | ||||
|             var tex2D = Resources.Load(Strings.CharaErrorPrefab) as Texture2D; | ||||
|             foreach (var bundle in icons) | ||||
|             { | ||||
|                 KF3AssetBundle b = bundle; | ||||
|  | ||||
|                 GameObject go = Instantiate(_main.Resources.ModelIcon, panel); | ||||
|                 go.name = bundle.FileName; | ||||
|                 go.GetComponentInChildren<Text>().text = bundle.DisplayName; | ||||
|                 go.GetComponentInChildren<Button>().onClick.AddListener(() => | ||||
|                 { | ||||
|                     _main.StartCoroutine(_main.Builder.Spawn(bundle)); | ||||
|                     Close(); | ||||
|                 }); | ||||
|                 go.GetComponentInChildren<RawImage>().texture = tex2D; | ||||
|                 LoadedIcons.Add(go); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private IEnumerator LoadFurnitureIcons() | ||||
|         { | ||||
|             var abIcons = _main.Assets.Icons.ToList(); | ||||
|             var abFurniture = _main.Assets.Furniture.ToList(); | ||||
|             var tex2D = Resources.Load(Strings.CharaErrorPrefab) as Texture2D; | ||||
|             Dictionary<GameObject, KF3AssetBundle> icons = new Dictionary<GameObject, KF3AssetBundle>(); | ||||
|  | ||||
|             foreach (var bundle in abFurniture) | ||||
|             { | ||||
|                 string name = bundle.FileName; | ||||
|                 string[] split = name.Split(new char[] { '.', '_' }); | ||||
|                 string id = ""; | ||||
|                 int idNum = -1; | ||||
|                 for (int i = split.Length; i >= 0; i--) | ||||
|                 { | ||||
|                     id = split[split.Length - 3]; | ||||
|                     if (int.TryParse(id, out idNum)) | ||||
|                     { | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|                 if (idNum == -1) | ||||
|                 { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 var icon = abIcons.FirstOrDefault(ab => ab.FileName == $"icon_item_{id}.png"); | ||||
|  | ||||
|                 GameObject go = Instantiate(_main.Resources.ModelIcon, FurnitureSelection.content.transform); | ||||
|                 go.name = bundle.FileName; | ||||
|                 go.GetComponentInChildren<Text>().text = bundle.DisplayName; | ||||
|                 go.GetComponentInChildren<Button>().onClick.AddListener(() => | ||||
|                 { | ||||
|                     _main.StartCoroutine(_main.Builder.SpawnFurniture(bundle.FileName)); | ||||
|                     Close(); | ||||
|                 }); | ||||
|                 if (icon != null) | ||||
|                 { | ||||
|                     icons.Add(go, icon); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     go.GetComponentInChildren<RawImage>().texture = tex2D; | ||||
|                 } | ||||
|                 LoadedIcons.Add(go); | ||||
|             } | ||||
|  | ||||
|             foreach (var i in icons) | ||||
|             { | ||||
|                 var go = i.Key; | ||||
|                 var icon = i.Value; | ||||
|                 yield return _main.Assets.LoadAsset(icon, (ab) => { | ||||
|                     if (ab == null) | ||||
|                     { | ||||
|                         go.GetComponentInChildren<RawImage>().texture = tex2D; | ||||
|                         return; | ||||
|                     } | ||||
|                     go.GetComponentInChildren<RawImage>().texture = ab.LoadAsset(ab.GetAllAssetNames()[0]) as Texture2D; | ||||
|                     ab.Unload(false); | ||||
|                 }); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/KF3/Scripts/UI/SpawnPanel.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/KF3/Scripts/UI/SpawnPanel.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: dcef769ff1dac2b42ac4b52271712b20 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										177
									
								
								Assets/KF3/Scripts/UI/UIKF3CharacterPanel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										177
									
								
								Assets/KF3/Scripts/UI/UIKF3CharacterPanel.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,177 @@ | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| public class UIKF3CharacterPanel : MonoBehaviour | ||||
| { | ||||
|     public KF3CharacterContainer Container; | ||||
|  | ||||
|     public TMPro.TMP_Dropdown | ||||
|         AnimationSetDropdown, | ||||
|         BodyAnimationDropdown, | ||||
|         CostumeDropdown, | ||||
|         EarsAnimationDropdown, | ||||
|         TailAnimationDropdown; | ||||
|  | ||||
|     public ScrollRect WeaponToggle; | ||||
|  | ||||
|     private static KF3ModelViewerMain Main => KF3ModelViewerMain.Instance; | ||||
|  | ||||
|     public static UIKF3CharacterPanel Create(KF3CharacterContainer container) | ||||
|     { | ||||
|         var panel = Instantiate(Main.Resources.Pfb_KF3CharacterPanel, KF3ModelViewerInterface.Instance.DynamicPanels); | ||||
|         panel.Container = container; | ||||
|         panel.Init(); | ||||
|         panel.UpdateSelection(); | ||||
|  | ||||
|         return panel; | ||||
|     } | ||||
|  | ||||
|     public void Init() | ||||
|     { | ||||
|         if (Container as KF3FriendContainer != null) | ||||
|         { | ||||
|             var friend = Container as KF3FriendContainer; | ||||
|             KF3ModelViewerInterface.SetDropdownData(CostumeDropdown, Main.Assets.GetCostumesFromId(Container.ModelId).Select(c => KF3Names.GetDressName(c.DisplayName.Split('_', '.')[2])).ToList()); | ||||
|             KF3ModelViewerInterface.SetDropdownData(AnimationSetDropdown, Main.Assets.AnimationSets.Select(a => a.DisplayName).ToList()); | ||||
|             KF3ModelViewerInterface.SetDropdownData(BodyAnimationDropdown, Container.BodyAnimation.prefabAnimeList.Where(anim => anim.clip != null).Select(kf => kf.name).ToList(), true, true); | ||||
|             KF3ModelViewerInterface.SetDropdownData(EarsAnimationDropdown, friend.EarsAnimation == null ? null : friend.EarsAnimation.prefabAnimeList.Where(anim => anim.clip != null).Select(kf => kf.name).ToList(), true, true); | ||||
|             KF3ModelViewerInterface.SetDropdownData(TailAnimationDropdown, friend.TailAnimation == null ? null : friend.TailAnimation.prefabAnimeList.Where(anim => anim.clip != null).Select(kf => kf.name).ToList(), true, true); | ||||
|  | ||||
|             foreach (Renderer r in friend.Renderers) | ||||
|             { | ||||
|                 UIKF3MorphSlider go = Instantiate(Main.Resources.Pfb_KF3MorphToggle, WeaponToggle.content); | ||||
|                 go.Text.text = KF3CharacterContainerSerializable.GetRendererName(friend, r); | ||||
|                 go.Toggle.isOn = r.enabled; | ||||
|                 go.Toggle.onValueChanged.AddListener((value) => { friend.ToggleRendererVisible(r, value); friend.SetKeyframe(); }); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             var friend = Container as KF3CeruleanContainer; | ||||
|             KF3ModelViewerInterface.SetDropdownData(CostumeDropdown, Main.Assets.GetCeruleans(KF3Names.GetEnemyName(friend.ModelId)).Select(m => m.FileName).ToList()); | ||||
|             KF3ModelViewerInterface.SetDropdownData(AnimationSetDropdown, null); | ||||
|             KF3ModelViewerInterface.SetDropdownData(BodyAnimationDropdown, friend.BodyAnimation.prefabAnimeList.Where(anim => anim.clip != null).Select(kf => kf.name).ToList(), true, true); | ||||
|             KF3ModelViewerInterface.SetDropdownData(EarsAnimationDropdown, null); | ||||
|             KF3ModelViewerInterface.SetDropdownData(TailAnimationDropdown, null); | ||||
|         } | ||||
|  | ||||
|         foreach (var dd in new TMPro.TMP_Dropdown[] { AnimationSetDropdown, BodyAnimationDropdown, CostumeDropdown, EarsAnimationDropdown, TailAnimationDropdown }) | ||||
|         { | ||||
|             foreach (Transform t in dd.transform) | ||||
|             { | ||||
|                 if (t.name == "LeftButton") | ||||
|                 { | ||||
|                     t.gameObject.GetComponent<Button>().onClick.AddListener(() => { ModelViewerInterface.DropdownPrevious(dd); }); | ||||
|                 } | ||||
|                 else if (t.name == "RightButton") | ||||
|                 { | ||||
|                     t.gameObject.GetComponent<Button>().onClick.AddListener(() => { ModelViewerInterface.DropdownNext(dd); }); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void UpdateSelection() | ||||
|     { | ||||
|         string currentAnimation = Container.CurrentAnimation; | ||||
|  | ||||
|         if (currentAnimation == "") | ||||
|         { | ||||
|             BodyAnimationDropdown.SetValueWithoutNotify(0); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             int index = BodyAnimationDropdown.options.IndexOf(BodyAnimationDropdown.options.FirstOrDefault(o => o.text == currentAnimation)); | ||||
|             BodyAnimationDropdown.SetValueWithoutNotify(index); | ||||
|         } | ||||
|  | ||||
|         if (Container as KF3FriendContainer != null) | ||||
|         { | ||||
|             CostumeDropdown.SetValueWithoutNotify(CostumeDropdown.options.IndexOf(CostumeDropdown.options.First(o => o.text == KF3Names.GetDressName(Container.CostumeName.Split('_', '.')[2])))); | ||||
|             EarsAnimationDropdown.SetValueWithoutNotify(0); | ||||
|             TailAnimationDropdown.SetValueWithoutNotify(0); | ||||
|             AnimationSetDropdown.SetValueWithoutNotify(Main.Assets.AnimationSets.IndexOf(Main.Assets.GetAnimationSet(Container.AnimationName))); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             CostumeDropdown.SetValueWithoutNotify(CostumeDropdown.options.IndexOf(CostumeDropdown.options.FirstOrDefault(o => o.text == Container.CostumeName))); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void OnAnimationSetDropdownSelected(int index) | ||||
|     { | ||||
|         //if (index == 0) return; | ||||
|         KF3AssetBundle animations = Main.Assets.GetAnimationSet(AnimationSetDropdown.options[index].text); | ||||
|         List<KF3AssetBundle> costumes = Main.Assets.GetCostumesFromId(Main.SelectedObject.ModelId); | ||||
|  | ||||
|         Main.StartCoroutine(Main.Builder.UpdateCharacter(Container, costumes[CostumeDropdown.value].FileName, animations.FileName)); | ||||
|     } | ||||
|  | ||||
|     public void OnCostumeDropdownSelected(int index) | ||||
|     { | ||||
|         if (Container as KF3FriendContainer != null) | ||||
|         { | ||||
|             List<KF3AssetBundle> costumes = Main.Assets.GetCostumesFromId(Main.SelectedObject.ModelId); | ||||
|             KF3AssetBundle animation = Main.Assets.GetAnimationSet(AnimationSetDropdown.options[AnimationSetDropdown.value].text); | ||||
|             Main.StartCoroutine(Main.Builder.UpdateCharacter(Container, costumes[index].FileName, animation.FileName)); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             //var cells = Main.Assets.GetCeruleans(KF3Names.GetEnemyName(Main.SelectedObject.ModelId)); | ||||
|             //var t = Main.SelectedObject.transform; | ||||
|             //var pos = t.position; | ||||
|             //var rot = t.rotation; | ||||
|             //var siz = t.localScale; | ||||
|             //Destroy(Main.SelectedObject); | ||||
|             //StartCoroutine(Main.ModelBuilder.BuildCerulean(cells[index].FileName, cells[0].FileName, (go) => | ||||
|             //{ | ||||
|             //    t = go.transform; | ||||
|             //    t.position = pos; | ||||
|             //    t.rotation = rot; | ||||
|             //    t.localScale = siz; | ||||
|             //})); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void OnBodyAnimationDropdownSelected(int index) | ||||
|     { | ||||
|         Debug.Log("Click"); | ||||
|         if (index == 0) | ||||
|         { | ||||
|             Container.CurrentAnimation = ""; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             Container.CurrentAnimation = BodyAnimationDropdown.options[index].text; | ||||
|         } | ||||
|         Container.SetKeyframe(); | ||||
|         TimelineController.SetCurrentFrame(Container); | ||||
|         Container.SetKeyframe(); | ||||
|     } | ||||
|  | ||||
|     public void OnEarsAnimationDropdownSelected(int index) | ||||
|     { | ||||
|         var friend = Container as KF3FriendContainer; | ||||
|         if (friend == null) return; | ||||
|         if (index == 0) | ||||
|         { | ||||
|             friend.PlayEarsAnimation(""); | ||||
|             return; | ||||
|         } | ||||
|         friend.PlayEarsAnimation(EarsAnimationDropdown.options[index].text); | ||||
|     } | ||||
|  | ||||
|     public void OnTailAnimationDropdownSelected(int index) | ||||
|     { | ||||
|         var friend = Container as KF3FriendContainer; | ||||
|         if (friend == null) return; | ||||
|         if (index == 0) | ||||
|         { | ||||
|             friend.PlayTailAnimation(""); | ||||
|             return; | ||||
|         } | ||||
|         friend.PlayTailAnimation(TailAnimationDropdown.options[index].text); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3CharacterPanel.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3CharacterPanel.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: c0edd5564ed877d428ef35ddeb40ba16 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										25
									
								
								Assets/KF3/Scripts/UI/UIKF3Container.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								Assets/KF3/Scripts/UI/UIKF3Container.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| using TMPro; | ||||
| using UnityEngine; | ||||
| using UnityEngine.Events; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| public class UIKF3Container : MonoBehaviour | ||||
| { | ||||
|     public Button Button; | ||||
|     public RawImage RawImage; | ||||
|     public TextMeshProUGUI Label; | ||||
|  | ||||
|     public UIKF3Container SetNames(string name, string label, Texture2D icon) | ||||
|     { | ||||
|         gameObject.name = name; | ||||
|         Label.text = label; | ||||
|         RawImage.texture = icon; | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public UIKF3Container AddCallback(UnityAction action) | ||||
|     { | ||||
|         Button.onClick.AddListener(action); | ||||
|         return this; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3Container.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3Container.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 6a78bbcf1fa1e924595665b866401df5 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										139
									
								
								Assets/KF3/Scripts/UI/UIKF3MorphPanel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										139
									
								
								Assets/KF3/Scripts/UI/UIKF3MorphPanel.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,139 @@ | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| public class UIKF3MorphPanel : MonoBehaviour | ||||
| { | ||||
|     public Transform | ||||
|         EyesPanel, | ||||
|         EyebrowsPanel, | ||||
|         MouthPanel; | ||||
|  | ||||
|     public ToggleGroup EyesToggleGroup; | ||||
|  | ||||
|     public static UIKF3MorphPanel Create(KF3FriendContainer container) | ||||
|     { | ||||
|         var main = KF3ModelViewerMain.Instance; | ||||
|         var morphPanel = Instantiate(main.Resources.Pfb_KF3MorphPanel, main.UI.DynamicPanels); | ||||
|         //morphPanel.Init(container); | ||||
|         return morphPanel; | ||||
|     } | ||||
|  | ||||
|     //public void Init(KF3FriendContainer container) | ||||
|     //{ | ||||
|     //    foreach (Transform child in container.GetComponentsInChildren<Transform>()) | ||||
|     //    { | ||||
|     //        GameObject go = null; | ||||
|     //        switch (child.name) | ||||
|     //        { | ||||
|     //            case "md_eye_base": | ||||
|     //                { | ||||
|     //                    go = Instantiate(KF3ModelViewerInterface.Instance.Pfb_MorphSliderToggle, EyesPanel); | ||||
|     //                    go.GetChild<Text>().text = "Look At Camera"; | ||||
|     //                    go.Get<Slider>().wholeNumbers = false; | ||||
|     //                    go.Get<Slider>().minValue = 0; | ||||
|     //                    go.Get<Slider>().maxValue = 1; | ||||
|     //                    go.Get<Slider>().value = container.LookAtStrength; | ||||
|     //                    go.Get<Slider>().onValueChanged.AddListener((value) => { container.UpdateLookAtTarget(value); }); | ||||
|     //                    go.GetChild<Toggle>().isOn = container.EyesLocked; | ||||
|     //                    go.GetChild<Toggle>().onValueChanged.AddListener((val) => container.EyesLocked = val); | ||||
|  | ||||
|     //                    SkinnedMeshRenderer meshRenderer = child.GetComponent<SkinnedMeshRenderer>(); | ||||
|     //                    if (meshRenderer == null) break; | ||||
|     //                    if (meshRenderer.sharedMesh == null) break; | ||||
|     //                    for (int i = 0; i < meshRenderer.sharedMesh.blendShapeCount; i++) | ||||
|     //                    { | ||||
|     //                        CreateMorph(meshRenderer, EyesPanel.transform, i, "BS_eye.eye_"); | ||||
|     //                    } | ||||
|  | ||||
|     //                    if (HumanBones.ContainsKey(HumanBodyBones.Head) && HumanBones[HumanBodyBones.Head] != null && !EyeTarget) | ||||
|     //                    { | ||||
|     //                        Transform head = HumanBones[HumanBodyBones.Head]; | ||||
|     //                        EyeTarget = (UIHandleEyes)new GameObject().AddComponent<UIHandleEyes>() | ||||
|     //                            .Init(this) | ||||
|     //                            .SetScale(2) | ||||
|     //                            .SetColor(Color.red); | ||||
|     //                        EyeTarget.name = $"Eyes_{ModelId}"; | ||||
|     //                        EyeTarget.transform.localScale = 0.1f * Vector3.one; | ||||
|     //                        EyeTarget.transform.SetParent(head); | ||||
|     //                        EyeTarget.transform.position = head.position + head.forward; | ||||
|     //                    } | ||||
|     //                    goto case "md_eye_special_a"; | ||||
|     //                } | ||||
|     //            case "md_eye_special_a": | ||||
|     //            case "md_eye_special_b": | ||||
|     //                { | ||||
|     //                    go = Instantiate(KF3ModelViewerInterface.EyeTogglePrefab, EyesMorphsPanel.transform); | ||||
|     //                    go.GetChild<Text>().text = child.name; | ||||
|     //                    go.Get<Toggle>().isOn = child.gameObject.activeSelf; | ||||
|     //                    go.Get<Toggle>().onValueChanged.AddListener((value) => { ToggleVisible(child.gameObject, value); }); | ||||
|     //                    InstantiatedObjects.Add(go); | ||||
|     //                    break; | ||||
|     //                } | ||||
|     //            case "md_mouth_base": | ||||
|     //                { | ||||
|     //                    SkinnedMeshRenderer meshRenderer = child.GetComponent<SkinnedMeshRenderer>(); | ||||
|     //                    if (meshRenderer == null) break; | ||||
|     //                    if (meshRenderer.sharedMesh == null) break; | ||||
|     //                    for (int i = 0; i < meshRenderer.sharedMesh.blendShapeCount; i++) | ||||
|     //                    { | ||||
|     //                        CreateMorph(meshRenderer, MouthMorphsPanel.transform, i, "BS_mouth.mouth_"); | ||||
|     //                    } | ||||
|     //                    break; | ||||
|     //                } | ||||
|     //            case "md_eye_l": LeftEye = child; break; | ||||
|     //            case "md_eye_r": RightEye = child; break; | ||||
|     //            case "md_brow_base": | ||||
|     //                { | ||||
|     //                    SkinnedMeshRenderer meshRenderer = child.GetComponent<SkinnedMeshRenderer>(); | ||||
|     //                    if (meshRenderer == null) break; | ||||
|     //                    if (meshRenderer.sharedMesh == null) break; | ||||
|  | ||||
|     //                    for (int i = 0; i < meshRenderer.sharedMesh.blendShapeCount; i++) | ||||
|     //                    { | ||||
|     //                        CreateMorph(meshRenderer, EyebrowsMorphsPanel.transform, i, "BS_brow.brow_"); | ||||
|     //                    } | ||||
|  | ||||
|     //                    break; | ||||
|     //                } | ||||
|     //            case "md_subweapon": | ||||
|     //                { | ||||
|     //                    SubWeapon = child; | ||||
|     //                    if (SubWeaponBone == null) break; | ||||
|     //                    SubWeapon.SetParent(SubWeaponBone); | ||||
|     //                    SubWeapon.SetPositionAndRotation(Vector3.zero, Quaternion.identity); | ||||
|     //                    break; | ||||
|     //                } | ||||
|     //            case "subweapon": | ||||
|     //                { | ||||
|     //                    SubWeaponBone = child; | ||||
|     //                    if (SubWeapon == null) break; | ||||
|     //                    SubWeapon.SetParent(SubWeaponBone); | ||||
|     //                    SubWeapon.SetPositionAndRotation(Vector3.zero, Quaternion.identity); | ||||
|     //                    break; | ||||
|     //                } | ||||
|     //        } | ||||
|     //    } | ||||
|     //} | ||||
|  | ||||
|     public void ResetChildMorphs(Transform self) | ||||
|     { | ||||
|         foreach(var helper in self.GetComponentsInChildren<MorphHelper>()) | ||||
|         { | ||||
|             helper.Slider.value = 0; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     //public void PasteValues(KF3MorphHelper[] helpers) | ||||
|     //{ | ||||
|  | ||||
|     //    foreach (var morph in keyframe.Morphs) | ||||
|     //    { | ||||
|     //        var rend = this.Morphs.Keys.FirstOrDefault(k => k.name == morph.ParentName); | ||||
|     //        if (rend == null) continue; | ||||
|  | ||||
|     //        KF3MorphHelper h = this.Morphs[rend].FirstOrDefault(m => m.Name == morph.Name); | ||||
|     //        if (h != null) this.UpdateMorph(rend, rend.sharedMesh.GetBlendShapeIndex(morph.Name), morph.Strength, h.Slider); | ||||
|     //    } | ||||
|     //} | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3MorphPanel.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3MorphPanel.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: c065bfa1db3360149aed82a772567310 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										65
									
								
								Assets/KF3/Scripts/UI/UIKF3MorphSlider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								Assets/KF3/Scripts/UI/UIKF3MorphSlider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,65 @@ | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| public class UIKF3MorphSlider : MonoBehaviour | ||||
| { | ||||
|     public Slider Slider; | ||||
|     public UICallbacks ToggleCallbacks; | ||||
|     public TMPro.TMP_Text Text; | ||||
|     public Toggle Toggle; | ||||
|  | ||||
|     static KF3ModelViewerInterface UI => KF3ModelViewerInterface.Instance; | ||||
|     static KF3ModelViewerMain Main => KF3ModelViewerMain.Instance; | ||||
|  | ||||
|     public static UIKF3MorphSlider CreateLookAt(KF3FriendContainer container, Transform parent) | ||||
|     { | ||||
|         UIKF3MorphSlider panel = Instantiate(Main.Resources.Pfb_KF3MorphSliderToggle, parent); | ||||
|         panel.Text.text = "Look At Camera"; | ||||
|         panel.Slider.wholeNumbers = false; | ||||
|         panel.Slider.minValue = 0; | ||||
|         panel.Slider.maxValue = 1; | ||||
|         panel.Slider.value = container.LookAtStrength; | ||||
|         panel.Slider.onValueChanged.AddListener((value) => { container.UpdateLookAtTarget(value); container.SetKeyframe(); }); | ||||
|         panel.Toggle.isOn = container.EyesLocked; | ||||
|         panel.Toggle.onValueChanged.AddListener((val) => { container.EyesLocked = val; container.SetKeyframe(); }); | ||||
|         panel.ToggleCallbacks.MouseHover.AddListener(() => | ||||
|         { | ||||
|             panel.ToggleCallbacks.SetTooltipText("Lock current look direction."); | ||||
|         }); | ||||
|         panel.ToggleCallbacks.MouseHoverEnd.AddListener(() => | ||||
|         { | ||||
|             panel.ToggleCallbacks.SetTooltipText(""); | ||||
|         }); | ||||
|         return panel; | ||||
|     } | ||||
|  | ||||
|     public static UIKF3MorphSlider CreateMorph(KF3FriendContainer container, SkinnedMeshRenderer meshRenderer, int index, string nameReplace, Transform parent) | ||||
|     { | ||||
|         UIKF3MorphSlider panel = Instantiate(Main.Resources.Pfb_KF3MorphSlider, parent); | ||||
|          | ||||
|         var helper = new MorphHelper(meshRenderer, meshRenderer.sharedMesh.GetBlendShapeName(index), panel.Slider); | ||||
|         if (container.Morphs.ContainsKey(meshRenderer)) | ||||
|             container.Morphs[meshRenderer].Add(helper); | ||||
|         else | ||||
|             container.Morphs.Add(meshRenderer, new List<MorphHelper>() { helper }); | ||||
|  | ||||
|         panel.Text.text = helper.Name.Replace(nameReplace, ""); | ||||
|         panel.Slider.value = meshRenderer.GetBlendShapeWeight(index); | ||||
|         panel.Slider.onValueChanged.AddListener((value) => { | ||||
|             helper.UpdateMorph(value); | ||||
|             container.SetKeyframe(); | ||||
|         }); | ||||
|         return panel; | ||||
|     } | ||||
|  | ||||
|     public static UIKF3MorphSlider CreateEyeToggle(KF3FriendContainer container, Renderer rend, Transform parent, ToggleGroup group) | ||||
|     { | ||||
|         UIKF3MorphSlider panel = Instantiate(Main.Resources.Pfb_KF3MorphToggle, parent); | ||||
|         panel.Text.text = rend.name; | ||||
|         panel.Toggle.group = group; | ||||
|         panel.Toggle.isOn = rend.gameObject.activeSelf; | ||||
|         panel.Toggle.onValueChanged.AddListener((value) => { container.ToggleVisible(rend.gameObject, value); container.SetKeyframe(); }); | ||||
|         return panel; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3MorphSlider.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3MorphSlider.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: ce70097e989567b4c8cdc841bea38e7c | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										61
									
								
								Assets/KF3/Scripts/UI/UIKF3SceneSettings.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								Assets/KF3/Scripts/UI/UIKF3SceneSettings.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| using Newtonsoft.Json.Linq; | ||||
| using System.Linq; | ||||
| using TMPro; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| public class UIKF3SceneSettings : MonoBehaviour | ||||
| { | ||||
|     public KF3SceneContainer Container; | ||||
|     public TMPro.TMP_Dropdown StageDropdown; | ||||
|     public TMPro.TMP_Dropdown BackgroundDropdown; | ||||
|  | ||||
|     public static UIKF3SceneSettings Create(KF3SceneContainer container) | ||||
|     { | ||||
|         var panel = Instantiate(KF3ModelViewerMain.Instance.Resources.Pfb_KF3SceneSettings, KF3ModelViewerInterface.Instance.DynamicPanels); | ||||
|         panel.Container = container; | ||||
|  | ||||
|         foreach (TMP_Dropdown dd in new TMP_Dropdown[] {panel.StageDropdown, panel.BackgroundDropdown}) | ||||
|         { | ||||
|             foreach (Transform t in dd.transform) | ||||
|             { | ||||
|                 if (t.name == "LeftButton") | ||||
|                 { | ||||
|                     t.gameObject.GetComponent<Button>().onClick.AddListener(() => { ModelViewerInterface.DropdownPrevious(dd); }); | ||||
|                 } | ||||
|                 else if (t.name == "RightButton") | ||||
|                 { | ||||
|                     t.gameObject.GetComponent<Button>().onClick.AddListener(() => { ModelViewerInterface.DropdownNext(dd); }); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return panel; | ||||
|     } | ||||
|  | ||||
|     public void OnBackgroundDropdownSelected(int value) | ||||
|     { | ||||
|         if (value == 0) | ||||
|         { | ||||
|             Container.SetBackground(""); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             Container.SetBackground(BackgroundDropdown.options[value].text); | ||||
|         } | ||||
|         Container.SetKeyframe(); | ||||
|     } | ||||
|  | ||||
|     public void OnStageDropdownSelected(int value) | ||||
|     { | ||||
|         if (value == 0) | ||||
|         { | ||||
|             Container.SetStage(""); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             Container.SetStage(StageDropdown.options[value].text); | ||||
|         } | ||||
|         Container.SetKeyframe(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3SceneSettings.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3SceneSettings.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 6603c3d220825e143a6b998beb9a503b | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										20
									
								
								Assets/KF3/Scripts/UI/UIKF3StaticSettings.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Assets/KF3/Scripts/UI/UIKF3StaticSettings.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
|  | ||||
| public class UIKF3StaticSettings : MonoBehaviour | ||||
| { | ||||
|     public KF3StaticContainer Container; | ||||
|  | ||||
|     public static UIKF3StaticSettings Create(KF3StaticContainer container) | ||||
|     { | ||||
|         var panel = Instantiate(KF3ModelViewerMain.Instance.Resources.Pfb_KF3StaticSettings, KF3ModelViewerInterface.Instance.DynamicPanels); | ||||
|         panel.Container = container; | ||||
|         return panel; | ||||
|     } | ||||
|      | ||||
|     public void SetMaterialVariant(int index) | ||||
|     { | ||||
|         Container.SetMaterialVariant(index); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3StaticSettings.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/KF3/Scripts/UI/UIKF3StaticSettings.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: c73b775d1cbc65946992a0a659009786 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
		Reference in New Issue
	
	Block a user