using UnityEngine;
|
using TableConfig;
|
using System.Collections.Generic;
|
using System;
|
|
public class UI3DModelFactory
|
{
|
|
static UI3DModelFactory()
|
{
|
GlobalTimeEvent.Instance.minuteEvent += OnPerMinute;
|
}
|
|
static Dictionary<int, GameObject> jobModels = new Dictionary<int, GameObject>();
|
|
public static void LoadCreateRole(int job, Action<bool, UnityEngine.Object> _callBack)
|
{
|
if (jobModels.ContainsKey(job))
|
{
|
if (_callBack != null)
|
{
|
_callBack(true, jobModels[job]);
|
}
|
|
return;
|
}
|
|
Action<bool, UnityEngine.Object> assetCallBack = (bool _ok, UnityEngine.Object _asset) =>
|
{
|
GameObject instance = null;
|
if (_ok)
|
{
|
instance = GameObject.Instantiate(_asset) as GameObject;
|
if (instance != null)
|
{
|
jobModels[job] = instance;
|
}
|
}
|
|
if (_callBack != null)
|
{
|
_callBack(_ok && instance != null, instance);
|
}
|
};
|
|
InstanceResourcesLoader.LoadCreateRole(job, assetCallBack);
|
}
|
|
public static void ReleaseCreateRole(int job)
|
{
|
if (jobModels.ContainsKey(job))
|
{
|
jobModels[job].gameObject.SetActive(false);
|
}
|
}
|
|
public static void ClearCreateRole()
|
{
|
jobModels.Clear();
|
|
if (!AssetSource.mobFromEditor)
|
{
|
AssetBundleUtility.Instance.UnloadAssetBundle("mob/createrole", true, false);
|
}
|
}
|
|
public static GameObject LoadUINPC(int id)
|
{
|
var config = Config.Instance.Get<NPCConfig>(id);
|
var model = GameObjectPoolManager.Instance.RequestNpcGameObject(id);
|
|
if (!model && config.NPCType == (int)E_NpcType.Func)
|
{
|
model = GameObjectPoolManager.Instance.RequestDefaultFuncNpc();
|
}
|
|
if (!model)
|
{
|
return null;
|
}
|
|
var animator = model.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.enabled = true;
|
animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Idle);
|
animator.Play(GAStaticDefine.State_IdleHash);
|
}
|
|
LayerUtility.SetLayer(model, LayerUtility.Monster, true);
|
return model;
|
}
|
|
public static void ReleaseUINPC(int id, GameObject model)
|
{
|
var animator = model.GetComponent<Animator>();
|
if (animator != null)
|
{
|
ResetRealmBossAnimator(id, animator);
|
animator.enabled = false;
|
}
|
|
if (model)
|
{
|
model.transform.localScale = Vector3.one;
|
}
|
|
var prefab = InstanceResourcesLoader.LoadNpcPrefab(id);
|
if (prefab)
|
{
|
GameObjectPoolManager.Instance.ReleaseGameObject(prefab, model);
|
}
|
else
|
{
|
GameObjectPoolManager.Instance.ReleaseDefaultFuncNPC(model);
|
}
|
}
|
|
private static void ResetRealmBossAnimator(int _id, Animator animator)
|
{
|
var configs = Config.Instance.GetAllValues<RealmConfig>();
|
var index = configs.FindIndex((x) =>
|
{
|
return x.BossID == _id;
|
});
|
if (index != -1)
|
{
|
var npcConfig = Config.Instance.Get<NPCConfig>(_id);
|
if (npcConfig != null)
|
{
|
var runtimeController = AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerSuffix, npcConfig.MODE);
|
if (runtimeController != null)
|
{
|
animator.runtimeAnimatorController = runtimeController;
|
}
|
}
|
}
|
}
|
|
public static GameObject LoadUIHorse(int id)
|
{
|
var prefab = InstanceResourcesLoader.LoadModelRes(id, true);
|
if (prefab == null)
|
{
|
return null;
|
}
|
|
var pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
var model = pool.Request();
|
|
var animator = model.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.enabled = true;
|
animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Idle);
|
animator.Play(GAStaticDefine.State_IdleHash);
|
}
|
|
return model;
|
}
|
|
public static void ReleaseUIHourse(int id, GameObject model)
|
{
|
var prefab = InstanceResourcesLoader.LoadModelRes(id, true);
|
var pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
|
var animator = model.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.enabled = false;
|
}
|
|
pool.Release(model);
|
}
|
|
static Dictionary<int, GameObject> treasureModels = new Dictionary<int, GameObject>();
|
static Dictionary<int, DateTime> treasureModelReleaseTimes = new Dictionary<int, DateTime>();
|
|
public static GameObject LoadUITreasure(int _id)
|
{
|
GameObject instance = null;
|
if (treasureModels.ContainsKey(_id))
|
{
|
instance = treasureModels[_id];
|
if (instance == null)
|
{
|
treasureModels.Remove(_id);
|
}
|
}
|
|
if (instance == null)
|
{
|
var config = Config.Instance.Get<TreasureConfig>(_id);
|
var prefab = UILoader.LoadPrefab(config.Model);
|
instance = GameObject.Instantiate(prefab);
|
treasureModels[_id] = instance;
|
|
UILoader.UnLoadPrefab(config.Model);
|
}
|
|
var animator = instance.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.enabled = true;
|
}
|
|
LayerUtility.SetLayer(instance, LayerUtility.UILayer, true);
|
if (treasureModelReleaseTimes.ContainsKey(_id))
|
{
|
treasureModelReleaseTimes.Remove(_id);
|
}
|
return instance;
|
}
|
|
public static void ReleaseUITreasure(int _id, GameObject _model)
|
{
|
treasureModelReleaseTimes[_id] = DateTime.Now;
|
var animator = _model.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.enabled = false;
|
}
|
|
_model.SetActive(false);
|
}
|
|
private static void OnPerMinute()
|
{
|
var keys = new List<int>(treasureModelReleaseTimes.Keys);
|
for (int i = 0; i < keys.Count; i++)
|
{
|
var key = keys[i];
|
var releaseTime = treasureModelReleaseTimes[key];
|
if ((DateTime.Now - releaseTime).TotalSeconds > Constants.UnUsedRes_Unload_Delay)
|
{
|
if (treasureModels.ContainsKey(key))
|
{
|
var model = treasureModels[key];
|
treasureModels.Remove(key);
|
if (model != null)
|
{
|
GameObject.Destroy(model);
|
}
|
}
|
}
|
}
|
}
|
|
public static GameObject LoadUIGodWeapon(int _type)
|
{
|
var prefab = UILoader.LoadPrefab(GeneralConfig.Instance.godWeaponMobs[_type]);
|
var pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
var model = pool.Request();
|
|
var animator = model.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.enabled = true;
|
}
|
|
LayerUtility.SetLayer(model, LayerUtility.UILayer, true);
|
return model;
|
}
|
|
public static void ReleaseUIGodWeapon(int _type, GameObject _model)
|
{
|
if (!GameObjectPoolManager.IsValid())
|
{
|
return;
|
}
|
if (!GeneralConfig.Instance.godWeaponMobs.ContainsKey(_type))
|
{
|
return;
|
}
|
var prefab = UILoader.LoadPrefab(GeneralConfig.Instance.godWeaponMobs[_type]);
|
var pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
|
var animator = _model.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.enabled = false;
|
}
|
|
pool.Release(_model);
|
}
|
|
|
public static GameObject LoadUIWing(int _id)
|
{
|
var prefab = InstanceResourcesLoader.LoadModelRes(_id, true);
|
if (prefab == null)
|
{
|
return null;
|
}
|
|
var pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
var model = pool.Request();
|
var animator = model.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.enabled = true;
|
}
|
return model;
|
}
|
|
public static void ReleaseUIWing(int _id, GameObject _model)
|
{
|
var prefab = InstanceResourcesLoader.LoadModelRes(_id, true);
|
var pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
var animator = _model.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.enabled = false;
|
}
|
|
pool.Release(_model);
|
}
|
}
|