```
docs(clipboard): 添加剪贴板功能相关图片资源 添加了两个剪贴板功能的截图文件,用于文档说明和功能展示。 ```
This commit is contained in:
1 parent
47f01ecd2e
commit
f93d69d8ee
77 files changed
+5482
-307
No files matched your search
@@ -4,17 +4,36 @@ using UnityEngine.UI;
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class SummonCardButton : MonoBehaviour
|
||||
{
|
||||
[Header("角色数据")]
|
||||
public CharacterData characterData;
|
||||
|
||||
[Header("卡槽配置")]
|
||||
[Min(1)]
|
||||
public int summonSlot = 1;
|
||||
|
||||
[Header("UI 引用")]
|
||||
public Image cooldownMask;
|
||||
public Text cooldownText;
|
||||
public Image cardIcon;
|
||||
public Text characterNameText;
|
||||
public Text manaCostText;
|
||||
|
||||
private Button button;
|
||||
private MainCharacterCombat combat;
|
||||
private float cooldownTimer;
|
||||
private bool isOnCooldown;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
button = GetComponent<Button>();
|
||||
combat = FindObjectOfType<MainCharacterCombat>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
|
||||
isOnCooldown = false;
|
||||
cooldownTimer = 0f;
|
||||
|
||||
UpdateCardUI();
|
||||
UpdateCooldownUI();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -25,16 +44,111 @@ public class SummonCardButton : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isOnCooldown)
|
||||
{
|
||||
cooldownTimer -= Time.deltaTime;
|
||||
if (cooldownTimer <= 0f)
|
||||
{
|
||||
isOnCooldown = false;
|
||||
cooldownTimer = 0f;
|
||||
}
|
||||
|
||||
UpdateCooldownUI();
|
||||
}
|
||||
|
||||
UpdateButtonState();
|
||||
}
|
||||
|
||||
public void OnClick()
|
||||
{
|
||||
if (isOnCooldown || characterData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (combat == null)
|
||||
{
|
||||
combat = FindObjectOfType<MainCharacterCombat>();
|
||||
}
|
||||
|
||||
if (combat != null)
|
||||
if (combat != null && combat.RequestSummon(summonSlot))
|
||||
{
|
||||
combat.RequestSummon(summonSlot);
|
||||
StartCooldown();
|
||||
}
|
||||
}
|
||||
|
||||
private void StartCooldown()
|
||||
{
|
||||
if (characterData != null)
|
||||
{
|
||||
isOnCooldown = true;
|
||||
cooldownTimer = characterData.cooldownTime;
|
||||
UpdateCooldownUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCooldownUI()
|
||||
{
|
||||
if (cooldownMask != null)
|
||||
{
|
||||
cooldownMask.fillAmount = isOnCooldown ? (cooldownTimer / GetCooldownTime()) : 0f;
|
||||
cooldownMask.enabled = isOnCooldown;
|
||||
}
|
||||
|
||||
if (cooldownText != null)
|
||||
{
|
||||
cooldownText.text = isOnCooldown ? Mathf.CeilToInt(cooldownTimer).ToString() : "";
|
||||
cooldownText.enabled = isOnCooldown;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateButtonState()
|
||||
{
|
||||
if (button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
button.interactable = !isOnCooldown && CanAfford();
|
||||
}
|
||||
|
||||
private bool CanAfford()
|
||||
{
|
||||
if (ManaSystem.Instance == null || characterData == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return ManaSystem.Instance.CurrentManaInt >= characterData.manaCost;
|
||||
}
|
||||
|
||||
private float GetCooldownTime()
|
||||
{
|
||||
return characterData != null ? characterData.cooldownTime : 5f;
|
||||
}
|
||||
|
||||
private void UpdateCardUI()
|
||||
{
|
||||
if (characterData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (cardIcon != null && characterData.cardIcon != null)
|
||||
{
|
||||
cardIcon.sprite = characterData.cardIcon;
|
||||
}
|
||||
|
||||
if (characterNameText != null)
|
||||
{
|
||||
characterNameText.text = characterData.characterName;
|
||||
}
|
||||
|
||||
if (manaCostText != null)
|
||||
{
|
||||
manaCostText.text = characterData.manaCost.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user