法杖,武器切换

This commit is contained in:
SoulliesOfficial
2025-12-24 16:58:51 -05:00
parent 2a2aa728d5
commit 3bcd7c1cf8
78 changed files with 230589 additions and 50400 deletions

View File

@@ -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);
}

View File

@@ -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;
}
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3fab41e279f53e64581303af20901fbd