public static D2D_SplitGroup CreateGroup() { if (destructible != null) { var group = D2D_ClassPool <D2D_SplitGroup> .Pop() ?? new D2D_SplitGroup(); Groups.Add(group); return(group); } return(null); }
public static void BeginSplitting(D2D_Destructible newDestructible) { if (newDestructible != null) { D2D_ClassPool <D2D_SplitGroup> .Add(Groups, g => g.AddToPool()); // EndSplitting may not get called, so call here in case destructible = newDestructible; AlphaTex = newDestructible.AlphaTex; AlphaTexWidth = AlphaTex.width; AlphaTexHeight = AlphaTex.height; } }
public static void DiscardTinyBits(int minPixels) { for (var i = Groups.Count - 1; i >= 0; i--) { var group = Groups[i]; if (group.Count < minPixels) { D2D_ClassPool <D2D_SplitGroup> .Add(group, g => g.AddToPool()); Groups.RemoveAt(i); } } }
public static void EndSplitting(D2D_SplitOrder order, bool blur) { if (destructible != null) { if (Groups.Count > 0) { // Sort switch (order) { case D2D_SplitOrder.KeepLargest: Groups.Sort((a, b) => b.Count.CompareTo(a.Count)); break; case D2D_SplitOrder.KeepSmallest: Groups.Sort((a, b) => a.Count.CompareTo(b.Count)); break; } // Store list of others splitData.SolidPixelCounts.Clear(); for (var i = 0; i < Groups.Count; i++) { splitData.SolidPixelCounts.Add(Groups[i].Count); } // Split for (var i = Groups.Count - 1; i >= 0; i--) { var group = Groups[i]; splitData.Index = i; splitData.IsClone = i > 0; // Split if (i > 0) { var tempAlphaData = destructible.AlphaData; destructible.AlphaData = null; // Clone this destructible without alpha data, because we will manually set it after this var clonedDestructible = D2D_Helper.CloneGameObject(destructible.gameObject, destructible.transform.parent).GetComponent <D2D_Destructible>(); destructible.AlphaData = tempAlphaData; Split(clonedDestructible, group, true, blur); } // Overwrite original else { Split(destructible, group, false, blur); } } } else { D2D_Helper.Destroy(destructible.gameObject); } destructible = null; } D2D_ClassPool <D2D_SplitGroup> .Add(Groups, g => g.AddToPool()); }