备份CatanBuilding瘦身独立工程
This commit is contained in:
699
Assets/Scripts/UI/Grade/PlayerGradeAquariumPanel.cs
Normal file
699
Assets/Scripts/UI/Grade/PlayerGradeAquariumPanel.cs
Normal file
@@ -0,0 +1,699 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using game;
|
||||
using Game;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
public class InGradeAquariumEvent
|
||||
{
|
||||
public int type;
|
||||
}
|
||||
|
||||
public class PlayerGradeAquariumPanel : MonoBehaviour
|
||||
{
|
||||
IUIService uiService;
|
||||
Transform bg;
|
||||
Transform bgbg;
|
||||
Button btn_close;
|
||||
Button btn_location;
|
||||
Animation root_aquarium;
|
||||
CanvasGroup root_aquarium_canvasGroup;
|
||||
Animation root_fish;
|
||||
Transform iconRoot;
|
||||
TMP_Text bg_title;
|
||||
Button btn_questionmark_reward;
|
||||
Button btn_questionmark;
|
||||
GameObject info_tips;
|
||||
TMP_Text text_pts;
|
||||
Image bar;
|
||||
GameObject effect_jiman;
|
||||
RewardItemNew rewardItemNew;
|
||||
Transform claim;
|
||||
Button btn_claim;
|
||||
MapData mapData;
|
||||
GetCurSelectMapEvent getCurSelectMapEvent;
|
||||
PlayerFishData playerFishData;
|
||||
/// <summary>
|
||||
/// 鱼的模型
|
||||
/// </summary>
|
||||
ScrollRect scrollRect;
|
||||
Transform content;
|
||||
RectTransform viewport;
|
||||
List<GradeAquariumFishUI> gradeAquariumFishUIs;
|
||||
GradeAquariumFishUI curAquariumFishUI;
|
||||
Camera _camera;
|
||||
//模型存放节点
|
||||
Transform avatar;
|
||||
RenderTexture rt;
|
||||
private List<GameObject> fishPrefab = new List<GameObject>();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
UIDrag uiDrag;
|
||||
RawImage rawImage;
|
||||
CanvasGroup rawImageGroup;
|
||||
Transform model;
|
||||
Image icon_rate;
|
||||
TMP_Text text_name;
|
||||
TMP_Text info_text_weight;
|
||||
TMP_Text info_text_pts;
|
||||
TMP_Text text_tag1;
|
||||
TMP_Text text_tag2;
|
||||
TMP_Text text_detail;
|
||||
int AllPTS;
|
||||
int progress;
|
||||
|
||||
int rtWidth = 2048;
|
||||
int rtHeight = 4096;
|
||||
Vector3 rawImage2Size;
|
||||
public int fieldOfView = 60;
|
||||
//鱼距离相机的位置
|
||||
public int fishPosZ = 50;
|
||||
//特写时鱼距离相机的位置
|
||||
public int fishPosZ2 = 20;
|
||||
public float inTime = 0.7f;
|
||||
public float outTime = 0.7f;
|
||||
public float rewImageDOFadeTime = 0.7f;
|
||||
//左初始高度
|
||||
public float leftHeight = 217;
|
||||
//右初始高度
|
||||
public float rightHeight = 437;
|
||||
public float[] heights = new float[] { 400, 450, 500, 550, 600 };
|
||||
public float moveXLeft = 20;
|
||||
public float moveXRight = 40;
|
||||
//随机时间
|
||||
public float randomTime = 0.5f;
|
||||
//相机y轴旋转参数
|
||||
public float rotateY = 25;
|
||||
float leftAllHeight = 0;
|
||||
float rightAllHeight = 0;
|
||||
Transform curFishTran;
|
||||
FishData curFishData;
|
||||
//位移比例
|
||||
float scale = 0.5f;
|
||||
string DotweenId = "PlayerGradeAquariumPanel";
|
||||
bool enableFog;
|
||||
private void Awake()
|
||||
{
|
||||
uiService = GContext.container.Resolve<IUIService>();
|
||||
playerFishData = GContext.container.Resolve<PlayerFishData>();
|
||||
btn_questionmark = transform.Find("root/title/btn_questionmark").GetComponent<Button>();
|
||||
bg = transform.Find("bg");
|
||||
btn_close = transform.Find("root/btn_close").GetComponent<Button>();
|
||||
btn_location = transform.Find("root/title/btn_location").GetComponent<Button>();
|
||||
root_aquarium = transform.Find("root/root_aquarium").GetComponent<Animation>();
|
||||
root_aquarium_canvasGroup = root_aquarium.GetComponent<CanvasGroup>();
|
||||
root_fish = transform.Find("root/root_fish").GetComponent<Animation>();
|
||||
bg_title = transform.Find("root/title/text_title").GetComponent<TMP_Text>();
|
||||
btn_questionmark_reward = transform.Find("root/root_aquarium/reward/btn_questionmark").GetComponent<Button>();
|
||||
info_tips = transform.Find("root/root_aquarium/reward/info_tips").gameObject;
|
||||
text_pts = transform.Find("root/root_aquarium/reward/text_pts").GetComponent<TMP_Text>();
|
||||
bar = transform.Find("root/root_aquarium/reward/bg_bar/bar").GetComponent<Image>();
|
||||
effect_jiman = transform.Find("root/root_aquarium/reward/bg_bar/effect_jiman").gameObject;
|
||||
rewardItemNew = transform.Find("root/root_aquarium/reward/reward").GetComponent<RewardItemNew>();
|
||||
claim = transform.Find("root/root_aquarium/reward/reward/claim");
|
||||
btn_claim = claim.Find("effect_up_loop/claim/btn_common_green_c/btn_green_c").GetComponent<Button>();
|
||||
scrollRect = transform.Find("root/root_aquarium/ScrollView").GetComponent<ScrollRect>();
|
||||
viewport = transform.Find("root/root_aquarium/ScrollView/Viewport").GetComponent<RectTransform>();
|
||||
content = transform.Find("root/root_aquarium/ScrollView/Viewport/Content");
|
||||
gradeAquariumFishUIs = new List<GradeAquariumFishUI>();
|
||||
for (int i = 1; i < 13; i++)
|
||||
{
|
||||
gradeAquariumFishUIs.Add(content.Find($"Item{i}").GetComponent<GradeAquariumFishUI>());
|
||||
}
|
||||
|
||||
model = transform.Find("root/ScrollView/Viewport/model");
|
||||
icon_rate = transform.Find("root/root_fish/icon_rate").GetComponent<Image>();
|
||||
text_name = transform.Find("root/root_fish/text_name").GetComponent<TMP_Text>();
|
||||
info_text_weight = transform.Find("root/root_fish/info/text_weight").GetComponent<TMP_Text>();
|
||||
info_text_pts = transform.Find("root/root_fish/info/text_pts").GetComponent<TMP_Text>();
|
||||
text_tag1 = transform.Find("root/root_fish/layout_tag/tag1/text_tag1").GetComponent<TMP_Text>();
|
||||
text_tag2 = transform.Find("root/root_fish/layout_tag/tag2/text_tag2").GetComponent<TMP_Text>();
|
||||
text_detail = transform.Find("root/root_fish/text_detail").GetComponent<TMP_Text>();
|
||||
|
||||
rawImage = transform.Find("root/Viewport/RawImage").GetComponent<RawImage>();
|
||||
uiDrag = rawImage.transform.GetComponent<UIDrag>();
|
||||
rawImageGroup = rawImage.GetComponent<CanvasGroup>();
|
||||
rawImage2Size = rawImage.rectTransform.rect.size;
|
||||
rtWidth = (int)rawImage2Size.x;
|
||||
rtHeight = (int)rawImage2Size.y;
|
||||
|
||||
iconRoot = transform.Find("IconRoot");
|
||||
avatar = transform.Find("IconRoot/Avatar");
|
||||
_camera = transform.Find("IconRoot/Camera").GetComponent<Camera>();
|
||||
|
||||
rt = new RenderTexture(rtWidth, rtHeight, 24, RenderTextureFormat.ARGB32);
|
||||
_camera.targetTexture = rt;
|
||||
_camera.Render();
|
||||
rawImage.texture = rt;
|
||||
enableFog = RenderSettings.fog;
|
||||
RenderSettings.fog = false;
|
||||
GContext.Publish(new InGradeAquariumEvent());
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_camera.fieldOfView = fieldOfView;
|
||||
root_aquarium.gameObject.SetActive(true);
|
||||
root_fish.gameObject.SetActive(false);
|
||||
info_tips.SetActive(false);
|
||||
getCurSelectMapEvent = new GetCurSelectMapEvent();
|
||||
getCurSelectMapEvent.type = 0;
|
||||
GContext.Publish(getCurSelectMapEvent);
|
||||
mapData = getCurSelectMapEvent.selectMap;
|
||||
bgbg = transform.Find($"bg/{mapData.AquariumBg}");
|
||||
bgbg.gameObject.SetActive(true);
|
||||
AllPTS = playerFishData.GetAllPTSByMap(mapData.ID);
|
||||
InitFishAvatar();
|
||||
InitBar();
|
||||
bg_title.text = $"{mapData.ID % 100}.{LocalizationMgr.GetText(mapData.Name_l10n_key)}";
|
||||
btn_questionmark.onClick.AddListener(OpenQuestionmark);
|
||||
btn_close.onClick.AddListener(OnClickClose);
|
||||
btn_location.onClick.AddListener(OnClickClose);
|
||||
btn_claim.onClick.AddListener(OnClickClaim);
|
||||
btn_questionmark_reward.onClick.AddListener(() =>
|
||||
{
|
||||
info_tips.SetActive(!info_tips.activeSelf);
|
||||
});
|
||||
rewardItemNew.btn_click.onClick.AddListener(HideTips);
|
||||
uiDrag.OnDragCall += OnDragFishing;
|
||||
rawImageGroup.alpha = 0;
|
||||
rawImageGroup.DOFade(1, rewImageDOFadeTime);
|
||||
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide(name);
|
||||
}
|
||||
async void OpenQuestionmark()
|
||||
{
|
||||
GameObject go = await UIManager.Instance.ShowUI(UITypes.PlayerGradeAquariumInfoPanel);
|
||||
PlayerGradeAquariumInfoPanel playerGradeAquariumInfoPanel = go.GetComponent<PlayerGradeAquariumInfoPanel>();
|
||||
int dorpID = mapData.PointsReward[0];
|
||||
playerGradeAquariumInfoPanel.Init(dorpID);
|
||||
}
|
||||
void InitCameraPos()
|
||||
{
|
||||
Vector3 posWorld = UIToWorldPoint(new Vector3(0, 1000, 0), rawImage2Size);
|
||||
scale = -posWorld.y / 1000;
|
||||
SetCameraPos();
|
||||
scrollRect.onValueChanged.AddListener((v) =>
|
||||
{
|
||||
SetCameraPos();
|
||||
});
|
||||
}
|
||||
void SetCameraPos()
|
||||
{
|
||||
_camera.transform.position = new Vector3(0, scale * content.localPosition.y, 0);
|
||||
}
|
||||
void OnDragFishing(PointerEventData eventData)
|
||||
{
|
||||
if (curFishTran != null)
|
||||
{
|
||||
curFishTran.Rotate(Vector3.up, -eventData.delta.x * 0.5f);
|
||||
}
|
||||
}
|
||||
void InitFishAvatar()
|
||||
{
|
||||
iconRoot.localScale = Vector3.one / iconRoot.lossyScale.x;
|
||||
iconRoot.position = new Vector3(0, 0, 0);
|
||||
viewport.pivot = new Vector2(0.5f, 0.5f);
|
||||
RectTransform contentRect = content.GetComponent<RectTransform>();
|
||||
contentRect.pivot = new Vector2(0.5f, 0.5f);
|
||||
//rawImage2.color = Color.clear;
|
||||
//显示当前地图的鱼
|
||||
var fishes = mapData.FishList;
|
||||
var count = fishes.Count;
|
||||
var Tables = GContext.container.Resolve<Tables>();
|
||||
bool isLeft = false, isRight = false;
|
||||
float curHigh = 0;
|
||||
RectTransform fishRectTransform;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
FishData fishData = Tables.TbFishData.GetOrDefault(fishes[i]);
|
||||
gradeAquariumFishUIs[i].SetData(fishData, i);
|
||||
if (fishData.Quality > heights.Length)
|
||||
{
|
||||
curHigh = heights[^1];
|
||||
}
|
||||
else
|
||||
{
|
||||
curHigh = heights[fishData.Quality - 1];
|
||||
}
|
||||
fishRectTransform = gradeAquariumFishUIs[i].GetComponent<RectTransform>();
|
||||
float posX = fishRectTransform.anchoredPosition.x;
|
||||
if (gradeAquariumFishUIs[i].fishDirection == GradeAquariumFishUI.FishDirection.Left)
|
||||
{
|
||||
if (!isLeft)
|
||||
{
|
||||
isLeft = true;
|
||||
fishRectTransform.anchoredPosition = new Vector2(posX, -leftHeight);
|
||||
leftAllHeight = leftHeight + curHigh / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
fishRectTransform.anchoredPosition = new Vector2(posX, -leftAllHeight - curHigh / 2);
|
||||
leftAllHeight += curHigh;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isRight)
|
||||
{
|
||||
isRight = true;
|
||||
fishRectTransform.anchoredPosition = new Vector2(posX, -rightHeight);
|
||||
rightAllHeight = rightHeight + curHigh / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
fishRectTransform.anchoredPosition = new Vector2(posX, -rightAllHeight - curHigh / 2);
|
||||
rightAllHeight += curHigh;
|
||||
}
|
||||
}
|
||||
int index = i;
|
||||
gradeAquariumFishUIs[i].button.onClick.AddListener(() =>
|
||||
{
|
||||
HideTips();
|
||||
SetFishDetail(index);
|
||||
});
|
||||
}
|
||||
|
||||
contentRect.sizeDelta = new Vector2(contentRect.sizeDelta.x, Mathf.Max(leftAllHeight, rightAllHeight));
|
||||
scrollRect.verticalNormalizedPosition = 1f;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
LoadAvatar(gradeAquariumFishUIs[i]);
|
||||
}
|
||||
InitCameraPos();
|
||||
}
|
||||
void SetFishDetail(int index)
|
||||
{
|
||||
btn_close.onClick.RemoveAllListeners();
|
||||
curAquariumFishUI = gradeAquariumFishUIs[index];
|
||||
curFishData = curAquariumFishUI.fishData;
|
||||
text_name.text = curAquariumFishUI.text_name.text;
|
||||
info_text_weight.text = curAquariumFishUI.text_weight.text;
|
||||
info_text_pts.text = curAquariumFishUI.text_pts.text;
|
||||
text_detail.text = LocalizationMgr.GetText(curFishData.Story_l10n_key);
|
||||
text_tag1.text = LocalizationMgr.GetText(curFishData.VerticalDistribution.ToString());
|
||||
text_tag2.text = LocalizationMgr.GetText(curFishData.Categories.ToString());
|
||||
uiService.SetImageSprite(icon_rate, $"icon_fish_rate_tag_{curFishData.Quality}", BasePanel.PanelName);
|
||||
PlayDetail();
|
||||
}
|
||||
async void PlayDetail()
|
||||
{
|
||||
ShowFish(true);
|
||||
scrollRect.enabled = false;
|
||||
Vector3 pos = curAquariumFishUI.AvatarPos.localPosition;
|
||||
Vector3 offsetPos = curAquariumFishUI.model.position;
|
||||
root_fish.gameObject.SetActive(true);
|
||||
root_aquarium_canvasGroup.blocksRaycasts = false;
|
||||
root_aquarium.Play("root_out");
|
||||
root_fish.Play("root_show");
|
||||
float zOffset = fishPosZ - fishPosZ2;
|
||||
float xOffset = Mathf.Tan(rotateY * Mathf.Deg2Rad) * zOffset;
|
||||
if (curAquariumFishUI.fishDirection == GradeAquariumFishUI.FishDirection.Left)
|
||||
{
|
||||
pos.x += xOffset;
|
||||
_camera.transform.DOLocalRotate(new Vector3(0, -rotateY, 0), inTime).SetEase(Ease.Linear);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos.x -= xOffset;
|
||||
_camera.transform.DOLocalRotate(new Vector3(0, rotateY, 0), inTime).SetEase(Ease.Linear);
|
||||
}
|
||||
_camera.transform.DOLocalMove(new Vector3(pos.x, pos.y, fishPosZ2), inTime).SetEase(Ease.Linear);
|
||||
bg.transform.DOScale(Vector3.one * 1.5f, inTime).SetEase(Ease.Linear);
|
||||
bgbg.transform.DOLocalMove(bg.position - offsetPos, inTime).SetEase(Ease.Linear);
|
||||
await new WaitForSeconds(inTime);
|
||||
root_aquarium.gameObject.SetActive(false);
|
||||
btn_close.onClick.AddListener(CloseDetail);
|
||||
if (curAquariumFishUI.FishGo)
|
||||
{
|
||||
curFishTran = curAquariumFishUI.FishGo.transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
curFishTran = null;
|
||||
}
|
||||
}
|
||||
void ShowFish(bool isOut)
|
||||
{
|
||||
int index = curAquariumFishUI.index;
|
||||
if (isOut)
|
||||
{
|
||||
GContext.Publish(new EventUISound("audio_ui_whoosh_in"));
|
||||
|
||||
for (int i = 0; i < gradeAquariumFishUIs.Count; i++)
|
||||
{
|
||||
if (i != index)
|
||||
{
|
||||
GradeAquariumFishUI gradeAquariumFishUI = gradeAquariumFishUIs[i];
|
||||
bool isLeft = gradeAquariumFishUI.fishDirection == 0;
|
||||
float moveX = isLeft ? moveXLeft : moveXRight;
|
||||
float moveX2 = isLeft ? moveXRight : moveXLeft;
|
||||
if (gradeAquariumFishUI.FishGo != null)
|
||||
{
|
||||
Transform fishTrans = gradeAquariumFishUI.FishGo.transform;
|
||||
fishTrans.DOLocalMoveX(-moveX, inTime).OnComplete(() =>
|
||||
{
|
||||
fishTrans.localPosition = Vector3.right * moveX2;
|
||||
}).SetEase(Ease.OutSine).SetDelay(Random.Range(0, randomTime)).SetId(DotweenId);
|
||||
if (gradeAquariumFishUI.isAvatar)
|
||||
{
|
||||
gradeAquariumFishUI.FishGo.animator.SetTrigger("Swim01");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GContext.Publish(new EventUISound("audio_ui_whoosh_out"));
|
||||
|
||||
for (int i = 0; i < gradeAquariumFishUIs.Count; i++)
|
||||
{
|
||||
if (i != index)
|
||||
{
|
||||
GradeAquariumFishUI gradeAquariumFishUI = gradeAquariumFishUIs[i];
|
||||
if (gradeAquariumFishUI.FishGo != null)
|
||||
{
|
||||
gradeAquariumFishUI.FishGo.transform.DOLocalMoveX(0, outTime).
|
||||
OnComplete(() =>
|
||||
{
|
||||
if (gradeAquariumFishUI.isAvatar)
|
||||
{
|
||||
gradeAquariumFishUI.FishGo.animator.SetTrigger("Show01");
|
||||
}
|
||||
}).SetEase(Ease.OutSine).SetDelay(Random.Range(0, randomTime)).SetId(DotweenId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async void CloseDetail()
|
||||
{
|
||||
ShowFish(false);
|
||||
Quaternion rot = Quaternion.Euler(curFishData.TankRotation[0], curFishData.TankRotation[1], curFishData.TankRotation[2]);
|
||||
if (curFishTran != null)
|
||||
{
|
||||
curFishTran.DORotateQuaternion(rot, outTime);
|
||||
curFishTran = null;
|
||||
}
|
||||
root_aquarium.gameObject.SetActive(true);
|
||||
btn_close.onClick.RemoveAllListeners();
|
||||
_camera.transform.DOLocalRotate(Vector3.zero, outTime).SetEase(Ease.Linear);
|
||||
_camera.transform.DOLocalMove(new Vector3(0, scale * content.localPosition.y, 0), outTime).SetEase(Ease.Linear);
|
||||
bg.transform.DOScale(Vector3.one, outTime).SetEase(Ease.Linear);
|
||||
bgbg.transform.DOLocalMove(Vector3.zero, outTime).SetEase(Ease.Linear);
|
||||
root_aquarium.Play("root_show");
|
||||
root_fish.Play("root_out");
|
||||
await new WaitForSeconds(outTime);
|
||||
root_fish.gameObject.SetActive(false);
|
||||
btn_close.onClick.AddListener(OnClickClose);
|
||||
scrollRect.enabled = true;
|
||||
curAquariumFishUI = null;
|
||||
root_aquarium_canvasGroup.blocksRaycasts = true;
|
||||
}
|
||||
async void LoadAvatar(GradeAquariumFishUI gradeAquariumFishUI)
|
||||
{
|
||||
FishData fishData = gradeAquariumFishUI.fishData;
|
||||
bool isAvatar = gradeAquariumFishUI.isAvatar;
|
||||
//先计算位置,以免查看详情时,模型位置不对
|
||||
Vector3 pos = gradeAquariumFishUI.FishModelPos();
|
||||
Vector3 posWorld = UIToWorldPoint(pos, rawImage2Size);
|
||||
Transform avatarPos = new GameObject(fishData.Fbx).transform;
|
||||
avatarPos.SetParent(avatar);
|
||||
posWorld.x += fishData.TankPosition[0];
|
||||
posWorld.y += fishData.TankPosition[1];
|
||||
posWorld.z += fishData.TankPosition[2];
|
||||
avatarPos.localPosition = posWorld;
|
||||
avatarPos.localScale = Vector3.one;
|
||||
avatarPos.localRotation = Quaternion.identity;
|
||||
gradeAquariumFishUI.AvatarPos = avatarPos;
|
||||
var goPrefab = await Addressables.LoadAssetAsync<GameObject>(fishData.Fbx).Task;
|
||||
if (rt == null)
|
||||
{
|
||||
Addressables.Release(goPrefab);
|
||||
}
|
||||
else if (goPrefab != null)
|
||||
{
|
||||
fishPrefab.Add(goPrefab);
|
||||
var go = Instantiate(goPrefab, avatarPos);
|
||||
Fish fish = go.GetComponent<Fish>();
|
||||
fish.animator.transform.localPosition = Vector3.zero;
|
||||
go.transform.rotation = Quaternion.Euler(fishData.TankRotation[0], fishData.TankRotation[1], fishData.TankRotation[2]);
|
||||
go.transform.localScale = Vector3.one * fishData.TankScale;
|
||||
gradeAquariumFishUI.loading.SetActive(false);
|
||||
gradeAquariumFishUI.FishGo = fish;
|
||||
gradeAquariumFishUI.button.enabled = true;
|
||||
|
||||
//游入场中
|
||||
bool isLeft = gradeAquariumFishUI.fishDirection == 0;
|
||||
float moveX2 = isLeft ? moveXRight : moveXLeft;
|
||||
go.transform.localPosition = Vector3.right * moveX2;
|
||||
go.transform.DOLocalMoveX(0, outTime).OnComplete(() =>
|
||||
{
|
||||
if (isAvatar)
|
||||
{
|
||||
fish.animator.SetTrigger("Show01");
|
||||
}
|
||||
}).SetEase(Ease.OutSine).SetDelay(Random.Range(0, randomTime)).SetId(DotweenId);
|
||||
|
||||
if (!isAvatar)
|
||||
{
|
||||
fish.animator.speed = 0;
|
||||
Renderer[] meshRenderer = go.GetComponentsInChildren<Renderer>();
|
||||
if (meshRenderer != null && meshRenderer.Length > 0)
|
||||
{
|
||||
var render = meshRenderer[0];
|
||||
var materials = render.materials;
|
||||
for (int i = 0; i < materials.Length; i++)
|
||||
{
|
||||
var material = new Material(materials[i]);
|
||||
material.SetColor("_BaseColor", Color.black);
|
||||
material.SetFloat("_Smoothness", 0);
|
||||
materials[i] = material;
|
||||
}
|
||||
render.materials = materials;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
string Mode = "prop_buckethat";
|
||||
string Bone = "Head";
|
||||
string FishAnimationName = "Swim01";
|
||||
bool isShowMode = false;
|
||||
private void OnGUI()
|
||||
{
|
||||
int fontSize = 40; // Replace with your desired font size
|
||||
|
||||
// Set the font size for text fields, buttons, and labels
|
||||
GUI.skin.textField.fontSize = fontSize;
|
||||
GUI.skin.button.fontSize = fontSize;
|
||||
GUI.skin.label.fontSize = fontSize;
|
||||
GUILayout.Label("Mode:");
|
||||
Mode = GUILayout.TextField(Mode);
|
||||
GUILayout.Label("Bone:");
|
||||
Bone = GUILayout.TextField(Bone);
|
||||
if (GUILayout.Button("ShowMode"))
|
||||
{
|
||||
ShowMode();
|
||||
}
|
||||
FishAnimationName = GUILayout.TextField(FishAnimationName);
|
||||
if (GUILayout.Button("FishAnimation"))
|
||||
{
|
||||
FishAnimation();
|
||||
}
|
||||
}
|
||||
async void ShowMode()
|
||||
{
|
||||
if (isShowMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
isShowMode = true;
|
||||
string mode = Mode;
|
||||
string bone = Bone;
|
||||
var modego = await Addressables.LoadAssetAsync<GameObject>(mode).Task;
|
||||
var _tables = GContext.container.Resolve<Tables>();
|
||||
if (modego != null)
|
||||
{
|
||||
Debug.Log("ShowMode Bone");
|
||||
for (int i = 0; i < gradeAquariumFishUIs.Count; i++)
|
||||
{
|
||||
var modeGo = Instantiate(modego);
|
||||
GradeAquariumFishUI gradeAquariumFishUI = gradeAquariumFishUIs[i];
|
||||
var dropAfterDropParent = gradeAquariumFishUI.FishGo.Find(bone);
|
||||
CollectingPropScale collectingPropScale = _tables.TbCollectingPropScale[gradeAquariumFishUI.fishData.Quality];
|
||||
var eulerAngles = modeGo.transform.localEulerAngles;
|
||||
var localPosition = modeGo.transform.localPosition;
|
||||
modeGo.transform.SetParent(dropAfterDropParent);
|
||||
modeGo.transform.localScale *= collectingPropScale.Scale * 4.25f;
|
||||
modeGo.transform.localEulerAngles = eulerAngles;
|
||||
modeGo.transform.localPosition = localPosition;
|
||||
}
|
||||
}
|
||||
Debug.Log("ShowMode");
|
||||
|
||||
Addressables.Release(modego);
|
||||
isShowMode = false;
|
||||
}
|
||||
void FishAnimation()
|
||||
{
|
||||
for (int i = 0; i < gradeAquariumFishUIs.Count; i++)
|
||||
{
|
||||
GradeAquariumFishUI gradeAquariumFishUI = gradeAquariumFishUIs[i];
|
||||
if (gradeAquariumFishUI != null && gradeAquariumFishUI.FishGo != null)
|
||||
{
|
||||
gradeAquariumFishUI.FishGo.animator.Play(FishAnimationName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.UpArrow))
|
||||
{
|
||||
LocalizationMgr.SetLanguageAsync((LocalizationMgr.LanguageIndex - 1 + LocalizationMgr.enumLanguage.Count) % LocalizationMgr.enumLanguage.Count);
|
||||
OnClickClose();
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.DownArrow))
|
||||
{
|
||||
LocalizationMgr.SetLanguageAsync((LocalizationMgr.LanguageIndex + 1) % LocalizationMgr.enumLanguage.Count);
|
||||
OnClickClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Vector3 UIToWorldPoint(Vector3 pos, Vector3 pos2)
|
||||
{
|
||||
pos.x += pos2.x * 0.5f;
|
||||
pos.y += pos2.y * 0.5f;
|
||||
pos.z = fishPosZ;
|
||||
Vector3 targetPos = _camera.ScreenToWorldPoint(pos);
|
||||
return targetPos;
|
||||
}
|
||||
void InitBar()
|
||||
{
|
||||
progress = playerFishData.GetMapProgress(mapData.ID);
|
||||
bool isMax = progress >= mapData.PointsRequire.Count;
|
||||
if (isMax)
|
||||
{
|
||||
OnProgressMax();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnProgress();
|
||||
}
|
||||
}
|
||||
|
||||
void OnProgress()
|
||||
{
|
||||
int pointsRequire = mapData.PointsRequire[progress];
|
||||
claim.gameObject.SetActive(AllPTS >= pointsRequire);
|
||||
text_pts.text = $"{AllPTS}/{pointsRequire}";
|
||||
if (AllPTS >= pointsRequire)
|
||||
{
|
||||
bar.fillAmount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bar.fillAmount = (float)AllPTS / pointsRequire;
|
||||
}
|
||||
int dorpID = mapData.PointsReward[progress];
|
||||
ItemData drop = GContext.container.Resolve<PlayerItemData>().GetItemDataOne(dorpID);
|
||||
rewardItemNew.SetData(drop);
|
||||
}
|
||||
void OnProgressMax()
|
||||
{
|
||||
int pointsRequire = mapData.PointsRequire[^1];
|
||||
claim.gameObject.SetActive(false);
|
||||
text_pts.text = $"{pointsRequire}/{pointsRequire}";
|
||||
bar.fillAmount = 1;
|
||||
|
||||
int dorpID = mapData.PointsReward[^1];
|
||||
ItemData drop = GContext.container.Resolve<PlayerItemData>().GetItemDataOne(dorpID);
|
||||
rewardItemNew.SetData(drop);
|
||||
}
|
||||
void HideTips()
|
||||
{
|
||||
info_tips.SetActive(false);
|
||||
}
|
||||
async void OnClickClaim()
|
||||
{
|
||||
HideTips();
|
||||
playerFishData.GetMapProgressReward(mapData);
|
||||
claim.gameObject.SetActive(false);
|
||||
effect_jiman.gameObject.SetActive(false);
|
||||
btn_close.enabled = false;
|
||||
await rewardItemNew.ParticleAttractor();
|
||||
GContext.Publish(new ShowData());
|
||||
await SetBarUp();
|
||||
btn_close.enabled = true;
|
||||
}
|
||||
|
||||
async System.Threading.Tasks.Task SetBarUp()
|
||||
{
|
||||
progress = playerFishData.GetMapProgress(mapData.ID);
|
||||
bool isMax = progress >= mapData.PointsRequire.Count;
|
||||
if (isMax)
|
||||
{
|
||||
OnProgressMax();
|
||||
}
|
||||
else
|
||||
{
|
||||
int pointsRequire = mapData.PointsRequire[progress];
|
||||
int dorpID = mapData.PointsReward[progress];
|
||||
ItemData drop = GContext.container.Resolve<PlayerItemData>().GetItemDataOne(dorpID);
|
||||
rewardItemNew.SetData(drop);
|
||||
bar.DOKill();
|
||||
bar.fillAmount = 0;
|
||||
text_pts.text = $"{AllPTS}/{pointsRequire}";
|
||||
if (AllPTS >= pointsRequire)
|
||||
{
|
||||
bar.DOFillAmount(1, 0.5f);
|
||||
effect_jiman.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
bar.DOFillAmount((float)AllPTS / pointsRequire, 0.5f);
|
||||
}
|
||||
await new WaitForSeconds(0.5f);
|
||||
claim.gameObject.SetActive(AllPTS >= pointsRequire);
|
||||
}
|
||||
}
|
||||
void OnClickClose()
|
||||
{
|
||||
bar.DOKill();
|
||||
getCurSelectMapEvent.type = 1;
|
||||
GContext.Publish(getCurSelectMapEvent);
|
||||
UIManager.Instance.DestroyUI(UITypes.PlayerGradeAquariumPanel);
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
DOTween.Kill(DotweenId);
|
||||
if (enableFog)
|
||||
{
|
||||
RenderSettings.fog = true;
|
||||
}
|
||||
GContext.Publish(new InGradeAquariumEvent() { type = 1 });
|
||||
if (rt != null)
|
||||
{
|
||||
rt.Release();
|
||||
Destroy(rt);
|
||||
rt = null;
|
||||
}
|
||||
for (int i = 0; i < fishPrefab.Count; i++)
|
||||
{
|
||||
Addressables.Release(fishPrefab[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user