221 lines
8.2 KiB
C#
221 lines
8.2 KiB
C#
using Cal.DataTable;
|
||
using ET;
|
||
using FairyGUI;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using Cal;
|
||
using ET.EventType;
|
||
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
|
||
{
|
||
private FUI_PetUI ui;
|
||
private NTexture nTexture;
|
||
private Camera rtCamera;
|
||
private Transform skinTran;
|
||
private RenderTexture rt;
|
||
private Pet.PetState petState;
|
||
private bool canQuickEnd;
|
||
private Pet pet;
|
||
private Scene zoneScene;
|
||
|
||
public void Awake()
|
||
{
|
||
zoneScene = this.ZoneScene();
|
||
ui = GetParent<FUI_PetUI>();
|
||
AwakeAsync().Coroutine();
|
||
}
|
||
|
||
private async ETVoid AwakeAsync()
|
||
{
|
||
pet = zoneScene.GetComponent<UnitComponent>().MyUnit.GetComponent<Pet>();
|
||
ShowSkin(pet.petId).Coroutine();
|
||
ShowPage().Coroutine();
|
||
RegisterEvent();
|
||
await ETTask.CompletedTask;
|
||
}
|
||
|
||
private async ETVoid ShowPage()
|
||
{
|
||
M2C_GetPetInfo ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetPetInfo>(new C2M_GetPetInfo());
|
||
if (!ret.Message.IsNullOrEmpty())
|
||
{
|
||
TipHelper.OpenUI(ret.Message);
|
||
return;
|
||
}
|
||
|
||
this.ui.m_txtStute.text = $"名字:{pet.name}\n等级:{this.pet.level}\n经验:{this.pet.exp}\n亲密度:{this.pet.intimacy}\n剩余喂养次数:{ret.eatCount}\n活跃度:{ret.active}";
|
||
string addStr = null;
|
||
PetConfig petConfig = PetConfigCategory.Instance.Get(this.pet.petId);
|
||
foreach (PetConfig.AddAttibuteMap addAttibuteMap in petConfig.AddAttibuteMapArr)
|
||
{
|
||
var key = (AttributeType) addAttibuteMap.Key;
|
||
addStr += TabHelper.GetAttributeString(key,addAttibuteMap.BaseValue+ addAttibuteMap.Value*this.pet.level)+"\n";
|
||
}
|
||
this.ui.m_txtAdd.text = addStr;
|
||
string timeStr = TimeSpan.FromMilliseconds(ret.remainTime > 0? ret.remainTime : 0).ToString("hh\\:mm\\:ss");
|
||
petState = (Pet.PetState) ret.petState;
|
||
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()
|
||
};
|
||
canQuickEnd = ret.remainTime > 0;
|
||
this.ui.m_btnEnd.title = canQuickEnd?"立即完成":"领取奖励";
|
||
}
|
||
|
||
private void RegisterEvent()
|
||
{
|
||
//溜宠
|
||
ui.m_listBtn.GetChildAt(1).asButton.onClick.Set(() => { zoneScene.GetComponent<SessionComponent>().Session.Send(new C2M_ShowPet { }); });
|
||
//嬉戏
|
||
this.ui.m_listBtn.GetChildAt(2).asButton.onClick.Set(async () =>
|
||
{
|
||
if (this.petState != Pet.PetState.Play)
|
||
{
|
||
var ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_StartPetPlay>(new C2M_StartPetPlay());
|
||
if (!ret.Message.IsNullOrEmpty())
|
||
{
|
||
TipHelper.OpenUI(ret.Message);
|
||
return;
|
||
}
|
||
|
||
this.ShowPage().Coroutine();
|
||
}
|
||
});
|
||
//锻炼
|
||
this.ui.m_listBtn.GetChildAt(3).asButton.onClick.Set(async () =>
|
||
{
|
||
if (this.petState != Pet.PetState.Experience)
|
||
{
|
||
if (this.petState != Pet.PetState.Play)
|
||
{
|
||
var ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_StartPetExperience>(new C2M_StartPetExperience());
|
||
if (!ret.Message.IsNullOrEmpty())
|
||
{
|
||
TipHelper.OpenUI(ret.Message);
|
||
return;
|
||
}
|
||
|
||
this.ShowPage().Coroutine();
|
||
}
|
||
}
|
||
});
|
||
//探险
|
||
this.ui.m_listBtn.GetChildAt(4).asButton.onClick.Set(async () =>
|
||
{
|
||
if (this.petState != Pet.PetState.Explore)
|
||
{
|
||
if (this.petState != Pet.PetState.Play)
|
||
{
|
||
var ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_StartPetExplore>(new C2M_StartPetExplore());
|
||
if (!ret.Message.IsNullOrEmpty())
|
||
{
|
||
TipHelper.OpenUI(ret.Message);
|
||
return;
|
||
}
|
||
|
||
this.ShowPage().Coroutine();
|
||
}
|
||
}
|
||
});
|
||
//进化
|
||
this.ui.m_listBtn.GetChildAt(5).asButton.onClick.Set(async () =>
|
||
{
|
||
Game.EventSystem.Publish(new OpenPetUpgradeUI() {zoneScene = this.ui.ZoneScene()});
|
||
});
|
||
this.ui.m_btnEnd.onClick.Set(async () =>
|
||
{
|
||
if (this.canQuickEnd)
|
||
{
|
||
switch (petState)
|
||
{
|
||
case Pet.PetState.Play:
|
||
case Pet.PetState.Experience:
|
||
case Pet.PetState.Explore:
|
||
break;
|
||
default:
|
||
return;
|
||
}
|
||
|
||
await SessionComponentHelper.TipCall(this.zoneScene,new C2M_GetPetQuickEndPrice() { }, (M2C_GetPetQuickEndPrice query) =>
|
||
{
|
||
string str = $"是否花费{query.voucher}代金券立即完成?";
|
||
return (str, new C2M_EndPetAction());
|
||
},
|
||
(M2C_EndPetAction ret) => { this.ShowPage().Coroutine(); });
|
||
}
|
||
else
|
||
{
|
||
var ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetPetActionReword>(new C2M_GetPetActionReword());
|
||
if (!ret.Message.IsNullOrEmpty())
|
||
{
|
||
TipHelper.OpenUI(ret.Message);
|
||
return;
|
||
}
|
||
|
||
this.ShowPage().Coroutine();
|
||
}
|
||
});
|
||
}
|
||
|
||
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(-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);
|
||
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
|
||
};
|
||
}
|
||
|
||
public void Destroy()
|
||
{
|
||
if (rtCamera)
|
||
rtCamera.enabled = false;
|
||
ResourceViewHelper.DestoryPrefabAsync(skinTran);
|
||
}
|
||
}
|
||
} |