编队系统重置 选角页面基本完成 等待存入playerprefs
This commit is contained in:
@@ -3,8 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class CharacterCardView : MonoBehaviour
|
||||
public class CharacterCardView : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
public int characterID;
|
||||
public string currentBoundaryLevel;
|
||||
@@ -14,10 +15,16 @@ public class CharacterCardView : MonoBehaviour
|
||||
public Image occupationIcon;
|
||||
public bool isSelected=false;
|
||||
|
||||
// drag
|
||||
private GameObject dragGhost;
|
||||
private Canvas rootCanvas;
|
||||
private CanvasGroup canvasGroup;
|
||||
|
||||
void Start()
|
||||
{
|
||||
charactCard = gameObject;
|
||||
rootCanvas = GetComponentInParent<Canvas>();
|
||||
canvasGroup = GetComponent<CanvasGroup>() ?? gameObject.AddComponent<CanvasGroup>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 未在队中的卡点击后进入被操纵状态。若在队伍中默认进入已经入队状态
|
||||
@@ -40,6 +47,62 @@ public class CharacterCardView : MonoBehaviour
|
||||
TeamManager.Instance.removeTeamCharacter(characterID);
|
||||
characterImage.color = new Color(1f, 1f, 1f,1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Drag handlers: create ghost based on characterImage.sprite
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
Debug.Log($"CharacterCardView OnBeginDrag: {gameObject.name}");
|
||||
if (characterImage == null || characterImage.sprite == null) return;
|
||||
if (rootCanvas == null) rootCanvas = GetComponentInParent<Canvas>();
|
||||
if (rootCanvas == null) return;
|
||||
|
||||
// prevent the original from blocking raycasts so drop targets can receive events
|
||||
if (canvasGroup == null) canvasGroup = GetComponent<CanvasGroup>() ?? gameObject.AddComponent<CanvasGroup>();
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
|
||||
// ensure pointerDrag references this object for drop handlers
|
||||
eventData.pointerDrag = gameObject;
|
||||
|
||||
dragGhost = new GameObject("_RoleDragGhost");
|
||||
dragGhost.transform.SetParent(rootCanvas.transform, false);
|
||||
var img = dragGhost.AddComponent<Image>();
|
||||
img.raycastTarget = false;
|
||||
img.sprite = characterImage.sprite;
|
||||
img.SetNativeSize();
|
||||
var cg = dragGhost.AddComponent<CanvasGroup>();
|
||||
cg.blocksRaycasts = false;
|
||||
|
||||
UpdateGhostPosition(eventData);
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (dragGhost == null) return;
|
||||
UpdateGhostPosition(eventData);
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
Debug.Log($"CharacterCardView OnEndDrag: {gameObject.name}");
|
||||
if (dragGhost != null)
|
||||
{
|
||||
Destroy(dragGhost);
|
||||
dragGhost = null;
|
||||
}
|
||||
// restore raycast blocking on the original
|
||||
if (canvasGroup != null)
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
}
|
||||
|
||||
private void UpdateGhostPosition(PointerEventData eventData)
|
||||
{
|
||||
if (rootCanvas == null) return;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||||
rootCanvas.transform as RectTransform,
|
||||
eventData.position,
|
||||
eventData.pressEventCamera,
|
||||
out Vector2 localPoint);
|
||||
if (dragGhost != null)
|
||||
dragGhost.transform.localPosition = localPoint;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user