public void ReplaceAlphaWith(D2D_Pixels newPixels) { DeserializeAlphaTex(); #if UNITY_EDITOR if (alphaTex != null) { D2D_Helper.Record(alphaTex, "Modify Alpha Tex"); } #endif if (newPixels != null) { // Remake texture? if (alphaTex == null || alphaTex.width != newPixels.Width || alphaTex.height != newPixels.Height) { DestroyAlphaTex(); alphaTex = newPixels.Apply(TextureFormat.Alpha8); alphaScaleX = D2D_Helper.Reciprocal(alphaTex.width - 1); alphaScaleY = D2D_Helper.Reciprocal(alphaTex.height - 1); alphaTex.wrapMode = TextureWrapMode.Clamp; } // Copy settings over? else { alphaTex.SetPixels32(newPixels.Pixels); alphaTex.Apply(); } UpdateRect(0, alphaTex.width, 0, alphaTex.height); } else { DestroyAlphaTex(); UpdateRect(0, 0, 0, 0); } cachedSolidPixelCount = 0; alphaTexData = null; alphaTexWidth = 0; alphaTexHeight = 0; Dirty = true; NotifyChanges(); #if UNITY_EDITOR D2D_Helper.SetDirty(this); #endif }
private void DrawAlphaTex() { var newAlphaTex = (Texture2D)EditorGUI.ObjectField(D2D_Helper.Reserve(), "Alpha Tex", Target.AlphaTex, typeof(Texture2D), false); if (newAlphaTex != Target.AlphaTex) { D2D_Helper.Record(Targets, "Replace Destructible Sprite Alpha"); foreach (var t in Targets) { t.ReplaceAlphaWith(newAlphaTex); t.RecalculateOriginalSolidPixelCount(); D2D_Helper.SetDirty(t); } } }