LoadHelper.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace ET
  7. {
  8. public static class LoadHelper
  9. {
  10. public static TextAsset LoadTextAsset(string path)
  11. {
  12. if (Application.isEditor)
  13. {
  14. TextAsset resource = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(path) as TextAsset;
  15. return resource ;
  16. }
  17. path = path + ".unity3d";
  18. string p = Path.Combine(PathHelper.AppHotfixResPath, path);
  19. AssetBundle assetBundle = null;
  20. if (File.Exists(p))
  21. {
  22. assetBundle = AssetBundle.LoadFromFile(p);
  23. }
  24. else
  25. {
  26. p = Path.Combine(PathHelper.AppResPath, path);
  27. assetBundle = AssetBundle.LoadFromFile(p);
  28. }
  29. if (assetBundle == null)
  30. {
  31. // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功
  32. Debug.LogError($"assets bundle not found: {path}");
  33. return default(TextAsset);
  34. }
  35. return assetBundle.LoadAsset(path) as TextAsset;
  36. }
  37. public static UnityEngine.Object LoadAssetAtPath(string assetPath)
  38. {
  39. return AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
  40. }
  41. public static int GetAssetPathsFromAssetBundleCount(string assetBundleName)
  42. {
  43. string[] resultArr = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
  44. return resultArr.Length;
  45. }
  46. public static string[] GetAssetPathsFromAssetBundle(string assetBundleName)
  47. {
  48. return AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
  49. }
  50. public static int GetAssetBundleDependenciesCount(string assetBundleName, bool recursive)
  51. {
  52. string[] result = AssetDatabase.GetAssetBundleDependencies(assetBundleName, recursive);
  53. return result.Length;
  54. }
  55. public static string[] GetAssetBundleDependencies(string assetBundleName, bool recursive)
  56. {
  57. return AssetDatabase.GetAssetBundleDependencies(assetBundleName, recursive);
  58. }
  59. public static int GetanimationClipsLength(this Animator self )
  60. {
  61. return self.runtimeAnimatorController.animationClips.Length;
  62. }
  63. public static int GetAnimatorControllerParameterLength(this Animator self )
  64. {
  65. return self.parameters.Length;
  66. }
  67. }
  68. }