2021-04-16 00:06:30 +08:00
|
|
|
|
using Cal.DataTable;
|
2021-04-09 00:48:56 +08:00
|
|
|
|
using ET;
|
|
|
|
|
using FairyGUI;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-04-16 00:06:30 +08:00
|
|
|
|
using Cal;
|
|
|
|
|
using ET.EventType;
|
2021-04-09 00:48:56 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
2021-04-16 00:06:30 +08:00
|
|
|
|
public class PetUIAwakeSyatem: AwakeSystem<PetUI>
|
2021-04-09 00:48:56 +08:00
|
|
|
|
{
|
|
|
|
|
public override void Awake(PetUI self)
|
|
|
|
|
{
|
|
|
|
|
self.Awake();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-16 00:06:30 +08:00
|
|
|
|
|
|
|
|
|
public class PetUIDestroySyatem: DestroySystem<PetUI>
|
2021-04-09 00:48:56 +08:00
|
|
|
|
{
|
|
|
|
|
public override void Destroy(PetUI self)
|
|
|
|
|
{
|
|
|
|
|
self.Destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-16 00:06:30 +08:00
|
|
|
|
|
|
|
|
|
public class PetUI: Entity
|
2021-04-09 00:48:56 +08:00
|
|
|
|
{
|
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;
|
2021-04-16 00:06:30 +08:00
|
|
|
|
private Pet.PetState petState;
|
|
|
|
|
private bool canQuickEnd;
|
|
|
|
|
private Pet pet;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
private Scene zoneScene;
|
2021-04-16 00:06:30 +08:00
|
|
|
|
|
2021-04-09 00:48:56 +08:00
|
|
|
|
public void Awake()
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene = this.ZoneScene();
|
2021-04-09 00:48:56 +08:00
|
|
|
|
ui = GetParent<FUI_PetUI>();
|
|
|
|
|
AwakeAsync().Coroutine();
|
|
|
|
|
}
|
2021-04-16 00:06:30 +08:00
|
|
|
|
|
2021-04-09 00:48:56 +08:00
|
|
|
|
private async ETVoid AwakeAsync()
|
2021-04-16 00:06:30 +08:00
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
pet = zoneScene.GetComponent<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()
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_GetPetInfo ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetPetInfo>(new C2M_GetPetInfo());
|
2021-04-15 00:12:07 +08:00
|
|
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-16 00:06:30 +08:00
|
|
|
|
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;
|
2021-05-29 15:07:44 +08:00
|
|
|
|
addStr += TabHelper.GetAttributeString(key,addAttibuteMap.BaseValue+ addAttibuteMap.Value*this.pet.level)+"\n";
|
2021-04-16 00:06:30 +08:00
|
|
|
|
}
|
|
|
|
|
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;
|
2021-04-15 00:12:07 +08:00
|
|
|
|
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-16 00:06:30 +08:00
|
|
|
|
canQuickEnd = ret.remainTime > 0;
|
2021-04-15 00:12:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
private void RegisterEvent()
|
|
|
|
|
{
|
|
|
|
|
//溜宠
|
2021-04-20 00:25:04 +08:00
|
|
|
|
ui.m_listBtn.GetChildAt(1).asButton.onClick.Set(() => { zoneScene.GetComponent<SessionComponent>().Session.Send(new C2M_ShowPet { }); });
|
2021-04-16 00:06:30 +08:00
|
|
|
|
//嬉戏
|
|
|
|
|
this.ui.m_listBtn.GetChildAt(2).asButton.onClick.Set(async () =>
|
|
|
|
|
{
|
|
|
|
|
if (this.petState != Pet.PetState.Play)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
var ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_StartPetPlay>(new C2M_StartPetPlay());
|
2021-04-16 00:06:30 +08:00
|
|
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.ShowPage().Coroutine();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//锻炼
|
|
|
|
|
this.ui.m_listBtn.GetChildAt(3).asButton.onClick.Set(async () =>
|
2021-04-11 19:50:39 +08:00
|
|
|
|
{
|
2021-04-16 00:06:30 +08:00
|
|
|
|
if (this.petState != Pet.PetState.Experience)
|
|
|
|
|
{
|
|
|
|
|
if (this.petState != Pet.PetState.Play)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
var ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_StartPetExperience>(new C2M_StartPetExperience());
|
2021-04-16 00:06:30 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
var ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_StartPetExplore>(new C2M_StartPetExplore());
|
2021-04-16 00:06:30 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 00:25:04 +08:00
|
|
|
|
await SessionComponentHelper.TipCall(this.zoneScene,new C2M_GetPetQuickEndPrice() { }, (M2C_GetPetQuickEndPrice query) =>
|
2021-04-16 00:06:30 +08:00
|
|
|
|
{
|
|
|
|
|
string str = $"是否花费{query.voucher}代金券立即完成?";
|
|
|
|
|
return (str, new C2M_EndPetAction());
|
|
|
|
|
},
|
|
|
|
|
(M2C_EndPetAction ret) => { this.ShowPage().Coroutine(); });
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
var ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetPetActionReword>(new C2M_GetPetActionReword());
|
2021-04-16 00:06:30 +08:00
|
|
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.ShowPage().Coroutine();
|
|
|
|
|
}
|
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);
|
2021-04-16 00:06:30 +08:00
|
|
|
|
rt = CreateTexture((int) this.ui.m_icon.width, (int) this.ui.m_icon.height);
|
2021-04-09 00:48:56 +08:00
|
|
|
|
rtCamera = characterTran.GetComponentInChildren<Camera>();
|
|
|
|
|
rtCamera.targetTexture = rt;
|
|
|
|
|
nTexture = new NTexture(rt);
|
|
|
|
|
this.ui.m_icon.texture = nTexture;
|
|
|
|
|
}
|
2021-04-16 00:06:30 +08:00
|
|
|
|
|
2021-04-09 00:48:56 +08:00
|
|
|
|
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
|
|
|
|
}
|
2021-04-16 00:06:30 +08:00
|
|
|
|
|
2021-04-09 00:48:56 +08:00
|
|
|
|
private static RenderTexture CreateTexture(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
return new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32)
|
|
|
|
|
{
|
2021-04-16 00:06:30 +08:00
|
|
|
|
antiAliasing = 1, filterMode = FilterMode.Bilinear, anisoLevel = 0, useMipMap = false
|
2021-04-09 00:48:56 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2021-04-16 00:06:30 +08:00
|
|
|
|
|
2021-04-09 00:48:56 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-16 00:06:30 +08:00
|
|
|
|
}
|