1

Юзаю Unity3D, NGUI. Имеется ScrollView, в нем вложена сетка UIGrid, туда динамически впиливаю около 1000 нетекстурированных спрайтов с необходимой инфой в лейблах. При прокрутке всё это дело очень сильно тормозит, FPS падает до 8-10. Вопрос: как мне повысить производительность? Может скрыть все элементы, которые находятся за пределами видимости? Если да, то как? Заранее спасибо!

P.S. Я написал этот код, он работает, но очень некорректно. Элементы скрываются, но при прокрутке расстояние между элементами нарушается. Там вообще рандом какой-то. Меня еще смущает, что всё это на апдейте, а по другому нет идей как реализовать

public bool the_test_bool = false;
public int counts;

void Update ()
{


    UIRoot mRoot = GameObject.FindObjectOfType (typeof(UIRoot)) as UIRoot;
    float ratio = (float)mRoot.activeHeight / Screen.height;
    int width = (int)Mathf.Ceil (Screen.width * ratio);
    int height = (int)Mathf.Ceil (Screen.height * ratio);


    float cHeight = NAVI.grid_main.GetComponent<UIGrid> ().cellHeight;


    float y = NAVI.grid_main.transform.parent.GetComponent<UIPanel> ().clipOffset.y;
    float cBot = y - (height / 2f);
    float cTop = y + (height / 2f);

    if (!the_test_bool) {
        counts = NAVI.grid_main.transform.childCount;
        if (counts > 1) {
            the_test_bool = true;
            counts = NAVI.grid_main.transform.childCount;
        }
    }

    int counter = 0;
    for (int i = 0; i < counts; i++) {

        float itemXCenter = (cHeight * counter);
        float itemBCenter = itemXCenter + (cHeight * 2f);
        float itemTCenter = itemXCenter - (cHeight * 2f);

        bool isVis = 
            (itemTCenter < cTop && itemBCenter > cBot) || 
            (itemBCenter > cBot && itemTCenter < cTop) || 
            (itemTCenter < cTop && itemBCenter > cBot);
        NAVI.grid_main.transform.GetChild (i).gameObject.SetActive (isVis);
        counter++;
    }
}

1 ответ 1

1

Тут 2 варианта:

  1. Действительно скрыть элементы (Например, проверкой на попадание в rect видимости).

  2. Перемещать не сами элементы, а камеру (Но придется использовать другой подход). В NGUI был пример где-то похожий с камерой.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.