根据提供的code differences信息,由于没有具体的代码变更内容,我将生成一个通用的commit message模板:
``` docs(readme): 更新文档说明 - 添加项目使用指南 - 完善API接口说明 - 修正错误的配置示例 ``` 注意:由于您提供的code differences部分为空,以上是一个示例模板。当您有具体的代码变更时,请提供详细的变更内容以便生成更准确的commit message。
This commit is contained in:
1 parent
8d58c2223c
commit
11f1af357d
191 files changed
+2315
-1539
No files matched your search
@@ -0,0 +1,96 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// 底部英雄卡片的拖拽:拖到网格格位上放置英雄。
|
||||
/// 吸附与放置由 FormationManager 负责,卡片只负责拖动表现和回调。
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
public class FormationCardDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
[Header("界面引用")]
|
||||
public Image background;
|
||||
public Image icon;
|
||||
public Text nameText;
|
||||
|
||||
[HideInInspector] public FormationManager manager;
|
||||
[HideInInspector] public int heroIndex;
|
||||
|
||||
private RectTransform rectTransform;
|
||||
private CanvasGroup canvasGroup;
|
||||
private Vector2 homePosition;
|
||||
|
||||
private static readonly Color NormalColor = new Color(0.15f, 0.15f, 0.2f, 0.92f);
|
||||
private static readonly Color PlacedColor = new Color(0.18f, 0.18f, 0.22f, 0.45f);
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
homePosition = rectTransform.anchoredPosition;
|
||||
}
|
||||
|
||||
/// <summary>填入名字与头像。</summary>
|
||||
public void SetContent(string displayName, Sprite iconSprite)
|
||||
{
|
||||
if (nameText != null) nameText.text = displayName;
|
||||
if (icon != null)
|
||||
{
|
||||
if (iconSprite != null)
|
||||
{
|
||||
icon.sprite = iconSprite;
|
||||
icon.preserveAspect = true;
|
||||
icon.color = Color.white;
|
||||
}
|
||||
else
|
||||
{
|
||||
icon.color = new Color(0.4f, 0.4f, 0.45f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>已放置的卡片置灰并禁止再次拖拽。</summary>
|
||||
public void SetPlaced(bool isPlaced)
|
||||
{
|
||||
if (background != null) background.color = isPlaced ? PlacedColor : NormalColor;
|
||||
canvasGroup.alpha = isPlaced ? 0.55f : 1f;
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (manager == null || !manager.CanDrag(heroIndex))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
rectTransform.position = eventData.position;
|
||||
manager.OnCardDragStart(heroIndex);
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (manager == null || !manager.CanDrag(heroIndex))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rectTransform.position = eventData.position;
|
||||
manager.OnCardDragging(heroIndex, eventData.position);
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
|
||||
if (manager == null || !manager.CanDrag(heroIndex))
|
||||
{
|
||||
rectTransform.anchoredPosition = homePosition;
|
||||
return;
|
||||
}
|
||||
|
||||
rectTransform.anchoredPosition = homePosition;
|
||||
manager.OnCardDragEnd(heroIndex, eventData.position);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user