1.设置物体显示隐藏
网上说设置物体显示隐藏(GameObject.SetActive())会消耗性能.其实这种说法是片面的,或者是错误的。
测试代码
在一个节点里初始化5000左右个物体。将物体显示和隐藏,添加标记"xxxxxxxxxxxxxxxxxxx",然后查看性能。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.UI;
public class ProfilerTest : MonoBehaviour
{
public GameObject gm;
public Button bt;
private Transform parent;
private void initGM()
{
Profiler.BeginSample("xxxxxxxxxxxxxxxxxxx"); //添加标记
float tm = Time.realtimeSinceStartup;
for (int i = 0; i < 5000; i++)
{
GameObject g = new GameObject("GM",typeof(UnityFunctionTest));
//GameObject g = new GameObject("GM");
if (!parent)
{
parent = g.transform;
}
if (i % 10 =&