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; public float RodApperXOffset = -0.5f; public float RodAppearTime = 0.2f; IconRodRoot icon_rod; RawImage rawImageRod; GameObject loading; private Dictionary rodAvatar = new Dictionary(); private List rodPrefab = new List(); RodData config; RodSkinData skin; GameObject currentRod; Rod RodBehaviour; ReviewNewRod reviewNewRod; private void Awake() { GContext.container.Resolve().InspectTriggerGuide("FishingAppearancePanel"); _tables = GContext.container.Resolve(); loading = transform.Find("root/loading").gameObject; rawImageRod = transform.Find("root/RawImageRod").GetComponent(); icon_rod = transform.Find("root/icon_rod").GetComponent(); icon_rod.gameObject.SetActive(true); icon_rod.SetRawImage(rawImageRod); reviewNewRod = transform.Find("root/new_rod").GetComponent(); } List rodIds; public void ShowNewRod(List itemDatas) { this.rodIds = new List(); 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(fbx).Task; if (this == null) { Addressables.Release(prefab); return; } if (rodAvatar.ContainsKey(fbx)) { 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.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(); RodBehaviour.rod.GetComponent().Play("Show01"); for (int i = 0; i < icon_rod.fx_fishingrods.Length; i++) { icon_rod.fx_fishingrods[i].SetActive(config.Quality - 2 == i); } StartDoRotate(); icon_rod.avatar.DOKill(); icon_rod.avatar.localPosition = new Vector3(RodApperXOffset, 0, 0); icon_rod.avatar.DOLocalMove(Vector3.zero, RodAppearTime); } } private Transform _rotateTarget; void StartDoRotate() { if (currentRod is null) { Debug.Log($"Empty rod. No rod to rotate."); return; } // Debug.Log($"{currentRod.transform.GetChild(0).name}"); 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($"Empty rod."); Debug.Log($"Empty rod."); 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]); } } }