using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif public class AnimatorControllerLoader { public static readonly string controllerSuffix = "AnimatorController_"; public static readonly string controllerUISuffix = "AnimatorController_UI_"; public static readonly string controllerShowSuffix = "AnimatorController_Show_"; public static readonly string controllerRealmSuffix = "AnimatorController_Realm_"; public static AnimationClip LoadAnimationClip(string name, string clipName) { AnimationClip _animationClip = null; if (AssetSource.mobFromEditor) { #if UNITY_EDITOR string _resourcesPath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, "gmodels/", name, "/AnimationClips/", clipName, ".anim"); _animationClip = AssetDatabase.LoadAssetAtPath(_resourcesPath); #endif } else { string _bundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, ResourcesPath.MOB_SUFFIX, name); string _assetName = clipName; AssetInfo _assetInfo = new AssetInfo(_bundleName, _assetName); _animationClip = AssetBundleUtility.Instance.Sync_LoadAsset(_assetInfo) as AnimationClip; } if (_animationClip == null) { DebugEx.LogErrorFormat("LoadAnimationClip.Load() => 加载不到资源: {0} => {1}.", name, clipName); } return _animationClip; } public static RuntimeAnimatorController LoadDefaultMobAnimatorController_Fight() { return AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerSuffix, GeneralDefine.ModeDefaultConfig[1][1].Replace("Prefab_Race_", "")); } public static RuntimeAnimatorController LoadDefaultMobAnimatorController_Func() { return AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerSuffix, GeneralDefine.ModeDefaultConfig[0][1].Replace("Prefab_Race_", "")); } public static RuntimeAnimatorController LoadDefaultMobAnimatorController_Horse() { return AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerSuffix, GeneralDefine.ModeDefaultConfig[3][1].Replace("Prefab_Horse_", "")); } public static RuntimeAnimatorController LoadDefaultMobAnimatorController_Pet() { return AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerSuffix, GeneralDefine.ModeDefaultConfig[2][1].Replace("Prefab_Race_", "")); } public static RuntimeAnimatorController Load(string suffix, int id) { ModelResConfig _modelRes = ModelResConfig.Get(id); string _name = _modelRes.ResourcesName; if (_name.IndexOf('/') != -1) { _name = _name.Substring(0, _modelRes.ResourcesName.IndexOf('/')); } return LoadMobController(suffix, _name); } public static RuntimeAnimatorController LoadMobController(string suffix, string _name) { RuntimeAnimatorController _controller = null; if (AssetSource.mobFromEditor) { #if UNITY_EDITOR string _resourcesPath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, "gmodels/", _name, "/", suffix, _name, ".controller"); _controller = AssetDatabase.LoadAssetAtPath(_resourcesPath); #endif } else { string _bundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, ResourcesPath.MOB_SUFFIX, _name.ToLower()); string _assetName = StringUtility.Contact(suffix, _name); AssetInfo _assetInfo = new AssetInfo(_bundleName, _assetName); _controller = AssetBundleUtility.Instance.Sync_LoadAsset(_assetInfo) as RuntimeAnimatorController; } if (_controller == null) { DebugEx.LogErrorFormat("AnimatorControllerLoader.Load() => 加载不到资源: {0}.", _name); } return _controller; } }