空的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()
    {
        
    }
}
原文地址:https://www.cnblogs.com/sifenkesi/p/9629713.html