using System; using SLSUtilities.General; using UnityEngine; namespace Cielonos.MainGame.Characters { public partial class AuxiliaryDrone : MonoBehaviour { public Player player => MainGameManager.Player; public GameObject droneModel; public Transform center; public Transform muzzle; public Vector3 velocity, offset; private void Start() { SetDroneEmissionColor(Color.cyan); } private void Update() { // selfTimeSm.TimeScale 不包含 Unity 的 Time.timeScale, // 因此暂停时 TimeScale 可能非零但 DeltaTime 为零,需检查 DeltaTime 避免除零。 float deltaTime = player.selfTimeSm.DeltaTime; if (deltaTime < Mathf.Epsilon) { return; } Vector3 moveDirection = player.landMovementSc.horizontalMovement / deltaTime; moveDirection *= 0.1f; Transform playerTransform = player.transform; Vector3 cameraRight = player.viewSc.playerCamera.transform.right; float dot = Vector3.Dot(moveDirection.normalized, cameraRight); Vector3 realOffset = cameraRight * offset.x + playerTransform.up * offset.y; Vector3 targetPosition = playerTransform.position + moveDirection * Mathf.Max(0, dot) + realOffset; Vector3 dronePosition = transform.position; float posX = Mathf.SmoothDamp(dronePosition.x, targetPosition.x, ref velocity.x, 0.1f); float posY = Mathf.SmoothDamp(dronePosition.y, targetPosition.y, ref velocity.y, 0.3f); float posZ = Mathf.SmoothDamp(dronePosition.z, targetPosition.z, ref velocity.z, 0.1f); dronePosition = new Vector3(posX, posY, posZ); transform.position = dronePosition; /*EnemyController availableEnemy = GameManager.enemyManager.GetIdealEnemy(float.MaxValue, true); if (availableEnemy != null) { Vector3 enemyPosition = availableEnemy.flexibleCenterPoint.position; Vector3 lookAtDirection = (enemyPosition - dronePosition).normalized; transform.forward = Vector3.Lerp(transform.forward, lookAtDirection, 0.2f); } else*/ { Vector3 lookAtDirection = player.viewSc.playerCamera.transform.forward; transform.forward = Vector3.Lerp(transform.forward, lookAtDirection, 0.2f); } } } public partial class AuxiliaryDrone { private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor"); private Color _currentEmissionColor; public void SetDroneEmissionColor(Color color, float intensity = 3) { if (color == _currentEmissionColor) return; _currentEmissionColor = color * Mathf.Pow(2, intensity); Material droneMaterial = droneModel.GetComponent().material; droneMaterial.SetColor(EmissionColor, _currentEmissionColor); } } }