350 lines
15 KiB
C#
350 lines
15 KiB
C#
using Cal.DataTable;
|
|
using ET.EventType;
|
|
using ET;
|
|
using FairyGUI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEditor.Graphs;
|
|
using UnityEngine;
|
|
|
|
namespace ET
|
|
{
|
|
public class CharacterUIAwakeSyatem: AwakeSystem<CharacterUI>
|
|
{
|
|
public override void Awake(CharacterUI self)
|
|
{
|
|
self.Awake();
|
|
}
|
|
}
|
|
|
|
public class CharacterUIDestroySyatem: DestroySystem<CharacterUI>
|
|
{
|
|
public override void Destroy(CharacterUI self)
|
|
{
|
|
self.Destroy();
|
|
}
|
|
}
|
|
|
|
public class CharacterUI: Entity
|
|
{
|
|
public enum SlotUIEffect: byte
|
|
{
|
|
None,
|
|
StarSoul = 1,
|
|
Strength_15 = 1 << 1,
|
|
StarSoul_10 = 1 << 2,
|
|
StarSoul_20 = 1 << 3
|
|
}
|
|
|
|
public static Dictionary<string, GTextField> AttributeDic { get; private set; }
|
|
public FUI_CharacterUI ui;
|
|
private NTexture nTexture;
|
|
private Camera rtCamera;
|
|
private Transform skinTran;
|
|
private RenderTexture rt;
|
|
private Scene zoneScene;
|
|
private bool isMine;
|
|
private long id;
|
|
|
|
public void Awake()
|
|
{
|
|
zoneScene = this.ZoneScene();
|
|
AwakeAsync().Coroutine();
|
|
}
|
|
|
|
private async ETVoid AwakeAsync()
|
|
{
|
|
ui = GetParent<FUI_CharacterUI>();
|
|
if (AttributeDic == null)
|
|
{
|
|
AttributeDic = new Dictionary<string, GTextField>();
|
|
foreach (var o in ui.m_infoList.GetChildrenList())
|
|
{
|
|
var item = (GLabel) o;
|
|
AttributeDic.Add(item.name, item.GetChild("txt").asTextField);
|
|
}
|
|
|
|
foreach (var o in ui.m_basicAttributeList.GetChildrenList())
|
|
{
|
|
var item = (GLabel) o;
|
|
AttributeDic.Add(item.name, item.GetChild("txt").asTextField);
|
|
}
|
|
|
|
foreach (var o in ui.m_battleAttributeList.GetChildrenList())
|
|
{
|
|
var item = (GLabel) o;
|
|
AttributeDic.Add(item.name, item.GetChild("txt").asTextField);
|
|
}
|
|
}
|
|
|
|
//!临时变量
|
|
isMine = zoneScene.GetComponent<GlobalVariable>().IsMineCharacter;
|
|
|
|
//!+获取数据并更新人物信息
|
|
id = isMine? zoneScene.GetComponent<GlobalVariable>().MyId : zoneScene.GetComponent<GlobalVariable>().SelectUnitId;
|
|
M2C_GetCharacter m2cGetCharacter =
|
|
await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetCharacter>(new C2M_GetCharacter() { Id = id });
|
|
if (!m2cGetCharacter.Message.IsNullOrEmpty())
|
|
{
|
|
TipHelper.OpenUI(m2cGetCharacter.Message);
|
|
return;
|
|
}
|
|
|
|
UnitCharacter unitCharacter = m2cGetCharacter.UnitCharacter;
|
|
ClientUnitCharacterComponent.Instance.Update(unitCharacter);
|
|
ShowNumText(this.zoneScene, id);
|
|
//!显示形象
|
|
ShowSkin(unitCharacter.SkinId).Coroutine();
|
|
//!更新装备栏
|
|
Game.EventSystem.Publish(new ET.EventType.UpdateWornEquipUI { list = m2cGetCharacter.WornBagMapList }).Coroutine();
|
|
//!+添加按钮事件
|
|
RegisterEvent();
|
|
await ETTask.CompletedTask;
|
|
}
|
|
|
|
private void RegisterEvent()
|
|
{
|
|
//!武器等装备栏
|
|
int atkListCount = this.ui.m_atkEquipList.numChildren;
|
|
for (int i = 0; i < atkListCount; i++)
|
|
{
|
|
int index = i;
|
|
GButton btn = this.ui.m_atkEquipList.GetChildAt(i).asButton;
|
|
AddSlotBtnEvent(btn, index);
|
|
}
|
|
|
|
//!普通装备栏
|
|
for (int i = 0; i < this.ui.m_commonEquipList.numChildren; i++)
|
|
{
|
|
int index = i;
|
|
index += atkListCount;
|
|
GButton btn = this.ui.m_commonEquipList.GetChildAt(i).asButton;
|
|
AddSlotBtnEvent(btn, index);
|
|
}
|
|
|
|
//!加点按钮监听
|
|
{
|
|
this.ui.m_btnAddPoint.self.onClick.Clear();
|
|
if (isMine)
|
|
this.ui.m_btnAddPoint.self.onClick.Set(async () =>
|
|
{
|
|
int count = this.ui.m_addPointAttributeList.numChildren;
|
|
C2M_AddPoint c2M_AddPoint = new C2M_AddPoint();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
GLabel label = this.ui.m_addPointAttributeList.GetChildAt(i).asLabel;
|
|
FUI_LabelAddPoint item = FUI_LabelAddPoint.GetFormPool(this.ui, label);
|
|
if (!int.TryParse(item.m_iptPoint.text, out int pointCount))
|
|
{
|
|
pointCount = 0;
|
|
}
|
|
|
|
if (pointCount < 0)
|
|
pointCount = 0;
|
|
c2M_AddPoint.PointList.Add(pointCount);
|
|
item.m_iptPoint.text = "0";
|
|
}
|
|
|
|
M2C_AddPoint ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_AddPoint>(c2M_AddPoint);
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
{
|
|
TipHelper.OpenUI(ret.Message);
|
|
return;
|
|
}
|
|
|
|
ClientUnitCharacterComponent.Instance.Update(ret.Character);
|
|
ShowNumText(this.zoneScene, id);
|
|
});
|
|
|
|
this.ui.m_btnResetPoint.self.onClick.Clear();
|
|
if (isMine)
|
|
this.ui.m_btnResetPoint.self.onClick.Set(async () =>
|
|
{
|
|
M2C_ResetPoint ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_ResetPoint>(new C2M_ResetPoint());
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
{
|
|
TipHelper.OpenUI(ret.Message);
|
|
return;
|
|
}
|
|
|
|
ClientUnitCharacterComponent.Instance.Update(ret.Character);
|
|
ShowNumText(this.zoneScene, id);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void AddSlotBtnEvent(GButton btn, int index)
|
|
{
|
|
if (!ClientItemDataComponent.Instance.WornEquipDic.TryGetValue(index, out ClientItemData data))
|
|
{
|
|
Log.Error($"data =null where index = {index}");
|
|
return;
|
|
}
|
|
|
|
ShowEffect(btn, index, data);
|
|
if (this.isMine)
|
|
{
|
|
btn.onClick.Clear();
|
|
btn.onClick.Add1(async context =>
|
|
{
|
|
//!卸下装备
|
|
if (context.inputEvent.isDoubleClick)
|
|
{
|
|
if (this.zoneScene.GetComponent<UnitComponent>().MyUnit.IsFight)
|
|
{
|
|
TipHelper.OpenUI("战斗中,不能卸下装备!");
|
|
return;
|
|
}
|
|
|
|
M2C_Takeoff ret = await this.zoneScene.GetComponent<SessionComponent>()
|
|
.Call<M2C_Takeoff>(new C2M_Takeoff() { Index = index });
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
{
|
|
TipHelper.OpenUI(ret.Message);
|
|
return;
|
|
}
|
|
|
|
Game.EventSystem.Publish(new UpdateWornEquipUI { list = ret.WornBagMapList }).Coroutine();
|
|
Game.EventSystem.Publish_Sync(new UpdateBagUI { list = ret.BagMapList });
|
|
}
|
|
});
|
|
}
|
|
|
|
//!Roll事件
|
|
AddRollEvent(btn, data);
|
|
}
|
|
|
|
private void ShowEffect(GButton btn, int index, ClientItemData data)
|
|
{
|
|
SlotUIEffect effectIndex = SlotUIEffect.None;
|
|
if (data.ItemType != ItemType.EquipItem)
|
|
{
|
|
btn.GetController("effect").selectedIndex = (int) effectIndex;
|
|
return;
|
|
}
|
|
|
|
if (data.Equip.level >= 15)
|
|
effectIndex += (byte) SlotUIEffect.Strength_15;
|
|
|
|
Unit unit = zoneScene.GetComponent<UnitComponent>().Get(id);
|
|
StarSoulBag bag = unit.GetComponent<StarSoulBag>();
|
|
if (bag.usedStarSoulDic.TryGetValue((byte) index, out var starSoulId))
|
|
{
|
|
var starSoul = bag.Get(starSoulId);
|
|
if (starSoul is { quality: Quality.Ulti })
|
|
{
|
|
if (starSoul.level == 20)
|
|
effectIndex += (byte) SlotUIEffect.StarSoul_20;
|
|
else if (starSoul.level >= 10)
|
|
effectIndex += (byte) SlotUIEffect.StarSoul_10;
|
|
else
|
|
effectIndex += (byte) SlotUIEffect.StarSoul;
|
|
}
|
|
}
|
|
|
|
btn.GetController("effect").selectedIndex = (int) effectIndex;
|
|
}
|
|
|
|
private void AddRollEvent(GButton btn, ClientItemData data)
|
|
{
|
|
//!显示页签
|
|
TabHelper.SetTab(btn, () =>
|
|
{
|
|
var gv = zoneScene.GetComponent<GlobalVariable>();
|
|
long selectUnitId = gv.IsMineCharacter? 0 : gv.SelectUnitId;
|
|
TabHelper.OpenUI(zoneScene, data, false, selectUnitId);
|
|
});
|
|
}
|
|
|
|
public static void ShowNumText(Scene zoneScene, long id)
|
|
{
|
|
var _attributeDic = CharacterUI.AttributeDic;
|
|
if (_attributeDic == null) return;
|
|
ClientUnitCharacter unitCharacter = ClientUnitCharacterComponent.Instance.Get(id);
|
|
Unit unit = zoneScene.GetComponent<UnitComponent>().Get(id);
|
|
if (!unit)
|
|
{
|
|
TipHelper.OpenUI("找不到玩家");
|
|
return;
|
|
}
|
|
|
|
NumericComponent num = unit.GetComponent<NumericComponent>();
|
|
_attributeDic["昵称"].text = unitCharacter.NickName;
|
|
_attributeDic["性别"].text = unitCharacter.Sex;
|
|
_attributeDic["阵营"].text = unitCharacter.Camp;
|
|
_attributeDic["荣誉值"].text = num.Get(NumericType.Honor).FloatToIntString();
|
|
_attributeDic["职业"].text = unitCharacter.Job;
|
|
_attributeDic["家族"].text = unitCharacter.Family;
|
|
_attributeDic["等级"].text = CharacterHelper.GetLevelString(unit);
|
|
_attributeDic["经验"].text = num.Get(NumericType.Exp).FloatToIntString();
|
|
_attributeDic["竞技币"].text = num.Get(NumericType.PvpMoney).FloatToIntString();
|
|
_attributeDic["家族贡献"].text = 0f.FloatToIntString();
|
|
|
|
_attributeDic["力量"].text = num.Get(NumericType.Str).FloatToIntString();
|
|
_attributeDic["智慧"].text = num.Get(NumericType.Wim).FloatToIntString();
|
|
_attributeDic["体质"].text = num.Get(NumericType.Phy).FloatToIntString();
|
|
_attributeDic["耐力"].text = num.Get(NumericType.Sta).FloatToIntString();
|
|
_attributeDic["敏捷"].text = num.Get(NumericType.Quk).FloatToIntString();
|
|
_attributeDic["精神"].text = num.Get(NumericType.Spi).FloatToIntString();
|
|
|
|
_attributeDic["生命"].text = $"{num.Get(NumericType.Hp).FloatToIntString()}/{num.Get(NumericType.MaxHp).FloatToIntString()}";
|
|
_attributeDic["精力"].text = $"{num.Get(NumericType.Mp).FloatToIntString()}/{num.Get(NumericType.MaxMp).FloatToIntString()}";
|
|
_attributeDic["物理攻击"].text = num.Get(NumericType.PhyAtk).FloatToIntString();
|
|
_attributeDic["精神攻击"].text = num.Get(NumericType.SpiAtk).FloatToIntString();
|
|
_attributeDic["物理防御"].text = num.Get(NumericType.PhyDef).FloatToIntString();
|
|
_attributeDic["精神防御"].text = num.Get(NumericType.SpiDef).FloatToIntString();
|
|
_attributeDic["物理暴击率"].text = num.Get(NumericType.Pcrir).FloatToPercentString();
|
|
_attributeDic["精神暴击率"].text = num.Get(NumericType.Mcrir).FloatToPercentString();
|
|
_attributeDic["物理暴击值"].text = num.Get(NumericType.Pcri).FloatToPercentString();
|
|
_attributeDic["精神暴击值"].text = num.Get(NumericType.Mcri).FloatToPercentString();
|
|
_attributeDic["抗物理暴击率"].text = num.Get(NumericType.Rpcrir).FloatToPercentString();
|
|
_attributeDic["抗精神暴击率"].text = num.Get(NumericType.Rmcrir).FloatToPercentString();
|
|
_attributeDic["抗物理暴击值"].text = num.Get(NumericType.Rpcri).FloatToPercentString();
|
|
_attributeDic["抗精神暴击值"].text = num.Get(NumericType.Rmcri).FloatToPercentString();
|
|
_attributeDic["物理免伤"].text = num.Get(NumericType.Nphyi).FloatToPercentString();
|
|
_attributeDic["精神免伤"].text = num.Get(NumericType.Nmeni).FloatToPercentString();
|
|
_attributeDic["辅助值"].text = num.Get(NumericType.Dvo).FloatToPercentString();
|
|
|
|
//!更新属性点
|
|
FUI_CharacterUI characterUI = FUIComponent.Instance.Get(FUIPackage.Character_CharacterUI)?.As<FUI_CharacterUI>();
|
|
if (characterUI)
|
|
{
|
|
characterUI.m_txtPoint.text = "属性点:" + unitCharacter.CharacterPoint;
|
|
}
|
|
}
|
|
|
|
private async ETVoid ShowSkin(int skinId)
|
|
{
|
|
SkinBase skinBase = DataTableHelper.Get<SkinBase>(skinId);
|
|
skinTran = await ResourceViewHelper.LoadPrefabAsync(skinBase.PrfabId);
|
|
if (nTexture == null)
|
|
{
|
|
Transform characterTran = await ResourceViewHelper.LoadPrefabAsync(Sys_PrefabId.Character);
|
|
characterTran.localPosition = new Vector3(-2000, 0, 0);
|
|
rt = CreateTexture((int) this.ui.m_icon.width, (int) this.ui.m_icon.height);
|
|
rtCamera = characterTran.GetComponentInChildren<Camera>();
|
|
rtCamera.targetTexture = rt;
|
|
nTexture = new NTexture(rt);
|
|
this.ui.m_icon.texture = nTexture;
|
|
}
|
|
|
|
rtCamera.enabled = true;
|
|
skinTran.SetParent(rtCamera.transform.parent);
|
|
skinTran.localPosition = Vector3.forward * 5;
|
|
}
|
|
|
|
private static RenderTexture CreateTexture(int width, int height)
|
|
{
|
|
return new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32)
|
|
{
|
|
antiAliasing = 1, filterMode = FilterMode.Bilinear, anisoLevel = 0, useMipMap = false
|
|
};
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
rtCamera.enabled = false;
|
|
ResourceViewHelper.DestoryPrefabAsync(skinTran);
|
|
}
|
|
}
|
|
} |