//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, September 22, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
using LitJson;
|
|
namespace Snxxz.UI
|
{
|
|
public class UI3DShowHero
|
{
|
int weaponId;
|
int clothesId;
|
int wingsId;
|
int secondaryId;
|
int extraSecondaryId;
|
int job;
|
|
GameObject weaponModel;
|
GameObject clothesModel;
|
GameObject wingsModel;
|
GameObject secondaryModel;
|
GameObject extraSecondaryModel;
|
|
Animator wingsAnimator;
|
Animator clothesAnimator;
|
RuntimeAnimatorController cacheClothedAC;
|
|
Transform showPoint;
|
List<SFXController> godWeaponSFXList = new List<SFXController>();
|
|
public GameObject Show(UI3DPlayerExhibitionData data, Transform showPoint)
|
{
|
this.showPoint = showPoint;
|
this.job = data.job;
|
|
var clothes = data.fashionClothesId > 0 ? data.fashionClothesId : data.clothesId;
|
var suitID = data.suitLevel;
|
var weaponId = data.fashionWeaponId > 0 ? data.fashionWeaponId : data.weaponId;
|
var wingsId = data.wingsId;
|
var secondaryId = data.fashionSecondaryId > 0 ? data.fashionSecondaryId : data.secondaryId;
|
|
var jobConfig = JobSetupConfig.Get(job);
|
|
var clothesResId = 0;
|
if (clothes == 0)
|
{
|
clothesResId = jobConfig.BaseEquip[0];
|
}
|
else
|
{
|
var item = ItemConfig.Get(clothes);
|
clothesResId = item == null ? clothesResId = jobConfig.BaseEquip[0] : item.ChangeOrd;
|
}
|
PutOnClothes(job, clothesResId, suitID);
|
|
var weaponResId = 0;
|
if (weaponId == 0)
|
{
|
weaponResId = jobConfig.BaseEquip[1];
|
}
|
else
|
{
|
var item = ItemConfig.Get(weaponId);
|
weaponResId = item == null ? weaponResId = jobConfig.BaseEquip[1] : item.ChangeOrd;
|
}
|
PutOnWeapon(job, weaponResId);
|
|
var secondaryResId = 0;
|
if (secondaryId == 0)
|
{
|
if (data.fashionClothesId == 0)
|
{
|
if (this.job == 1)
|
{
|
secondaryResId = ModelResConfig.GetHandByClothesID(clothesId);
|
}
|
else if (this.job == 2)
|
{
|
secondaryResId = jobConfig.BaseEquip[2];
|
}
|
}
|
}
|
else
|
{
|
var item = ItemConfig.Get(secondaryId);
|
if (item != null)
|
{
|
secondaryResId = item.ChangeOrd;
|
}
|
}
|
|
if (secondaryResId != 0)
|
{
|
PutOnSecondary(job, secondaryResId);
|
}
|
|
var extraSecondaryId = 0;
|
if (data.job == 1)
|
{
|
extraSecondaryId = ModelResConfig.GetHandByClothesID(0);
|
if (data.fashionClothesId > 0)
|
{
|
var _item = ItemConfig.Get(data.fashionClothesId);
|
if (_item != null)
|
{
|
extraSecondaryId = ModelResConfig.GetHandByClothesID(_item.ChangeOrd);
|
}
|
}
|
else if (data.clothesId > 0)
|
{
|
var _item = ItemConfig.Get(data.clothesId);
|
if (_item != null)
|
{
|
extraSecondaryId = ModelResConfig.GetHandByClothesID(_item.ChangeOrd);
|
}
|
}
|
|
if (secondaryResId == 0
|
|| (data.fashionClothesId != 0 && data.fashionSecondaryId > 0)
|
|| (data.fashionClothesId == 0 && data.fashionSecondaryId > 0))
|
{
|
PutOnExtraSecondary(job, extraSecondaryId);
|
}
|
}
|
|
var wingsResId = 0;
|
if (wingsId != 0)
|
{
|
var item = ItemConfig.Get(wingsId);
|
wingsResId = item == null ? 0 : item.ChangeOrd;
|
}
|
|
PutOnWing(wingsResId);
|
LoadClothesEffect();
|
return clothesModel;
|
}
|
|
public GameObject Show(GameObject clothesModel, int job, int weaponResId, int wingsResId, int secondaryResId, Transform showPoint)
|
{
|
this.showPoint = showPoint;
|
this.job = job;
|
this.clothesModel = clothesModel;
|
SwitchMaterial(false);
|
PutOnWeapon(job, weaponResId);
|
PutOnSecondary(job, secondaryResId);
|
PutOnWing(wingsResId);
|
LoadClothesEffect();
|
return clothesModel;
|
}
|
|
public void Dispose()
|
{
|
GameObject prefab = null;
|
GameObjectPoolManager.GameObjectPool pool = null;
|
|
HideWeaponEffect();
|
HideSecondaryEffect();
|
|
if (weaponId != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(weaponId);
|
if (prefab)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(weaponModel);
|
}
|
weaponModel = null;
|
}
|
|
if (secondaryId != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(secondaryId);
|
if (prefab)
|
{
|
if (secondaryModel)
|
{
|
secondaryModel.SetActive(true);
|
}
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(secondaryModel);
|
}
|
secondaryModel = null;
|
}
|
|
if (extraSecondaryId != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(extraSecondaryId);
|
if (prefab)
|
{
|
if (extraSecondaryModel)
|
{
|
extraSecondaryModel.SetActive(true);
|
}
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(extraSecondaryModel);
|
}
|
extraSecondaryModel = null;
|
}
|
|
if (wingsId != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(wingsId);
|
if (prefab)
|
{
|
wingsModel.transform.localScale = Vector3.one;
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(wingsModel);
|
}
|
wingsModel = null;
|
wingsAnimator = null;
|
}
|
|
if (clothesId != 0)
|
{
|
if (clothesModel)
|
{
|
var smRenderer = clothesModel.GetComponentInChildren<SkinnedMeshRenderer>();
|
if (smRenderer != null)
|
{
|
MaterialLoader.Release(smRenderer.material);
|
smRenderer.material = smRenderer.sharedMaterial = null;
|
smRenderer.materials = smRenderer.sharedMaterials = new Material[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.enabled = false;
|
clothesAnimator = null;
|
}
|
}
|
|
clothesModel = null;
|
clothesId = 0;
|
weaponId = 0;
|
wingsId = 0;
|
secondaryId = 0;
|
extraSecondaryId = 0;
|
}
|
|
public void StandUp()
|
{
|
if (clothesModel != null)
|
{
|
var animator = clothesModel.GetComponent<Animator>();
|
if (animator)
|
{
|
animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Idle);
|
}
|
}
|
}
|
|
public void SitDown()
|
{
|
if (clothesModel != null)
|
{
|
var animator = clothesModel.GetComponent<Animator>();
|
if (animator)
|
{
|
animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Dazuo);
|
}
|
}
|
|
if (weaponModel)
|
{
|
GameObject prefab = InstanceResourcesLoader.LoadModelRes(weaponId, true);
|
if (prefab)
|
{
|
GameObjectPoolManager.Instance.ReleaseGameObject(prefab, weaponModel);
|
}
|
weaponModel = null;
|
}
|
|
if (job == 2)
|
{
|
if (secondaryModel)
|
{
|
secondaryModel.SetActive(false);
|
}
|
}
|
}
|
|
private void PutOnClothes(int _job, int clothesResId, int suitLevel)
|
{
|
var config = JobSetupConfig.Get(_job);
|
if (clothesId == clothesResId)
|
{
|
return;
|
}
|
|
if (clothesId != 0)
|
{
|
UnloadClothes();
|
}
|
|
var _prefab = InstanceResourcesLoader.LoadModelRes(clothesResId, true);
|
if (!_prefab)
|
{
|
clothesResId = config.BaseEquip[0];
|
}
|
|
LoadClothes(clothesResId);
|
clothesId = clothesResId;
|
|
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);
|
}
|
}
|
}
|
|
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 smRenderer = clothesModel.GetComponentInChildren<SkinnedMeshRenderer>();
|
if (smRenderer != null)
|
{
|
MaterialLoader.Release(smRenderer.material);
|
smRenderer.material = smRenderer.sharedMaterial = null;
|
smRenderer.materials = smRenderer.sharedMaterials = new Material[0];
|
}
|
|
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;
|
}
|
}
|
|
private void PutOnWeapon(int _job, int resoureceId)
|
{
|
var config = JobSetupConfig.Get(_job);
|
|
var oldWeapon = weaponId;
|
if (oldWeapon == resoureceId)
|
{
|
return;
|
}
|
|
GameObject prefab = null;
|
GameObjectPoolManager.GameObjectPool pool = null;
|
|
if (oldWeapon != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(oldWeapon);
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(weaponModel);
|
weaponModel = null;
|
}
|
|
prefab = InstanceResourcesLoader.LoadModelRes(resoureceId);
|
|
if (!prefab)
|
{
|
resoureceId = config.BaseEquip[1];
|
prefab = InstanceResourcesLoader.LoadModelRes(resoureceId);
|
}
|
|
if (prefab)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
weaponModel = pool.Request();
|
|
LayerUtility.SetLayer(weaponModel, LayerUtility.Player, false);
|
if (clothesModel)
|
{
|
var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.WeaponBindBoneName);
|
weaponModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
|
var _resConfig = ModelResConfig.Get(resoureceId);
|
ShowSecondaryEffect(weaponModel.transform, _resConfig.ResourcesName);
|
}
|
|
weaponId = resoureceId;
|
}
|
|
private void PutOnExtraSecondary(int job, int extraSecondaryId)
|
{
|
var oldSecondary = this.extraSecondaryId;
|
if (oldSecondary == extraSecondaryId)
|
{
|
return;
|
}
|
|
GameObject prefab = null;
|
GameObjectPoolManager.GameObjectPool pool = null;
|
|
if (oldSecondary != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(oldSecondary);
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(extraSecondaryModel);
|
extraSecondaryModel = null;
|
}
|
|
if (extraSecondaryId != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(extraSecondaryId);
|
if (!prefab)
|
{
|
var config = JobSetupConfig.Get(job);
|
extraSecondaryId = config.BaseEquip[2];
|
prefab = InstanceResourcesLoader.LoadModelRes(extraSecondaryId);
|
}
|
|
if (prefab)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
extraSecondaryModel = pool.Request();
|
|
var parent = this.clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.SecondaryBindBoneName[this.job - 1]);
|
extraSecondaryModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
}
|
|
this.extraSecondaryId = extraSecondaryId;
|
}
|
|
private void PutOnSecondary(int _job, int secondaryResId)
|
{
|
var oldSecondary = secondaryId;
|
if (oldSecondary == secondaryResId)
|
{
|
return;
|
}
|
|
GameObject prefab = null;
|
GameObjectPoolManager.GameObjectPool pool = null;
|
|
if (oldSecondary != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(oldSecondary);
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(secondaryModel);
|
secondaryModel = null;
|
}
|
|
if (secondaryResId != 0)
|
{
|
var _resConfig = ModelResConfig.Get(secondaryResId);
|
prefab = InstanceResourcesLoader.LoadModelRes(secondaryResId);
|
if (!prefab)
|
{
|
var config = JobSetupConfig.Get(_job);
|
secondaryResId = config.BaseEquip[2];
|
prefab = InstanceResourcesLoader.LoadModelRes(secondaryResId);
|
}
|
|
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);
|
}
|
|
ShowSecondaryEffect(secondaryModel.transform, _resConfig.ResourcesName);
|
}
|
|
secondaryId = secondaryResId;
|
}
|
|
private void PutOnWing(int resourceId)
|
{
|
var config = JobSetupConfig.Get(job);
|
var oldWings = wingsId;
|
if (resourceId == oldWings)
|
{
|
return;
|
}
|
|
GameObject prefab = null;
|
GameObjectPoolManager.GameObjectPool pool = null;
|
|
if (oldWings != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(oldWings);
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pool.Release(wingsModel);
|
wingsModel = null;
|
}
|
|
if (resourceId != 0)
|
{
|
prefab = InstanceResourcesLoader.LoadModelRes(resourceId);
|
|
if (!prefab)
|
{
|
resourceId = config.BaseEquip[3];
|
prefab = InstanceResourcesLoader.LoadModelRes(resourceId);
|
}
|
|
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);
|
var modelResConfig = ModelResConfig.Get(resourceId);
|
wingsModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, modelResConfig.UIScale);
|
|
wingsAnimator = wingsModel.GetComponent<Animator>();
|
if (wingsAnimator == null)
|
{
|
DebugEx.LogErrorFormat("翅膀资源{0}没有动画控制器", resourceId);
|
}
|
wingsAnimator.enabled = true;
|
wingsAnimator.Play("UI_Idle", 0);
|
}
|
}
|
|
wingsId = resourceId;
|
}
|
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
private void LoadClothesEffect()
|
{
|
var _equipModel = packModel.GetSinglePack(PackType.Equip);
|
if (_equipModel == null)
|
{
|
SwitchMaterial(false);
|
return;
|
}
|
|
int _suitCount = 0;
|
|
int _start = (int)RoleEquipType.Hat;
|
int _end = (int)RoleEquipType.Shoes;
|
|
ItemModel _itemModel = null;
|
|
_itemModel = _equipModel.GetItemByIndex((int)RoleEquipType.Clothes);
|
|
if (_itemModel == null)
|
{
|
SwitchMaterial(false);
|
return;
|
}
|
|
int _rank = _itemModel.config.LV;
|
|
for (int i = _start; i <= _end; ++i)
|
{
|
_itemModel = _equipModel.GetItemByIndex(i);
|
|
if (_itemModel == null)
|
{
|
continue;
|
}
|
|
if (_itemModel.config.SuiteiD <= 0)
|
{
|
continue;
|
}
|
|
if (i == (int)RoleEquipType.Clothes)
|
{
|
_rank = _itemModel.config.LV;
|
}
|
}
|
|
SwitchMaterial(_suitCount >= 5);
|
}
|
|
private List<SFXController> m_WeaponEffectList = new List<SFXController>();
|
private List<SFXController> m_SecondaryEffectList = new List<SFXController>();
|
|
private void ShowWeaponEffect(Transform parent, string modelName)
|
{
|
HideWeaponEffect();
|
|
var _boneList = ModelResConfig.GetBoneList(modelName);
|
var _effectlist = ModelResConfig.GetEffectList(modelName);
|
|
if (_boneList != null && _effectlist != null)
|
{
|
for (int i = 0; i < _boneList.Count; ++i)
|
{
|
if (_boneList[i].Equals("null"))
|
{
|
var _ctrl = SFXPlayUtility.Instance.PlayBattleEffect(_effectlist[i], parent);
|
m_WeaponEffectList.Add(_ctrl);
|
}
|
else
|
{
|
|
var _ctrl = SFXPlayUtility.Instance.PlayBattleEffect(_effectlist[i], parent.GetChildTransformDeeply(_boneList[i]));
|
m_WeaponEffectList.Add(_ctrl);
|
}
|
}
|
}
|
}
|
|
private void ShowSecondaryEffect(Transform parent, string modelName)
|
{
|
HideWeaponEffect();
|
|
var _boneList = ModelResConfig.GetBoneList(modelName);
|
var _effectlist = ModelResConfig.GetEffectList(modelName);
|
|
if (_boneList != null && _effectlist != null)
|
{
|
for (int i = 0; i < _boneList.Count; ++i)
|
{
|
if (_boneList[i].Equals("null"))
|
{
|
var _ctrl = SFXPlayUtility.Instance.PlayBattleEffect(_effectlist[i], parent);
|
m_SecondaryEffectList.Add(_ctrl);
|
}
|
else
|
{
|
|
var _ctrl = SFXPlayUtility.Instance.PlayBattleEffect(_effectlist[i], parent.GetChildTransformDeeply(_boneList[i]));
|
m_SecondaryEffectList.Add(_ctrl);
|
}
|
}
|
}
|
}
|
|
private void HideSecondaryEffect()
|
{
|
foreach (var _ctrl in m_SecondaryEffectList)
|
{
|
SFXPlayUtility.Instance.Release(_ctrl);
|
}
|
m_SecondaryEffectList.Clear();
|
}
|
|
private void HideWeaponEffect()
|
{
|
foreach (var _ctrl in m_WeaponEffectList)
|
{
|
SFXPlayUtility.Instance.Release(_ctrl);
|
}
|
m_WeaponEffectList.Clear();
|
}
|
|
public void SwitchMaterial(bool isSuit)
|
{
|
if (clothesModel == null)
|
{
|
return;
|
}
|
|
var smRenderer = clothesModel.GetComponentInChildren<SkinnedMeshRenderer>();
|
if (smRenderer == null)
|
{
|
return;
|
}
|
|
MaterialLoader.Release(smRenderer.material);
|
|
var newMat = MaterialLoader.LoadClothesMaterial(this.clothesId, true, isSuit);
|
if (newMat != null)
|
{
|
smRenderer.material = newMat;
|
}
|
}
|
|
}
|
|
}
|
|
|
|