迁移敌人模型到新素材上并加入动画

This commit is contained in:
2026-10-05 18:53:10 +08:00
parent 7590d78e74
commit fc8f720e57
289 changed files with 100572 additions and 3243 deletions
@@ -0,0 +1,102 @@
using SepCore.Debugger;
using SepCore.Entity;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace SepCore.Components
{
public class EnemyMovementComponent : MonoBehaviour
{
[SerializeField] private float _enemyBodyRadius;
private bool _isMoving;
private Vector3 _direction;
private bool _avoidEnemyOverlap;
private int _separationIterations;
private float _speedBase;
private EnemyBase _enemy;
public float Speed => _speedBase;
public bool AvoidEnemyOverlap => _avoidEnemyOverlap;
public float EnemyBodyRadius => _enemyBodyRadius;
public int SeparationIterations => _separationIterations;
public bool IsMoving => _isMoving;
public Vector3 Direction => _direction;
public void OnInit(float speed, bool avoidEnemyOverlap = false,
float? enemyBodyRadius = null, int? separationIterations = null)
{
_speedBase = speed;
_direction = Vector3.forward;
_avoidEnemyOverlap = avoidEnemyOverlap;
_enemyBodyRadius = enemyBodyRadius ?? GameEntry.Luban.Global.EnemyBodyRadius;
_separationIterations = separationIterations ?? GameEntry.Luban.Global.EnemySeparationIterations;
_enemy = GetComponentInParent<EnemyBase>();
SyncToSimulationWorld();
}
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
SyncToSimulationWorld();
}
public void OnReset()
{
_enemyBodyRadius = GameEntry.Luban.Global.EnemyBodyRadius;
_separationIterations = GameEntry.Luban.Global.EnemySeparationIterations;
_speedBase = 0f;
_direction = Vector3.zero;
_isMoving = false;
_avoidEnemyOverlap = false;
_enemy = null;
}
public void SetMove(bool isMoving)
{
_isMoving = isMoving;
SyncToSimulationWorld();
}
public void SetDirection(Vector3 direction)
{
_direction = direction;
SyncToSimulationWorld();
}
private void SyncToSimulationWorld()
{
using (CustomProfilerMarker.Movement_Update.Auto())
{
Vector3 direction = _direction;
direction.y = 0f;
if (direction.sqrMagnitude > Mathf.Epsilon)
{
direction.Normalize();
}
GameEntry.SimulationWorld.SyncEnemyMovementInput(_enemy.Id, _isMoving, direction, Speed,
_avoidEnemyOverlap, _enemyBodyRadius, _separationIterations);
}
}
#if UNITY_EDITOR
private void OnDrawGizmosSelected()
{
if (_enemyBodyRadius <= 0f)
{
return;
}
Color previousColor = Handles.color;
Handles.color = Color.cyan;
Handles.DrawWireDisc(transform.position, Vector3.up, _enemyBodyRadius);
Handles.color = previousColor;
}
#endif
}
}
@@ -1,140 +0,0 @@
using System;
using SepCore.Definition;
using SepCore.Entity;
using SepCore.Simulation;
using UnityEngine;
using SepCore.Debugger;
namespace SepCore.Components
{
public class MovementComponent : MonoBehaviour
{
[SerializeField] private bool _isMoving;
[SerializeField] private Vector3 _direction;
[SerializeField] private Transform _cachedTransform;
[SerializeField] private bool _avoidEnemyOverlap;
[SerializeField] private float _enemyBodyRadius;
[SerializeField] private int _separationIterations;
public float Speed => _statComponent != null ? _statComponent.GetStatValue(StatType.MoveSpeed) : _speedBase;
public bool AvoidEnemyOverlap => _avoidEnemyOverlap;
public float EnemyBodyRadius => _enemyBodyRadius;
public int SeparationIterations => _separationIterations;
public bool IsMoving => _isMoving;
public Vector3 Direction => _direction;
public Transform CachedTransform => _cachedTransform;
[SerializeField] private float _speedBase;
private StatComponent _statComponent;
private Player _player;
private EnemyBase _enemy;
private Action<StatType, float> _onStatChangedAction;
public void OnInit(float speed, Transform target, StatComponent statComponent = null,
bool avoidEnemyOverlap = false, float? enemyBodyRadius = null, int? separationIterations = null)
{
_speedBase = speed;
_cachedTransform = target;
_direction = Vector3.forward;
_avoidEnemyOverlap = avoidEnemyOverlap;
_enemyBodyRadius = enemyBodyRadius ?? GameEntry.Luban.Global.EnemyBodyRadius;
_separationIterations = separationIterations ?? GameEntry.Luban.Global.EnemySeparationIterations;
TryGetComponent(out _player);
TryGetComponent(out _enemy);
_statComponent = statComponent;
if (_statComponent != null)
{
_statComponent.Pipeline.SetBaseValue(StatType.MoveSpeed, speed);
_onStatChangedAction = OnStatChanged;
_statComponent.Pipeline.OnStatChanged += _onStatChangedAction;
}
SyncToSimulationWorld();
}
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
SyncToSimulationWorld();
}
public void OnReset()
{
Transform transformToUnregister = _cachedTransform;
_enemyBodyRadius = GameEntry.Luban.Global.EnemyBodyRadius;
_separationIterations = GameEntry.Luban.Global.EnemySeparationIterations;
_speedBase = 0;
_cachedTransform = null;
_direction = Vector3.zero;
_isMoving = false;
_avoidEnemyOverlap = false;
_player = null;
_enemy = null;
if (_statComponent != null && _onStatChangedAction != null)
{
_statComponent.Pipeline.OnStatChanged -= _onStatChangedAction;
_onStatChangedAction = null;
}
_statComponent = null;
if (transformToUnregister != null && GameEntry.SimulationWorld != null)
{
GameEntry.SimulationWorld.UnregisterPlayerMovement(transformToUnregister);
}
}
public void SetMove(bool isMoving)
{
_isMoving = isMoving;
SyncToSimulationWorld();
}
public void SetDirection(Vector3 direction)
{
_direction = direction;
SyncToSimulationWorld();
}
private void SyncToSimulationWorld()
{
using (CustomProfilerMarker.Movement_Update.Auto())
{
if (_cachedTransform == null || GameEntry.SimulationWorld == null)
{
return;
}
Vector3 direction = _direction;
direction.y = 0f;
if (direction.sqrMagnitude > Mathf.Epsilon)
{
direction.Normalize();
}
if (_player != null)
{
GameEntry.SimulationWorld.SyncPlayerMovementInput(_cachedTransform, _isMoving, direction, Speed);
return;
}
if (_enemy != null)
{
GameEntry.SimulationWorld.SyncEnemyMovementInput(_enemy.Id, _isMoving, direction, Speed,
_avoidEnemyOverlap, _enemyBodyRadius, _separationIterations);
}
}
}
private void OnStatChanged(StatType statType, float newValue)
{
if (statType == StatType.MoveSpeed)
{
SyncToSimulationWorld();
}
}
}
}