using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; using System; using TMPro; /// /// Radial menu (decision wheel) for selecting battle actions /// public class BattleActionWheel : MonoBehaviour { [Header("UI References")] public Canvas wheelCanvas; public GameObject wheelBackground; public GameObject actionButtonPrefab; public Transform wheelCenter; [Header("Wheel Settings")] public float wheelRadius = 100f; public float buttonSize = 60f; public float animationDuration = 0.3f; public AnimationCurve scaleCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f); [Header("Action Icons")] public Sprite moveIcon; public Sprite attackIcon; public Sprite itemIcon; public Sprite spellIcon; public Sprite runAwayIcon; public Sprite defendIcon; public Sprite waitIcon; [Header("Colors")] public Color defaultColor = Color.white; public Color hoverColor = Color.yellow; public Color disabledColor = Color.gray; private List actionButtons = new List(); private Character currentCharacter; private bool isVisible = false; private Vector3 worldPosition; private Camera mainCamera; // Events public event Action OnActionSelected; public event Action OnWheelClosed; [System.Serializable] private class ActionButton { public GameObject buttonObject; public Button button; public Image icon; public TextMeshProUGUI label; public BattleActionType actionType; public bool isEnabled = true; public void SetEnabled(bool enabled) { isEnabled = enabled; button.interactable = enabled; icon.color = enabled ? Color.white : Color.gray; } public void SetHighlight(bool highlighted, Color normalColor, Color highlightColor) { icon.color = highlighted ? highlightColor : (isEnabled ? normalColor : Color.gray); } } void Awake() { mainCamera = Camera.main; if (wheelCanvas == null) wheelCanvas = GetComponentInChildren(); if (wheelCanvas != null) wheelCanvas.worldCamera = mainCamera; SetVisible(false); } void Start() { InitializeWheel(); } void Update() { if (isVisible) { // Update wheel position to follow character or world position UpdateWheelPosition(); // Handle input for closing wheel if (Input.GetKeyDown(KeyCode.Escape) || Input.GetMouseButtonDown(1)) { HideWheel(); } } } private void InitializeWheel() { if (actionButtonPrefab == null) { Debug.LogError("BattleActionWheel: Action button prefab not assigned!"); return; } CreateActionButtons(); } private void CreateActionButtons() { // Define actions and their properties var actionDefinitions = new[] { new { type = BattleActionType.Attack, icon = attackIcon, label = "Attack" }, new { type = BattleActionType.Move, icon = moveIcon, label = "Move" }, new { type = BattleActionType.UseItem, icon = itemIcon, label = "Use Item" }, new { type = BattleActionType.CastSpell, icon = spellIcon, label = "Cast Spell" }, new { type = BattleActionType.Defend, icon = defendIcon, label = "Defend" }, new { type = BattleActionType.RunAway, icon = runAwayIcon, label = "Run Away" } }; int actionCount = actionDefinitions.Length; float angleStep = 360f / actionCount; for (int i = 0; i < actionCount; i++) { var actionDef = actionDefinitions[i]; float angle = i * angleStep - 90f; // Start from top Vector3 position = GetPositionOnCircle(angle, wheelRadius); CreateActionButton(actionDef.type, actionDef.icon, actionDef.label, position, i); } } private void CreateActionButton(BattleActionType actionType, Sprite icon, string label, Vector3 position, int index) { GameObject buttonObj = Instantiate(actionButtonPrefab, wheelCenter); buttonObj.name = $"ActionButton_{actionType}"; // Position the button RectTransform rectTransform = buttonObj.GetComponent(); if (rectTransform != null) { rectTransform.anchoredPosition = position; rectTransform.sizeDelta = Vector2.one * buttonSize; } // Get components Button button = buttonObj.GetComponent