级别选择多个屏幕尺寸问题
Posted
技术标签:
【中文标题】级别选择多个屏幕尺寸问题【英文标题】:Level Select Multiple Screen Size Issue 【发布时间】:2020-04-04 18:17:12 【问题描述】:我想统一使用滑动菜单。它在 1080x1920 分辨率下工作,但不适用于其他屏幕尺寸。
我的代码:
private Vector3 panelLocation;
public float percentThreshold = 0.2f;
public float easing = 0.5f;
private int totalPages = 3;
private int currentPage = 1;
GameObject slide_right, slide_left;
void Start()
panelLocation = transform.position;
slide_right = GameObject.FindWithTag("slide_right");
slide_left = GameObject.FindWithTag("slide_left");
void Update()
if (currentPage == 1)
slide_left.SetActive(false);
else if(currentPage == totalPages)
slide_right.SetActive(false);
else
slide_left.SetActive(true);
slide_right.SetActive(true);
//sağa doğru çekersem -
//sola doğru çeekrsem +
public void OnDrag(PointerEventData data)
float difference = data.pressPosition.x - data.position.x;
transform.position = panelLocation - new Vector3(difference, 0, 0);
public void OnEndDrag(PointerEventData data)
float percentage = (data.pressPosition.x - data.position.x) / Screen.width;
if (Mathf.Abs(percentage) >= percentThreshold)
Vector3 newLocation = panelLocation;
if (percentage > 0 && currentPage < totalPages)
currentPage++;
newLocation += new Vector3(-Screen.width, 0, 0);
else if (percentage < 0 && currentPage > 1)
currentPage--;
newLocation += new Vector3(Screen.width, 0, 0);
StartCoroutine(SmoothMove(transform.position, newLocation, easing));
panelLocation = newLocation;
else
StartCoroutine(SmoothMove(transform.position, panelLocation, easing));
IEnumerator SmoothMove(Vector3 startpos, Vector3 endpos, float seconds)
float t = 0f;
while (t <= 1.0)
t += Time.deltaTime / seconds;
transform.position = Vector3.Lerp(startpos, endpos, Mathf.SmoothStep(0f, 1f, t));
yield return null;
其他级别代码的位置:
public RectTransform menu2, menu3;
void Start()
Debug.Log(Screen.width);
/*menu2.offsetMin += new Vector2(Screen.width, 0);
menu2.offsetMax += new Vector2(Screen.width, 0);
menu3.offsetMin += new Vector2(Screen.width * 2, 0);
menu3.offsetMax += new Vector2(Screen.width * 2, 0);*/
menu2.offsetMin += new Vector2(1080, 0);
menu2.offsetMax += new Vector2(1080, 0);
menu3.offsetMin += new Vector2(1080 * 2, 0);
menu3.offsetMax += new Vector2(1080 * 2, 0);
我尝试使用屏幕尺寸设置位置,但没有奏效。
我的画布缩放选项: 随屏幕尺寸和默认分辨率 1080x1920 缩放。
我试过这个 youtube 视频。
https://www.youtube.com/watch?v=rjFgThTjLso&t=241s
请帮忙。
【问题讨论】:
"我尝试使用屏幕尺寸设置位置,但没有成功。"什么不完全有效?发生了什么? 当我尝试设置位置时,1080x1920 再次起作用,但在 480x800 时,菜单 2 在游戏菜单中。喜欢:i.hizliresim.com/XxzPUt.png 【参考方案1】:当我使用 match: 0 而不是 1 (在画布缩放选项下方) 时,它解决了。
【讨论】:
以上是关于级别选择多个屏幕尺寸问题的主要内容,如果未能解决你的问题,请参考以下文章