130 lines
4.4 KiB
C#
130 lines
4.4 KiB
C#
using Cal.DataTable;
|
|
using ET;
|
|
using FairyGUI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using NPOI.SS.Formula.Functions;
|
|
using UnityEngine;
|
|
|
|
namespace ET
|
|
{
|
|
public class PetupgradeUIAwakeSyatem: AwakeSystem<PetUpgradeUI>
|
|
{
|
|
public override void Awake(PetUpgradeUI self)
|
|
{
|
|
self.Awake();
|
|
}
|
|
}
|
|
|
|
public class PetupgradeUIDestroySyatem: DestroySystem<PetUpgradeUI>
|
|
{
|
|
public override void Destroy(PetUpgradeUI self)
|
|
{
|
|
self.Destroy();
|
|
}
|
|
}
|
|
|
|
public class PetUpgradeUI: Entity
|
|
{
|
|
private FUI_PetUpgradeUI ui;
|
|
private NTexture nTexture;
|
|
private Camera rtCamera;
|
|
private Transform skinTran;
|
|
private RenderTexture rt;
|
|
private PetConfig petConfig;
|
|
private int showIndex;
|
|
private Scene zoneScene;
|
|
|
|
public void Awake()
|
|
{
|
|
zoneScene = this.ZoneScene();
|
|
ui = GetParent<FUI_PetUpgradeUI>();
|
|
showIndex = -1;
|
|
AwakeAsync().Coroutine();
|
|
}
|
|
|
|
private async ETVoid AwakeAsync()
|
|
{
|
|
Pet pet = zoneScene.GetComponent<UnitComponent>().MyUnit.GetComponent<Pet>();
|
|
petConfig = PetConfigCategory.Instance.Get(pet.petId);
|
|
if (petConfig.UpgradeIdArr.Length > 0)
|
|
{
|
|
showIndex = 0;
|
|
ShowSkin(petConfig.UpgradeIdArr[0]).Coroutine();
|
|
}
|
|
ShowPage().Coroutine();
|
|
RegisterEvent();
|
|
await ETTask.CompletedTask;
|
|
}
|
|
|
|
private async ETVoid ShowPage()
|
|
{
|
|
Pet pet = zoneScene.GetComponent<UnitComponent>().MyUnit.GetComponent<Pet>();
|
|
this.ui.m_txtLevel.text = $"所需:{petConfig.NeedLevel}/[color={(pet.level<=petConfig.NeedLevel?"#ff0000":"#00ff00")}]{pet.level}[/color]";
|
|
this.ui.m_txtImatcy.text = $"所需:{petConfig.NeedIntimacy}/[color={(pet.intimacy<=petConfig.NeedIntimacy?"#ff0000":"#00ff00")}]{pet.intimacy}[/color]";
|
|
}
|
|
|
|
private void RegisterEvent()
|
|
{
|
|
this.ui.m_btnChange.self.onClick.Set((() =>
|
|
{
|
|
int length = petConfig.UpgradeIdArr.Length;
|
|
if (length<= 1) return;
|
|
DestorySkin();
|
|
showIndex = ++showIndex % length;
|
|
ShowSkin(this.petConfig.UpgradeIdArr[showIndex]).Coroutine();
|
|
}));
|
|
this.ui.m_btnUpgrade.self.onClick.Set((async() =>
|
|
{
|
|
var ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_UpgradePet>(new C2M_UpgradePet(){index = this.showIndex});
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
{
|
|
TipHelper.OpenUI(ret.Message);
|
|
return;
|
|
}
|
|
this.ui.GetComponent<FUIWindowComponent>().Window.Hide();
|
|
}));
|
|
}
|
|
|
|
private async ETVoid ShowSkin(int petId)
|
|
{
|
|
if (petId == 0) return;
|
|
PetConfig petConfig = PetConfigCategory.Instance.Get(petId);
|
|
if (petConfig == null) return;
|
|
skinTran = await ResourceViewHelper.LoadPrefabAsync(petConfig.PrefabId);
|
|
if (nTexture == null)
|
|
{
|
|
Transform characterTran = await ResourceViewHelper.LoadPrefabAsync(Sys_PrefabId.Character);
|
|
characterTran.localPosition = new Vector3(-2200, 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 = new Vector3(0, 1.25f, 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
|
|
};
|
|
}
|
|
|
|
private void DestorySkin()
|
|
{
|
|
if (rtCamera)
|
|
rtCamera.enabled = false;
|
|
ResourceViewHelper.DestoryPrefabAsync(skinTran);
|
|
}
|
|
public void Destroy()
|
|
{
|
|
DestorySkin();
|
|
}
|
|
}
|
|
} |