1
This commit is contained in:
1 parent
fb353c45a7
commit
84d0a510bb
46 files changed
+9866
-94
No files matched your search
@@ -0,0 +1,73 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class ArcherSkill : UnitSkill
|
||||
{
|
||||
[Min(1)]
|
||||
public int volleyArrowCount = 3;
|
||||
|
||||
[Min(0f)]
|
||||
public float volleyArrowDamageMultiplier = 0.7f;
|
||||
|
||||
[Min(0f)]
|
||||
public float volleyArrowInterval = 0.15f;
|
||||
|
||||
private Coroutine volleyCoroutine;
|
||||
|
||||
public override void ReleaseSkill()
|
||||
{
|
||||
if (volleyCoroutine != null)
|
||||
{
|
||||
StopCoroutine(volleyCoroutine);
|
||||
}
|
||||
|
||||
volleyCoroutine = StartCoroutine(FireVolley());
|
||||
}
|
||||
|
||||
private IEnumerator FireVolley()
|
||||
{
|
||||
for (int i = 0; i < volleyArrowCount; i++)
|
||||
{
|
||||
// 三连射优先攻击当前目标;目标阵亡后剩余箭矢改打最近敌人。
|
||||
GameObject volleyTarget = unit.Target != null ? unit.Target : FindNearestOpponent();
|
||||
if (volleyTarget == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
unit.FireSkillProjectile(volleyTarget, volleyArrowDamageMultiplier);
|
||||
yield return new WaitForSeconds(volleyArrowInterval);
|
||||
}
|
||||
|
||||
volleyCoroutine = null;
|
||||
}
|
||||
|
||||
private GameObject FindNearestOpponent()
|
||||
{
|
||||
string opponentTag = unit.OpponentTag;
|
||||
if (string.IsNullOrEmpty(opponentTag))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject nearestOpponent = null;
|
||||
float nearestSqrDistance = float.PositiveInfinity;
|
||||
GameObject[] opponents = GameObject.FindGameObjectsWithTag(opponentTag);
|
||||
foreach (GameObject opponent in opponents)
|
||||
{
|
||||
if (opponent == null || opponent.transform.root == unit.transform.root)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float sqrDistance = (opponent.transform.position - unit.transform.position).sqrMagnitude;
|
||||
if (sqrDistance < nearestSqrDistance)
|
||||
{
|
||||
nearestSqrDistance = sqrDistance;
|
||||
nearestOpponent = opponent;
|
||||
}
|
||||
}
|
||||
|
||||
return nearestOpponent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: CSxJtC6rW31/KwEkK4ivs38SznYbHeuYb86/3jXHHQflxor/O1l4M7U=
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,7 +5,7 @@ public class StatusEffectController : MonoBehaviour
|
||||
[Header("通用眩晕显示")]
|
||||
[SerializeField] private bool showStunIndicator = true;
|
||||
[SerializeField] private float indicatorHeight = 0.35f;
|
||||
[SerializeField] private float indicatorSize = 0.5f;
|
||||
[SerializeField] private GameObject stunIndicatorPrefab;
|
||||
|
||||
private Animator animator;
|
||||
private float stunnedRemaining;
|
||||
@@ -92,34 +92,18 @@ public class StatusEffectController : MonoBehaviour
|
||||
bounds.max.y + indicatorHeight,
|
||||
bounds.center.z);
|
||||
|
||||
Camera camera = Camera.main;
|
||||
if (camera != null)
|
||||
{
|
||||
indicatorTransform.rotation = Quaternion.LookRotation(
|
||||
camera.transform.position - indicatorTransform.position,
|
||||
camera.transform.up)
|
||||
* Quaternion.Euler(0f, 0f, Time.unscaledTime * 180f);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureIndicator()
|
||||
{
|
||||
if (stunIndicator != null)
|
||||
if (stunIndicator != null || stunIndicatorPrefab == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
stunIndicator = new GameObject("StunIndicator_Star");
|
||||
stunIndicator = Instantiate(stunIndicatorPrefab);
|
||||
stunIndicator.name = "StunIndicator_Particle";
|
||||
indicatorTransform = stunIndicator.transform;
|
||||
|
||||
TextMesh text = stunIndicator.AddComponent<TextMesh>();
|
||||
text.text = "★";
|
||||
text.anchor = TextAnchor.MiddleCenter;
|
||||
text.alignment = TextAlignment.Center;
|
||||
text.fontSize = 64;
|
||||
text.characterSize = indicatorSize;
|
||||
text.fontStyle = FontStyle.Bold;
|
||||
text.color = new Color(1f, 0.85f, 0.05f, 1f);
|
||||
}
|
||||
|
||||
private void DestroyIndicator()
|
||||
|
||||
@@ -25,6 +25,7 @@ public class StoneGolemSkill : UnitSkill
|
||||
return;
|
||||
}
|
||||
|
||||
unit.FaceCurrentTarget(0f);
|
||||
isSkillReady = true;
|
||||
unit.PlaySkillAnimation(OnSkillFinished, skillAnimationDuration);
|
||||
}
|
||||
|
||||
+49
-20
@@ -409,6 +409,11 @@ public class UnitBase : MonoBehaviour
|
||||
|
||||
FaceTarget(friend);
|
||||
|
||||
if (TryReleaseSkill())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//根据目标攻击时长加速或减速完整攻击动画
|
||||
SetAttackAnimationSpeed();
|
||||
|
||||
@@ -419,6 +424,11 @@ public class UnitBase : MonoBehaviour
|
||||
}
|
||||
|
||||
private void FaceTarget(GameObject opponent)
|
||||
{
|
||||
FaceTarget(opponent, modelFacingOffset);
|
||||
}
|
||||
|
||||
private void FaceTarget(GameObject opponent, float facingOffset)
|
||||
{
|
||||
if (opponent == null)
|
||||
{
|
||||
@@ -432,10 +442,38 @@ public class UnitBase : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyFacingRotation(direction);
|
||||
ApplyFacingRotation(direction, facingOffset);
|
||||
}
|
||||
|
||||
private void ApplyFacingRotation(Vector3 direction)
|
||||
public void FaceCurrentTarget()
|
||||
{
|
||||
FaceTarget(target);
|
||||
}
|
||||
|
||||
public void FaceCurrentTarget(float facingOffset)
|
||||
{
|
||||
FaceTarget(target, facingOffset);
|
||||
}
|
||||
|
||||
private bool TryReleaseSkill()
|
||||
{
|
||||
if (worldHealthBar == null
|
||||
|| !worldHealthBar.IsEnergyFull
|
||||
|| unitSkill == null
|
||||
|| target == null
|
||||
|| !target.activeInHierarchy)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
worldHealthBar.ResetEnergy();
|
||||
state = State.Alert;
|
||||
animator.SetInteger("speed", 0);
|
||||
unitSkill.ReleaseSkill();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ApplyFacingRotation(Vector3 direction, float facingOffset)
|
||||
{
|
||||
direction.y = 0f;
|
||||
if (direction.sqrMagnitude <= 0.0001f)
|
||||
@@ -446,7 +484,7 @@ public class UnitBase : MonoBehaviour
|
||||
Quaternion targetRotation = Quaternion.LookRotation(direction, Vector3.up);
|
||||
transform.rotation = Quaternion.Euler(
|
||||
0f,
|
||||
targetRotation.eulerAngles.y + modelFacingOffset,
|
||||
targetRotation.eulerAngles.y + facingOffset,
|
||||
0f);
|
||||
}
|
||||
|
||||
@@ -622,6 +660,11 @@ public class UnitBase : MonoBehaviour
|
||||
}
|
||||
|
||||
public void FireSkillProjectile(GameObject opponent)
|
||||
{
|
||||
FireSkillProjectile(opponent, 1f);
|
||||
}
|
||||
|
||||
public void FireSkillProjectile(GameObject opponent, float damageMultiplier)
|
||||
{
|
||||
if (opponent == null || projectilePrefab == null || projectileSpawnPoint == null)
|
||||
{
|
||||
@@ -636,11 +679,11 @@ public class UnitBase : MonoBehaviour
|
||||
if (projectile != null)
|
||||
{
|
||||
// 技能箭不再次积攒能量,避免技能触发递归。
|
||||
projectile.Initialize(opponent, attackPower, gameObject, projectileSpeed, projectileLifetime, false);
|
||||
projectile.Initialize(opponent, attackPower * Mathf.Max(0f, damageMultiplier), gameObject, projectileSpeed, projectileLifetime, false);
|
||||
}
|
||||
}
|
||||
|
||||
// 普通攻击命中后积攒能量,满能量时清空能量并调用技能占位方法。
|
||||
// 普通攻击命中后只积攒能量,大招在下一次普攻开始前释放。
|
||||
private void AddAttackEnergy()
|
||||
{
|
||||
if (worldHealthBar == null || energyPerAttack <= 0f)
|
||||
@@ -648,21 +691,7 @@ public class UnitBase : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
if (!worldHealthBar.AddEnergy(energyPerAttack))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
worldHealthBar.ResetEnergy();
|
||||
ReleaseSkill();
|
||||
}
|
||||
|
||||
private void ReleaseSkill()
|
||||
{
|
||||
if (unitSkill != null)
|
||||
{
|
||||
unitSkill.ReleaseSkill();
|
||||
}
|
||||
worldHealthBar.AddEnergy(energyPerAttack);
|
||||
}
|
||||
|
||||
private float GetSkillAnimationSpeed(float targetDuration)
|
||||
|
||||
@@ -16,6 +16,8 @@ public class WorldHealthBar : MonoBehaviour
|
||||
// 当前技能能量,范围会自动限制在 0 到 maxEnergy 之间。
|
||||
[Min(0f)] public float currentEnergy = 0f;
|
||||
|
||||
public bool IsEnergyFull => !isDead && currentEnergy >= maxEnergy;
|
||||
|
||||
// 血条相对于单位头顶的额外高度。
|
||||
[Min(0f)] public float heightOffset = 0.25f;
|
||||
|
||||
|
||||
Reference in new issue
Block a user