373 lines
12 KiB
C#
373 lines
12 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using DG.Tweening;
|
|
using Game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UniRx;
|
|
|
|
public class AquariumReportPopupPanel : MonoBehaviour
|
|
{
|
|
public Button btn_next;
|
|
public GameObject receive;
|
|
public GameObject photo;
|
|
|
|
public TMP_Text text_gold;
|
|
public TMP_Text text_energy;
|
|
public TMP_Text txt_diamond;
|
|
public TMP_Text text_num;
|
|
public GameObject[] _lights;
|
|
public float showTime = 0.3f;
|
|
public Transform reward_show;
|
|
public RawImage icon;
|
|
public Image tag_fish;
|
|
public TMP_Text text_fish_name;
|
|
|
|
public Transform fishIconRT;
|
|
public RawImage rawImage;
|
|
RenderTexture rt;
|
|
Camera rtCamera;
|
|
Transform avatarCapture;
|
|
int fieldOfView = 60;
|
|
//鱼距离相机的位置
|
|
int fishPosZ = 20;
|
|
public GameObject mutated;
|
|
|
|
List<AquariumSlotData> aquariumSlotDatas;
|
|
AquariumSlotData curData;
|
|
int curIndex;
|
|
int allCount;
|
|
int Energy;
|
|
int curDiamond;
|
|
ulong Gold;
|
|
bool isClose;
|
|
bool isClickClose;
|
|
IDisposable disposable;
|
|
private Tables _tables;
|
|
Item item;
|
|
AquariumManager AM;
|
|
Vector3 startPosition;
|
|
FishingAquariumAct aquariumAct;
|
|
Item fishItem;
|
|
bool isEnable = true;
|
|
public SpriteRenderer bg_photo;
|
|
private void Awake()
|
|
{
|
|
_tables = GContext.container.Resolve<Tables>();
|
|
item = _tables.TbItem.GetOrDefault(1002);
|
|
|
|
AM = GContext.container.Resolve<AquariumManager>();
|
|
aquariumSlotDatas = AM.sellList;
|
|
|
|
Energy = GContext.container.Resolve<PlayerData>().Energy;
|
|
Gold = GContext.container.Resolve<PlayerData>().gold;
|
|
curDiamond = GContext.container.Resolve<PlayerData>().diamond;
|
|
ShowItemCount();
|
|
text_energy.text = ConvertTools.GetNumberString2(Energy);
|
|
text_gold.text = ConvertTools.GetNumberString2(Gold);
|
|
txt_diamond.text = ConvertTools.GetNumberString2(curDiamond);
|
|
allCount = aquariumSlotDatas.Count;
|
|
|
|
avatarCapture = fishIconRT.Find("avatarCapture");
|
|
rtCamera = fishIconRT.Find("Camera").GetComponent<Camera>();
|
|
startPosition = avatarCapture.localPosition;
|
|
curIndex = 0;
|
|
disposable = GContext.OnEvent<ResAddEvent>().Subscribe(x =>
|
|
{
|
|
NumPlay(x.id);
|
|
});
|
|
}
|
|
|
|
public void InitData(FishingAquariumAct aquariumAct)
|
|
{
|
|
this.aquariumAct = aquariumAct;
|
|
SetRT();
|
|
SetData();
|
|
}
|
|
|
|
void SetRT()
|
|
{
|
|
fishIconRT.transform.position = Vector3.back * 30;
|
|
RectTransform raw = rawImage.GetComponent<RectTransform>();
|
|
rt = new RenderTexture((int)raw.rect.width, (int)raw.rect.height, 24, RenderTextureFormat.ARGB32);
|
|
|
|
rtCamera.fieldOfView = fieldOfView;
|
|
rtCamera.enabled = true;
|
|
rtCamera.targetTexture = rt;
|
|
rawImage.texture = rt;
|
|
rtCamera.Render();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
var mapData = _tables.TbMapData.DataMap[AM.MapId];
|
|
|
|
string prefabName = mapData.AquariumPrefab;
|
|
Transform bg = photo.transform.Find($"bg_{prefabName}");
|
|
if (bg != null)
|
|
{
|
|
bg_photo.sprite = bg.GetComponent<Image>().sprite;
|
|
}
|
|
btn_next.onClick.AddListener(OnClickNext);
|
|
}
|
|
async void ShowFish()
|
|
{
|
|
GameObject fishGo = await aquariumAct.LoadFish(curData.index, avatarCapture);
|
|
if (fishGo != null)
|
|
{
|
|
var fishData = _tables.TbFishData.GetOrDefault(fishItem.RedirectID);
|
|
|
|
var TankPosition = fishData.TankPosition;
|
|
Vector3 pos = new Vector3(TankPosition[0], TankPosition[1], TankPosition[2] + fishPosZ);
|
|
Transform avatar = avatarCapture;
|
|
pos += startPosition;
|
|
avatar.localPosition = pos;
|
|
//fish.transform.localPosition = pos;
|
|
}
|
|
}
|
|
|
|
async void SetData()
|
|
{
|
|
isClose = false;
|
|
isClickClose = false;
|
|
curData = aquariumSlotDatas[curIndex];
|
|
mutated.SetActive(curData.mutants > 0);
|
|
photo.SetActive(false);
|
|
fishItem = _tables.TbItem.GetOrDefault(curData.fishItemID);
|
|
ShowFish();
|
|
photo.SetActive(true);
|
|
text_fish_name.text = LocalizationMgr.GetText(fishItem.Name_l10n_key);
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(tag_fish, "icon_fish_rate_tag_" + fishItem.Quality);
|
|
|
|
int audioName = curIndex % 4 + 1;
|
|
GContext.Publish(new EventUISound($"audio_ui_getreward_{audioName}"));
|
|
float showCount = curData.allCash;
|
|
ItemShow itemShow = GContext.container.Resolve<Tables>().TbItemShow.GetOrDefault(1002);
|
|
int light_index = 1;
|
|
if (itemShow != null)
|
|
{
|
|
light_index = 0;
|
|
showCount = (showCount / GContext.container.Resolve<PlayerItemData>().ExtraCoinMag());
|
|
for (int i = itemShow.Count.Count - 1; i >= 0; i--)
|
|
{
|
|
if (showCount > itemShow.Count[i])
|
|
{
|
|
light_index = i + 1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (light_index >= _lights.Length)
|
|
{
|
|
light_index = _lights.Length - 1;
|
|
}
|
|
for (int i = 0; i < _lights.Length; i++)
|
|
{
|
|
_lights[i].SetActive(i == light_index);
|
|
}
|
|
curIndex++;
|
|
receive.SetActive(false);
|
|
receive.SetActive(true);
|
|
var progress = 0f;
|
|
//text_num.text = ConvertTools.GetNumberString2(curData.cash);
|
|
int cash = curData.cash;
|
|
DOTween.Kill("AddCash");
|
|
await Awaiters.Seconds(showTime);
|
|
|
|
DOTween.To(() => progress, x => progress = x, 1f, 0.8f).OnUpdate(() =>
|
|
{
|
|
text_num.text = ConvertTools.GetNumberString2((int)(cash * progress));
|
|
}).SetId("AddCash");
|
|
await Awaiters.Seconds(0.5f);
|
|
await ParticleAttractor(showCount);
|
|
isClose = true;
|
|
if (isClickClose)
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
void NumPlay(int id)
|
|
{
|
|
if (id != 1002)
|
|
{
|
|
return;
|
|
}
|
|
GoldAddAnim(curData.cash);
|
|
}
|
|
void GoldAddAnim(float add)
|
|
{
|
|
DOTween.Kill("report_text_gold");
|
|
text_gold.text = ConvertTools.GetNumberString2(Gold);
|
|
float progress = 0;
|
|
ulong glod = Gold;
|
|
DOTween.To(() => progress, x => progress = x, 1, 0.4f).OnUpdate(() =>
|
|
{
|
|
Gold = glod + (ulong)(add * progress);
|
|
text_gold.text = ConvertTools.GetNumberString2(Gold);
|
|
}).SetDelay(0.5f).SetId("report_text_gold");
|
|
}
|
|
|
|
void ShowItemCount()
|
|
{
|
|
if (aquariumSlotDatas != null)
|
|
{
|
|
for (int i = 0; i < aquariumSlotDatas.Count; i++)
|
|
{
|
|
ulong curGold = (ulong)aquariumSlotDatas[i].cash;
|
|
if (Gold > curGold)
|
|
{
|
|
Gold -= curGold;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void Close()
|
|
{
|
|
isClickClose = false;
|
|
isClose = false;
|
|
receive.SetActive(false);
|
|
UIManager.Instance.DestroyUI(UITypes.AquariumReportPopupPanel);
|
|
if (AM.data.isHome)
|
|
{
|
|
FishingAquariumAct.eventAggregator.Publish(new AquariumEnterMapScene());
|
|
}
|
|
}
|
|
|
|
void OnClickNext()
|
|
{
|
|
if (curIndex >= allCount)
|
|
{
|
|
receive.SetActive(false);
|
|
if (isClose)
|
|
{
|
|
Close();
|
|
}
|
|
else
|
|
{
|
|
isClickClose = true;
|
|
}
|
|
return;
|
|
}
|
|
SetData();
|
|
}
|
|
|
|
public async System.Threading.Tasks.Task ParticleAttractor(float showCount)
|
|
{
|
|
//1001 1002 另外一种配法
|
|
//ItemShow itemShow = _tables.TbItemShow.GetOrDefault(item.ID);
|
|
//string fxName = itemShow.Fx[0];
|
|
//for (int i = itemShow.Count.Count - 1; i >= 0; i--)
|
|
//{
|
|
// if (showCount > itemShow.Count[i])
|
|
// {
|
|
// fxName = itemShow.Fx[i + 1];
|
|
// break;
|
|
// }
|
|
//}
|
|
string fxName = "fx_ui_reward_common_money_01";// item.Fx;
|
|
if (fishItem.Quality > 3)
|
|
{
|
|
fxName = "fx_ui_reward_common_money_02";
|
|
}
|
|
|
|
Transform fxP = reward_show.Find(fxName);
|
|
|
|
if (fxP == null)
|
|
{
|
|
GContext.Publish(new ResAddEvent(item.ID, item.Type, item.SubType));
|
|
return;
|
|
}
|
|
GameObject fx = Instantiate(fxP.gameObject, reward_show);
|
|
ParticleSystem particleSystem = fx.transform.Find("Scale/quan03").GetComponent<ParticleSystem>();
|
|
if (particleSystem != null)
|
|
{
|
|
reward_show.gameObject.SetActive(true);
|
|
//fx.transform.position = transform.position;
|
|
ParticleAttractorData particleAttractorData = new ParticleAttractorData()
|
|
{
|
|
Type = item.Type,
|
|
SubType = item.SubType,
|
|
Priority = -1,
|
|
};
|
|
GContext.Publish(particleAttractorData);
|
|
if (particleAttractorData.Priority > -1 && particleAttractorData.uIParticleAttractorCenter != null)
|
|
{
|
|
var particleRenderer = particleSystem.GetComponent<ParticleSystemRenderer>();
|
|
var sprite = icon.texture;
|
|
|
|
var uIParticleAttractorCenter = particleAttractorData.uIParticleAttractorCenter;
|
|
//多个粒子飞向同一个target时,隐藏前一个粒子
|
|
var particleAttractor = uIParticleAttractorCenter.GetUIParticleAttractor();
|
|
particleAttractor?.Clear();
|
|
particleAttractor.particleSystem = null;
|
|
//particleAttractor.enabled = false;
|
|
Texture texture = sprite;// await GContext.container.Resolve<IUIService>().GetTexture(item.Icon, "RewardPopupPanel");
|
|
if (!isEnable)
|
|
{
|
|
return;
|
|
}
|
|
//_TextureSample0
|
|
particleRenderer.material.SetTexture("_TextureSample0", texture);
|
|
//particleRenderer.material.SetTextureScale("_TextureSample0", new Vector2(sprite.textureRect.width / texture.width, sprite.textureRect.height / texture.height));
|
|
//particleRenderer.material.SetTextureOffset("_TextureSample0", new Vector2(sprite.textureRect.x / texture.width, sprite.textureRect.y / texture.height));
|
|
particleSystem.Clear();
|
|
|
|
var main = particleSystem.main;
|
|
int maxCount = main.maxParticles;
|
|
if (showCount < maxCount)
|
|
{
|
|
int addCount = (int)showCount;
|
|
main.maxParticles = addCount;
|
|
//var emission = particleSystem.emission;
|
|
//emission.rateOverTime = 0;
|
|
//emission.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, addCount) });
|
|
}
|
|
fx.SetActive(true);
|
|
if (particleAttractor != null)
|
|
{
|
|
particleAttractor.particleSystem = particleSystem;
|
|
particleAttractor.enabled = true;
|
|
}
|
|
await Awaiters.Seconds(0.2f);
|
|
if (!isEnable)
|
|
{
|
|
return;
|
|
}
|
|
GContext.Publish(new ResAddEvent(item.ID, item.Type, item.SubType));
|
|
await Awaiters.Seconds(1.8f);
|
|
if (!isEnable)
|
|
{
|
|
return;
|
|
}
|
|
if (particleAttractor != null && particleAttractor.particleSystem == particleSystem)
|
|
{
|
|
particleAttractor.Clear();
|
|
particleAttractor.enabled = false;
|
|
particleAttractor = null;
|
|
}
|
|
}
|
|
}
|
|
Destroy(fx);
|
|
return;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
isEnable = false;
|
|
disposable?.Dispose();
|
|
disposable = null;
|
|
rtCamera.targetTexture = null;
|
|
if (rt != null)
|
|
{
|
|
rt.Release();
|
|
Destroy(rt);
|
|
rt = null;
|
|
}
|
|
}
|
|
}
|