法杖,武器切换
This commit is contained in:
@@ -14,7 +14,7 @@ using Random = UnityEngine.Random;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public abstract partial class AttackAreaBase : MonoBehaviour
|
||||
public abstract partial class AttackAreaBase : SerializedMonoBehaviour
|
||||
{
|
||||
private static Dictionary<string, int> areaNameCountDictionary = new Dictionary<string, int>();
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace Cielonos.MainGame
|
||||
public Action updateAction;
|
||||
|
||||
[Title("Submodules")]
|
||||
[HideInEditorMode] public TransformSubmodule transformSm;
|
||||
[HideInEditorMode] public AttackSubmodule attackSm;
|
||||
[HideInEditorMode] public TimeSubmodule timeSm;
|
||||
[HideInEditorMode] public HitSubmodule hitSm;
|
||||
@@ -96,12 +97,19 @@ namespace Cielonos.MainGame
|
||||
}
|
||||
|
||||
this.SetReactionSubmodule<T>();
|
||||
|
||||
BattleManager.AttackAreaSm.Register(this);
|
||||
topParent.GetComponent<VFXObject>().onDespawnAction = () =>
|
||||
{
|
||||
BattleManager.AttackAreaSm.Unregister(this);
|
||||
};
|
||||
|
||||
return this as T;
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
transformSm?.Update();
|
||||
raycastSm?.Update();
|
||||
updateAction?.Invoke();
|
||||
hitSm?.Update();
|
||||
@@ -112,6 +120,16 @@ namespace Cielonos.MainGame
|
||||
|
||||
public partial class AttackAreaBase
|
||||
{
|
||||
#region TransformSubmodule
|
||||
|
||||
public T SetTransformSubmodule<T>(Transform target = null, float delay = 0) where T : AttackAreaBase
|
||||
{
|
||||
transformSm = new TransformSubmodule(this, target, delay);
|
||||
return this as T;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AttackSubmodule
|
||||
public T SetAttackSubmodule<T>(AttackUnit attackUnit, GameObject hitVFX = null) where T : AttackAreaBase
|
||||
{
|
||||
@@ -163,10 +181,41 @@ namespace Cielonos.MainGame
|
||||
|
||||
#region TraceMoveModule
|
||||
|
||||
public T SetTraceMoveModule<T>(CharacterBase target, float moveSpeed, float moveAcceleration,
|
||||
/// <summary>
|
||||
/// 设置自适应追踪移动子模块,根据和目标的距离自动连接和断开追踪
|
||||
/// 断开追踪后,自动选择范围内最近的目标进行追踪
|
||||
/// </summary>
|
||||
public T SetAdaptiveTraceMoveModule<T>(CharacterBase target, float moveSpeed, float moveAcceleration,
|
||||
float angularSpeed, float angularAcceleration, Vector3 initialDirection,
|
||||
bool autoConnect = true, bool autoDisconnect = true, float detectRadius = 10f, bool stopWhenHit = true) where T : AttackAreaBase
|
||||
{
|
||||
moveSm = new TraceMoveSubmodule(this, target, moveSpeed, moveAcceleration, angularSpeed,
|
||||
angularAcceleration, initialDirection, autoConnect, autoDisconnect, detectRadius, stopWhenHit);
|
||||
return this as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置不可更改目标的追踪移动子模块
|
||||
/// 永远追踪指定目标,不会断开
|
||||
/// </summary>
|
||||
public T SetUnchangeableTraceMoveModule<T>(CharacterBase target, float moveSpeed, float moveAcceleration,
|
||||
float angularSpeed, float angularAcceleration, Vector3 initialDirection, bool stopWhenHit = true) where T : AttackAreaBase
|
||||
{
|
||||
moveSm = new TraceMoveSubmodule(this, target, moveSpeed, moveAcceleration, angularSpeed, angularAcceleration, initialDirection, stopWhenHit);
|
||||
moveSm = new TraceMoveSubmodule(this, target, moveSpeed, moveAcceleration, angularSpeed,
|
||||
angularAcceleration, initialDirection, false, false, 0, stopWhenHit);
|
||||
return this as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置可分离目标的追踪移动子模块
|
||||
/// 一旦目标超出检测范围则断开追踪,断开后不再追踪其他目标
|
||||
/// </summary>
|
||||
public T SeDetachableTraceMoveModule<T>(CharacterBase target, float moveSpeed, float moveAcceleration,
|
||||
float angularSpeed, float angularAcceleration, Vector3 initialDirection,
|
||||
float detectRadius = 10f, bool stopWhenHit = true) where T : AttackAreaBase
|
||||
{
|
||||
moveSm = new TraceMoveSubmodule(this, target, moveSpeed, moveAcceleration, angularSpeed,
|
||||
angularAcceleration, initialDirection, false, true, detectRadius, stopWhenHit);
|
||||
return this as T;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,8 +96,13 @@ namespace Cielonos.MainGame
|
||||
}
|
||||
}
|
||||
|
||||
public void Explode(Vector3 hitPosition)
|
||||
public void Explode(Vector3 hitPosition = default)
|
||||
{
|
||||
if (hitPosition == default)
|
||||
{
|
||||
hitPosition = transform.position;
|
||||
}
|
||||
|
||||
GenerateHitEffect(hitPosition);
|
||||
PlaySoundFX(hitPosition);
|
||||
LeanPool.Despawn(topParent.gameObject);
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Cielonos.MainGame
|
||||
Vector3 point1 = owner.transform.position - rayDirection.normalized * capsuleHeight;
|
||||
Collider[] hitColliders = new Collider[8];
|
||||
int size = Physics.OverlapCapsuleNonAlloc(point0, point1, capsuleRadius, hitColliders,
|
||||
LayerMask.GetMask("Player", "Enemy", "Default", "FadableEnvironment", "UnfadableEnvironment", "Wall", "Ground"));
|
||||
LayerMask.GetMask("HurtBox", "Default", "FadableEnvironment", "UnfadableEnvironment", "Wall", "Ground"));
|
||||
if (size >= 1)
|
||||
{
|
||||
Debug.Log("RaycastSubmodule detected colliders: " + size);
|
||||
@@ -74,7 +74,7 @@ namespace Cielonos.MainGame
|
||||
else
|
||||
{
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, rayLength,
|
||||
LayerMask.GetMask("Player", "Enemy", "Default", "FadableEnvironment", "UnfadableEnvironment", "Wall", "Ground")))
|
||||
LayerMask.GetMask("HurtBox", "Default", "FadableEnvironment", "UnfadableEnvironment", "Wall", "Ground")))
|
||||
{
|
||||
onHit?.Invoke(hit.collider, hit.point);
|
||||
}
|
||||
|
||||
@@ -3,26 +3,34 @@ using UnityEngine;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public class TraceMoveSubmodule : MoveSubmoduleBase
|
||||
public partial class TraceMoveSubmodule : MoveSubmoduleBase
|
||||
{
|
||||
public Transform projectile => owner.topParent;
|
||||
public CharacterBase target;
|
||||
public Transform targetTransform;
|
||||
public float angularSpeed;
|
||||
public float angularAcceleration;
|
||||
public float moveSpeed;
|
||||
public float moveAcceleration;
|
||||
|
||||
public bool autoConnect;
|
||||
public bool autoDisconnect;
|
||||
public float detectRadius;
|
||||
|
||||
private float deltaTime => owner.creator.selfTimeSm.DeltaTime;
|
||||
private Vector3 step;
|
||||
|
||||
public TraceMoveSubmodule(AttackAreaBase attackArea, CharacterBase target, float moveSpeed, float moveAcceleration,
|
||||
float angularSpeed, float angularAcceleration, Vector3 initialDirection, bool stopWhenHit) : base(attackArea, stopWhenHit)
|
||||
public TraceMoveSubmodule(AttackAreaBase attackArea, CharacterBase target,
|
||||
float moveSpeed, float moveAcceleration, float angularSpeed, float angularAcceleration, Vector3 initialDirection,
|
||||
bool autoConnect, bool autoDisconnect, float detectRadius, bool stopWhenHit) : base(attackArea, stopWhenHit)
|
||||
{
|
||||
this.target = target;
|
||||
this.targetTransform = target != null ? target.transform : null;
|
||||
this.angularSpeed = angularSpeed;
|
||||
this.angularAcceleration = angularAcceleration;
|
||||
this.moveSpeed = moveSpeed;
|
||||
this.moveAcceleration = moveAcceleration;
|
||||
this.autoConnect = autoConnect;
|
||||
this.autoDisconnect = autoDisconnect;
|
||||
this.detectRadius = detectRadius;
|
||||
projectile.forward = initialDirection;
|
||||
}
|
||||
|
||||
@@ -30,16 +38,29 @@ namespace Cielonos.MainGame
|
||||
{
|
||||
if (target == null || target.statusSm.isDead)
|
||||
{
|
||||
moveSpeed += moveAcceleration * Time.deltaTime;
|
||||
moveSpeed += moveAcceleration * deltaTime;
|
||||
moveSpeed = Mathf.Max(moveSpeed, 0f);
|
||||
unscaledVelocity = projectile.forward * moveSpeed;
|
||||
scaledVelocity = unscaledVelocity * timeScaleCoefficient; //attackArea.creator.selfTimeModule
|
||||
projectile.position += scaledVelocity * Time.deltaTime;
|
||||
scaledVelocity = timeScaleCoefficient * unscaledVelocity;
|
||||
projectile.position += scaledVelocity * deltaTime;
|
||||
|
||||
if (autoConnect)
|
||||
{
|
||||
if (owner.creator == MainGameManager.Player)
|
||||
{
|
||||
CharacterBase detectEnemy = BattleManager.EnemySm.GetNearestEnemy(detectRadius, owner.transform);
|
||||
if (detectEnemy != null)
|
||||
{
|
||||
target = detectEnemy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
angularSpeed += angularAcceleration * Time.deltaTime;
|
||||
moveSpeed += moveAcceleration * Time.deltaTime;
|
||||
angularSpeed += angularAcceleration * deltaTime;
|
||||
moveSpeed += moveAcceleration * deltaTime;
|
||||
angularSpeed = Mathf.Max(angularSpeed, 0f);
|
||||
moveSpeed = Mathf.Max(moveSpeed, 0f);
|
||||
|
||||
@@ -48,12 +69,21 @@ namespace Cielonos.MainGame
|
||||
{
|
||||
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
||||
// RotateTowards 保证恒定转速,不会因为角度小而变慢
|
||||
projectile.rotation = Quaternion.RotateTowards(projectile.rotation, targetRotation, angularSpeed * Time.deltaTime);
|
||||
projectile.rotation = Quaternion.RotateTowards(projectile.rotation, targetRotation, angularSpeed * deltaTime);
|
||||
}
|
||||
|
||||
unscaledVelocity = projectile.forward * moveSpeed;
|
||||
scaledVelocity = unscaledVelocity * timeScaleCoefficient; //attackArea.creator.selfTimeModule.EntityDeltaTime);
|
||||
projectile.position += scaledVelocity * Time.deltaTime;
|
||||
scaledVelocity = unscaledVelocity * timeScaleCoefficient;
|
||||
projectile.position += scaledVelocity * deltaTime;
|
||||
|
||||
if (autoDisconnect)
|
||||
{
|
||||
float distanceToTarget = Vector3.Distance(projectile.position, target.flexibleCenterPoint.position);
|
||||
if (distanceToTarget > detectRadius)
|
||||
{
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
using SLSFramework.General;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public partial class TransformSubmodule : AttackAreaSubmoduleBase
|
||||
{
|
||||
public Transform targetTransform;
|
||||
public float delay;
|
||||
public float timer;
|
||||
|
||||
public bool applyPosition;
|
||||
public float positionMoveDuration;
|
||||
public EaseType positionEaseType;
|
||||
public Vector3 startPosition;
|
||||
public Vector3 endPosition;
|
||||
private AnimationCurve positionCurve;
|
||||
|
||||
public bool applyRotation;
|
||||
public float rotationMoveDuration;
|
||||
public EaseType rotationEaseType;
|
||||
public Vector3 startEulerAngles;
|
||||
public Vector3 endEulerAngles;
|
||||
private AnimationCurve rotationCurve;
|
||||
|
||||
public bool applyScale;
|
||||
public float scaleMoveDuration;
|
||||
public EaseType scaleEaseType;
|
||||
public Vector3 startScale;
|
||||
public Vector3 endScale;
|
||||
private AnimationCurve scaleCurve;
|
||||
|
||||
public TransformSubmodule(AttackAreaBase attackArea, Transform targetTransform = null, float delay = 0f) : base(attackArea)
|
||||
{
|
||||
this.targetTransform = targetTransform ?? attackArea.topParent.transform;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public AttackAreaBase ApplyPositionMove(Vector3 startPosition, Vector3 endPosition, float duration, EaseType easeType = EaseType.Linear)
|
||||
{
|
||||
this.applyPosition = true;
|
||||
this.startPosition = startPosition;
|
||||
this.endPosition = endPosition;
|
||||
this.positionMoveDuration = duration;
|
||||
this.positionEaseType = easeType;
|
||||
this.positionCurve = Ease.GetCurve(easeType);
|
||||
return attackArea;
|
||||
}
|
||||
|
||||
public AttackAreaBase ApplyRotationMove(Vector3 startEulerAngles, Vector3 endEulerAngles, float duration, EaseType easeType = EaseType.Linear)
|
||||
{
|
||||
this.applyRotation = true;
|
||||
this.startEulerAngles = startEulerAngles;
|
||||
this.endEulerAngles = endEulerAngles;
|
||||
this.rotationMoveDuration = duration;
|
||||
this.rotationEaseType = easeType;
|
||||
this.rotationCurve = Ease.GetCurve(easeType);
|
||||
return attackArea;
|
||||
}
|
||||
|
||||
public AttackAreaBase ApplyScaleMove(Vector3 startScale, Vector3 endScale, float duration, EaseType easeType = EaseType.Linear)
|
||||
{
|
||||
this.applyScale = true;
|
||||
this.startScale = startScale;
|
||||
this.endScale = endScale;
|
||||
this.scaleMoveDuration = duration;
|
||||
this.scaleEaseType = easeType;
|
||||
this.scaleCurve = Ease.GetCurve(easeType);
|
||||
return attackArea;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class TransformSubmodule
|
||||
{
|
||||
public virtual void Update()
|
||||
{
|
||||
if(timer > Mathf.Max(positionMoveDuration, rotationMoveDuration, scaleMoveDuration))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float deltaTime = attackArea.creator != null ? attackArea.creator.selfTimeSm.DeltaTime : Time.deltaTime;
|
||||
if (delay > 0f)
|
||||
{
|
||||
delay -= deltaTime;
|
||||
return;
|
||||
}
|
||||
|
||||
timer += deltaTime;
|
||||
|
||||
if (applyPosition)
|
||||
{
|
||||
float t = Mathf.Clamp01(timer / positionMoveDuration);
|
||||
t = positionCurve.Evaluate(t);
|
||||
attackArea.topParent.transform.localPosition = Vector3.LerpUnclamped(startPosition, endPosition, t);
|
||||
}
|
||||
|
||||
if (applyRotation)
|
||||
{
|
||||
float t = Mathf.Clamp01(timer / rotationMoveDuration);
|
||||
t = rotationCurve.Evaluate(t);
|
||||
Vector3 currentEulerAngles = Vector3.LerpUnclamped(startEulerAngles, endEulerAngles, t);
|
||||
attackArea.topParent.transform.localRotation = Quaternion.Euler(currentEulerAngles);
|
||||
}
|
||||
|
||||
if (applyScale)
|
||||
{
|
||||
float t = Mathf.Clamp01(timer / scaleMoveDuration);
|
||||
t = scaleCurve.Evaluate(t);
|
||||
attackArea.topParent.transform.localScale = Vector3.LerpUnclamped(startScale, endScale, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fab41e279f53e64581303af20901fbd
|
||||
Reference in New Issue
Block a user