From fc6de82e75310b4c007d80753a5f58e6692f4855 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 13 Oct 2020 10:33:05 +0800 Subject: +misc --- .../Scripts/Application/AssetResourcesFile.cs | 238 ++++++++++----------- 1 file changed, 119 insertions(+), 119 deletions(-) (limited to 'Assets/ThirdParty/UMotion/UMotionEditor/Scripts/Application/AssetResourcesFile.cs') diff --git a/Assets/ThirdParty/UMotion/UMotionEditor/Scripts/Application/AssetResourcesFile.cs b/Assets/ThirdParty/UMotion/UMotionEditor/Scripts/Application/AssetResourcesFile.cs index 7f5392be..0380f56b 100644 --- a/Assets/ThirdParty/UMotion/UMotionEditor/Scripts/Application/AssetResourcesFile.cs +++ b/Assets/ThirdParty/UMotion/UMotionEditor/Scripts/Application/AssetResourcesFile.cs @@ -1,120 +1,120 @@ -#if UNITY_EDITOR -using UnityEngine; -using UnityEditor; -using System; -using System.Collections.Generic; -using System.IO; - -namespace UMotionEditor -{ - public class AssetResourcesFile : ScriptableObject - { - //******************************************************************************** - // Public Properties - //******************************************************************************** - - //******************************************************************************** - // Private Properties - //******************************************************************************** - - #pragma warning disable 0649 // Suppress "Field 'field' is never assigned to, and will always have its default value 'value'" - [Serializable] - private struct ResourceDefinition - { - public string Name; - public UnityEngine.Object Reference; - } - #pragma warning restore 0649 - - //---------------------- - // Inspector - //---------------------- - [SerializeField]private List resourcesList = new List(); - [SerializeField]private List optionalResourcesList = new List(); - private Dictionary resourcesDictionary = new Dictionary(); - - //---------------------- - // Internal - //---------------------- - - //******************************************************************************** - // Public Methods - //******************************************************************************** - - public static AssetResourcesFile FindAssetResourcesFile() - { - string[] resourceFilesGUID = AssetDatabase.FindAssets("UMotionResources t:AssetResourcesFile"); - - if (resourceFilesGUID.Length > 1) - { - throw new UnityException("More than one resource file was found. Please remove all UMotion files and install UMotion again."); - } - else if (resourceFilesGUID.Length == 0) - { - throw new UnityException("Resource file not found. Please install UMotion again."); - } - else - { - AssetResourcesFile resourceFile = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(resourceFilesGUID[0])); - - resourceFile.InitializeDictionary(); - - return resourceFile; - } - } - - public string GetEditorDataPath() - { - string resourcesPath = AssetDatabase.GetAssetPath(this); - - string dataPath = Path.GetDirectoryName(resourcesPath); - dataPath = Path.Combine(Path.GetDirectoryName(dataPath), "Data"); - - return dataPath; - } - - public T GetResource(string name, bool required = true) where T : UnityEngine.Object - { - T loadedObject = null; - UnityEngine.Object obj; - if (resourcesDictionary.TryGetValue(name, out obj)) - { - loadedObject = obj as T; - } - - if (required && (loadedObject == null)) - { - throw new Exception(string.Format("Resource \"{0}\" can not be loaded.", name)); - } - else - { - return loadedObject; - } - } - - //******************************************************************************** - // Private Methods - //******************************************************************************** - - private void InitializeDictionary() - { - resourcesDictionary.Clear(); - foreach (ResourceDefinition resourceDef in resourcesList) - { - if (resourceDef.Reference == null) - { - throw new UnityException(string.Format("Required resource \"{0}\" not found. Please reinstall UMotion.", resourceDef.Name)); - } - else - { - resourcesDictionary.Add(resourceDef.Name, resourceDef.Reference); - } - } - foreach (ResourceDefinition resourceDef in optionalResourcesList) - { - resourcesDictionary.Add(resourceDef.Name, resourceDef.Reference); - } - } - } -} +#if UNITY_EDITOR +using UnityEngine; +using UnityEditor; +using System; +using System.Collections.Generic; +using System.IO; + +namespace UMotionEditor +{ + public class AssetResourcesFile : ScriptableObject + { + //******************************************************************************** + // Public Properties + //******************************************************************************** + + //******************************************************************************** + // Private Properties + //******************************************************************************** + + #pragma warning disable 0649 // Suppress "Field 'field' is never assigned to, and will always have its default value 'value'" + [Serializable] + private struct ResourceDefinition + { + public string Name; + public UnityEngine.Object Reference; + } + #pragma warning restore 0649 + + //---------------------- + // Inspector + //---------------------- + [SerializeField]private List resourcesList = new List(); + [SerializeField]private List optionalResourcesList = new List(); + private Dictionary resourcesDictionary = new Dictionary(); + + //---------------------- + // Internal + //---------------------- + + //******************************************************************************** + // Public Methods + //******************************************************************************** + + public static AssetResourcesFile FindAssetResourcesFile() + { + string[] resourceFilesGUID = AssetDatabase.FindAssets("UMotionResources t:AssetResourcesFile"); + + if (resourceFilesGUID.Length > 1) + { + throw new UnityException("More than one resource file was found. Please remove all UMotion files and install UMotion again."); + } + else if (resourceFilesGUID.Length == 0) + { + throw new UnityException("Resource file not found. Please install UMotion again."); + } + else + { + AssetResourcesFile resourceFile = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(resourceFilesGUID[0])); + + resourceFile.InitializeDictionary(); + + return resourceFile; + } + } + + public string GetEditorDataPath() + { + string resourcesPath = AssetDatabase.GetAssetPath(this); + + string dataPath = Path.GetDirectoryName(resourcesPath); + dataPath = Path.Combine(Path.GetDirectoryName(dataPath), "Data"); + + return dataPath; + } + + public T GetResource(string name, bool required = true) where T : UnityEngine.Object + { + T loadedObject = null; + UnityEngine.Object obj; + if (resourcesDictionary.TryGetValue(name, out obj)) + { + loadedObject = obj as T; + } + + if (required && (loadedObject == null)) + { + throw new Exception(string.Format("Resource \"{0}\" can not be loaded.", name)); + } + else + { + return loadedObject; + } + } + + //******************************************************************************** + // Private Methods + //******************************************************************************** + + private void InitializeDictionary() + { + resourcesDictionary.Clear(); + foreach (ResourceDefinition resourceDef in resourcesList) + { + if (resourceDef.Reference == null) + { + throw new UnityException(string.Format("Required resource \"{0}\" not found. Please reinstall UMotion.", resourceDef.Name)); + } + else + { + resourcesDictionary.Add(resourceDef.Name, resourceDef.Reference); + } + } + foreach (ResourceDefinition resourceDef in optionalResourcesList) + { + resourcesDictionary.Add(resourceDef.Name, resourceDef.Reference); + } + } + } +} #endif \ No newline at end of file -- cgit v1.1-26-g67d0