Merge branch 'feature/本地化内容导入' into 'develop'
Feature/本地化内容导入 See merge request aibis-dream/aibis-dream!706
This commit is contained in:
@@ -8630,8 +8630,8 @@ RectTransform:
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -0.091, y: -0.038}
|
||||
m_SizeDelta: {x: 1.7891, y: 1.0227}
|
||||
m_AnchoredPosition: {x: -0.145, y: -0.2658}
|
||||
m_SizeDelta: {x: 1.897, y: 1.4784}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &993713977258796821
|
||||
MonoBehaviour:
|
||||
@@ -9388,8 +9388,8 @@ RectTransform:
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -0.206, y: 0.69}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: -0.206, y: 0.768}
|
||||
m_SizeDelta: {x: 1.19, y: 0.31}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!23 &8463051385821152497
|
||||
MeshRenderer:
|
||||
|
||||
@@ -126,8 +126,8 @@ MonoBehaviour:
|
||||
m_faceColor:
|
||||
serializedVersion: 2
|
||||
rgba: 4294967295
|
||||
m_fontSize: 2.5
|
||||
m_fontSizeBase: 2.5
|
||||
m_fontSize: 2.2
|
||||
m_fontSizeBase: 2.2
|
||||
m_fontWeight: 400
|
||||
m_enableAutoSizing: 0
|
||||
m_fontSizeMin: 18
|
||||
|
||||
@@ -4239,6 +4239,7 @@ GameObject:
|
||||
- component: {fileID: 519420034}
|
||||
- component: {fileID: 519420035}
|
||||
- component: {fileID: 519420036}
|
||||
- component: {fileID: 519420037}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
@@ -4432,6 +4433,18 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
nonRigidbodyVelocity: 0
|
||||
attenuationObject: {fileID: 0}
|
||||
--- !u!114 &519420037
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 519420028}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 33f7f5bc5b633e14f84576fbec0652a7, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &527148463
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -6662,7 +6675,7 @@ MonoBehaviour:
|
||||
m_ReferencePixelsPerUnit: 100
|
||||
m_ScaleFactor: 1
|
||||
m_ReferenceResolution: {x: 1920, y: 1080}
|
||||
m_ScreenMatchMode: 0
|
||||
m_ScreenMatchMode: 1
|
||||
m_MatchWidthOrHeight: 0
|
||||
m_PhysicalUnit: 3
|
||||
m_FallbackScreenDPI: 96
|
||||
@@ -7529,6 +7542,7 @@ GameObject:
|
||||
- component: {fileID: 1078778571}
|
||||
- component: {fileID: 1078778570}
|
||||
- component: {fileID: 1078778572}
|
||||
- component: {fileID: 1078778573}
|
||||
m_Layer: 0
|
||||
m_Name: UI Camera
|
||||
m_TagString: Untagged
|
||||
@@ -7662,6 +7676,18 @@ MonoBehaviour:
|
||||
serializedVersion: 2
|
||||
m_Bits: 32
|
||||
m_MaxRayIntersections: 0
|
||||
--- !u!114 &1078778573
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1078778568}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 33f7f5bc5b633e14f84576fbec0652a7, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &1100283194
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -12386,7 +12412,6 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: f0d1630fcebe4fb38afd0a2bc7b3112b, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
advanceInput: {fileID: 1977401368}
|
||||
defaultViewType: 1
|
||||
--- !u!1 &1850675824
|
||||
GameObject:
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
|
||||
namespace AibisDream.Framework
|
||||
{
|
||||
[RequireComponent(typeof(Camera))]
|
||||
public class CameraAspectAdapter : MonoBehaviour
|
||||
{
|
||||
private Camera _targetCamera;
|
||||
|
||||
private Vector2Int _lastScreenSize;
|
||||
private Rect _targetRect;
|
||||
private IUnRegister _resolutionChangeUnRegister;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_targetCamera = GetComponent<Camera>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_lastScreenSize = new Vector2Int(Screen.width, Screen.height);
|
||||
CalculateTargetRect();
|
||||
ApplyToAllCameras();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_resolutionChangeUnRegister = EnumEventSystem.Global.Register(
|
||||
GameLoopEnum.ScreenResolutionChanged, OnResolutionChanged);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_resolutionChangeUnRegister?.UnRegister();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
bool screenChanged = Screen.width != _lastScreenSize.x
|
||||
|| Screen.height != _lastScreenSize.y;
|
||||
if (screenChanged)
|
||||
{
|
||||
_lastScreenSize = new Vector2Int(Screen.width, Screen.height);
|
||||
CalculateTargetRect();
|
||||
}
|
||||
|
||||
ApplyToAllCameras();
|
||||
}
|
||||
|
||||
public void Refresh(bool reset = false)
|
||||
{
|
||||
if (_targetCamera == null) return;
|
||||
|
||||
if (reset)
|
||||
{
|
||||
_targetRect = new Rect(0, 0, 1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
CalculateTargetRect();
|
||||
}
|
||||
|
||||
ApplyToAllCameras();
|
||||
}
|
||||
|
||||
private void OnResolutionChanged()
|
||||
{
|
||||
_lastScreenSize = new Vector2Int(Screen.width, Screen.height);
|
||||
CalculateTargetRect();
|
||||
ApplyToAllCameras();
|
||||
}
|
||||
|
||||
private void CalculateTargetRect()
|
||||
{
|
||||
const float Epsilon = 0.0001f;
|
||||
float windowAspect = (float)Screen.width / Screen.height;
|
||||
float targetAspect = ConstRef.TargetAspect;
|
||||
float diff = windowAspect - targetAspect;
|
||||
|
||||
if (Mathf.Abs(diff) < Epsilon)
|
||||
{
|
||||
_targetRect = new Rect(0, 0, 1, 1);
|
||||
}
|
||||
else if (diff < 0)
|
||||
{
|
||||
float scaleHeight = windowAspect / targetAspect;
|
||||
_targetRect = new Rect(0, (1f - scaleHeight) / 2f, 1f, scaleHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
float scaleWidth = targetAspect / windowAspect;
|
||||
_targetRect = new Rect((1f - scaleWidth) / 2f, 0, scaleWidth, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyToAllCameras()
|
||||
{
|
||||
ApplyRect(_targetCamera);
|
||||
|
||||
if (_targetCamera != null &&
|
||||
_targetCamera.TryGetComponent(out UniversalAdditionalCameraData cameraData))
|
||||
{
|
||||
foreach (var overlay in cameraData.cameraStack)
|
||||
{
|
||||
if (overlay != null)
|
||||
ApplyRect(overlay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyRect(Camera camera)
|
||||
{
|
||||
if (camera == null) return;
|
||||
|
||||
const float Epsilon = 0.0001f;
|
||||
Rect current = camera.rect;
|
||||
if (Mathf.Abs(current.x - _targetRect.x) > Epsilon ||
|
||||
Mathf.Abs(current.y - _targetRect.y) > Epsilon ||
|
||||
Mathf.Abs(current.width - _targetRect.width) > Epsilon ||
|
||||
Mathf.Abs(current.height - _targetRect.height) > Epsilon)
|
||||
{
|
||||
camera.rect = _targetRect;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33f7f5bc5b633e14f84576fbec0652a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -53,15 +53,6 @@ namespace AibisDream.Framework
|
||||
|
||||
#region 相机信息注册
|
||||
|
||||
public void UpdateCameraViewport(bool reset = false)
|
||||
{
|
||||
foreach (var overlayCam in _orthoMainCamera.GetUniversalAdditionalCameraData().cameraStack)
|
||||
{
|
||||
overlayCam.UpdateCameraViewport(reset);
|
||||
}
|
||||
_orthoMainCamera.UpdateCameraViewport(reset);
|
||||
}
|
||||
|
||||
public void RegisterUICamera(Camera overlayCamera)
|
||||
{
|
||||
var mainCameraData = _orthoMainCamera.GetUniversalAdditionalCameraData();
|
||||
@@ -70,7 +61,6 @@ namespace AibisDream.Framework
|
||||
{
|
||||
if (!mainCameraData.cameraStack.Contains(overlayCamera))
|
||||
{
|
||||
overlayCamera.rect = _orthoMainCamera.rect;
|
||||
mainCameraData.cameraStack.Insert(0, overlayCamera);
|
||||
}
|
||||
}
|
||||
@@ -392,40 +382,6 @@ namespace AibisDream.Framework
|
||||
.OnUpdate(() => virtualCamera.m_Lens.OrthographicSize = currentOrthoSize);
|
||||
}
|
||||
|
||||
public static void UpdateCameraViewport(this Camera camera, bool reset = false)
|
||||
{
|
||||
if (reset)
|
||||
{
|
||||
camera.rect = new Rect(0, 0, 1, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// 当前屏幕宽高比
|
||||
float windowAspect = (float)Screen.width / (float)Screen.height;
|
||||
|
||||
// 计算缩放比例
|
||||
float scaleHeight = windowAspect / ConstRef.TargetAspect;
|
||||
|
||||
Rect rect = camera.rect;
|
||||
if (scaleHeight < 1.0f)
|
||||
{
|
||||
// 添加黑边
|
||||
rect.width = 1.0f;
|
||||
rect.height = scaleHeight;
|
||||
rect.x = 0;
|
||||
rect.y = (1.0f - scaleHeight) / 2.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 屏幕比目标更宽,左右添加黑边(pillarbox)
|
||||
rect.width = 1.0f / scaleHeight;
|
||||
rect.height = 1.0f;
|
||||
rect.x = (1.0f - 1.0f / scaleHeight) / 2.0f;
|
||||
rect.y = 0;
|
||||
}
|
||||
|
||||
camera.rect = rect;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CameraCommand
|
||||
|
||||
@@ -21,7 +21,8 @@ namespace AibisDream
|
||||
GameStart,
|
||||
GameQuit,
|
||||
PauseGame,
|
||||
UnPauseGame
|
||||
UnPauseGame,
|
||||
ScreenResolutionChanged
|
||||
}
|
||||
|
||||
public enum DialogEventEnum
|
||||
|
||||
@@ -219,11 +219,11 @@ namespace AibisDream
|
||||
}
|
||||
|
||||
StartCoroutine(WaitForResolutionAndUpdateViewport(
|
||||
targetWidth, targetHeight, windowMode == "Windowed"));
|
||||
targetWidth, targetHeight));
|
||||
}
|
||||
|
||||
private IEnumerator WaitForResolutionAndUpdateViewport(
|
||||
int targetWidth, int targetHeight, bool reset)
|
||||
int targetWidth, int targetHeight)
|
||||
{
|
||||
float timeout = Time.unscaledTime + 1f;
|
||||
while ((Screen.width != targetWidth || Screen.height != targetHeight)
|
||||
@@ -232,7 +232,7 @@ namespace AibisDream
|
||||
yield return null;
|
||||
}
|
||||
|
||||
CameraKit.Instance.UpdateCameraViewport(reset);
|
||||
EnumEventSystem.Global.Send(GameLoopEnum.ScreenResolutionChanged);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -45,7 +45,7 @@ TextureImporter:
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
spriteMeshType: 0
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 10
|
||||
|
||||
Reference in New Issue
Block a user