【屏幕适配】刘海屏左右适配功能提交

main
chenyuqi 2023-12-05 19:27:56 +08:00
parent f83e919534
commit 2735b97223
6 changed files with 107 additions and 5 deletions

View File

@ -34,7 +34,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -0.0068835267, y: 0.0038443035}
m_AnchoredPosition: {x: -0.00005066102, y: 0.0038443035}
m_SizeDelta: {x: 0, y: 300}
m_Pivot: {x: 0, y: 1}
--- !u!114 &5241968859315470040
@ -7956,7 +7956,7 @@ 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, y: 0}
m_AnchoredPosition: {x: -237, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &5091781664157853341

View File

@ -13,6 +13,8 @@ public abstract class UIWindow : MonoBehaviour
private const string DEFAULT_SHOW_ANIM = "show";
private const string DEFAULT_HIDE_ANIM = "hide";
private string mWindowName;
private ScreenOrientation _lastOrientation;
private Vector2 _offsets; //x,y代表左右的偏移量
// 是否播放默认的打开对话框的声音
public bool isPlayDefaultOpenAudio = true;
@ -36,6 +38,77 @@ public abstract class UIWindow : MonoBehaviour
OnAwake();
}
protected void OnStart()
{
_lastOrientation = Screen.orientation;
InitScreenUIOffset();
UpdateScreenAdaption();
}
protected void OnUpdate()
{
if (_lastOrientation != Screen.orientation)
{
//Debug.Log("Screen orientation has changed!");
// Add your orientation-specific actions here
// Update the last orientation for the next frame
_lastOrientation = Screen.orientation;
UpdateScreenAdaption();
//左右分别找到指定节点移动,当前的方案
//刘海屏适配
}
}
/// <summary>
/// 屏幕适配,目前方案是左右固定名称的节点下的各个物体需要适配,其他的不管
/// </summary>
protected void UpdateScreenAdaption()
{
var goLeft = FindObj("UI_LiuHaiLeft");
var goRight = FindObj("UI_LiuHaiRight");
if (goLeft)
{
var rectTrans = goLeft.GetComponent<RectTransform>();
var originPos = rectTrans.anchoredPosition;
rectTrans.anchoredPosition = new Vector2(_offsets.x, originPos.y);
}
if (goRight)
{
var rectTrans = goRight.GetComponent<RectTransform>();
var originPos = rectTrans.anchoredPosition;
rectTrans.anchoredPosition = new Vector2(_offsets.y, originPos.y);
}
}
protected void SetScreenOffsets(Vector2 offset)
{
_offsets = offset;
}
protected void InitScreenUIOffset()
{
var offset = DeviceHelper.GetWidthOffset();
var goLeft = FindObj("UI_LiuHaiLeft");
if (goLeft)
{
var rectTrans = goLeft.GetComponent<RectTransform>();
var originPos = rectTrans.anchoredPosition;
SetScreenOffsets(new Vector2(originPos.x + offset.x, 0));
}
var goRight = FindObj("UI_LiuHaiRight");
if (goRight)
{
var rectTrans = goRight.GetComponent<RectTransform>();
var originPos = rectTrans.anchoredPosition;
SetScreenOffsets(new Vector2(_offsets.x, originPos.x - offset.y));
}
}
public void OpenWindow(object data)
{
Show(data);

View File

@ -89,6 +89,17 @@ public class UI_Cultivate_DetailController : UIWindow
BindButton(GetComponent<Button>("Button_Detail"), OnButton_DetailClick);
mAnimator = GetComponent<Animator>();
}
private void Start()
{
OnStart();
}
private void Update()
{
OnUpdate();
}
private void RegisterEvent()
{
EventManager.Instance.Register(EventManager.EventName.EN_CharacterLevelUp, (Action<UpgradeType>)OnCharacterLevelup);

View File

@ -103,7 +103,18 @@ public class UI_Cultivate_ProAndInfoController : UIWindow
LoadCfg();
mAnimator = GetComponent<Animator>();
}
private void RegisterEvent()
private void Start()
{
OnStart();
}
private void Update()
{
OnUpdate();
}
private void RegisterEvent()
{
EventManager.Instance.Register(EventManager.EventName.EN_CharacterLevelUp, (Action<UpgradeType>)OnCharacterLevelup);
}

View File

@ -1,4 +1,5 @@
using cfg.UIInterfaceBannerGoToCfg;
using System;
using cfg.UIInterfaceBannerGoToCfg;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay;
@ -112,6 +113,11 @@ public class UI_MainPanelController: UIWindow
}
private void Start()
{
OnStart();
}
private async void OnButton_VehicleClickAsync()
{
await UIManager.Instance.OpenWindow(UINameConst.UI_VehicleChoose);
@ -169,6 +175,7 @@ public class UI_MainPanelController: UIWindow
string tempStr = "";
void Update()
{
OnUpdate();
if (!isMusicStart)
{
return;

@ -1 +1 @@
Subproject commit 8ebc885f0fc4229dadf2cc7896a852f10c60e73e
Subproject commit 242e5d616aeb9cf4541d82058a405dd8a9117d1d