public void ShouldCorrectlyParseMaterialNames() { var test1 = PbrMaterial.ParseId("__std_", new[] { "" }, new[] { "Töxture1", "Töxture" }); test1[0].Should().BeEmpty(); test1[1].Should().BeEmpty(); test1[2].Should().BeEmpty(); test1[3].Should().BeEmpty(); var test2 = PbrMaterial.ParseId("__std_ toexture1", new string[] { }, new[] { "Töxture1", "Töxture" }); test2[0].Should().BeEmpty(); test2[1].Should().Be("Töxture1"); test2[2].Should().BeEmpty(); test2[3].Should().BeEmpty(); var test3 = PbrMaterial.ParseId("mat tex normal env", new [] { "Mat" }, new[] { "Tex", "Normal", "Env" }); test3[0].Should().Be("Mat"); test3[1].Should().Be("Tex"); test3[2].Should().Be("Normal"); test3[3].Should().Be("Env"); var test4 = PbrMaterial.ParseId("mat tex __no_normal_map env", new [] { "Mat" }, new[] { "Tex", "Normal", "Env" }); test4[0].Should().Be("Mat"); test4[1].Should().Be("Tex"); test4[2].Should().BeEmpty(); test4[3].Should().Be("Env"); }
private static void CopyMaterialName(MeshRenderer mr, string[] materialNames, string[] textureNames, ref string materialName, ref string mapName, ref string normalMapName, ref string envMapName) { if (!mr || materialNames == null || textureNames == null || mr.sharedMaterial == null) { return; } var result = PbrMaterial.ParseId(mr.sharedMaterial.name, materialNames, textureNames); if (materialName != null && !string.IsNullOrEmpty(result[0])) { materialName = result[0]; } if (mapName != null) { var tex = mr.sharedMaterial.mainTexture; if (tex != null) { mapName = tex.name; } else if (!string.IsNullOrEmpty(result[1])) { mapName = result[1]; } } if (normalMapName != null) { var tex = mr.sharedMaterial.GetTexture(RenderPipeline.Current.MaterialConverter.NormalMapProperty); if (tex != null) { normalMapName = tex.name; } else if (!string.IsNullOrEmpty(result[2])) { normalMapName = result[2]; } } if (envMapName != null && !string.IsNullOrEmpty(result[3])) { envMapName = result[3]; } }