2025-06-03 02:42:28 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2025-09-05 10:14:45 -04:00
|
|
|
using DG.Tweening;
|
2025-06-03 02:42:28 -04:00
|
|
|
using Ichni.RhythmGame.Beatmap;
|
2025-07-26 04:20:25 -04:00
|
|
|
using Ichni.UI;
|
2025-06-03 02:42:28 -04:00
|
|
|
using UniRx;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
|
using UnityEngine.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Ichni.RhythmGame
|
|
|
|
|
{
|
|
|
|
|
public partial class GameCamera : GameElement, IHaveTransformSubmodule, IHaveTimeDurationSubmodule
|
|
|
|
|
{
|
2026-03-14 03:13:10 -04:00
|
|
|
#region [暴露属性字段] Camera View & Settings
|
2025-09-05 10:14:45 -04:00
|
|
|
public Camera cam;
|
2026-03-31 07:51:40 -04:00
|
|
|
//public Transform rotationPoint;
|
|
|
|
|
//public Transform positionPoint;
|
2025-06-03 02:42:28 -04:00
|
|
|
public Transform cameraTransform;
|
|
|
|
|
|
|
|
|
|
public CameraViewType cameraViewType;
|
|
|
|
|
public float perspectiveAngle;
|
|
|
|
|
public float orthographicSize;
|
|
|
|
|
|
2025-07-26 04:20:25 -04:00
|
|
|
public float perspectiveOffset;
|
2026-03-14 03:13:10 -04:00
|
|
|
#endregion
|
2025-07-26 04:20:25 -04:00
|
|
|
|
2026-03-14 03:13:10 -04:00
|
|
|
#region [子模块接口与关联引用] Submodules & References
|
2025-06-03 02:42:28 -04:00
|
|
|
public TransformSubmodule transformSubmodule { get; set; }
|
|
|
|
|
public TimeDurationSubmodule timeDurationSubmodule { get; set; }
|
2026-03-14 03:13:10 -04:00
|
|
|
private static CameraManager cameraManager => GameManager.Instance.cameraManager;
|
|
|
|
|
#endregion
|
2025-06-03 02:42:28 -04:00
|
|
|
|
2026-03-14 03:13:10 -04:00
|
|
|
#region [生命周期] Lifecycle & Factory
|
2025-06-03 02:42:28 -04:00
|
|
|
public static GameCamera GenerateElement(string elementName, Guid id,
|
|
|
|
|
List<string> tags, bool isFirstGenerated, GameElement parentElement,
|
|
|
|
|
CameraViewType cameraViewType, float perspectiveAngle, float orthographicSize)
|
|
|
|
|
{
|
2026-03-14 03:13:10 -04:00
|
|
|
GameCamera gameCamera = Instantiate(GameManager.Instance.basePrefabs.gameCamera).GetComponent<GameCamera>();
|
2025-06-03 02:42:28 -04:00
|
|
|
|
|
|
|
|
gameCamera.Initialize(elementName, id, tags, isFirstGenerated, parentElement);
|
|
|
|
|
|
|
|
|
|
cameraManager.gameCamera = gameCamera;
|
|
|
|
|
|
|
|
|
|
gameCamera.parentElement = parentElement;
|
|
|
|
|
gameCamera.cameraViewType = cameraViewType;
|
2025-09-05 10:14:45 -04:00
|
|
|
gameCamera.cam.orthographic = cameraViewType == CameraViewType.Orthographic;
|
2025-06-03 02:42:28 -04:00
|
|
|
gameCamera.perspectiveAngle = perspectiveAngle;
|
|
|
|
|
gameCamera.orthographicSize = orthographicSize;
|
|
|
|
|
gameCamera.cameraTransform = gameCamera.transform;
|
|
|
|
|
|
2025-07-26 04:20:25 -04:00
|
|
|
float ratioDifference = UIManager.GetScreenRatio() - UIManager.StandardRatio;
|
|
|
|
|
if (ratioDifference > 0)
|
|
|
|
|
{
|
|
|
|
|
gameCamera.perspectiveOffset = -22f * ratioDifference;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//gameCamera.perspectiveOffset = 11f * ratioDifference;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-05 10:14:45 -04:00
|
|
|
gameCamera.cam.fieldOfView = perspectiveAngle + gameCamera.perspectiveOffset;
|
2025-06-03 02:42:28 -04:00
|
|
|
return gameCamera;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-08 14:28:40 -04:00
|
|
|
public override void AfterInitialize()
|
|
|
|
|
{
|
|
|
|
|
base.AfterInitialize();
|
2025-08-11 14:04:06 -04:00
|
|
|
//gameCamera.GetComponent<UniversalAdditionalCameraData>().cameraStack.Add(cameraManager.uiCamera);
|
2026-03-14 03:13:10 -04:00
|
|
|
GameManager.Instance.backgroundController.backgroundCanvas.worldCamera = cam;
|
2025-07-08 14:28:40 -04:00
|
|
|
}
|
|
|
|
|
|
2025-06-03 02:42:28 -04:00
|
|
|
public override void SetDefaultSubmodules()
|
|
|
|
|
{
|
|
|
|
|
transformSubmodule = new TransformSubmodule(this);
|
|
|
|
|
}
|
2026-03-14 03:13:10 -04:00
|
|
|
#endregion
|
2025-06-03 02:42:28 -04:00
|
|
|
}
|
|
|
|
|
|
2026-03-14 03:13:10 -04:00
|
|
|
#region [枚举类型] Enums
|
2025-06-03 02:42:28 -04:00
|
|
|
public partial class GameCamera
|
|
|
|
|
{
|
|
|
|
|
public enum CameraViewType
|
|
|
|
|
{
|
|
|
|
|
Perspective = 0,
|
|
|
|
|
Orthographic = 1
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-14 03:13:10 -04:00
|
|
|
#endregion
|
2025-06-03 02:42:28 -04:00
|
|
|
|
2026-03-14 03:13:10 -04:00
|
|
|
#region [坐标变换逻辑更新] Transform Observe & Update Logics
|
2025-06-03 02:42:28 -04:00
|
|
|
public partial class GameCamera
|
|
|
|
|
{
|
|
|
|
|
public void SetTransformObserver()
|
|
|
|
|
{
|
2025-07-26 04:20:25 -04:00
|
|
|
transformSubmodule.observer = Observable.EveryLateUpdate()
|
2026-03-14 03:13:10 -04:00
|
|
|
.Where(_=>GameManager.Instance.songPlayer.isUpdating)
|
2025-07-26 04:20:25 -04:00
|
|
|
.Subscribe(_ => UpdateTransform())
|
|
|
|
|
.AddTo(transformSubmodule.attachedGameElement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateTransform(bool refreshAll = true)
|
|
|
|
|
{
|
|
|
|
|
bool willRefresh = false;
|
|
|
|
|
|
|
|
|
|
if (!transformSubmodule.eulerAnglesOffsetLock && transformSubmodule.eulerAnglesDirtyMark)
|
|
|
|
|
{
|
|
|
|
|
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + transformSubmodule.eulerAnglesOffset;
|
|
|
|
|
transform.localEulerAngles = transformSubmodule.currentEulerAngles;
|
|
|
|
|
transformSubmodule.eulerAnglesDirtyMark = false;
|
|
|
|
|
willRefresh = true;
|
|
|
|
|
transformSubmodule.eulerAnglesOffset = Vector3.zero;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (transformSubmodule.positionDirtyMark)
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
2025-07-26 04:20:25 -04:00
|
|
|
transformSubmodule.currentPosition = transformSubmodule.originalPosition + transformSubmodule.positionOffset;
|
|
|
|
|
transform.localPosition = transformSubmodule.currentPosition;
|
|
|
|
|
transformSubmodule.positionDirtyMark = false;
|
|
|
|
|
willRefresh = true;
|
|
|
|
|
transformSubmodule.positionOffset = Vector3.zero;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (refreshAll && willRefresh)
|
|
|
|
|
{
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
2025-06-03 02:42:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
2026-03-14 03:13:10 -04:00
|
|
|
#endregion
|
2025-06-03 02:42:28 -04:00
|
|
|
|
|
|
|
|
}
|