New file |
| | |
| | | #if UNITY_EDITOR |
| | | using UnityEditor; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | |
| | | public class TestActionEditorWindow : EditorWindow |
| | | { |
| | | protected int targetIndex = 0; |
| | | protected int selfIndex = 0; |
| | | protected int distance = 100; |
| | | protected float duration = 2f; |
| | | |
| | | [MenuItem("Battle/TestAction生成器")] |
| | | public static void ShowWindow() |
| | | { |
| | | GetWindow<TestActionEditorWindow>("TestAction生成器"); |
| | | } |
| | | |
| | | private void OnGUI() |
| | | { |
| | | GUILayout.Label("TestAction参数设置", EditorStyles.boldLabel); |
| | | |
| | | targetIndex = EditorGUILayout.IntField("Target Index", targetIndex); |
| | | selfIndex = EditorGUILayout.IntField("Self Index", selfIndex); |
| | | distance = EditorGUILayout.IntField("Distance", distance); |
| | | duration = EditorGUILayout.FloatField("Duration", duration); |
| | | |
| | | if (GUILayout.Button("生成并播放 TestAction")) |
| | | { |
| | | PlayTestAction(); |
| | | } |
| | | |
| | | if (GUILayout.Button("标记起点和终点")) |
| | | { |
| | | MarkStartAndEnd(); |
| | | } |
| | | |
| | | if (GUILayout.Button("复位RecordPlayer")) |
| | | { |
| | | ResetRecordPlayer(); |
| | | } |
| | | } |
| | | |
| | | private void PlayTestAction() |
| | | { |
| | | // 运行时才执行 |
| | | if (!Application.isPlaying) |
| | | { |
| | | Debug.LogWarning("请在运行时使用该功能!"); |
| | | return; |
| | | } |
| | | |
| | | var battleField = BattleManager.Instance.storyBattleField; |
| | | if (battleField == null || battleField.recordPlayer == null) |
| | | { |
| | | Debug.LogError("BattleManager.storyBattleField 或 recordPlayer 未初始化!"); |
| | | return; |
| | | } |
| | | |
| | | var action = new TestAction(battleField, targetIndex, selfIndex, distance, duration); |
| | | battleField.recordPlayer.PlayRecord(action); |
| | | Debug.Log($"已生成并播放 TestAction: targetIndex={targetIndex}, selfIndex={selfIndex}, distance={distance}, duration={duration}"); |
| | | } |
| | | |
| | | private void MarkStartAndEnd() |
| | | { |
| | | // 运行时才执行 |
| | | if (!Application.isPlaying) |
| | | { |
| | | Debug.LogWarning("请在运行时使用该功能!"); |
| | | return; |
| | | } |
| | | |
| | | var battleField = BattleManager.Instance.storyBattleField; |
| | | if (battleField == null) |
| | | { |
| | | Debug.LogError("BattleManager.storyBattleField 未初始化!"); |
| | | return; |
| | | } |
| | | |
| | | // 获取节点 |
| | | RectTransform startNode = battleField.GetTeamNode(BattleCamp.Red, selfIndex); |
| | | RectTransform endNode = battleField.GetTeamNode(BattleCamp.Blue, targetIndex); |
| | | |
| | | BattleWin battleWin = UIManager.Instance.GetUI<BattleWin>(); |
| | | RectTransform canvasRect = battleWin.transform as RectTransform; |
| | | |
| | | CreateMarker(canvasRect, startNode, "StartMarker"); |
| | | CreateMarker(canvasRect, endNode, "EndMarker"); |
| | | } |
| | | |
| | | private void CreateMarker(RectTransform canvasRect, RectTransform targetNode, string markerName) |
| | | { |
| | | // 获取目标节点的世界坐标(中心点) |
| | | Vector3 worldPos = targetNode.TransformPoint(targetNode.rect.center); |
| | | |
| | | // 转换到Canvas本地坐标 |
| | | Vector2 localPoint; |
| | | RectTransformUtility.ScreenPointToLocalPointInRectangle( |
| | | canvasRect, |
| | | RectTransformUtility.WorldToScreenPoint(null, worldPos), |
| | | null, |
| | | out localPoint); |
| | | |
| | | // 创建RawImage |
| | | GameObject marker = new GameObject(markerName, typeof(RawImage)); |
| | | marker.transform.SetParent(canvasRect, false); |
| | | var rawImage = marker.GetComponent<RawImage>(); |
| | | rawImage.color = Color.white; |
| | | rawImage.rectTransform.sizeDelta = new Vector2(100, 100); |
| | | rawImage.rectTransform.anchoredPosition = localPoint; |
| | | } |
| | | |
| | | private void ResetRecordPlayer() |
| | | { |
| | | if (!Application.isPlaying) |
| | | { |
| | | Debug.LogWarning("请在运行时使用该功能!"); |
| | | return; |
| | | } |
| | | |
| | | var battleField = BattleManager.Instance.storyBattleField; |
| | | if (battleField == null || battleField.recordPlayer == null) |
| | | { |
| | | Debug.LogError("BattleManager.storyBattleField 或 recordPlayer 未初始化!"); |
| | | return; |
| | | } |
| | | |
| | | battleField.recordPlayer.HaveRest(); |
| | | Debug.Log("RecordPlayer已复位!"); |
| | | } |
| | | } |
| | | #endif |