public void InitByMgr(BaseSurfaceMgr mgr, string matName = "", bool isInstance = true) { IsInstance = isInstance; SurfaceMgr = mgr; SourceMats.Clear(); SourceMatsArray.Clear(); Shaders.Clear(); var renders = GetRenderers(); if (renders != null) { for (int i = 0; i < renders.Length; ++i) { GetMaterial(renders[i], out Material material); SourceMats.Add(renders[i], material); } for (int i = 0; i < renders.Length; ++i) { GetMaterials(renders[i], out Material[] materials); SourceMatsArray.Add(renders[i], materials); if (materials != null) { foreach (var item in materials) { if (!Shaders.Contains(item.shader)) { Shaders.Add(item.shader); } } } } //获得材质 string tempMatName = matName.IsInv() ? GetDefaultMatName() : matName; if (UsedMaterials.Count == 0 && !tempMatName.IsInv()) { foreach (var key in Shaders) { var mat = GRMgr.Material.Spawn(tempMatName); if (DefaultUsedMaterial == null) { DefaultUsedMaterial = mat; } UsedMaterials.Add(key, mat); } } } OnInit(); }