CTT/Unity/Assets/HotfixView/UI/CharacterUI/CharacterUI.cs

350 lines
15 KiB
C#
Raw Normal View History

2021-05-16 17:22:42 +08:00
using Cal.DataTable;
2021-04-08 20:09:59 +08:00
using ET.EventType;
using ET;
using FairyGUI;
using System;
using System.Collections.Generic;
2021-05-16 17:22:42 +08:00
using UnityEditor.Graphs;
2021-04-08 20:09:59 +08:00
using UnityEngine;
namespace ET
{
2021-05-16 17:22:42 +08:00
public class CharacterUIAwakeSyatem: AwakeSystem<CharacterUI>
2021-04-08 20:09:59 +08:00
{
public override void Awake(CharacterUI self)
{
self.Awake();
}
}
2021-05-16 17:22:42 +08:00
public class CharacterUIDestroySyatem: DestroySystem<CharacterUI>
2021-04-08 20:09:59 +08:00
{
public override void Destroy(CharacterUI self)
{
self.Destroy();
}
}
2021-05-16 17:22:42 +08:00
public class CharacterUI: Entity
2021-04-08 20:09:59 +08:00
{
2021-05-16 17:22:42 +08:00
public enum SlotUIEffect: byte
{
None,
StarSoul = 1,
Strength_15 = 1 << 1,
StarSoul_10 = 1 << 2,
StarSoul_20 = 1 << 3
}
2021-04-08 20:09:59 +08:00
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;
2021-05-16 17:22:42 +08:00
private bool isMine;
private long id;
2021-04-08 20:09:59 +08:00
public void Awake()
{
zoneScene = this.ZoneScene();
2021-04-08 20:09:59 +08:00
AwakeAsync().Coroutine();
}
2021-05-16 17:22:42 +08:00
2021-04-08 20:09:59 +08:00
private async ETVoid AwakeAsync()
{
ui = GetParent<FUI_CharacterUI>();
if (AttributeDic == null)
{
AttributeDic = new Dictionary<string, GTextField>();
2021-05-13 20:14:23 +08:00
foreach (var o in ui.m_infoList.GetChildrenList())
2021-04-08 20:09:59 +08:00
{
2021-05-13 20:14:23 +08:00
var item = (GLabel) o;
2021-04-08 20:09:59 +08:00
AttributeDic.Add(item.name, item.GetChild("txt").asTextField);
}
2021-05-16 17:22:42 +08:00
2021-05-13 20:14:23 +08:00
foreach (var o in ui.m_basicAttributeList.GetChildrenList())
2021-04-08 20:09:59 +08:00
{
2021-05-13 20:14:23 +08:00
var item = (GLabel) o;
2021-04-08 20:09:59 +08:00
AttributeDic.Add(item.name, item.GetChild("txt").asTextField);
}
2021-05-16 17:22:42 +08:00
2021-05-13 20:14:23 +08:00
foreach (var o in ui.m_battleAttributeList.GetChildrenList())
2021-04-08 20:09:59 +08:00
{
2021-05-13 20:14:23 +08:00
var item = (GLabel) o;
2021-04-08 20:09:59 +08:00
AttributeDic.Add(item.name, item.GetChild("txt").asTextField);
}
}
2021-05-16 17:22:42 +08:00
2021-04-08 20:09:59 +08:00
//!临时变量
2021-05-16 17:22:42 +08:00
isMine = zoneScene.GetComponent<GlobalVariable>().IsMineCharacter;
2021-04-08 20:09:59 +08:00
//!+获取数据并更新人物信息
2021-05-16 17:22:42 +08:00
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 });
2021-04-08 20:09:59 +08:00
if (!m2cGetCharacter.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(m2cGetCharacter.Message);
return;
}
2021-05-16 17:22:42 +08:00
2021-04-11 19:50:39 +08:00
UnitCharacter unitCharacter = m2cGetCharacter.UnitCharacter;
2021-04-08 20:09:59 +08:00
ClientUnitCharacterComponent.Instance.Update(unitCharacter);
2021-05-16 17:22:42 +08:00
ShowNumText(this.zoneScene, id);
2021-04-08 20:09:59 +08:00
//!显示形象
ShowSkin(unitCharacter.SkinId).Coroutine();
//!更新装备栏
2021-05-16 17:22:42 +08:00
Game.EventSystem.Publish(new ET.EventType.UpdateWornEquipUI { list = m2cGetCharacter.WornBagMapList }).Coroutine();
2021-04-08 20:09:59 +08:00
//!+添加按钮事件
2021-05-16 17:22:42 +08:00
RegisterEvent();
await ETTask.CompletedTask;
}
private void RegisterEvent()
{
//!武器等装备栏
int atkListCount = this.ui.m_atkEquipList.numChildren;
for (int i = 0; i < atkListCount; i++)
2021-04-08 20:09:59 +08:00
{
2021-05-16 17:22:42 +08:00
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 () =>
2021-04-08 20:09:59 +08:00
{
2021-05-16 17:22:42 +08:00
int count = this.ui.m_addPointAttributeList.numChildren;
C2M_AddPoint c2M_AddPoint = new C2M_AddPoint();
for (int i = 0; i < count; i++)
2021-04-08 20:09:59 +08:00
{
2021-05-16 17:22:42 +08:00
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))
2021-04-08 20:09:59 +08:00
{
2021-05-16 17:22:42 +08:00
pointCount = 0;
2021-04-08 20:09:59 +08:00
}
2021-05-16 17:22:42 +08:00
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())
2021-04-08 20:09:59 +08:00
{
2021-05-16 17:22:42 +08:00
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())
2021-04-08 20:09:59 +08:00
{
2021-05-16 17:22:42 +08:00
TipHelper.OpenUI(ret.Message);
return;
}
2021-04-08 20:09:59 +08:00
2021-05-16 17:22:42 +08:00
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 =>
2021-04-08 20:09:59 +08:00
{
2021-05-16 17:22:42 +08:00
//!卸下装备
if (context.inputEvent.isDoubleClick)
2021-04-08 20:09:59 +08:00
{
2021-05-16 17:22:42 +08:00
if (this.zoneScene.GetComponent<UnitComponent>().MyUnit.IsFight)
2021-04-08 20:09:59 +08:00
{
2021-05-16 17:22:42 +08:00
TipHelper.OpenUI("战斗中,不能卸下装备!");
return;
2021-04-08 20:09:59 +08:00
}
2021-05-16 17:22:42 +08:00
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;
2021-04-08 20:09:59 +08:00
}
}
2021-05-16 17:22:42 +08:00
btn.GetController("effect").selectedIndex = (int) effectIndex;
2021-04-08 20:09:59 +08:00
}
2021-05-16 17:22:42 +08:00
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();
2021-05-17 00:19:52 +08:00
_attributeDic["竞技币"].text = num.Get(NumericType.PvpMoney).FloatToIntString();
_attributeDic["家族贡献"].text = 0f.FloatToIntString();
2021-05-16 17:22:42 +08:00
_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;
}
}
2021-04-08 20:09:59 +08:00
private async ETVoid ShowSkin(int skinId)
{
SkinBase skinBase = DataTableHelper.Get<SkinBase>(skinId);
skinTran = await ResourceViewHelper.LoadPrefabAsync(skinBase.PrfabId);
if (nTexture == null)
{
2021-04-11 19:50:39 +08:00
Transform characterTran = await ResourceViewHelper.LoadPrefabAsync(Sys_PrefabId.Character);
2021-04-09 00:48:56 +08:00
characterTran.localPosition = new Vector3(-2000, 0, 0);
2021-05-16 17:22:42 +08:00
rt = CreateTexture((int) this.ui.m_icon.width, (int) this.ui.m_icon.height);
2021-04-08 20:09:59 +08:00
rtCamera = characterTran.GetComponentInChildren<Camera>();
rtCamera.targetTexture = rt;
nTexture = new NTexture(rt);
this.ui.m_icon.texture = nTexture;
}
2021-05-16 17:22:42 +08:00
2021-04-08 20:09:59 +08:00
rtCamera.enabled = true;
skinTran.SetParent(rtCamera.transform.parent);
skinTran.localPosition = Vector3.forward * 5;
}
2021-05-16 17:22:42 +08:00
2021-04-08 20:09:59 +08:00
private static RenderTexture CreateTexture(int width, int height)
{
return new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32)
{
2021-05-16 17:22:42 +08:00
antiAliasing = 1, filterMode = FilterMode.Bilinear, anisoLevel = 0, useMipMap = false
2021-04-08 20:09:59 +08:00
};
}
2021-05-16 17:22:42 +08:00
2021-04-08 20:09:59 +08:00
public void Destroy()
{
rtCamera.enabled = false;
ResourceViewHelper.DestoryPrefabAsync(skinTran);
}
}
2021-05-16 17:22:42 +08:00
}