空的OnGUI也会有gc

一个空场景,添加如下代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    private void OnGUI()
    {
        
    }
}

可以看到每帧有一个固定的内存gc,可以用useGUILayout开关来关闭其gc消耗:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    private void Start()
    {
#if !UNITY_EDITOR
        useGUILayout = false;
#endif
    }

    private void OnGUI()
    {
        
    }
}

 

posted @ 2018-09-11 19:15  斯芬克斯  阅读(261)  评论(0编辑  收藏  举报