编队系统重置 选角页面基本完成 等待存入playerprefs
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public static class DragGhost
|
||||
{
|
||||
private static GameObject ghost;
|
||||
private static Image ghostImage;
|
||||
private static Canvas parentCanvas;
|
||||
|
||||
// Ensure ghost exists under given canvas
|
||||
public static void Show(Canvas canvas, Sprite sprite)
|
||||
{
|
||||
if (canvas == null || sprite == null) return;
|
||||
if (ghost == null || parentCanvas != canvas)
|
||||
{
|
||||
if (ghost != null) Object.Destroy(ghost);
|
||||
parentCanvas = canvas;
|
||||
ghost = new GameObject("_SharedDragGhost");
|
||||
ghost.transform.SetParent(parentCanvas.transform, false);
|
||||
ghostImage = ghost.AddComponent<Image>();
|
||||
ghostImage.raycastTarget = false;
|
||||
var cg = ghost.AddComponent<CanvasGroup>();
|
||||
cg.blocksRaycasts = false;
|
||||
}
|
||||
ghostImage.sprite = sprite;
|
||||
// set size to sprite rect (avoid SetNativeSize to reduce layout work)
|
||||
var rt = ghostImage.rectTransform;
|
||||
rt.sizeDelta = new Vector2(sprite.rect.width, sprite.rect.height);
|
||||
ghost.SetActive(true);
|
||||
}
|
||||
|
||||
public static void Hide()
|
||||
{
|
||||
if (ghost != null) ghost.SetActive(false);
|
||||
}
|
||||
|
||||
public static void UpdatePosition(Vector2 screenPosition, Camera cam)
|
||||
{
|
||||
if (ghost == null || parentCanvas == null) return;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||||
parentCanvas.transform as RectTransform,
|
||||
screenPosition,
|
||||
cam,
|
||||
out Vector2 localPoint);
|
||||
ghost.transform.localPosition = localPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9937514c93fcd0548bac60d489d9b0cc
|
||||
Reference in New Issue
Block a user