/// <summary> /// 检查是否需为属性创建纹理图集 /// </summary> /// <param name="propertyIndex"></param> /// <param name="considerNonTextureProperties"></param> /// <param name="allTexturesAreNullAndSameColor"></param> /// <returns></returns> internal static bool _ShouldWeCreateAtlasForThisProperty(int propertyIndex, bool considerNonTextureProperties, CreateAtlasForProperty[] allTexturesAreNullAndSameColor) { CreateAtlasForProperty v = allTexturesAreNullAndSameColor[propertyIndex]; if (considerNonTextureProperties) { if (!v.allNonTexturePropsAreSame || !v.allTexturesAreNull) { return(true); } else { return(false); } } else { if (!v.allTexturesAreNull) { return(true); } else { return(false); } } }
/// <summary> /// 检测所有 textures 中只有一种纹理 /// </summary> /// <param name="data"></param> /// <returns></returns> private static CreateAtlasForProperty[] CalculateAllTexturesAreNullAndSameColor(TexturePipelineData data) { // check if all textures are null and use same color for each atlas // will not generate an atlas if so CreateAtlasForProperty[] shouldWeCreateAtlasForProp = new CreateAtlasForProperty[data.texPropertyNames.Count]; for (int propIdx = 0; propIdx < data.texPropertyNames.Count; propIdx++) { MaterialPropTexture firstTexture = data.distinctMaterialTextures[0].ts[propIdx]; Color firstColor = Color.black; if (data._considerNonTextureProperties) { firstColor = data.nonTexturePropertyBlender.GetColorAsItWouldAppearInAtlasIfNoTexture( data.distinctMaterialTextures[0].matsAndGOs.mats[0].mat, data.texPropertyNames[propIdx]); } int numTexturesExisting = 0; int numTexturesMatchinFirst = 0; int numNonTexturePropertiesMatchingFirst = 0; for (int j = 0; j < data.distinctMaterialTextures.Count; j++) { if (!data.distinctMaterialTextures[j].ts[propIdx].isNull) { numTexturesExisting++; } if (firstTexture.AreTexturesEqual(data.distinctMaterialTextures[j].ts[propIdx])) { numTexturesMatchinFirst++; } if (data._considerNonTextureProperties) { Color colJ = data.nonTexturePropertyBlender.GetColorAsItWouldAppearInAtlasIfNoTexture(data.distinctMaterialTextures[j].matsAndGOs.mats[0].mat, data.texPropertyNames[propIdx]); if (colJ == firstColor) { numNonTexturePropertiesMatchingFirst++; } } } shouldWeCreateAtlasForProp[propIdx].allTexturesAreNull = numTexturesExisting == 0; shouldWeCreateAtlasForProp[propIdx].allTexturesAreSame = numTexturesMatchinFirst == data.distinctMaterialTextures.Count; shouldWeCreateAtlasForProp[propIdx].allNonTexturePropsAreSame = numNonTexturePropertiesMatchingFirst == data.distinctMaterialTextures.Count; Debug.Log(String.Format("AllTexturesAreNullAndSameColor prop: {0} createAtlas:{1} val:{2}", data.texPropertyNames[propIdx].name, _ShouldWeCreateAtlasForThisProperty(propIdx, data._considerNonTextureProperties, shouldWeCreateAtlasForProp), shouldWeCreateAtlasForProp[propIdx])); } return(shouldWeCreateAtlasForProp); }