using System; using AibisDream.Framework; using AibisDream.Kit; using UnityEngine; namespace AibisDream { public class BubbleSlot : MonoBehaviour { [SerializeField] private BubbleSlotData data; public BubbleSlotData Data { get { data.slotPosition = CameraKit.GetScreenPos(transform.position); return data; } } private void OnDrawGizmos() { // 画一个矩形 Gizmos.color = Color.white; // 计算长和宽 var width = data.maxWidth / 108f; var height = 0.5f * width; // 根据PivotType确定矩形位置 var centerNormal = GetSquareCenterOffset(data.pivotType); // Calculate the corners of the square var topLeftNormal = centerNormal + new Vector3(-0.5f, 0.5f, 0); var topRightNormal = centerNormal + new Vector3(0.5f, 0.5f, 0); var bottomLeftNormal = centerNormal + new Vector3(-0.5f, -0.5f, 0); var bottomRightNormal = centerNormal + new Vector3(0.5f, -0.5f, 0); // 计算实际位置 var topLeft = new Vector3(topLeftNormal.x * width, topLeftNormal.y * height, 0) + transform.position; var topRight = new Vector3(topRightNormal.x * width, topRightNormal.y * height, 0) + transform.position; var bottomLeft = new Vector3(bottomLeftNormal.x * width, bottomLeftNormal.y * height, 0) + transform.position; var bottomRight = new Vector3(bottomRightNormal.x * width, bottomRightNormal.y * height, 0) + transform.position; // Draw the square Gizmos.DrawLine(topLeft, topRight); Gizmos.DrawLine(topRight, bottomRight); Gizmos.DrawLine(bottomRight, bottomLeft); Gizmos.DrawLine(bottomLeft, topLeft); // pivot画圆 Gizmos.color = Color.green; Gizmos.DrawWireSphere(transform.position, 0.05f); } private static Vector3 GetSquareCenterOffset(PivotType pivotType) { return pivotType switch { PivotType.Top => new Vector3(0, -0.5f, 0), PivotType.Bottom => new Vector3(0, 0.5f, 0), PivotType.Left => new Vector3(0.5f, 0, 0), PivotType.Right => new Vector3(-0.5f, 0, 0), PivotType.TopLeft => new Vector3(0.5f, -0.5f, 0), PivotType.TopRight => new Vector3(-0.5f, -0.5f, 0), PivotType.BottomLeft => new Vector3(0.5f, 0.5f, 0), PivotType.BottomRight => new Vector3(-0.5f, 0.5f, 0), _ => Vector3.zero }; } } [Serializable] public struct BubbleSlotData { [HideInInspector] public Vector3 slotPosition; public ActorRole actorRole; public int idx; public int maxWidth; public int minWidth; public BubbleStyle bubbleStyle; public PivotType pivotType; } }