public TextureChangeTag this[TextureRole index] { get { return(m_internalList.ContainsKey(index) ? m_internalList[index] : null); } set { if (!m_internalList.ContainsKey(index)) { m_internalList.Add(index, value); } else { throw new ArgumentException("Cannot have two texture changes with the same role!"); } } }
public TextureChangeTag() { m_textureName = null; m_role = TextureRole.Background; }
void Combine(TextureSetForForCombinedMaps set, PlaytimePainter p) { TextureRole.Clear(); int size; var id = p?.ImgData; Color[] dst; Texture2D tex = null; if (id != null) { size = id.width * id.height; dst = id.Pixels; tex = id.texture2D; } else { size = set.width * set.height; tex = new Texture2D(set.width, set.height, TextureFormat.ARGB32, true, set.isColor); dst = new Color[size]; tex.wrapMode = TextureWrapMode.Repeat; tex.name = set.name; } var mips = new List <Color[]>(); for (int i = 1; i < tex.mipmapCount; i++) { mips.Add(tex.GetPixels(i)); } for (int colChan = 0; colChan < 4; colChan++) { var c = channel[colChan]; if (c.enabled) { var ch = c.sourceChannel; var col = c.Role.GetPixels(set, id); if (c.flip) { for (int i = 0; i < size; i++) { dst[i][colChan] = 1 - col[i][ch]; } } else { for (int i = 0; i < size; i++) { dst[i][colChan] = col[i][ch]; } } var newMips = c.Role.GetMipPixels(set, id); for (int m = 1; m < tex.mipmapCount; m++) { var mlevel = mips[m - 1]; var newLevel = newMips[m - 1]; if (c.flip) { for (int si = 0; si < mlevel.Length; si++) { mlevel[si][colChan] = 1 - newLevel[si][colChan]; } } else { for (int si = 0; si < mlevel.Length; si++) { mlevel[si][colChan] = newLevel[si][colChan]; } } mips[m - 1] = mlevel; } } } for (int i = 1; i < tex.mipmapCount; i++) { tex.SetPixels(mips[i - 1], i); } if (id != null) { id.SetAndApply(false); set.LastProduct = tex; } else { tex.SetPixels(dst); tex.Apply(false, false); set.LastProduct = tex; #if UNITY_EDITOR set.LastProduct = tex.SaveTextureAsAsset(TexMGMTdata.texturesFolderName, ref set.name, false); TextureImporter importer = set.LastProduct.GetTextureImporter(); bool needReimport = importer.WasNotReadable(); needReimport |= importer.WasWrongIsColor(isColor); needReimport |= importer.WasClamped(); if (needReimport) { importer.SaveAndReimport(); } #endif } TextureRole.Clear(); }