看板娘位置调整增加了对屏幕左右边缘的检测

main
Yuntao Hu 2024-06-05 16:52:15 +08:00
parent d08e8dbe7a
commit b26feb3331
1 changed files with 18 additions and 4 deletions

View File

@ -467,10 +467,10 @@ public class UI_MainPanelController : UIWindow
{
GoRoot.GetComponent<RectTransform>().anchoredPosition += data.delta;
drag.transform.position = GoRoot.transform.position;
PosterViewportFitter();
}
private void OnEndDrag(PointerEventData data)
{
PosterViewportFitter();
positionDelta = new Vector2(GoRoot.transform.position.x, GoRoot.transform.position.y) - defaultPostion;
}
@ -499,12 +499,26 @@ public class UI_MainPanelController : UIWindow
/// </summary>
public void PosterViewportFitter()
{
//TODO
var rt = GoRoot.GetComponent<RectTransform>();
//上方边缘
var height = PerformanceManager.instance.fullScreenHeight;
if (GoRoot.GetComponent<RectTransform>().sizeDelta.y / 2 * Scale + GoRoot.GetComponent<RectTransform>().anchoredPosition.y > height)
if (rt.sizeDelta.y / 2 * Scale + rt.anchoredPosition.y > height)
{
GoRoot.GetComponent<RectTransform>().anchoredPosition = new Vector2(GoRoot.GetComponent<RectTransform>().anchoredPosition.x, height - Scale * GoRoot.GetComponent<RectTransform>().sizeDelta.y / 2);
rt.anchoredPosition = new Vector2(rt.anchoredPosition.x, height - Scale * rt.sizeDelta.y / 2);
}
//左右边缘
var allowMaxDisplayDistance = Scale * rt.sizeDelta.x / 4;//目前允许左右超出1/4图片的距离
var width = PerformanceManager.instance.fullScreenWidth;
if (rt.anchoredPosition.x - allowMaxDisplayDistance < 0)
{
rt.anchoredPosition = new Vector2(allowMaxDisplayDistance, rt.anchoredPosition.y);
}//左
if (rt.anchoredPosition.x + allowMaxDisplayDistance > width)
{
rt.anchoredPosition = new Vector2(width - allowMaxDisplayDistance, rt.anchoredPosition.y);
}//右
}
#endregion