Files
bansonic_beta_main/Assets/scripts/UI/Panel/UI_Panel_Character.cs
T
FloatGaming 1d818fa4eb 整合包
gameplay bundle has been imported together
2025-08-09 18:29:32 +08:00

121 lines
4.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* FancyScrollView (https://github.com/setchi/FancyScrollView)
* Copyright (c) 2020 setchi
* Licensed under MIT (https://github.com/setchi/FancyScrollView/blob/master/LICENSE)
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
class UI_Panel_Character : MonoBehaviour
{
[SerializeField] float anim_Time = 0.5f;
float Anim_Speed => 1f / anim_Time;
[SerializeField] List<Animator> ui_Anim;
[SerializeField] Transform content_Character_Slot;
[SerializeField] Button button_Character_Slot_Prefab;
[SerializeField] Text text_Character_Name;
[SerializeField] Image Image_Character_Illustration;
[SerializeField] Image Image_Character_Illustration_BG;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
gameObject.SetActive(false);
}
}
void Start()
{
if (Image_Character_Illustration.transform.parent.TryGetComponent(out CanvasGroup canvasGroup))
{
canvasGroup.alpha = 0;
}
else if(canvasGroup == null)
{
//Debug.LogError("Error for getting canvas group");
return;
}
foreach (var item in ui_Anim)
{
item.speed = Anim_Speed;
}
content_Character_Slot.Get_Childrens_Component<UI_Button_Character_Head_Slot>(true, true);
for (int i = 0; i < UI_Panel_Main.Singleton.Data_List.Count; i++)
{
var obj = Instantiate(button_Character_Slot_Prefab, content_Character_Slot);
var data = UI_Panel_Main.Singleton.Data_List[i];
obj.image.sprite = data.Image_Head;
if (obj.TryGetComponent(out UI_Button_Character_Head_Slot head_Slot))
{
head_Slot.index = data.index;
obj.onClick.AddListener(() => Set_Character_Index(head_Slot.index));
}
}
}
public void Set_Character_Index(int index)
{
if (UI_Panel_Main.Singleton.Character_Index == index) return;
UI_Panel_Main.Singleton.Character_Index = index;
Set_Character();
}
private void OnEnable()
{
Set_Character();
}
Coroutine c_Character_Illustration_Anim;
public void Set_Character()
{
if (c_Character_Illustration_Anim != null)
{
StopCoroutine(c_Character_Illustration_Anim);
}
if (Image_Character_Illustration.transform.parent.TryGetComponent(out CanvasGroup canvasGroup))
{
c_Character_Illustration_Anim = StartCoroutine(C_Character_Illustration_Anim(canvasGroup, Set_Character_Show));
}
}
public void Set_Character_Show()
{
var data = UI_Panel_Main.Singleton.Get_Character_Image_Data();
var pos1 = Image_Character_Illustration.rectTransform.anchoredPosition;
Image_Character_Illustration.sprite = data.Image_Full;
DOTween.To(value =>
{ Image_Character_Illustration.rectTransform.anchoredPosition = new Vector2(value, pos1.y); },
startValue: Image_Character_Illustration.rectTransform.anchoredPosition.x - 200,
pos1.x, anim_Time);
Image_Character_Illustration.SetNativeSize();
var pos = Image_Character_Illustration_BG.rectTransform.anchoredPosition;
Image_Character_Illustration_BG.sprite = data.Image_Full;
DOTween.To(value =>
{ Image_Character_Illustration_BG.rectTransform.anchoredPosition = new Vector2(value, pos.y); },
startValue: Image_Character_Illustration_BG.rectTransform.anchoredPosition.x - 200,
pos.x, anim_Time);
Image_Character_Illustration_BG.SetNativeSize();
Image_Character_Illustration_BG.transform.localScale = new(2.7f, 2.7f, 2.7f);
string text = text_Character_Name.text;
var t = DOTween.To(() => string.Empty, value => text_Character_Name.text = value, text, anim_Time).SetEase(Ease.Linear);
t.SetOptions(true);
}
IEnumerator C_Character_Illustration_Anim(CanvasGroup canvasGroup, Action onHide)
{
while (canvasGroup.alpha > 0)
{
canvasGroup.alpha -= Anim_Speed * Time.deltaTime;
yield return null;
}
onHide?.Invoke();
while (canvasGroup.alpha < 1)
{
canvasGroup.alpha += Anim_Speed * Time.deltaTime;
yield return null;
}
}
}