(client) chore:Clean code
This commit is contained in:
@ -16,7 +16,7 @@ namespace CameraControl
|
||||
private bool _isDragging = false;
|
||||
|
||||
private Camera _camera;
|
||||
|
||||
|
||||
private int dimensionId;
|
||||
private string[] dimensionList;
|
||||
|
||||
@ -46,7 +46,7 @@ namespace CameraControl
|
||||
// 这确保了如果CameraControl是DontDestroyOnLoad,在切换场景后也能正确工作。
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void Init()
|
||||
{
|
||||
@ -68,7 +68,7 @@ namespace CameraControl
|
||||
|
||||
// 初始化维度数据 (假设 Program.Instance 总是已初始化)
|
||||
dimensionId = 0; // 默认从第一个维度开始
|
||||
dimensionList = Program.Instance.Dimensions;
|
||||
dimensionList = Program.Instance.Dimensions;
|
||||
if (dimensionList != null && dimensionList.Length > 0)
|
||||
{
|
||||
SetCameraPositionForDimension(0);
|
||||
@ -78,7 +78,7 @@ namespace CameraControl
|
||||
Debug.LogWarning("Dimension list is empty or null from Program.Instance. Cannot set initial camera position for dimensions.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void NextDimension()
|
||||
{
|
||||
if (_camera == null)
|
||||
@ -94,10 +94,10 @@ namespace CameraControl
|
||||
|
||||
// 1. 保存当前相机的真实位置到当前维度 (假设 Program.Instance 总是已初始化)
|
||||
// 维度ID范围检查仍然保留,因为这是数组访问的安全保障
|
||||
if (dimensionId >= 0 && dimensionId < dimensionList.Length)
|
||||
if (dimensionId >= 0 && dimensionId < dimensionList.Length)
|
||||
{
|
||||
// Program.Instance 假设不会为 null
|
||||
var currentDimension = Program.Instance.GetDimension(dimensionList[dimensionId]);
|
||||
var currentDimension = Program.Instance.GetDimension(dimensionList[dimensionId]);
|
||||
if (currentDimension != null)
|
||||
{
|
||||
currentDimension.cameraPosition = _camera.transform.position;
|
||||
@ -135,7 +135,7 @@ namespace CameraControl
|
||||
// Program.Instance 假设不会为 null
|
||||
|
||||
// 确保获取到的 Dimension 对象不为 null
|
||||
var dimension = Program.Instance.GetDimension(dimensionList[id]);
|
||||
var dimension = Program.Instance.GetDimension(dimensionList[id]);
|
||||
if (dimension)
|
||||
{
|
||||
Vector3 cameraPosition = dimension.cameraPosition;
|
||||
@ -152,7 +152,7 @@ namespace CameraControl
|
||||
if (_camera == null) return; // 确保相机存在
|
||||
|
||||
// 假设 Program.Instance 总是已初始化
|
||||
if (Program.Instance.FocusedEntity)
|
||||
if (Program.Instance.FocusedEntity)
|
||||
{
|
||||
var targetPosition = new Vector3(
|
||||
Program.Instance.FocusedEntity.Position.x,
|
||||
@ -171,7 +171,7 @@ namespace CameraControl
|
||||
NextDimension();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void TickUI()
|
||||
{
|
||||
if (!_camera) // 确保相机存在
|
||||
@ -199,7 +199,7 @@ namespace CameraControl
|
||||
_dragOrigin = _camera.ScreenToWorldPoint(Input.mousePosition);
|
||||
_isDragging = true;
|
||||
// 假设 Program.Instance 总是已初始化
|
||||
if (Program.Instance.FocusedEntity)
|
||||
if (Program.Instance.FocusedEntity)
|
||||
{
|
||||
Program.Instance.FocusedEntity.PlayerControlled = false;
|
||||
Program.Instance.SetFocusedEntity(null);
|
||||
|
Reference in New Issue
Block a user