事情起因
写了个instance的shader,理论上能通过instance减少dc,但实际测试,dc并没有减少。单独把instance部分拿出来是可以合批的。然后看到运用过程中会改变材质球,代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class testInstance : MonoBehaviour {
public List<MeshRenderer> meshRenderer;
public Texture2D tex;
public GameObject flagGo;
List<Material> tempMaterials;
// Use this for initialization
void Start () {
#if UNITY_EDITOR
Debug.LogError("Error: in editor");
Renderer[] flagRenderComponent = flagGo.GetComponentsInChildren<Renderer>(false);
for (int i = 0; i < flagRenderComponent.Length; i++)
{
Material flagMaterial = new Material(flagRenderComponent[i].sharedMaterial);
flagMaterial.SetTexture("_MainTex", tex);