```
feat(gameplay): 实现召唤师对决模式核心功能 - 新增召唤师对决管理模式,支持点卡片直接召唤单位 - 添加召唤师点地移动控制,移动时不攻击、站定时自动攻击 - 实现召唤师模式开关,单位不再自动追击远处敌人 - 更新卡牌按钮逻辑,对决模式下按能量消耗直接召唤 - 修改单位基础行为,支持移动中不攻击的召唤师模式 - 更新核心玩法文档,从建筑生产模式转向召唤师对决模式 - 添加召唤师对决测试场景,整合新的战斗逻辑 ```
This commit is contained in:
1 parent
1cdb7c3910
commit
f06a1d8f92
21 files changed
+870
-220
No files matched your search
@@ -0,0 +1,102 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗管理器:监听双方召唤师死亡,触发胜负判定并显示结果 UI。
|
||||
/// </summary>
|
||||
public class BattleManager : MonoBehaviour
|
||||
{
|
||||
[Header("召唤师引用")]
|
||||
public GameObject playerSummoner;
|
||||
public GameObject enemySummoner;
|
||||
|
||||
[Header("胜负 UI")]
|
||||
public GameObject victoryPanel;
|
||||
public GameObject defeatPanel;
|
||||
|
||||
private WorldHealthBar playerHealthBar;
|
||||
private WorldHealthBar enemyHealthBar;
|
||||
private bool battleEnded = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 获取双方召唤师的血条组件
|
||||
if (playerSummoner != null)
|
||||
{
|
||||
playerHealthBar = playerSummoner.GetComponent<WorldHealthBar>();
|
||||
}
|
||||
|
||||
if (enemySummoner != null)
|
||||
{
|
||||
enemyHealthBar = enemySummoner.GetComponent<WorldHealthBar>();
|
||||
}
|
||||
|
||||
// 隐藏胜负 UI
|
||||
if (victoryPanel != null) victoryPanel.SetActive(false);
|
||||
if (defeatPanel != null) defeatPanel.SetActive(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (battleEnded) return;
|
||||
|
||||
// 检测己方召唤师死亡
|
||||
if (playerHealthBar != null && playerHealthBar.IsDead)
|
||||
{
|
||||
OnBattleEnd(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 检测敌方召唤师死亡
|
||||
if (enemyHealthBar != null && enemyHealthBar.IsDead)
|
||||
{
|
||||
OnBattleEnd(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBattleEnd(bool victory)
|
||||
{
|
||||
battleEnded = true;
|
||||
|
||||
// 暂停游戏
|
||||
Time.timeScale = 0f;
|
||||
|
||||
// 显示对应 UI
|
||||
if (victory)
|
||||
{
|
||||
Debug.Log("胜利!");
|
||||
if (victoryPanel != null)
|
||||
{
|
||||
victoryPanel.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("失败!");
|
||||
if (defeatPanel != null)
|
||||
{
|
||||
defeatPanel.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重新开始按钮回调
|
||||
public void OnRestartButtonClicked()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene(
|
||||
UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
|
||||
}
|
||||
|
||||
// 退出按钮回调
|
||||
public void OnQuitButtonClicked()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: Di4etymsUXvNaAtAYCGTjqWlsQBo5CkpSQWOamGKNe31K6x/sOO8dpY=
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -206,6 +206,23 @@ public class MainCharacterCombat : MonoBehaviour
|
||||
return true;
|
||||
}
|
||||
|
||||
// 召唤师对决模式:点卡片按 CharacterData 直接召唤(能量消耗在 RequestSummon 同路径处理)。
|
||||
public bool RequestSummonByData(CharacterData characterData)
|
||||
{
|
||||
if (summoning || animator == null || characterData == null || characterData.unitPrefab == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = System.Array.IndexOf(summonableCharacters, characterData);
|
||||
if (index < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return RequestSummon(index + 1);
|
||||
}
|
||||
|
||||
private void BeginSummon(GameObject prefab, CharacterData characterData, PlayerCharacterData playerData)
|
||||
{
|
||||
if (prefab == null)
|
||||
|
||||
@@ -79,6 +79,16 @@ public class SummonCardButton : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
// 召唤师对决模式:点卡片直接在召唤师身边召唤,消耗能量。
|
||||
if (SummonerDuelManager.Instance != null)
|
||||
{
|
||||
if (SummonerDuelManager.Instance.TrySummon(characterData))
|
||||
{
|
||||
StartCooldown();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 建筑模式:检查建筑费用是否足够
|
||||
if (GoldSystem.Instance == null || GoldSystem.Instance.CurrentGold < characterData.buildingCost)
|
||||
{
|
||||
@@ -163,6 +173,12 @@ public class SummonCardButton : MonoBehaviour
|
||||
return BattleSetupManager.Instance.CanAfford(characterData);
|
||||
}
|
||||
|
||||
// 召唤师对决模式按能量判断。
|
||||
if (SummonerDuelManager.Instance != null)
|
||||
{
|
||||
return SummonerDuelManager.Instance.CanAfford(characterData);
|
||||
}
|
||||
|
||||
// 建筑模式按金币判断。
|
||||
if (GoldSystem.Instance == null)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
/// <summary>
|
||||
/// 召唤师对决:召唤师点地移动操控(直线移动,无寻路)。
|
||||
/// 点击己方区域地面 → 直线走到目标点(clamp 在己方带内)。
|
||||
/// 移动时不攻击;站定后自动攻击射程内目标。
|
||||
/// </summary>
|
||||
public class SummonerClickMovement : MonoBehaviour
|
||||
{
|
||||
[Header("己方半场 clamp(世界坐标)")]
|
||||
public float minX = -9f;
|
||||
public float maxX = 9f;
|
||||
public float minZ = -29f;
|
||||
public float maxZ = -11f;
|
||||
|
||||
[Header("移动速度")]
|
||||
public float moveSpeed = 5f;
|
||||
public float stopDistance = 0.2f;
|
||||
|
||||
[Header("地面射线")]
|
||||
public LayerMask groundMask = ~0;
|
||||
|
||||
private Camera mainCamera;
|
||||
private MainCharacterCombat combat;
|
||||
private Animator animator;
|
||||
private Vector3 targetPosition;
|
||||
private bool hasTarget;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
combat = GetComponent<MainCharacterCombat>();
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
mainCamera = Camera.main;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
HandleClickToMove();
|
||||
HandleMovement();
|
||||
}
|
||||
|
||||
// 点地移动:点击地面即设置目标点(EventSystem 判定不在 UI 上时才生效)。
|
||||
private void HandleClickToMove()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0) && !IsPointerOverUI())
|
||||
{
|
||||
if (RaycastGround(out Vector3 groundPoint))
|
||||
{
|
||||
Vector3 clamped = ClampToOwnHalf(groundPoint);
|
||||
MoveTo(clamped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行直线移动
|
||||
private void HandleMovement()
|
||||
{
|
||||
if (!hasTarget) return;
|
||||
|
||||
Vector3 currentPos = transform.position;
|
||||
Vector3 direction = targetPosition - currentPos;
|
||||
direction.y = 0f;
|
||||
float distance = direction.magnitude;
|
||||
|
||||
// 到达目标
|
||||
if (distance <= stopDistance)
|
||||
{
|
||||
ClearTarget();
|
||||
return;
|
||||
}
|
||||
|
||||
// 移动
|
||||
direction.Normalize();
|
||||
transform.position += direction * moveSpeed * Time.deltaTime;
|
||||
|
||||
// 朝向移动方向
|
||||
if (direction.sqrMagnitude > 0.001f)
|
||||
{
|
||||
transform.rotation = Quaternion.LookRotation(direction, Vector3.up);
|
||||
}
|
||||
|
||||
// 播放走路动画
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetInteger("speed", 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 外部入口:把召唤师移动到某点(clamp 后设置目标)。
|
||||
public void MoveTo(Vector3 worldPosition)
|
||||
{
|
||||
Vector3 clamped = ClampToOwnHalf(worldPosition);
|
||||
targetPosition = clamped;
|
||||
targetPosition.y = transform.position.y; // 保持 Y 不变
|
||||
hasTarget = true;
|
||||
|
||||
// 移动中暂停攻击(防风筝规则)
|
||||
if (combat != null)
|
||||
{
|
||||
combat.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearTarget()
|
||||
{
|
||||
hasTarget = false;
|
||||
|
||||
// 停止动画
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetInteger("speed", 0);
|
||||
}
|
||||
|
||||
// 站定后恢复自动攻击
|
||||
if (combat != null)
|
||||
{
|
||||
combat.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 半场 clamp:X 与 Z 均限制在己方带内。
|
||||
private Vector3 ClampToOwnHalf(Vector3 position)
|
||||
{
|
||||
return new Vector3(
|
||||
Mathf.Clamp(position.x, minX, maxX),
|
||||
position.y,
|
||||
Mathf.Clamp(position.z, minZ, maxZ));
|
||||
}
|
||||
|
||||
private bool RaycastGround(out Vector3 point)
|
||||
{
|
||||
point = Vector3.zero;
|
||||
if (mainCamera == null)
|
||||
{
|
||||
mainCamera = Camera.main;
|
||||
if (mainCamera == null) return false;
|
||||
}
|
||||
|
||||
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 200f, groundMask.value))
|
||||
{
|
||||
point = hit.point;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsPointerOverUI()
|
||||
{
|
||||
return EventSystem.current != null && EventSystem.current.IsPointerOverGameObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: D3MZ53/+Bi5T65J7i/sGjy4OrNmkAPexctr/dMT82/ffKFb1P6oQ0Co=
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 召唤师对决模式:点卡片直接在召唤师身边召唤单位(能量消耗 + 卡片冷却沿用现有系统)。
|
||||
/// 复用 SummonCardButton 的点击入口:无 BattleSetupManager、无 GoldSystem 时走本模式。
|
||||
/// </summary>
|
||||
public class SummonerDuelManager : MonoBehaviour
|
||||
{
|
||||
public static SummonerDuelManager Instance { get; private set; }
|
||||
|
||||
[Header("召唤师")]
|
||||
public MainCharacterCombat summonerCombat;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (summonerCombat == null)
|
||||
{
|
||||
summonerCombat = FindObjectOfType<MainCharacterCombat>();
|
||||
}
|
||||
}
|
||||
|
||||
// 卡片点击入口:能量足够时由召唤师执行召唤动画与生成。
|
||||
public bool TrySummon(CharacterData data)
|
||||
{
|
||||
if (summonerCombat == null)
|
||||
{
|
||||
Debug.LogError("找不到召唤师 MainCharacterCombat");
|
||||
return false;
|
||||
}
|
||||
|
||||
// RequestSummon 内部走能量判断(TryConsumeMana)与召唤动画。
|
||||
return summonerCombat.RequestSummonByData(data);
|
||||
}
|
||||
|
||||
// 卡片可用性:能量是否足够(供 SummonCardButton 判断置灰)。
|
||||
public bool CanAfford(CharacterData data)
|
||||
{
|
||||
return data != null
|
||||
&& ManaSystem.Instance != null
|
||||
&& ManaSystem.Instance.CurrentManaInt >= data.manaCost;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: DCtO4X/+USoIwkGoI7+2kj00a9R1yMRAYBXPILcLhDHrIqmIIORGtp8=
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// 召唤师专属血条 UI:顶部 HUD 显示双方召唤师血量,区别于单位头顶血条。
|
||||
/// </summary>
|
||||
public class SummonerHealthBarUI : MonoBehaviour
|
||||
{
|
||||
[Header("UI 引用")]
|
||||
public Image playerHealthFill;
|
||||
public Image enemyHealthFill;
|
||||
public Text playerHealthText;
|
||||
public Text enemyHealthText;
|
||||
|
||||
[Header("召唤师引用")]
|
||||
public GameObject playerSummoner;
|
||||
public GameObject enemySummoner;
|
||||
|
||||
private WorldHealthBar playerHealthBar;
|
||||
private WorldHealthBar enemyHealthBar;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 获取双方召唤师的血条组件
|
||||
if (playerSummoner != null)
|
||||
{
|
||||
playerHealthBar = playerSummoner.GetComponent<WorldHealthBar>();
|
||||
}
|
||||
|
||||
if (enemySummoner != null)
|
||||
{
|
||||
enemyHealthBar = enemySummoner.GetComponent<WorldHealthBar>();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateHealthBar(playerHealthBar, playerHealthFill, playerHealthText);
|
||||
UpdateHealthBar(enemyHealthBar, enemyHealthFill, enemyHealthText);
|
||||
}
|
||||
|
||||
private void UpdateHealthBar(WorldHealthBar healthBar, Image fillImage, Text healthText)
|
||||
{
|
||||
if (healthBar == null || fillImage == null) return;
|
||||
|
||||
float ratio = healthBar.currentHealth / healthBar.maxHealth;
|
||||
fillImage.fillAmount = ratio;
|
||||
|
||||
if (healthText != null)
|
||||
{
|
||||
healthText.text = $"{Mathf.CeilToInt(healthBar.currentHealth)}/{Mathf.CeilToInt(healthBar.maxHealth)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: CilJ4H+sVH2HTBsacd3p++uNBi+u613d+RUcMwWW0wsoqCmwgU2DNms=
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -72,6 +72,13 @@ public class UnitBase : MonoBehaviour
|
||||
[Min(0f)] public float separationWeight = 3f;
|
||||
[Min(0f)] public float targetSpreadBias = 6f;
|
||||
|
||||
[Header("召唤师模式")]
|
||||
// 召唤师:不自动追击远处敌人,只在站定后攻击射程内的目标;移动由 SummonerClickMovement 控制。
|
||||
public bool summonerMode = false;
|
||||
|
||||
//召唤师模式下允许自动攻击的开关(移动时由操控脚本关闭,站定时开启)。
|
||||
private bool summonerAttackEnabled = true;
|
||||
|
||||
private static Collider[] s_separationBuffer = new Collider[30];
|
||||
|
||||
//角色状态
|
||||
@@ -243,6 +250,20 @@ public class UnitBase : MonoBehaviour
|
||||
target = FindNearestOpponent();
|
||||
if (target != null)
|
||||
{
|
||||
// 召唤师模式:不主动追击,站定且攻击开关开启时才攻击射程内目标。
|
||||
if (summonerMode)
|
||||
{
|
||||
if (!IsWithinAttackReach(target) || !summonerAttackEnabled)
|
||||
{
|
||||
state = State.Alert;
|
||||
// 动画由 SummonerClickMovement 控制,这里不设置
|
||||
applyGravity();
|
||||
return;
|
||||
}
|
||||
attack(target);
|
||||
return;
|
||||
}
|
||||
|
||||
state = State.Track;
|
||||
|
||||
//目标在攻击范围外则朝目标移动,否则开始攻击
|
||||
@@ -260,7 +281,11 @@ public class UnitBase : MonoBehaviour
|
||||
|
||||
//场上没有敌人时进入待机,不再巡逻移动
|
||||
state = State.Alert;
|
||||
animator.SetInteger("speed", 0);
|
||||
// 召唤师模式下动画由 SummonerClickMovement 控制(移动时 speed=1,站定后 speed=0)
|
||||
if (!summonerMode)
|
||||
{
|
||||
animator.SetInteger("speed", 0);
|
||||
}
|
||||
applyGravity();
|
||||
}
|
||||
|
||||
@@ -268,6 +293,16 @@ public class UnitBase : MonoBehaviour
|
||||
|
||||
public string OpponentTag => GetOpponentTag();
|
||||
|
||||
// 召唤师模式下控制"移动中不攻击":移动时 false,站定后 true。
|
||||
public void SetSummonerAttackEnabled(bool enabled)
|
||||
{
|
||||
summonerAttackEnabled = enabled;
|
||||
if (!enabled && state == State.Track)
|
||||
{
|
||||
state = State.Alert;
|
||||
}
|
||||
}
|
||||
|
||||
public float AttackSpeedMultiplier => attackSpeedMultiplier;
|
||||
|
||||
public bool IsStunned => statusEffectController != null && statusEffectController.IsStunned;
|
||||
|
||||
@@ -89,6 +89,9 @@ public class WorldHealthBar : MonoBehaviour
|
||||
// 防止死亡逻辑重复执行。
|
||||
private bool isDead;
|
||||
|
||||
// 公开死亡状态供外部查询(用于胜负判定)
|
||||
public bool IsDead => isDead;
|
||||
|
||||
// 初始化血量和血条 UI。
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user