You've already forked UniversalViewer
							
							Eversoul:
-compatibility improvements Core: -new settings class
This commit is contained in:
		
							
								
								
									
										8
									
								
								Assets/Eversoul/Scripts/Containers.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assets/Eversoul/Scripts/Containers.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 7d5bef7f2ad289347b89e09aafc21308 | ||||
| folderAsset: yes | ||||
| DefaultImporter: | ||||
|   externalObjects: {} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
| @@ -1,9 +1,6 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using System.ComponentModel; | ||||
| using System.IO; | ||||
| using System.Linq; | ||||
| using UnityEditor.VersionControl; | ||||
| using UnityEngine; | ||||
| 
 | ||||
| public class EversoulCharacterContainer : ObjectContainer, IAnimated | ||||
| @@ -12,6 +9,7 @@ public class EversoulCharacterContainer : ObjectContainer, IAnimated | ||||
|     public string AnimationSet; | ||||
|     public string Animation; | ||||
| 
 | ||||
|     public MorphPanel MorphPanel; | ||||
|     public List<AnimationClip> Animations; | ||||
|     private Animator _animator; | ||||
|     private AnimatorOverrideController _animatorController; | ||||
| @@ -19,10 +17,18 @@ public class EversoulCharacterContainer : ObjectContainer, IAnimated | ||||
| 
 | ||||
