//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, September 22, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using TableConfig;
|
using System.Collections.Generic;
|
|
namespace Snxxz.UI
|
{
|
|
public class UI3DShowHero
|
{
|
int weaponId;
|
int clothesId;
|
int wingsId;
|
int secondaryId;
|
int job;
|
|
GameObject weaponModel;
|
GameObject clothesModel;
|
GameObject wingsModel;
|
GameObject secondaryModel;
|
Animator wingsAnimator;
|
Animator clothesAnimator;
|
RuntimeAnimatorController cacheClothedAC;
|
|
Transform showPoint;
|
|
List<SFXController> closthesSFXList = new List<SFXController>();
|
|
public GameObject Show(int _job, int _clothes, int suitID, int _weaponId, int _wingsId, int _secondaryId, Transform _showPoint)
|
{
|
showPoint = _showPoint;
|
job = _job;
|
PutOnClothes(_job, _clothes, suitID);
|
PutOnWeapon(_job, _weaponId);
|
PutOnSecondary(_job, _secondaryId);
|
PutOnWing(_wingsId);
|
|
return clothesModel;
|
}
|
|
public void Dispose()
|
{
|
GameObject prefab = null;
|
GameObjectPoolManager.GameObjectPool pool = null;
|
|
if (weaponId != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(weaponId, true);
|
if (prefab)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(weaponModel);
|
}
|
weaponModel = null;
|
}
|
|
if (secondaryId != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(secondaryId, true);
|
if (prefab)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(secondaryModel);
|
}
|
secondaryModel = null;
|
}
|
|
if (wingsId != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(wingsId, true);
|
if (prefab)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(wingsModel);
|
}
|
wingsModel = null;
|
wingsAnimator = null;
|
}
|
|
if (clothesId != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(clothesId, true);
|
if (prefab)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(clothesModel);
|
}
|
clothesModel = null;
|
if (clothesAnimator)
|
{
|
if (cacheClothedAC)
|
{
|
clothesAnimator.runtimeAnimatorController = cacheClothedAC;
|
cacheClothedAC = null;
|
}
|
clothesAnimator = null;
|
}
|
}
|
|
clothesId = 0;
|
weaponId = 0;
|
wingsId = 0;
|
secondaryId = 0;
|
|
UnloadClothedEffect();
|
}
|
|
public void StandUp()
|
{
|
if (clothesModel != null)
|
{
|
var animator = clothesModel.GetComponent<Animator>();
|
if (animator)
|
{
|
animator.Play(GAStaticDefine.State_IdleHash);
|
}
|
}
|
}
|
|
public void SitDown()
|
{
|
if (clothesModel != null)
|
{
|
var animator = clothesModel.GetComponent<Animator>();
|
if (animator)
|
{
|
animator.Play(GAStaticDefine.State_SitDown);
|
}
|
}
|
|
if (weaponModel)
|
{
|
GameObject prefab = InstanceResourcesLoader.LoadModelRes(weaponId, true);
|
if (prefab)
|
{
|
GameObjectPoolManager.Instance.ReleaseGameObject(prefab, weaponModel);
|
}
|
weaponModel = null;
|
}
|
|
if (secondaryModel)
|
{
|
secondaryModel.SetActive(false);
|
}
|
}
|
|
public void PutOnClothes(int _job, int itemID, int suitID)
|
{
|
var newClothes = 0;
|
var config = Config.Instance.Get<JobSetupConfig>(_job);
|
|
if (itemID == 0)
|
{
|
newClothes = config.BaseEquip[0];
|
}
|
else
|
{
|
var item = Config.Instance.Get<ItemConfig>(itemID);
|
newClothes = item == null ? newClothes = config.BaseEquip[0] : item.ChangeOrd;
|
}
|
|
var oldClothes = clothesId;
|
if (oldClothes == newClothes)
|
{
|
return;
|
}
|
|
if (oldClothes != 0)
|
{
|
UnloadClothes();
|
}
|
|
var _prefab = InstanceResourcesLoader.LoadModelRes(newClothes, true);
|
if (!_prefab)
|
{
|
newClothes = config.BaseEquip[0];
|
}
|
|
LoadClothes(newClothes);
|
clothesId = newClothes;
|
|
if (clothesModel)
|
{
|
if (weaponModel)
|
{
|
var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.WeaponBindBoneName);
|
weaponModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
|
if (wingsModel)
|
{
|
var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.WingBindBoneName);
|
wingsModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
|
if (secondaryModel)
|
{
|
var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.SecondaryBindBoneName[job - 1]);
|
wingsModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
|
LoadClothesEffect(itemID, suitID);
|
}
|
}
|
|
private void LoadClothes(int resID)
|
{
|
var prefab = InstanceResourcesLoader.LoadModelRes(resID, true);
|
if (prefab)
|
{
|
var pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
clothesModel = pool.Request();
|
|
LayerUtility.SetLayer(clothesModel, LayerUtility.Player, false);
|
var skinnedMeshRenderer = clothesModel.GetComponentInChildren<SkinnedMeshRenderer>(true);
|
LayerUtility.SetLayer(skinnedMeshRenderer.gameObject, LayerUtility.Player, false);
|
clothesModel.SetActive(true);
|
clothesModel.transform.SetParentEx(showPoint, Vector3.zero, Quaternion.identity, Vector3.one);
|
clothesAnimator = clothesModel.GetComponent<Animator>();
|
|
// 动画状态机修改
|
if (clothesAnimator)
|
{
|
cacheClothedAC = clothesAnimator.runtimeAnimatorController;
|
RuntimeAnimatorController _controller = AnimatorControllerLoader.Load(AnimatorControllerLoader.controllerUISuffix, resID);
|
clothesAnimator.runtimeAnimatorController = _controller;
|
clothesAnimator.enabled = true;
|
}
|
else
|
{
|
DebugEx.LogErrorFormat("角色资源: {0} 没有动画控制器", resID);
|
}
|
}
|
}
|
|
private void UnloadClothes()
|
{
|
if (clothesModel == null)
|
{
|
return;
|
}
|
|
var prefab = InstanceResourcesLoader.LoadModelRes(clothesId, true);
|
var pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(clothesModel);
|
clothesModel = null;
|
if (clothesAnimator != null)
|
{
|
if (cacheClothedAC)
|
{
|
clothesAnimator.runtimeAnimatorController = cacheClothedAC;
|
cacheClothedAC = null;
|
}
|
clothesAnimator.enabled = false;
|
clothesAnimator = null;
|
}
|
}
|
|
public void PutOnWeapon(int _job, int itemID)
|
{
|
var newWeapon = 0;
|
var config = Config.Instance.Get<JobSetupConfig>(_job);
|
|
if (itemID == 0)
|
{
|
newWeapon = config.BaseEquip[1];
|
}
|
else
|
{
|
var item = Config.Instance.Get<ItemConfig>(itemID);
|
newWeapon = item == null ? config.BaseEquip[1] : item.ChangeOrd;
|
}
|
|
var oldWeapon = weaponId;
|
if (oldWeapon == newWeapon)
|
{
|
return;
|
}
|
|
GameObject prefab = null;
|
GameObjectPoolManager.GameObjectPool pool = null;
|
|
if (oldWeapon != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(oldWeapon, true);
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(weaponModel);
|
weaponModel = null;
|
}
|
|
prefab = InstanceResourcesLoader.LoadModelRes(newWeapon, true);
|
|
if (!prefab)
|
{
|
newWeapon = config.BaseEquip[1];
|
prefab = InstanceResourcesLoader.LoadModelRes(newWeapon, true);
|
}
|
|
if (prefab)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
weaponModel = pool.Request();
|
|
LayerUtility.SetLayer(weaponModel, LayerUtility.Player, false);
|
var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.WeaponBindBoneName);
|
weaponModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
|
weaponId = newWeapon;
|
}
|
|
public void PutOnSecondary(int _job, int itemID)
|
{
|
var newSecondary = 0;
|
var config = Config.Instance.Get<JobSetupConfig>(_job);
|
|
if (itemID == 0)
|
{
|
newSecondary = config.BaseEquip[2];
|
}
|
else
|
{
|
var item = Config.Instance.Get<ItemConfig>(itemID);
|
newSecondary = item == null ? config.BaseEquip[2] : item.ChangeOrd;
|
}
|
|
var oldSecondary = secondaryId;
|
if (oldSecondary == newSecondary)
|
{
|
return;
|
}
|
|
GameObject prefab = null;
|
GameObjectPoolManager.GameObjectPool pool = null;
|
|
if (oldSecondary != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(oldSecondary, true);
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(secondaryModel);
|
secondaryModel = null;
|
}
|
|
if (newSecondary != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(newSecondary, true);
|
if (!prefab)
|
{
|
newSecondary = config.BaseEquip[2];
|
prefab = InstanceResourcesLoader.LoadModelRes(newSecondary, true);
|
}
|
|
if (prefab)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
secondaryModel = pool.Request();
|
|
var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.SecondaryBindBoneName[job - 1]);
|
secondaryModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
}
|
|
secondaryId = newSecondary;
|
}
|
|
public void PutOnWing(int itemID)
|
{
|
var newWings = 0;
|
if (itemID != 0)
|
{
|
var item = Config.Instance.Get<ItemConfig>(itemID);
|
newWings = item == null ? 0 : item.ChangeOrd;
|
}
|
|
var config = Config.Instance.Get<JobSetupConfig>(job);
|
|
var oldWings = wingsId;
|
if (newWings == oldWings)
|
{
|
return;
|
}
|
|
GameObject prefab = null;
|
GameObjectPoolManager.GameObjectPool pool = null;
|
|
if (oldWings != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(oldWings, true);
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(wingsModel);
|
wingsModel = null;
|
}
|
|
if (newWings != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(newWings, true);
|
|
if (!prefab)
|
{
|
newWings = config.BaseEquip[3];
|
prefab = InstanceResourcesLoader.LoadModelRes(newWings, true);
|
}
|
|
if (prefab)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
wingsModel = pool.Request();
|
|
wingsModel.layer = LayerUtility.Player;
|
SkinnedMeshRenderer _renderer = wingsModel.GetComponentInChildren<SkinnedMeshRenderer>();
|
if (_renderer)
|
{
|
_renderer.gameObject.layer = LayerUtility.Player;
|
}
|
|
var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.WingBindBoneName);
|
wingsModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
|
|
wingsAnimator = wingsModel.GetComponent<Animator>();
|
if (wingsAnimator == null)
|
{
|
DebugEx.LogErrorFormat("翅膀资源{0}没有动画控制器", itemID);
|
}
|
wingsAnimator.enabled = true;
|
wingsAnimator.Play("UI_Idle", 0);
|
}
|
}
|
|
wingsId = newWings;
|
}
|
|
private PlayerSuitModel _suitModel;
|
private PlayerSuitModel SuitModel
|
{
|
get { return _suitModel ?? (_suitModel = ModelCenter.Instance.GetModel<PlayerSuitModel>()); }
|
}
|
|
private PlayerPackModel m_PlayerBackModel;
|
private PlayerPackModel PlayerBackModel
|
{
|
get
|
{
|
return m_PlayerBackModel ?? (m_PlayerBackModel = ModelCenter.Instance.GetModel<PlayerPackModel>());
|
}
|
}
|
|
|
public void LoadClothesEffect(int clothedID, int suitLevel)
|
{
|
UnloadClothedEffect();
|
|
var _equipModel = PlayerBackModel.GetSinglePackModel(PackType.rptEquip);
|
if (_equipModel == null)
|
{
|
if (DTC0309_tagPlayerLoginInfo.equipSuitID > 0)
|
{
|
PutOnEffect(DTC0309_tagPlayerLoginInfo.equipSuitID);
|
}
|
return;
|
}
|
|
int _suitCount = 0;
|
|
int _start = (int)RoleEquipType.retHat;
|
int _end = (int)RoleEquipType.retShoes;
|
|
ItemModel _itemModel = null;
|
|
_itemModel = _equipModel.GetItemModelByIndex((int)RoleEquipType.retClothes);
|
|
if (_itemModel == null)
|
{
|
return;
|
}
|
|
int _rank = _itemModel.chinItemModel.LV;
|
|
for (int i = _start; i <= _end; ++i)
|
{
|
_itemModel = _equipModel.GetItemModelByIndex(i);
|
|
if (_itemModel == null)
|
{
|
continue;
|
}
|
|
if (_itemModel.chinItemModel.SuiteiD <= 0)
|
{
|
continue;
|
}
|
|
if (i == (int)RoleEquipType.retClothes)
|
{
|
_rank = _itemModel.chinItemModel.LV;
|
}
|
|
if (SuitModel.suitModelDict.ContainsKey(i))
|
{
|
if (SuitModel.suitModelDict[i].ContainsKey(1)
|
|| SuitModel.suitModelDict[i].ContainsKey(2))
|
{
|
if (_itemModel.chinItemModel.LV >= _rank)
|
{
|
_suitCount += 1;
|
}
|
}
|
}
|
}
|
|
if (_suitCount == 5)
|
{
|
int _type = 1;
|
|
int _suitEffectID = _type * 1000 + job * 100 + _rank;
|
|
PutOnEffect(_suitEffectID);
|
}
|
}
|
|
public void PutOnEffect(int id)
|
{
|
SuitEffectConfig _suitEffect = Config.Instance.Get<SuitEffectConfig>(id);
|
|
// 上特效
|
if (_suitEffect != null)
|
{
|
Transform _parent = null;
|
SFXController _sfx = null;
|
for (int i = 0; _suitEffect.bindbones != null && i < _suitEffect.bindbones.Length; ++i)
|
{
|
if (string.IsNullOrEmpty(_suitEffect.bindbones[i])
|
|| _suitEffect.effectIds[i] == 0)
|
{
|
continue;
|
}
|
|
_parent = clothesModel.transform.GetChildTransformDeeply(_suitEffect.bindbones[i]);
|
|
if (_parent == null)
|
{
|
Debug.LogErrorFormat("套装: {0} 配置的骨骼节点: {1} 不存在", id, _suitEffect.bindbones[i]);
|
continue;
|
}
|
|
_sfx = SFXPlayUtility.Instance.PlayBattleEffect(_suitEffect.effectIds[i], _parent);
|
closthesSFXList.Add(_sfx);
|
}
|
}
|
}
|
|
public void UnloadClothedEffect()
|
{
|
for (int i = 0; i < closthesSFXList.Count; ++i)
|
{
|
SFXPlayUtility.Instance.Release(closthesSFXList[i]);
|
}
|
closthesSFXList.Clear();
|
}
|
}
|
|
}
|
|
|
|