备份CatanBuilding瘦身独立工程
This commit is contained in:
408
Assets/Scripts/UI/Rod/FishingRodPanel.cs
Normal file
408
Assets/Scripts/UI/Rod/FishingRodPanel.cs
Normal file
@@ -0,0 +1,408 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using GameCore;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public partial class FishingRodPanel : BasePanel
|
||||
{
|
||||
Animation ani;
|
||||
Tables _tables;
|
||||
Transform LevelRoot;
|
||||
Transform AscendRoot;
|
||||
GameObject loading;
|
||||
Image mask_bottom;
|
||||
Image mask_top;
|
||||
UIDrag uiDrag;
|
||||
public float speed = 0.5f;
|
||||
public float RodApperXOffset = -0.5f;
|
||||
public float RodAppearTime = 0.2f;
|
||||
private Dictionary<string, GameObject> rodAvatar = new Dictionary<string, GameObject>();
|
||||
private List<GameObject> rodPrefab = new List<GameObject>();
|
||||
GameObject currentRod;
|
||||
Rod RodBehaviour;
|
||||
TMP_Text text_damage_num;
|
||||
TMP_Text text_info;
|
||||
GameObject effect_yugan_shengji;
|
||||
|
||||
//下部列表
|
||||
Button btn_close;
|
||||
|
||||
attributes_tips attributes_tips;
|
||||
Button BtnCloseTips;
|
||||
|
||||
List<RodItemData> rodItemDatas = new List<RodItemData>();
|
||||
private RodItemData data;
|
||||
private RodAscend curRodAscend;
|
||||
RodData config;
|
||||
RodSkinData skin;
|
||||
|
||||
string[] sp_rod_title = { "sp_rod_title_blue", "sp_rod_title_blue", "sp_rod_title_purple", "sp_rod_title_yellow" };
|
||||
string[] sp_rod_level = { "sp_rod_level_blue", "sp_rod_level_blue", "sp_rod_level_purple", "sp_rod_level_yellow" };
|
||||
string[] sp_rod_bottom_mask = { "sp_rod_bottom_mask_blue", "sp_rod_bottom_mask_blue", "sp_rod_bottom_mask_purple", "sp_rod_bottom_mask_yellow" };
|
||||
string[] sp_rod_top_mask = { "sp_rod_top_mask_blue", "sp_rod_top_mask_blue", "sp_rod_top_mask_purple", "sp_rod_top_mask_yellow" };
|
||||
FishingRodInfoPanel fishingRodInfoPanel;
|
||||
PlayerFishData playerFishData;
|
||||
FishingRodUpSystem upSystem;
|
||||
RawImage rawImageRod;
|
||||
//GameObject particle;
|
||||
public Material Rod_black;
|
||||
IUIService uIService;
|
||||
private void Awake()
|
||||
{
|
||||
uIService = GContext.container.Resolve<IUIService>();
|
||||
upSystem = GContext.container.Resolve<FishingRodUpSystem>();
|
||||
UIManager.Instance.DestroyUI(UITypes.FishingShopPanel);
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
ani = GetComponent<Animation>();
|
||||
loading = transform.Find("root/loading").gameObject;
|
||||
playerFishData = GContext.container.Resolve<PlayerFishData>();
|
||||
LevelRoot = transform.Find("root/LevelRoot");
|
||||
AscendRoot = transform.Find("root/AscendRoot");
|
||||
rawImageRod = transform.Find("root/RawImageRod").GetComponent<RawImage>();
|
||||
rawImageRod.gameObject.SetActive(true);
|
||||
mask_bottom = transform.Find("root/mask_bottom").GetComponent<Image>();
|
||||
mask_top = transform.Find("root/mask_top").GetComponent<Image>();
|
||||
|
||||
uiDrag = rawImageRod.transform.GetComponent<UIDrag>();
|
||||
text_damage_num = transform.Find("root/attributes_tips/text_info2").GetComponent<TMP_Text>();
|
||||
text_info = transform.Find("root/attributes_tips/text_info3").GetComponent<TMP_Text>();
|
||||
effect_yugan_shengji = transform.Find($"root/effect_yugan_shengji").gameObject;
|
||||
|
||||
btn_close = transform.Find("bottom/btn_close").GetComponent<Button>();
|
||||
|
||||
BtnCloseTips = transform.Find("root/BtnCloseTips").GetComponent<Button>();
|
||||
attributes_tips = transform.Find("root/attributes_tips").GetComponent<attributes_tips>();
|
||||
|
||||
///partial 其他功能初始化
|
||||
InitLevelUpPanel();
|
||||
InitAscendUpPanel();
|
||||
ShowAscendRoot(false);
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
btn_close.onClick.AddListener(OnClickClose);
|
||||
BtnCloseTips.onClick.AddListener(HideAllTips);
|
||||
|
||||
rawImageRod.texture = upSystem.bagPanel.rt;
|
||||
uiDrag.OnBeginDragCall += OnBeginDragCall;
|
||||
uiDrag.OnDragCall += OnDragRod;
|
||||
uiDrag.OnEndDragCall += StartDoRotate;
|
||||
HideAllTips();
|
||||
Init();
|
||||
GuideDataCenter guideDataCenter = GContext.container.Resolve<GuideDataCenter>();
|
||||
bool isGuide = guideDataCenter.InspectTriggerGuide("FishingRodPanel");
|
||||
starItemRoot.ShowStar(data.star, curRodAscend.MaxAscent);
|
||||
}
|
||||
|
||||
void OnClickClose()
|
||||
{
|
||||
if (AscendRoot.gameObject.activeSelf)
|
||||
{
|
||||
ShowAscendRoot(false);
|
||||
starItemRoot.ShowStar(data.star, curRodAscend.MaxAscent);
|
||||
}
|
||||
else
|
||||
{
|
||||
upSystem.Publish(new RefreshRodBagEvent());
|
||||
UIManager.Instance.DestroyUI(UITypes.FishingRodPanel);
|
||||
}
|
||||
}
|
||||
|
||||
void ShowAscendRoot(bool isLevel)
|
||||
{
|
||||
LevelRoot.gameObject.SetActive(!isLevel);
|
||||
AscendRoot.gameObject.SetActive(isLevel);
|
||||
if (isLevel)
|
||||
{
|
||||
ani.Play("FishingRodPanel_show");
|
||||
}
|
||||
else
|
||||
{
|
||||
ani.Play("FishingRodPanel_ascend");
|
||||
}
|
||||
}
|
||||
|
||||
async void ShowFishingRodInfoPanel()
|
||||
{
|
||||
GameObject panel = await UIManager.Instance.ShowUI(UITypes.FishingRodInfoPanel);
|
||||
fishingRodInfoPanel = panel.GetComponent<FishingRodInfoPanel>();
|
||||
int skindID = playerFishData.GetRodSkin(data.config.ID);
|
||||
var fishRodSkinData = _tables.TbRodSkinData.GetOrDefault(skindID);
|
||||
|
||||
fishingRodInfoPanel.Show(fishRodSkinData, data.config, upSystem.bagPanel.avatar, _rotateTarget, upSystem.bagPanel.rt, loading.activeSelf);
|
||||
}
|
||||
void ShowAppearance()
|
||||
{
|
||||
//var go = await UIManager.Instance.ShowUI(UITypes.AppearancePanel);
|
||||
//AppearancePanel appearancePanel = go.GetComponent<AppearancePanel>();
|
||||
//appearancePanel.appearanceOpenType = AppearanceOpenType.FishingRodPanel;
|
||||
//UIManager.Instance.DestroyUI(UITypes.FishingRodPanel);
|
||||
//GContext.Publish(new MapShowEvent() { isShow = true });
|
||||
}
|
||||
|
||||
|
||||
void HideAllTips()
|
||||
{
|
||||
attributes_tips.gameObject.SetActive(false);
|
||||
BtnCloseTips.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void ShowAttributes(int index, Transform trans)
|
||||
{
|
||||
var pos = trans.position;
|
||||
SetPos(pos);
|
||||
BtnCloseTips.gameObject.SetActive(true);
|
||||
attributes_tips.gameObject.SetActive(true);
|
||||
text_damage_num.gameObject.SetActive(index == 0);
|
||||
text_info.gameObject.SetActive(index == 0);
|
||||
attributes_tips.Init(index, data.config);
|
||||
}
|
||||
void SetPos(Vector3 pos)
|
||||
{
|
||||
attributes_tips.transform.position = pos;
|
||||
RectTransform rectTransform = transform.GetComponent<RectTransform>();
|
||||
float limit = (rectTransform.rect.width - 700) / 2;
|
||||
//边界检测
|
||||
var localPosition = attributes_tips.transform.localPosition;
|
||||
if (localPosition.x > limit)
|
||||
{
|
||||
localPosition.x = limit;
|
||||
}
|
||||
else if (localPosition.x < -limit)
|
||||
{
|
||||
localPosition.x = -limit;
|
||||
}
|
||||
attributes_tips.transform.localPosition = localPosition;
|
||||
attributes_tips.arrow.position = new Vector3(pos.x, attributes_tips.arrow.position.y);
|
||||
}
|
||||
public async void ShowPerk(int index, Transform perk, int addLevel = -1)
|
||||
{
|
||||
item_tips _item_tips = await item_tips.Show();
|
||||
if (_item_tips == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_item_tips.ShowPerk(data.config.ID, index, perk.position, addLevel);
|
||||
}
|
||||
|
||||
private Transform _rotateTarget;
|
||||
void StartDoRotate()
|
||||
{
|
||||
if (currentRod is null)
|
||||
{
|
||||
Debug.Log($"<color=#9858ad>Empty rod. No rod to rotate.</color>");
|
||||
return;
|
||||
}
|
||||
_rotateTarget = currentRod.transform.GetChild(0);
|
||||
var endRotation = _rotateTarget.localRotation.eulerAngles + new Vector3(0, 360, 0);
|
||||
_rotateTarget.DOKill();
|
||||
_rotateTarget.DOLocalRotate(endRotation, 10f, RotateMode.FastBeyond360).SetEase(Ease.Linear).SetLoops(-1);
|
||||
|
||||
}
|
||||
void OnDragRod(PointerEventData eventData)
|
||||
{
|
||||
_rotateTarget.Rotate(Vector3.up, -eventData.delta.x * speed);
|
||||
}
|
||||
void OnBeginDragCall()
|
||||
{
|
||||
_rotateTarget.DOKill();
|
||||
}
|
||||
|
||||
void SetPanelData()
|
||||
{
|
||||
curRodAscend = _tables.TbRodAscend.GetOrDefault(data.config.AscendID);
|
||||
TbRodOperatingStats rodOperatingStats = _tables.TbRodOperatingStats;
|
||||
var values = playerFishData.GetRodAttribute(data.config.ID)[0];
|
||||
var minDrawingHP = playerFishData.GetAscendValue(values, rodOperatingStats.MaxDrawingHP) / data.config.DisplayDamageSpeed;
|
||||
|
||||
text_damage_num.text = LocalizationMgr.GetFormatTextValue("RodBasicStatsDesc_DPH", minDrawingHP.ToString("F0"));
|
||||
text_info.text = LocalizationMgr.GetFormatTextValue("RodBasicStatsDesc_ATKSPD", data.config.DisplayDamageSpeed);
|
||||
|
||||
SetLevel();
|
||||
InitPearksData();
|
||||
SetBtnState();
|
||||
}
|
||||
|
||||
|
||||
public void Init()
|
||||
{
|
||||
this.rodItemDatas = upSystem.rodItemDatas;
|
||||
int index = upSystem.SelectIndex;
|
||||
OnClickItem(rodItemDatas[index]);
|
||||
}
|
||||
|
||||
|
||||
void OnClickItem(RodItemData rodItemData)
|
||||
{
|
||||
upSystem.SelectIndex = rodItemData.sort;
|
||||
|
||||
data = rodItemData;
|
||||
if (data.isNew)
|
||||
{
|
||||
data.isNew = false;
|
||||
GContext.container.Resolve<PlayerData>().RewardNewRod(data.config.ID);
|
||||
}
|
||||
skin = data.skin;
|
||||
if (config == null || config.ID != data.config.ID)
|
||||
{
|
||||
//加载鱼竿模型
|
||||
upSystem.bagPanel.avatar.gameObject.SetActive(false);
|
||||
loading.SetActive(false);
|
||||
LoadRodAsync(skin.Fbx);
|
||||
curRodAscend = _tables.TbRodAscend.GetOrDefault(data.config.AscendID);
|
||||
}
|
||||
|
||||
GContext.Publish(new VibrationData(HapticTypes.Selection));
|
||||
|
||||
config = data.config;
|
||||
IUIService uIService = GContext.container.Resolve<IUIService>();
|
||||
|
||||
if (skin != null)
|
||||
{
|
||||
text_name.text = LocalizationMgr.GetText(skin.Name_l10n_key);
|
||||
}
|
||||
|
||||
|
||||
uIService.SetImageSprite(title_image, sp_rod_title[config.Quality - 1], PanelName);
|
||||
|
||||
SetPanelData();
|
||||
SetLevelStar();
|
||||
|
||||
uIService.SetImageSprite(mask_bottom, sp_rod_bottom_mask[config.Quality - 1], PanelName);
|
||||
uIService.SetImageSprite(mask_top, sp_rod_top_mask[config.Quality - 1], PanelName);
|
||||
GameObject[] gameObjects = upSystem.bagPanel.fx_fishingrods;
|
||||
for (int i = 0; i < gameObjects.Length; i++)
|
||||
{
|
||||
gameObjects[i].SetActive(config.Quality - 2 == i);
|
||||
}
|
||||
}
|
||||
void InitRod(GameObject _currentRod, string fbx)
|
||||
{
|
||||
if (fbx == data.skin.Fbx && _currentRod != null)
|
||||
{
|
||||
if (currentRod != null)
|
||||
{
|
||||
currentRod.SetActive(false);
|
||||
}
|
||||
//加载鱼竿模型完成
|
||||
if (fishingRodInfoPanel != null)
|
||||
{
|
||||
fishingRodInfoPanel.SetLoading(false);
|
||||
}
|
||||
loading.SetActive(false);
|
||||
upSystem.bagPanel.avatar.gameObject.SetActive(true);
|
||||
currentRod = _currentRod;
|
||||
currentRod.transform.localPosition = new Vector3(skin.DisplayPosition[0], skin.DisplayPosition[1], skin.DisplayPosition[2]);
|
||||
currentRod.transform.localRotation = Quaternion.Euler(skin.DisplayRotation[0], skin.DisplayRotation[1], skin.DisplayRotation[2]);
|
||||
currentRod.transform.localScale = Vector3.one * skin.DisplayScale;
|
||||
currentRod.SetActive(true);
|
||||
RodBehaviour = currentRod.GetComponent<Rod>();
|
||||
RodBehaviour.rod.GetComponent<Animator>().Play("Show01");
|
||||
StartDoRotate();
|
||||
upSystem.bagPanel.avatar.DOKill();
|
||||
upSystem.bagPanel.avatar.localPosition = new Vector3(RodApperXOffset, 0, 0);
|
||||
upSystem.bagPanel.avatar.DOLocalMove(Vector3.zero, RodAppearTime);
|
||||
}
|
||||
}
|
||||
async void LoadRodAsync(string fbx)
|
||||
{
|
||||
GameObject _currentRod = null;
|
||||
if (rodAvatar.ContainsKey(fbx))
|
||||
{
|
||||
_currentRod = rodAvatar[fbx];
|
||||
}
|
||||
else
|
||||
{
|
||||
var prefab = await Addressables.LoadAssetAsync<GameObject>(fbx).Task;
|
||||
await Awaiters.NextFrame;
|
||||
if (rodAvatar.ContainsKey(fbx) || this == null)
|
||||
{
|
||||
Addressables.Release(prefab);
|
||||
_currentRod = rodAvatar[fbx];
|
||||
}
|
||||
else if (prefab != null)
|
||||
{
|
||||
rodPrefab.Add(prefab);
|
||||
var go = Instantiate(prefab, upSystem.bagPanel.avatar);
|
||||
rodAvatar.Add(fbx, go);
|
||||
go.SetActive(false);
|
||||
Rod rod = go.GetComponent<Rod>();
|
||||
if (data.isLock)
|
||||
{
|
||||
SkinnedMeshRenderer[] smr = rod.rod.GetComponentsInChildren<SkinnedMeshRenderer>();
|
||||
//替换所有材质
|
||||
foreach (var item in smr)
|
||||
{
|
||||
Material[] materials = item.materials;
|
||||
for (int i = 0; i < materials.Length; i++)
|
||||
{
|
||||
materials[i] = Rod_black;
|
||||
}
|
||||
item.materials = materials;
|
||||
}
|
||||
}
|
||||
|
||||
rod.cCDIK.enabled = false;
|
||||
_currentRod = go;
|
||||
}
|
||||
}
|
||||
if (fbx == skin.Fbx && _currentRod != null)
|
||||
{
|
||||
InitRod(_currentRod, fbx);
|
||||
}
|
||||
}
|
||||
|
||||
void SetBtnState()
|
||||
{
|
||||
bool isEquiped = data.config.ID == GContext.container.Resolve<PlayerData>().equipRodID;
|
||||
btn_equip_go.gameObject.SetActive(!isEquiped && !data.isLock);
|
||||
equipped.SetActive(isEquiped);
|
||||
if (data.isLock)
|
||||
{
|
||||
int fragment = GContext.container.Resolve<PlayerFishData>().GetRodPiece(curRodAscend.FragmentID);
|
||||
int rquiredFragments = curRodAscend.AscentTransformed[0];
|
||||
bool isCombine = fragment >= rquiredFragments;
|
||||
if (isCombine)
|
||||
{
|
||||
Item item = _tables.TbItem.GetOrDefault(curRodAscend.FragmentID);
|
||||
icon_ticket_combine.sprite = uIService.GetSprite(item.Icon);
|
||||
icon_cost_num_combine.text = $"{fragment}/{rquiredFragments}";
|
||||
}
|
||||
btn_waytoget_go.SetActive(!isCombine);
|
||||
btn_combine_go.SetActive(isCombine);
|
||||
}
|
||||
else
|
||||
{
|
||||
btn_waytoget_go.SetActive(false);
|
||||
btn_combine_go.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
foreach (var item in rodAvatar)
|
||||
{
|
||||
Destroy(item.Value);
|
||||
}
|
||||
for (int i = 0; i < rodPrefab.Count; i++)
|
||||
{
|
||||
Addressables.Release(rodPrefab[i]);
|
||||
}
|
||||
UIManager.Instance.DestroyUI(UITypes.FishingRodInfoPanel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user