|     public override void Select() | ||||
|     { | ||||
|         if (MorphPanel != null) | ||||
|         { | ||||
|             MorphPanel.gameObject.SetActive(true); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public override void Deselect() | ||||
|     { | ||||
|         if (MorphPanel != null) | ||||
|         { | ||||
|             MorphPanel.gameObject.SetActive(false); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public IEnumerator Build(CharacterAsset model) | ||||
| @@ -31,6 +37,7 @@ public class EversoulCharacterContainer : ObjectContainer, IAnimated | ||||
|         var path = EversoulAssetLibrary.Instance.GetResourcePath(model.ResourceName, out var dependencies); | ||||
|         var modelPath = EversoulAssetLibrary.Instance.LocalFilesPath + path; | ||||
|         var dependencyPaths = dependencies.Select(path => EversoulAssetLibrary.Instance.LocalFilesPath + path).ToList(); | ||||
|         Debug.LogError(modelPath); | ||||
| 
 | ||||
|         yield return EversoulAssetLibrary.Instance.LoadAssets(dependencyPaths); | ||||
| 
 | ||||
| @@ -52,6 +59,7 @@ public class EversoulCharacterContainer : ObjectContainer, IAnimated | ||||
|         _animator.applyRootMotion = false; | ||||
|         _animator.runtimeAnimatorController = _animatorController = Instantiate(SharedResources.Instance.GenericAnimatorController); | ||||
|         SetBones(); | ||||
|         CreateMorphPanel(); | ||||
|     } | ||||
| 
 | ||||
|     public void PlayAnimation(AnimationClip anim) | ||||
| @@ -86,9 +94,15 @@ public class EversoulCharacterContainer : ObjectContainer, IAnimated | ||||
|                     case "NineArk/Character/PC_Basic_Body_Transparent": | ||||
|                         material.shader = Shader.Find("Eversoul/Lit Transparent"); | ||||
|                         break; | ||||
|                     case "NineArk/Character/NPC_Glass": | ||||
|                         material.shader = Shader.Find("Eversoul/Glass"); | ||||
|                         break; | ||||
|                     case "NineArk/Character/PC_Basic_Face": | ||||
|                         material.shader = Shader.Find("Eversoul/Unlit"); | ||||
|                         break; | ||||
|                     case "NineArk/Character/PC_Basic_Eye": | ||||
|                         material.shader = Shader.Find("Eversoul/BasicEye"); | ||||
|                         break; | ||||
|                     case "NineArk/Outline/PC_Outline": | ||||
|                         material.shader = Shader.Find("Eversoul/Outline"); | ||||
|                         break; | ||||
| @@ -96,12 +110,10 @@ public class EversoulCharacterContainer : ObjectContainer, IAnimated | ||||
|                         material.shader = Shader.Find("Eversoul/Outline Transparent"); | ||||
|                         break; | ||||
|                     default: | ||||
|                         Debug.Log("Shader not found: " + material.shader.name); | ||||
|                         Debug.LogError("Shader not found: " + material.shader.name); | ||||
|                         //material.shader = Shader.Find("Eversoul/Lit"); | ||||
|                         break; | ||||
|                 } | ||||
|                 Debug.Log(material.shader); | ||||
|                 // | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -109,7 +121,18 @@ public class EversoulCharacterContainer : ObjectContainer, IAnimated | ||||
|     public void SetBones() | ||||
|     { | ||||
|         var humanBones = new Dictionary<HumanBodyBones, Transform>(); | ||||
|         var allBones = _animator.transform.GetComponentsInChildren<Transform>().ToDictionary(b => b.name, b => b); | ||||
|         var allBones = new Dictionary<string, Transform>(); | ||||
|         foreach(var bone in _animator.transform.GetComponentsInChildren<Transform>()) | ||||
|         { | ||||
|             if (!allBones.ContainsKey(bone.name)) | ||||
|             { | ||||
|                 allBones.Add(bone.name, bone); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 Debug.LogWarning("Duplicate bone: " + bone.name); | ||||
|             } | ||||
|         } | ||||
|         humanBones.Add(HumanBodyBones.Hips,                     TryGet(allBones, "Bip001 Pelvis")); | ||||
|         humanBones.Add(HumanBodyBones.Spine,                    TryGet(allBones, "Bip001 Spine")); | ||||
|         humanBones.Add(HumanBodyBones.RightUpperLeg,            TryGet(allBones, "Bip001 R Thigh")); | ||||
| @@ -181,6 +204,41 @@ public class EversoulCharacterContainer : ObjectContainer, IAnimated | ||||
|         _humanBones = humanBones; | ||||
|     } | ||||
| 
 | ||||
|     public void CreateMorphPanel() | ||||
|     { | ||||
|         if (MorphPanel != null) | ||||
|         { | ||||
|             Destroy(MorphPanel.gameObject); | ||||
|         } | ||||
| 
 | ||||
|         var morphRenderers = new Dictionary<SkinnedMeshRenderer, List<MorphHelper>>(); | ||||
|         foreach (var rend in gameObject.GetComponentsInChildren<SkinnedMeshRenderer>()) | ||||
|         { | ||||
|             if (rend.sharedMesh.blendShapeCount > 0) | ||||
|             { | ||||
|                 morphRenderers.Add(rend, new List<MorphHelper>()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if (morphRenderers.Count == 0) return; | ||||
| 
 | ||||
|         MorphPanel = MorphPanel.Create(morphRenderers.Select(mr => mr.Key.sharedMesh.name).ToList()); | ||||
|         MorphPanel.name = $"{Data.Name} Morphs"; | ||||
| 
 | ||||
|         foreach (var rend in morphRenderers) | ||||
|         { | ||||
|             var mesh = rend.Key.sharedMesh; | ||||
|             for (int i = 0; i < mesh.blendShapeCount; i++) | ||||
|             { | ||||
|                 MorphPanel.CreateMorph(mesh.name, this, rend.Key, i, mesh.GetBlendShapeName(i)); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         Morphs = morphRenderers; | ||||
|         EversoulInterface.Instance.SelectedObjectToolbar.AttachToThis(MorphPanel.GetComponent<UIElementDragger>()); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public T TryGet<T>(Dictionary<string, T> dict, string key) | ||||
|     { | ||||
|         if (dict.ContainsKey(key)) | ||||
| @@ -202,6 +260,10 @@ public class EversoulCharacterContainer : ObjectContainer, IAnimated | ||||
|     protected override void OnDestroy() | ||||
|     { | ||||
|         if (_applicationQuitting) return; | ||||
|         if (MorphPanel != null) | ||||
|         { | ||||
|             Destroy(MorphPanel.gameObject); | ||||
|         } | ||||
|         base.OnDestroy(); | ||||
|     } | ||||
| 
 | ||||
| @@ -11,11 +11,6 @@ public class EversoulAssetLibrary : AssetLibrary | ||||
| { | ||||
|     public static EversoulAssetLibrary Instance => GetInstance<EversoulAssetLibrary>(); | ||||
|  | ||||
|     private List<string> assets = new List<string>(); | ||||
|     private Dictionary<string, string> hashDirectories = new Dictionary<string, string>(); | ||||
|     private Dictionary<string, string> hashAssets = new Dictionary<string, string>(); | ||||
|     private Dictionary<string, string> assetHashes = new Dictionary<string, string>(); | ||||
|  | ||||
|     public List<string> CharacterAssets = new List<string>(); | ||||
|     public List<string> AnimationAssets = new List<string>(); | ||||
|  | ||||
| @@ -24,33 +19,42 @@ public class EversoulAssetLibrary : AssetLibrary | ||||
|     IEnumerator Start() | ||||
|     { | ||||
|         var selectedFilePath = new string[0]; | ||||
|         var catalogPath = ModelViewerSettings.Get("CatalogPath", new ModelViewerSettings.Setting("", ModelViewerSettings.SettingType.FilePath)); | ||||
|         var assetsPath = ModelViewerSettings.Get("AssetsPath", new ModelViewerSettings.Setting("", ModelViewerSettings.SettingType.FolderPath)); | ||||
|  | ||||
|         while (true) | ||||
|         if (!File.Exists(catalogPath)) | ||||
|         { | ||||
|             Debug.LogError("IMPLEMENT SETTINGS!"); | ||||
|             selectedFilePath = StandaloneFileBrowser.OpenFilePanel("Select catalog_eversoul.json", "", "json", false); | ||||
|             if(selectedFilePath.Length > 0 && !string.IsNullOrEmpty(selectedFilePath[0])) | ||||
|             selectedFilePath = new string[0]; | ||||
|             while (true) | ||||
|             { | ||||
|                 break; | ||||
|                 selectedFilePath = StandaloneFileBrowser.OpenFilePanel("Select catalog_eversoul.json", catalogPath, "json", false); | ||||
|                 if (selectedFilePath.Length > 0 && !string.IsNullOrEmpty(selectedFilePath[0])) | ||||
|                 { | ||||
|                     break; | ||||
|                 } | ||||
|                 yield return new WaitForSeconds(5); | ||||
|             } | ||||
|             yield return new WaitForSeconds(5); | ||||
|             catalogPath = selectedFilePath[0]; | ||||
|             ModelViewerSettings.Set("CatalogPath", catalogPath); | ||||
|         } | ||||
|  | ||||
|         string catalogPath = selectedFilePath[0]; | ||||
|  | ||||
|         selectedFilePath = new string[0]; | ||||
|         while (true) | ||||
|         if (!Directory.Exists(assetsPath)) | ||||
|         { | ||||
|             Debug.LogError("IMPLEMENT SETTINGS!"); | ||||
|             selectedFilePath = StandaloneFileBrowser.OpenFolderPanel("Select folder with assets", "", false); | ||||
|             if (selectedFilePath.Length > 0 && !string.IsNullOrEmpty(selectedFilePath[0])) | ||||
|             selectedFilePath = new string[0]; | ||||
|             while (true) | ||||
|             { | ||||
|                 break; | ||||
|                 selectedFilePath = StandaloneFileBrowser.OpenFolderPanel("Select folder with converted assets", assetsPath, false); | ||||
|                 if (selectedFilePath.Length > 0 && !string.IsNullOrEmpty(selectedFilePath[0])) | ||||
|                 { | ||||
|                     break; | ||||
|                 } | ||||
|                 yield return new WaitForSeconds(5); | ||||
|             } | ||||
|             yield return new WaitForSeconds(5); | ||||
|             assetsPath = selectedFilePath[0] + "\\"; | ||||
|             ModelViewerSettings.Set("AssetsPath", assetsPath); | ||||
|         } | ||||
|  | ||||
|         LocalFilesPath = selectedFilePath[0] + "\\"; | ||||
|         ModelViewerSettings.Save(); | ||||
|  | ||||
|         yield return LoadAddressableCatalog(catalogPath); | ||||
|  | ||||
|   | ||||
| @@ -7,4 +7,5 @@ public class EversoulInterface : ModelViewerInterface | ||||
|     public static EversoulInterface Instance => GetInstance<EversoulInterface>(); | ||||
|  | ||||
|     public EversoulCharacterDropdown CharacterSelection; | ||||
|     public UIToolbar SelectedObjectToolbar; | ||||
| } | ||||
|   | ||||
| @@ -5,4 +5,9 @@ using UnityEngine; | ||||
| public class EversoulMain : ModelViewerMain | ||||
| { | ||||
|     public static EversoulMain Instance => GetInstance<EversoulMain>(); | ||||
|  | ||||
|     private void Awake() | ||||
|     { | ||||
|         base.Awake(); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user