using UnityEngine;
|
|
using System;
|
#if UNITY_EDITOR
|
using UnityEditor;
|
#endif
|
|
|
public class InstanceResourcesLoader
|
{
|
public static readonly string raceSuffix = "Prefab_Race_";
|
public static readonly string horseSuffix = "Prefab_Horse_";
|
public static readonly string weaponSuffix = "Prefab_Weapon_";
|
public static readonly string secondarySuffix = "Prefab_Secondary_";
|
public static readonly string handSuffix = "Prefab_Hand_";
|
public static readonly string wingSuffix = "Prefab_Wing_";
|
public static readonly string emptyJyName = "Prefab_Race_JY";
|
|
public static GameObject LoadEmptyJY()
|
{
|
GameObject _prefab = null;
|
|
if (AssetSource.mobFromEditor)
|
{
|
#if UNITY_EDITOR
|
string _resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
"Gmodels/",
|
emptyJyName,
|
".prefab");
|
|
_prefab = AssetDatabase.LoadAssetAtPath<GameObject>(_resourcePath);
|
#endif
|
}
|
else
|
{
|
_prefab = AssetBundleUtility.Instance.Sync_LoadAsset("gmodels/prefab_race_jy", emptyJyName) as GameObject;
|
}
|
|
if (_prefab == null)
|
{
|
DebugEx.LogErrorFormat("InstanceResourcesLoader.LoadModel() => 加载不到资源: {0}/{1} ", "gmodels/prefab_race_jy", emptyJyName);
|
}
|
|
return _prefab;
|
}
|
|
public static GameObject LoadNpc(int id)
|
{
|
NPCConfig _m = NPCConfig.Get(id);
|
|
if (_m == null || string.IsNullOrEmpty(_m.MODE) || _m.MODE.Equals("0"))
|
{
|
return null;
|
}
|
|
return LoadModelPrefab(raceSuffix, _m.MODE);
|
}
|
|
public static GameObject LoadDefaultFightNPC()
|
{
|
return LoadMob(GeneralDefine.ModeDefaultConfig[1][0],
|
GeneralDefine.ModeDefaultConfig[1][1]);
|
}
|
|
public static GameObject LoadDefaultFuncNPC()
|
{
|
return LoadMob(GeneralDefine.ModeDefaultConfig[0][0],
|
GeneralDefine.ModeDefaultConfig[0][1]);
|
}
|
|
public static void AsyncLoadDefaultFuncNpc(Action<bool, UnityEngine.Object> callBack)
|
{
|
AsyncLoadNpc(GeneralDefine.ModeDefaultConfig[0][0],
|
GeneralDefine.ModeDefaultConfig[0][1],
|
callBack);
|
}
|
public static void AsyncLoadDefaultFightNpc(Action<bool, UnityEngine.Object> callBack)
|
{
|
AsyncLoadNpc(GeneralDefine.ModeDefaultConfig[1][0],
|
GeneralDefine.ModeDefaultConfig[1][1],
|
callBack);
|
}
|
public static void AsyncLoadDefaultPet(Action<bool, UnityEngine.Object> callBack)
|
{
|
AsyncLoadNpc(GeneralDefine.ModeDefaultConfig[2][0],
|
GeneralDefine.ModeDefaultConfig[2][1],
|
callBack);
|
}
|
|
public static GameObject LoadDefaultHorse()
|
{
|
return LoadMob(GeneralDefine.ModeDefaultConfig[3][0],
|
GeneralDefine.ModeDefaultConfig[3][1]);
|
}
|
|
public static GameObject LoadDefaultPet()
|
{
|
return LoadMob(GeneralDefine.ModeDefaultConfig[2][0],
|
GeneralDefine.ModeDefaultConfig[2][1]);
|
}
|
|
public static GameObject LoadNpcPrefab(int npcID)
|
{
|
NPCConfig _m = NPCConfig.Get(npcID);
|
|
if (_m == null || _m.MODE.Equals("0"))
|
{
|
return null;
|
}
|
|
string _assetName;
|
string _assetBundleName;
|
|
if (GAMgr.Instance.s_NpcID2Assetname.TryGetValue(npcID, out _assetName))
|
{
|
_assetBundleName = GAMgr.Instance.s_NpcID2BundleName[npcID];
|
}
|
else
|
{
|
_assetName = StringUtility.Contact(raceSuffix, _m.MODE);
|
_assetBundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, _assetName);
|
GAMgr.Instance.s_NpcID2Assetname[npcID] = _assetName;
|
GAMgr.Instance.s_NpcID2BundleName[npcID] = _assetBundleName;
|
}
|
|
return LoadMob(_assetBundleName, _assetName);
|
}
|
|
public static GameObject LoadModelRes(int id, bool _ui = false)
|
{
|
|
ModelResConfig _m = ModelResConfig.Get(id);
|
|
if (_m == null)
|
{
|
return null;
|
}
|
|
string _name = _m.ResourcesName;
|
int _index = _name.IndexOf('/');
|
if (_index != -1)
|
{
|
_name = _name.Substring(_index + 1);
|
}
|
|
if (_m.Type == (int)E_ModelResType.Suit)
|
{
|
return LoadModelPrefab(raceSuffix, _name, _ui);
|
}
|
else if (_m.Type == (int)E_ModelResType.Horse)
|
{
|
return LoadModelPrefab(horseSuffix, _name, _ui);
|
}
|
else if (_m.Type == (int)E_ModelResType.Wing)
|
{
|
return LoadModelPrefab(wingSuffix, _name, _ui);
|
}
|
else if (_m.Type == (int)E_ModelResType.Weapon)
|
{
|
return LoadModelPrefab(weaponSuffix, _name, _ui);
|
}
|
else if (_m.Type == (int)E_ModelResType.Secondary)
|
{
|
return LoadModelPrefab(secondarySuffix, _name, _ui);
|
}
|
else if (_m.Type == (int)E_ModelResType.Hand)
|
{
|
return LoadModelPrefab(handSuffix, _name, _ui);
|
}
|
return null;
|
}
|
|
public static void LoadCreateRole(int job, Action<bool, UnityEngine.Object> _callBack)
|
{
|
string _name = "Zs";
|
switch (job)
|
{
|
case 1:
|
_name = "Zs";
|
break;
|
case 2:
|
_name = "Fs";
|
break;
|
case 3:
|
_name = "Zs";
|
break;
|
case 4:
|
_name = "Zs";
|
break;
|
}
|
|
if (AssetSource.mobFromEditor)
|
{
|
#if UNITY_EDITOR
|
string _resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
"Gmodels/CreateRole/",
|
_name,
|
".prefab");
|
|
var gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(_resourcePath);
|
|
if (_callBack != null)
|
{
|
_callBack(true, gameObject);
|
}
|
#endif
|
}
|
else
|
{
|
var assetInfo = new AssetInfo("gmodels/createrole", _name);
|
AssetBundleUtility.Instance.Co_LoadAsset(assetInfo, _callBack);
|
}
|
}
|
|
private static GameObject LoadModelPrefab(string _suffix, string name)
|
{
|
GameObject _gameObject = null;
|
if (AssetSource.mobFromEditor)
|
{
|
#if UNITY_EDITOR
|
string _resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
"Gmodels/",
|
_suffix + name,
|
".prefab");
|
|
_gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(_resourcePath);
|
#endif
|
}
|
else
|
{
|
string _bundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, "prefab_race_" + name.Replace("_UI", ""));
|
string _assetName = _suffix + name;
|
_gameObject = AssetBundleUtility.Instance.Sync_LoadAsset(_bundleName, _assetName) as GameObject;
|
}
|
|
if (_gameObject == null)
|
{
|
DebugEx.LogErrorFormat("InstanceResourcesLoader.LoadModel() => 加载不到资源: {0} ", name);
|
}
|
|
return _gameObject;
|
}
|
|
public static GameObject LoadModelPrefab(string _suffix, string name, bool _ui)
|
{
|
var prefab = LoadModelPrefab(_suffix, _ui ? name + "_UI" : name);
|
if (prefab == null)
|
{
|
prefab = LoadModelPrefab(_suffix, name);
|
}
|
|
return prefab;
|
}
|
|
public static void AsyncLoadModelRes(int id, Action<bool, UnityEngine.Object> callback = null)
|
{
|
ModelResConfig _m = ModelResConfig.Get(id);
|
|
if (_m == null)
|
{
|
return;
|
}
|
|
string _name = _m.ResourcesName;
|
int _index = _name.IndexOf('/');
|
if (_index != -1)
|
{
|
_name = _name.Substring(_index + 1);
|
}
|
|
string _suffix = string.Empty;
|
|
if (_m.Type == (int)E_ModelResType.Suit)
|
{
|
_suffix = raceSuffix;
|
}
|
else if (_m.Type == (int)E_ModelResType.Horse)
|
{
|
_suffix = horseSuffix;
|
}
|
else if (_m.Type == (int)E_ModelResType.Wing)
|
{
|
_suffix = wingSuffix;
|
}
|
else if (_m.Type == (int)E_ModelResType.Weapon)
|
{
|
_suffix = weaponSuffix;
|
}
|
else if (_m.Type == (int)E_ModelResType.Secondary)
|
{
|
_suffix = secondarySuffix;
|
}
|
else if (_m.Type == (int)E_ModelResType.Hand)
|
{
|
_suffix = handSuffix;
|
}
|
|
if (AssetSource.mobFromEditor)
|
{
|
#if UNITY_EDITOR
|
string _resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
"Gmodels/",
|
_suffix + _name,
|
".prefab");
|
|
var _gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(_resourcePath);
|
|
if (_gameObject)
|
{
|
if (callback != null)
|
{
|
callback(true, _gameObject);
|
}
|
}
|
else
|
{
|
if (callback != null)
|
{
|
callback(false, null);
|
}
|
}
|
#endif
|
}
|
else
|
{
|
string _bundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, "prefab_race_" + _name.Replace("_UI", ""));
|
string _assetName = _suffix + _name;
|
|
AssetBundleUtility.Instance.Co_LoadAsset(_bundleName, _assetName, callback);
|
}
|
}
|
|
public static GameObject LoadMob(string assetBundleName, string assetName)
|
{
|
GameObject _gameObject = null;
|
if (AssetSource.mobFromEditor)
|
{
|
#if UNITY_EDITOR
|
string _resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
"Gmodels/",
|
assetName,
|
".prefab");
|
|
_gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(_resourcePath);
|
#endif
|
}
|
else
|
{
|
_gameObject = AssetBundleUtility.Instance.Sync_LoadAsset(assetBundleName, assetName) as GameObject;
|
}
|
|
if (_gameObject == null)
|
{
|
DebugEx.LogErrorFormat("InstanceResourcesLoader.LoadModel() => 加载不到资源: {0}/{1} ", assetBundleName, assetName);
|
}
|
|
return _gameObject;
|
}
|
|
public static void UnloadAsset(string bundleName, string assetName)
|
{
|
if (!AssetSource.mobFromEditor)
|
{
|
AssetBundleUtility.Instance.UnloadAsset(bundleName, assetName);
|
AssetBundleUtility.Instance.UnloadAssetBundle(bundleName, true, false);
|
}
|
}
|
|
public static GameObject LoadEffect(int id)
|
{
|
GameObject _gameObject = null;
|
|
EffectConfig _effectModel = EffectConfig.Get(id);
|
|
if (_effectModel == null)
|
{
|
return null;
|
}
|
|
if (AssetSource.effectFromEditor)
|
{
|
#if UNITY_EDITOR
|
string _resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
"Effect/",
|
_effectModel.packageName,
|
"/",
|
_effectModel.fxName,
|
".prefab");
|
_gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(_resourcePath);
|
#endif
|
}
|
else
|
{
|
string _bundleName = StringUtility.Contact(ResourcesPath.EFFECT_Folder_Name, _effectModel.packageName);
|
_gameObject = AssetBundleUtility.Instance.Sync_LoadAsset(_bundleName, _effectModel.fxName) as GameObject;
|
}
|
|
if (_gameObject == null)
|
{
|
DebugEx.LogErrorFormat("InstanceResourcesLoader.LoadSkillEffect() => 加载不到资源: {0}", _effectModel.fxName);
|
}
|
|
return _gameObject;
|
}
|
|
public static void LoadEffectAsync(int _id, Action<bool, UnityEngine.Object> _callBack = null)
|
{
|
GameObject gameObject = null;
|
var config = EffectConfig.Get(_id);
|
if (config == null)
|
{
|
return;
|
}
|
|
if (AssetSource.effectFromEditor)
|
{
|
#if UNITY_EDITOR
|
string _resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
"Effect/",
|
config.packageName,
|
"/",
|
config.fxName,
|
".prefab");
|
gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(_resourcePath);
|
|
if (_callBack != null)
|
{
|
_callBack(gameObject != null, gameObject);
|
}
|
#endif
|
}
|
else
|
{
|
var bundleName = StringUtility.Contact(ResourcesPath.EFFECT_Folder_Name, config.packageName);
|
AssetBundleUtility.Instance.Co_LoadAsset(bundleName, config.fxName, _callBack);
|
}
|
}
|
|
public static void AsyncLoadNpc(int npcID, Action<bool, UnityEngine.Object> callBack = null)
|
{
|
NPCConfig _m = NPCConfig.Get(npcID);
|
|
if (_m == null || _m.MODE.Equals("0"))
|
{
|
if (callBack != null)
|
{
|
callBack(false, null);
|
}
|
}
|
|
string _assetName;
|
string _assetBundleName;
|
|
if (GAMgr.Instance.s_NpcID2Assetname.TryGetValue(npcID, out _assetName))
|
{
|
_assetBundleName = GAMgr.Instance.s_NpcID2BundleName[npcID];
|
}
|
else
|
{
|
_assetName = StringUtility.Contact(raceSuffix, _m.MODE);
|
_assetBundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, _assetName);
|
GAMgr.Instance.s_NpcID2Assetname[npcID] = _assetName;
|
GAMgr.Instance.s_NpcID2BundleName[npcID] = _assetBundleName;
|
}
|
|
AsyncLoadNpc(_assetBundleName, _assetName, callBack);
|
}
|
|
public static void AsyncLoadNpc(string assetBundleName, string assetName, Action<bool, UnityEngine.Object> callBack = null)
|
{
|
if (AssetSource.mobFromEditor)
|
{
|
#if UNITY_EDITOR
|
string _resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
"Gmodels/",
|
assetName,
|
".prefab");
|
|
var _p = AssetDatabase.LoadAssetAtPath<GameObject>(_resourcePath);
|
if (callBack != null)
|
{
|
callBack(true, _p);
|
}
|
#endif
|
}
|
else
|
{
|
AssetBundleUtility.Instance.Co_LoadAsset(assetBundleName, assetName, callBack);
|
}
|
}
|
|
public static void PreloadSkillEffect(int id)
|
{
|
var _skillInfo = SkillHelper.Instance.Get(id);
|
// 技能特效预加载
|
if (_skillInfo.config.EffectName > 0)
|
{
|
InstanceResourcesLoader.LoadEffectAsync(_skillInfo.config.EffectName);
|
}
|
if (_skillInfo.config.BuffEffectID > 0)
|
{
|
InstanceResourcesLoader.LoadEffectAsync(_skillInfo.config.EffectName);
|
}
|
|
var _soSkill = _skillInfo.soFile;
|
if (_soSkill != null)
|
{
|
for (int i = 0; i < _soSkill.animationEventList.Count; ++i)
|
{
|
if (_soSkill.animationEventList[i].frameEventType == E_FrameEventType.OnPlayEffect)
|
{
|
if (_soSkill.animationEventList[i].intParam > 0)
|
{
|
InstanceResourcesLoader.LoadEffectAsync(_soSkill.animationEventList[i].intParam);
|
}
|
}
|
else if (_soSkill.animationEventList[i].frameEventType == E_FrameEventType.OnSkillEvent)
|
{
|
var _param = _soSkill.animationEventList[i].intParam;
|
var _type = SoSkill.GetAttactType(_param);
|
var _id = SoSkill.GetFrameEventId(_param);
|
if (_type == SoSkill.E_AttackType.Sweep)
|
{
|
var _config = ScriptableObjectLoader.LoadSoSweepHit(_id);
|
if (_config.hitEffectId > 0)
|
{
|
InstanceResourcesLoader.LoadEffectAsync(_config.hitEffectId);
|
}
|
}
|
else if (_type == SoSkill.E_AttackType.FlyObject)
|
{
|
var _config = ScriptableObjectLoader.LoadSoFlyObject(_id);
|
if (_config.hitEffectId > 0)
|
{
|
InstanceResourcesLoader.LoadEffectAsync(_config.hitEffectId);
|
}
|
|
if (_config.ammoEffectId > 0)
|
{
|
InstanceResourcesLoader.LoadEffectAsync(_config.hitEffectId);
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|