public UVAdjuster_Atlas(MB2_TextureBakeResults tbr, MB2_LogLevel ll) { textureBakeResults = tbr; LOG_LEVEL = ll; matsAndSrcUVRect = tbr.materialsAndUVRects; { compareNamesWhenComparingMaterials = false; // This is an option if using addressables. // At runtime the materials can be different instances but are the same material. // We replaced this hack by adding the primary key (path to material asset) in the textureBakeResult // User can use this key to find the runtimeMaterial. However somebody could be using something other than // the path as the primary key. Could fall back to using this. if (MBVersion.IsUsingAddressables() && Application.isPlaying) { compareNamesWhenComparingMaterials = true; } else { compareNamesWhenComparingMaterials = false; } } //count the number of times a material appears in the atlas. used for fast lookup numTimesMatAppearsInAtlas = new int[matsAndSrcUVRect.Length]; for (int i = 0; i < matsAndSrcUVRect.Length; i++) { if (numTimesMatAppearsInAtlas[i] > 1) { continue; } int count = 1; for (int j = i + 1; j < matsAndSrcUVRect.Length; j++) { if (matsAndSrcUVRect[i].material == matsAndSrcUVRect[j].material) { count++; } } numTimesMatAppearsInAtlas[i] = count; if (count > 1) { //allMatsAreUnique = false; for (int j = i + 1; j < matsAndSrcUVRect.Length; j++) { if (matsAndSrcUVRect[i].material == matsAndSrcUVRect[j].material) { numTimesMatAppearsInAtlas[j] = count; } } } } /* * runtimeMat_2_buildtimeMap = new Dictionary<Material, Material>(); * for (int i = 0; i < matsAndSrcUVRect.Length; i++) * { * if (matsAndSrcUVRect[i].runtimeMaterial != null) * { * runtimeMat_2_buildtimeMap.Add(matsAndSrcUVRect[i].runtimeMaterial, matsAndSrcUVRect[i].material); * } else * { * runtimeMat_2_buildtimeMap.Add(matsAndSrcUVRect[i].material, matsAndSrcUVRect[i].material); * } * } */ }