备份CatanBuilding瘦身独立工程
This commit is contained in:
167
Assets/Scripts/UI/Rod/FishingAppearancePanel.cs
Normal file
167
Assets/Scripts/UI/Rod/FishingAppearancePanel.cs
Normal file
@@ -0,0 +1,167 @@
|
||||
using cfg;
|
||||
using asap.core;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using DG.Tweening;
|
||||
using GameCore;
|
||||
using game;
|
||||
|
||||
public class FishingAppearancePanel : MonoBehaviour
|
||||
{
|
||||
Tables _tables;
|
||||
|
||||
IconRodRoot icon_rod;
|
||||
RawImage rawImageRod;
|
||||
|
||||
GameObject loading;
|
||||
private Dictionary<string, GameObject> rodAvatar = new Dictionary<string, GameObject>();
|
||||
private List<GameObject> rodPrefab = new List<GameObject>();
|
||||
RodData config;
|
||||
RodSkinData skin;
|
||||
|
||||
GameObject currentRod;
|
||||
Rod RodBehaviour;
|
||||
ReviewNewRod reviewNewRod;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("FishingAppearancePanel");
|
||||
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
loading = transform.Find("root/loading").gameObject;
|
||||
rawImageRod = transform.Find("root/RawImageRod").GetComponent<RawImage>();
|
||||
icon_rod = transform.Find("root/icon_rod").GetComponent<IconRodRoot>();
|
||||
icon_rod.gameObject.SetActive(true);
|
||||
icon_rod.SetRawImage(rawImageRod);
|
||||
|
||||
reviewNewRod = transform.Find("root/new_rod").GetComponent<ReviewNewRod>();
|
||||
}
|
||||
|
||||
List<int> rodIds;
|
||||
public void ShowNewRod(List<ItemData> itemDatas)
|
||||
{
|
||||
this.rodIds = new List<int>();
|
||||
foreach (var item in itemDatas)
|
||||
{
|
||||
rodIds.Add(item.id);
|
||||
}
|
||||
rodIds.Sort();
|
||||
int id = rodIds[0];
|
||||
rodIds.RemoveAt(0);
|
||||
config = _tables.TbRodData.GetOrDefault(id);
|
||||
skin = _tables.TbRodSkinData.GetOrDefault(config.ID);
|
||||
reviewNewRod.SetCurData(config, NextNewRod);
|
||||
LoadRodAsync(skin.Fbx);
|
||||
}
|
||||
|
||||
public void NextNewRod()
|
||||
{
|
||||
if (rodIds.Count == 0)
|
||||
{
|
||||
UIManager.Instance.DestroyUI(UITypes.FishingAppearancePanel);
|
||||
GContext.Publish(new ShowData(RewardType.Destroy));
|
||||
return;
|
||||
}
|
||||
int id = rodIds[0];
|
||||
rodIds.RemoveAt(0);
|
||||
config = _tables.TbRodData.GetOrDefault(id);
|
||||
skin = _tables.TbRodSkinData.GetOrDefault(config.ID);
|
||||
reviewNewRod.gameObject.SetActive(true);
|
||||
reviewNewRod.SetCurData(config);
|
||||
LoadRodAsync(skin.Fbx);
|
||||
}
|
||||
|
||||
async void LoadRodAsync(string fbx)
|
||||
{
|
||||
GameObject _currentRod = null;
|
||||
if (rodAvatar.ContainsKey(fbx))
|
||||
{
|
||||
_currentRod = rodAvatar[fbx];
|
||||
}
|
||||
else
|
||||
{
|
||||
var prefab = await Addressables.LoadAssetAsync<GameObject>(fbx).Task;
|
||||
if (rodAvatar.ContainsKey(fbx) || this == null)
|
||||
{
|
||||
Addressables.Release(prefab);
|
||||
_currentRod = rodAvatar[fbx];
|
||||
}
|
||||
else if (prefab != null)
|
||||
{
|
||||
rodPrefab.Add(prefab);
|
||||
var go = Instantiate(prefab, icon_rod.avatar);
|
||||
rodAvatar.Add(fbx, go);
|
||||
go.SetActive(false);
|
||||
Rod rod = go.GetComponent<Rod>();
|
||||
rod.cCDIK.enabled = false;
|
||||
_currentRod = go;
|
||||
}
|
||||
}
|
||||
if (fbx == skin.Fbx && _currentRod != null)
|
||||
{
|
||||
InitRod(_currentRod, fbx);
|
||||
}
|
||||
}
|
||||
|
||||
void InitRod(GameObject _currentRod, string fbx)
|
||||
{
|
||||
icon_rod.avatar.gameObject.SetActive(false);
|
||||
loading.SetActive(true);
|
||||
if (fbx == skin.Fbx && _currentRod != null)
|
||||
{
|
||||
if (currentRod != null)
|
||||
{
|
||||
currentRod.SetActive(false);
|
||||
}
|
||||
//加载模型完成
|
||||
loading.SetActive(false);
|
||||
icon_rod.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");
|
||||
for (int i = 0; i < icon_rod.fx_fishingrods.Length; i++)
|
||||
{
|
||||
icon_rod.fx_fishingrods[i].SetActive(config.Quality - 2 == i);
|
||||
}
|
||||
StartDoRotate();
|
||||
}
|
||||
}
|
||||
|
||||
private Transform _rotateTarget;
|
||||
void StartDoRotate()
|
||||
{
|
||||
if (currentRod is null)
|
||||
{
|
||||
Debug.Log($"<color=#9858ad>Empty rod. No rod to rotate.</color>");
|
||||
return;
|
||||
}
|
||||
// Debug.Log($"<color=#9858ad>{currentRod.transform.GetChild(0).name}</color>");
|
||||
if (_rotateTarget != null)
|
||||
{
|
||||
_rotateTarget.DOKill();
|
||||
}
|
||||
_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);
|
||||
/*
|
||||
Debug.Log($"<color=#9858ad>Empty rod.</color>");
|
||||
Debug.Log($"<color=#9858ad>Empty rod.</color>");
|
||||
avatar.DOKill();
|
||||
avatar.DOLocalRotate(Vector3.up * (avatar.localEulerAngles.y + 360), 10f, RotateMode.FastBeyond360).SetEase(Ease.Linear).SetLoops(-1);
|
||||
*/
|
||||
}
|
||||
protected void OnDestroy()
|
||||
{
|
||||
for (int i = 0; i < rodPrefab.Count; i++)
|
||||
{
|
||||
Addressables.Release(rodPrefab[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user