养成基本完毕,新UI,修bug,装备初步,
This commit is contained in:
@@ -0,0 +1,281 @@
|
||||
using System;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class deSkillPrefab : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
[Header("basic")]
|
||||
public Image skillIcon;
|
||||
public Image skillIcon_btm;
|
||||
public Text skillName;
|
||||
public Button skillButton;
|
||||
|
||||
[Header("details")]
|
||||
public GameObject detailsPanel;
|
||||
public GameObject specialIconObj;
|
||||
|
||||
[Header("detailPanel")]
|
||||
public Image deSkillIcon;
|
||||
public Text details_skillName;
|
||||
public Text details_skillDes;
|
||||
public Toggle skill_enable;
|
||||
public Toggle skill_equip;
|
||||
public Text skill_enableText;
|
||||
public Text skill_equipText;
|
||||
|
||||
[Header("bool")]
|
||||
public bool display_DP_ungotten;
|
||||
|
||||
private Action clickAction;
|
||||
private CanvasGroup detailCanvasGroup;
|
||||
private Tween hoverDelayTween;
|
||||
private Material originalSkillIconMaterial;
|
||||
private Material originalDetailSkillIconMaterial;
|
||||
private bool useHoverToShowDetails;
|
||||
private bool canShowDetailsOnHover;
|
||||
private bool showDetailsImmediately;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (skillButton == null)
|
||||
{
|
||||
skillButton = GetComponent<Button>();
|
||||
}
|
||||
|
||||
if (skillButton != null)
|
||||
{
|
||||
skillButton.onClick.RemoveListener(HandleClick);
|
||||
skillButton.onClick.AddListener(HandleClick);
|
||||
}
|
||||
|
||||
if (skill_enableText == null && skill_enable != null)
|
||||
{
|
||||
skill_enableText = skill_enable.GetComponentInChildren<Text>(true);
|
||||
}
|
||||
|
||||
if (skill_equipText == null && skill_equip != null)
|
||||
{
|
||||
skill_equipText = skill_equip.GetComponentInChildren<Text>(true);
|
||||
}
|
||||
|
||||
if (detailsPanel != null)
|
||||
{
|
||||
detailCanvasGroup = detailsPanel.GetComponent<CanvasGroup>();
|
||||
if (detailCanvasGroup == null)
|
||||
{
|
||||
detailCanvasGroup = detailsPanel.AddComponent<CanvasGroup>();
|
||||
}
|
||||
}
|
||||
|
||||
if (skillIcon != null)
|
||||
{
|
||||
originalSkillIconMaterial = skillIcon.material;
|
||||
}
|
||||
|
||||
if (deSkillIcon != null)
|
||||
{
|
||||
originalDetailSkillIconMaterial = deSkillIcon.material;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
KillHoverTween();
|
||||
}
|
||||
|
||||
public void Bind(
|
||||
Sprite iconSprite,
|
||||
Sprite detailIconSprite,
|
||||
string displayName,
|
||||
string detailName,
|
||||
string detailDescription,
|
||||
Color bottomColor,
|
||||
Material iconMaterial,
|
||||
bool enableToggleValue,
|
||||
string enableToggleText,
|
||||
bool equipToggleValue,
|
||||
string equipToggleText,
|
||||
bool selected,
|
||||
bool interactable,
|
||||
bool showDetailsNow,
|
||||
bool hoverToShowDetails,
|
||||
bool allowDetailsHover,
|
||||
Action onClick)
|
||||
{
|
||||
clickAction = onClick;
|
||||
showDetailsImmediately = showDetailsNow;
|
||||
useHoverToShowDetails = hoverToShowDetails;
|
||||
canShowDetailsOnHover = allowDetailsHover;
|
||||
|
||||
SetImage(skillIcon, iconSprite, iconMaterial, originalSkillIconMaterial);
|
||||
SetImage(deSkillIcon, detailIconSprite, iconMaterial, originalDetailSkillIconMaterial);
|
||||
|
||||
if (skillIcon_btm != null)
|
||||
{
|
||||
skillIcon_btm.color = bottomColor;
|
||||
}
|
||||
|
||||
if (skillName != null)
|
||||
{
|
||||
skillName.text = displayName ?? string.Empty;
|
||||
}
|
||||
|
||||
if (details_skillName != null)
|
||||
{
|
||||
details_skillName.text = detailName ?? string.Empty;
|
||||
}
|
||||
|
||||
if (details_skillDes != null)
|
||||
{
|
||||
details_skillDes.text = detailDescription ?? string.Empty;
|
||||
}
|
||||
|
||||
SetToggle(skill_enable, enableToggleValue);
|
||||
SetToggle(skill_equip, equipToggleValue);
|
||||
SetText(skill_enableText, enableToggleText);
|
||||
SetText(skill_equipText, equipToggleText);
|
||||
SetSelected(selected);
|
||||
|
||||
if (skillButton != null)
|
||||
{
|
||||
skillButton.interactable = interactable;
|
||||
}
|
||||
|
||||
ConfigureDetailPanelState();
|
||||
}
|
||||
|
||||
public void SetSelected(bool selected)
|
||||
{
|
||||
if (skillIcon_btm != null)
|
||||
{
|
||||
skillIcon_btm.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (!useHoverToShowDetails || !canShowDetailsOnHover || detailCanvasGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
KillHoverTween();
|
||||
hoverDelayTween = DOVirtual.DelayedCall(0.5f, ShowDetailsPanel, true).SetUpdate(true);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!useHoverToShowDetails || detailCanvasGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
KillHoverTween();
|
||||
HideDetailsPanel();
|
||||
}
|
||||
|
||||
private void HandleClick()
|
||||
{
|
||||
if (skillButton != null && !skillButton.interactable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
clickAction?.Invoke();
|
||||
}
|
||||
|
||||
private void ConfigureDetailPanelState()
|
||||
{
|
||||
if (detailsPanel == null || detailCanvasGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
KillHoverTween();
|
||||
detailCanvasGroup.DOKill();
|
||||
|
||||
if (showDetailsImmediately)
|
||||
{
|
||||
detailsPanel.SetActive(true);
|
||||
detailCanvasGroup.alpha = 1f;
|
||||
detailCanvasGroup.blocksRaycasts = true;
|
||||
detailCanvasGroup.interactable = true;
|
||||
return;
|
||||
}
|
||||
|
||||
HideDetailsPanel();
|
||||
}
|
||||
|
||||
private void ShowDetailsPanel()
|
||||
{
|
||||
if (detailsPanel == null || detailCanvasGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
detailsPanel.SetActive(true);
|
||||
detailCanvasGroup.DOKill();
|
||||
detailCanvasGroup.alpha = 0f;
|
||||
detailCanvasGroup.blocksRaycasts = false;
|
||||
detailCanvasGroup.interactable = false;
|
||||
detailCanvasGroup.DOFade(1f, 0.15f).SetEase(Ease.OutQuad).SetUpdate(true).OnComplete(() =>
|
||||
{
|
||||
detailCanvasGroup.blocksRaycasts = true;
|
||||
detailCanvasGroup.interactable = true;
|
||||
});
|
||||
}
|
||||
|
||||
private void HideDetailsPanel()
|
||||
{
|
||||
if (detailsPanel == null || detailCanvasGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
detailCanvasGroup.DOKill();
|
||||
detailCanvasGroup.alpha = 0f;
|
||||
detailCanvasGroup.blocksRaycasts = false;
|
||||
detailCanvasGroup.interactable = false;
|
||||
detailsPanel.SetActive(false);
|
||||
}
|
||||
|
||||
private void KillHoverTween()
|
||||
{
|
||||
if (hoverDelayTween != null && hoverDelayTween.IsActive())
|
||||
{
|
||||
hoverDelayTween.Kill();
|
||||
hoverDelayTween = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetToggle(Toggle toggle, bool value)
|
||||
{
|
||||
if (toggle != null)
|
||||
{
|
||||
toggle.SetIsOnWithoutNotify(value);
|
||||
toggle.interactable = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetText(Text target, string value)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
target.text = value ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetImage(Image target, Sprite sprite, Material overrideMaterial, Material fallbackMaterial)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
target.sprite = sprite;
|
||||
target.material = overrideMaterial != null ? overrideMaterial : fallbackMaterial;
|
||||
target.enabled = sprite != null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user