void UpdateMaterials(SceneData scene) { int numMaterials = scene.numMaterials; bool needsUpdate = false; if (m_materialList.Count != numMaterials) { needsUpdate = true; } else { for (int i = 0; i < numMaterials; ++i) { var src = scene.GetMaterial(i); var dst = m_materialList[i]; if (src.id != dst.id || src.name != dst.name || src.color != dst.color) { needsUpdate = true; break; } } } if (!needsUpdate) { return; } var newlist = new List <MaterialHolder>(); for (int i = 0; i < numMaterials; ++i) { var src = scene.GetMaterial(i); var id = src.id; var dst = m_materialList.Find(a => a.id == id); if (dst == null) { dst = new MaterialHolder(); dst.id = id; #if UNITY_EDITOR var tmp = Instantiate(GetDefaultMaterial()); tmp.name = src.name; tmp.color = src.color; dst.material = tmp; #endif } dst.name = src.name; dst.color = src.color; if (dst.material.name == src.name) { dst.material.color = dst.color; } newlist.Add(dst); } m_materialList = newlist; ReassignMaterials(); }