2021-04-09 00:48:56 +08:00
|
|
|
|
|
|
|
|
|
using Cal.DataTable;
|
|
|
|
|
using ET;
|
|
|
|
|
using FairyGUI;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class PetUIAwakeSyatem : AwakeSystem<PetUI>
|
|
|
|
|
{
|
|
|
|
|
public override void Awake(PetUI self)
|
|
|
|
|
{
|
|
|
|
|
self.Awake();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class PetUIDestroySyatem : DestroySystem<PetUI>
|
|
|
|
|
{
|
|
|
|
|
public override void Destroy(PetUI self)
|
|
|
|
|
{
|
|
|
|
|
self.Destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class PetUI : Entity
|
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
private FUI_PetUI ui;
|
2021-04-09 00:48:56 +08:00
|
|
|
|
private NTexture nTexture;
|
|
|
|
|
private Camera rtCamera;
|
|
|
|
|
private Transform skinTran;
|
|
|
|
|
private RenderTexture rt;
|
|
|
|
|
public void Awake()
|
|
|
|
|
{
|
|
|
|
|
ui = GetParent<FUI_PetUI>();
|
|
|
|
|
AwakeAsync().Coroutine();
|
|
|
|
|
}
|
|
|
|
|
private async ETVoid AwakeAsync()
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Pet pet = UnitComponent.MyUnit.GetComponent<Pet>();
|
2021-04-10 19:49:32 +08:00
|
|
|
|
ShowSkin(pet.petId).Coroutine();
|
2021-04-15 00:12:07 +08:00
|
|
|
|
ShowPage().Coroutine();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
RegisterEvent();
|
2021-04-09 00:48:56 +08:00
|
|
|
|
await ETTask.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-15 00:12:07 +08:00
|
|
|
|
private async ETVoid ShowPage()
|
|
|
|
|
{
|
|
|
|
|
M2C_GetPetInfo ret = await SessionComponent.Instance.Call<M2C_GetPetInfo>(new C2M_GetPetInfo());
|
|
|
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.ui.m_txtStute.text = $"剩余喂养次数:{ret.eatCount}\n活跃度:{ret.active}";
|
|
|
|
|
string timeStr = TimeSpan.FromMilliseconds(ret.remainTime).ToString("hh\\:mm\\:ss");
|
|
|
|
|
this.ui.m_labTime.title = (Pet.PetState) ret.petState switch
|
|
|
|
|
{
|
|
|
|
|
Pet.PetState.Idle => $"等待中",
|
|
|
|
|
Pet.PetState.Follow => $"跟随中",
|
|
|
|
|
Pet.PetState.Play => $"嬉戏:{timeStr}",
|
|
|
|
|
Pet.PetState.Experience => $"锻炼:{timeStr}",
|
|
|
|
|
Pet.PetState.Explore => $"探险:{timeStr}",
|
|
|
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
private void RegisterEvent()
|
|
|
|
|
{
|
|
|
|
|
//溜宠
|
|
|
|
|
ui.m_listBtn.GetChildAt(1).asButton.onClick.Set(()=>
|
|
|
|
|
{
|
|
|
|
|
SessionComponent.Instance.Session.Send(new C2M_ShowPet { });
|
|
|
|
|
});
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-09 00:48:56 +08:00
|
|
|
|
private async ETVoid ShowSkin(int petId)
|
|
|
|
|
{
|
2021-04-10 19:49:32 +08:00
|
|
|
|
if (petId == 0) return;
|
2021-04-09 00:48:56 +08:00
|
|
|
|
PetConfig petConfig = PetConfigCategory.Instance.Get(petId);
|
|
|
|
|
if (petConfig == null) return;
|
|
|
|
|
skinTran = await ResourceViewHelper.LoadPrefabAsync(petConfig.PrefabId);
|
|
|
|
|
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(-2100, 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);
|
2021-04-10 19:49:32 +08:00
|
|
|
|
skinTran.localPosition = new Vector3(0, 1.25f, 5);
|
2021-04-09 00:48:56 +08:00
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
|
{
|
2021-04-10 19:49:32 +08:00
|
|
|
|
if (rtCamera)
|
|
|
|
|
rtCamera.enabled = false;
|
2021-04-09 00:48:56 +08:00
|
|
|
|
ResourceViewHelper.DestoryPrefabAsync(skinTran);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|