| | |
| | | using UnityEngine; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | |
| | | public class MaterialLoader |
| | | { |
| | | |
| | | public static Material Load(string modelName, string materialName) |
| | | { |
| | | |
| | | string _bundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, |
| | | ResourcesPath.MOB_SUFFIX, |
| | | modelName); |
| | | |
| | | string _assetName = materialName; |
| | | |
| | | AssetInfo _assetInfo = new AssetInfo(_bundleName, _assetName); |
| | | |
| | | Material _controller = AssetBundleUtility.Instance.Sync_LoadAsset(_assetInfo) as Material; |
| | | |
| | | if (_controller == null) |
| | | { |
| | | DebugEx.LogErrorFormat("MaterialLoader.Load() => 加载不到资源: {0}.", _assetName); |
| | | } |
| | | |
| | | return _controller; |
| | | |
| | | } |
| | | readonly static Dictionary<string, ObjectPool<Material>> s_MatDict = new Dictionary<string, ObjectPool<Material>>(); |
| | | |
| | | public static Material LoadClothesMaterial(int id, bool isUI, bool isSuit) |
| | | { |
| | |
| | | return null; |
| | | } |
| | | |
| | | //Debug.LogFormat("想要加载的材质的名称: {0}", _assetName); |
| | | |
| | | ObjectPool<Material> _pool = null; |
| | | |
| | | if (s_MatDict.TryGetValue(_assetName, out _pool)) |
| | | { |
| | | if (_pool.inactivedCount > 0) |
| | | { |
| | | //Debug.Log(" |-- 池里有, 从池里取"); |
| | | return _pool.Get(); |
| | | } |
| | | } |
| | | |
| | | string _name = _modelResConfig.ResourcesName; |
| | | int _index = _name.IndexOf('/'); |
| | | if (_index != -1) |
| | |
| | | _name = _name.Substring(_index + 1); |
| | | } |
| | | |
| | | var _parentDirName = string.Empty; |
| | | |
| | | if (_name.Contains("A_Zs")) |
| | | { |
| | | _name = "A_Zs"; |
| | | _parentDirName = "A_Zs"; |
| | | } |
| | | else if (_name.Contains("A_Fs")) |
| | | { |
| | | _name = "A_Fs"; |
| | | _parentDirName = "A_Fs"; |
| | | } |
| | | |
| | | Material _mat = null; |
| | |
| | | #if UNITY_EDITOR |
| | | string _resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, |
| | | "Mob/", |
| | | _name, |
| | | _parentDirName, |
| | | "/Materials/", |
| | | _assetName, |
| | | ".mat"); |
| | |
| | | } |
| | | else |
| | | { |
| | | string _bundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, _name.ToLower(), "_materials"); |
| | | string _bundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, InstanceResourcesLoader.raceSuffix, _name.ToLower()); |
| | | AssetInfo _assetInfo = new AssetInfo(_bundleName, _assetName); |
| | | _mat = AssetBundleUtility.Instance.Sync_LoadAsset(_assetInfo) as Material; |
| | | } |
| | | |
| | | if (_mat == null) |
| | | { |
| | | DebugEx.LogErrorFormat("MaterialLoader.Load() => 加载不到资源: {0}.", _assetName); |
| | | DebugEx.LogErrorFormat("MaterialLoader.Load() => 加载不到资源: {0}", _assetName); |
| | | } |
| | | |
| | | return _mat; |
| | | } |
| | | |
| | | public static void Release(Material mat) |
| | | { |
| | | if (!mat) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var _name = mat.name.Replace(" (Instance)", ""); |
| | | //Debug.LogFormat("要释放的材质的名称: {0}, 修改后的名称: {1}", mat.name, _name); |
| | | |
| | | ObjectPool<Material> _pool = null; |
| | | |
| | | if (!s_MatDict.TryGetValue(_name, out _pool)) |
| | | { |
| | | _pool = new ObjectPool<Material>(null, null); |
| | | s_MatDict.Add(_name, _pool); |
| | | } |
| | | |
| | | _pool.Add(mat); |
| | | } |
| | | } |