Уровень Выберите Несколько Размер экрана Проблема - PullRequest
1 голос
/ 04 апреля 2020

Я хочу использовать меню со смахиванием он работает с разрешением 1080x1920, но не работает с экранами других размеров.

example

Мои коды:

    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

Пожалуйста, помогите.

1 Ответ

0 голосов
/ 05 апреля 2020

Когда я использовал соответствие: 0 вместо 1 (ниже параметров масштабирования холста) это решено.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...