cultivation/Assets/Scripts/Common/Mono/ScreenResizeHandler.cs

39 lines
935 B
C#

using Common.Events;
using MessagePipe;
using UnityEngine;
namespace Common.Mono
{
public class ScreenResizeHandler : MonoBehaviour
{
private IPublisher<ScreenResizeEvent> _screenResizePublisher;
private int _lastWidth;
private int _lastHeight;
private void Start()
{
ScreenResizeFixation();
}
private void Update()
{
ScreenResizeFixation();
}
private void ScreenResizeFixation()
{
if (_lastWidth != Screen.width || _lastHeight != Screen.height)
{
_lastHeight = Screen.height;
_lastWidth = Screen.width;
_screenResizePublisher.Publish(new ScreenResizeEvent()
{
width = _lastWidth,
height = _lastHeight,
});
}
}
}
}