private void CheckFixtures() { UpdateState(); fixtures.RemoveAll(f => f == null); // Note: should go first, as the fixture list may change at runtime // Repopulate if it appears clear, as the list may be outdated if (fixtures.Find(f => f.Pinned == true) == null) { fixtures.Clear(); fixtures.AddRange(GetComponentsInChildren <D2D_Fixture>()); } // If we're sure there are no pinned fixtures left, detach! if (fixtures.Find(f => f.Pinned == true) == null) { D2D_Helper.Destroy(OldCollider); if (NewCollider != null) { NewCollider.enabled = true; } if (rigidbody2D.isKinematic == true) { rigidbody2D.isKinematic = false; } D2D_Helper.Destroy(this); } }
public void Destroy() { if (Collider != null) { Collider = D2D_Helper.Destroy(Collider); } }
public override void RebuildAllColliders() { UpdateCollidable(); DestroyCollider(); var alphaTex = destructibleSprite.AlphaTex; if (alphaTex != null) { var spriteRenderer = D2D_Helper.GetOrAddComponent <SpriteRenderer>(child); var sprite = Sprite.Create(alphaTex, new Rect(0, 0, alphaTex.width, alphaTex.height), Vector2.zero, 1.0f, 0, SpriteMeshType.FullRect); spriteRenderer.sprite = sprite; collider = child.AddComponent <PolygonCollider2D>(); // Disable the collider if it couldn't form any triangles collider.enabled = IsDefaultPolygonCollider2D(collider) == false; D2D_Helper.Destroy(sprite); D2D_Helper.Destroy(spriteRenderer); UpdateColliderSettings(); } }
protected virtual void Update() { if (RequiredFixture == null) { D2D_Helper.Destroy(gameObject); } }
public void Destroy() { if (PolygonCollider2D != null) { D2D_Helper.Destroy(PolygonCollider2D); PolygonCollider2D = null; } }
private void DestroyAutoPolygonCollider() { if (autoPolygonCollider != null) { D2D_Helper.Destroy(autoPolygonCollider.gameObject); autoPolygonCollider = null; } }
public void Destroy() { foreach (var edgeCollider2D in EdgeCollider2Ds) { D2D_Helper.Destroy(edgeCollider2D); } EdgeCollider2Ds.Clear(); }
private void DestroyEdgeColliders() { if (edgeColliders != null) { D2D_Helper.Destroy(edgeColliders.gameObject); edgeColliders = null; } }
private void DestroyPolygonColliders() { if (polygonColliders != null) { D2D_Helper.Destroy(polygonColliders.gameObject); polygonColliders = null; } }
private void DestroyPolygonCollider2D() { if (polygonCollider2D != null) { D2D_Helper.Destroy(polygonCollider2D); polygonCollider2D = null; } }
public void Destroy() { for (var i = Colliders.Count - 1; i >= 0; i--) { D2D_Helper.Destroy(Colliders[i]); } Colliders.Clear(); }
protected virtual void OnDestructibleValidSplit(D2D_SplitData splitData) { DamageLimit /= 2; Count /= 2; if (Count <= 0) { D2D_Helper.Destroy(this); } }
private void DestroyFixture() { if (Target != null) { D2D_Helper.Destroy(Target); D2D_Helper.Destroy(this); } else { D2D_Helper.Destroy(gameObject); } }
private void DestroyAlphaTex() { if (alphaTex != null) { D2D_Helper.Destroy(alphaTex); alphaTex = null; } alphaData = null; alphaWidth = 0; alphaHeight = 0; }
public void Trim(int pathCount) { if (pathCount > 0) { for (var i = Colliders.Count - 1; i >= pathCount; i--) { D2D_Helper.Destroy(Colliders[i]); Colliders.RemoveAt(i); } } else { Destroy(); } }
public void UpdateDestruction() { if (AllowDestruction == true) { #if UNITY_EDITOR if (Application.isPlaying == false) { return; } #endif if (Damage >= DamageLimit) { if (ReplaceWith != null) { D2D_Helper.CloneGameObject(ReplaceWith, transform.parent, transform.position, transform.rotation); } D2D_Helper.Destroy(gameObject); } } }
protected virtual void OnAlphaTexModified() { var destructibleSprite = GetComponent <D2D_DestructibleSprite>(); var rb2d = GetComponent <Rigidbody2D>(); var anchored = false; // Find which anchors we're connected to foreach (var anchor in Anchors) { var collider2Ds = Physics2D.OverlapCircleAll(anchor.transform.position, anchor.ScaledRadius); foreach (var collider2D in collider2Ds) { if (collider2D.attachedRigidbody == rb2d) { anchored = true; goto ExitLoops; } } } ExitLoops: // Broken off anchors? if (anchored == false) { // Enable physics rigidbody2D.isKinematic = false; // Change collider? if (ChangeColliderType == true && destructibleSprite.ColliderType != NewColliderType) { destructibleSprite.ColliderType = NewColliderType; destructibleSprite.RebuildColliders(); } // Now that it's broken, we no longer need this D2D_Helper.Destroy(this); } }
protected virtual void Update() { if (destructible == null) { destructible = GetComponent <D2D_Destructible>(); } if (splittable == null) { splittable = GetComponent <D2D_Splittable>(); } if (fracturer == null) { fracturer = GetComponent <D2D_Fracturer>(); } var splitDepth = destructible.SplitDepth; var pixelCount = destructible.SolidPixelCount; if (pixelCount < MinPixelsForDestructible || splitDepth > MaxDepthForDestructible) { destructible.Indestructible = true; } if (splittable != null) { if (pixelCount < MinPixelsForSplitting || splitDepth > MaxDepthForSplitting) { D2D_Helper.Destroy(splittable); } } if (fracturer != null) { if (pixelCount < MinPixelsForFracturing || splitDepth > MaxDepthForFracturing) { D2D_Helper.Destroy(fracturer); } } }
public void RebuildCollider(Texture2D alphaTex) { DestroyPolygonCollider2D(); if (alphaTex != null) { if (polygonCollider2D == null) { var spriteRenderer = D2D_Helper.GetOrAddComponent <SpriteRenderer>(gameObject); var sprite = Sprite.Create(alphaTex, new Rect(0, 0, alphaTex.width, alphaTex.height), Vector2.zero, 1.0f, 0, SpriteMeshType.FullRect); spriteRenderer.sprite = sprite; polygonCollider2D = gameObject.AddComponent <PolygonCollider2D>(); // Disable the collider if it couldn't form any triangles polygonCollider2D.enabled = IsDefaultPolygonCollider2D(polygonCollider2D) == false; D2D_Helper.Destroy(sprite); D2D_Helper.Destroy(spriteRenderer); } } }
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()); }
private void DestroySprite() { D2D_Helper.Destroy(sprite); sprite = null; }
public static bool Generate(D2D_Destructible destructible, D2D_SpriteSplitOrder splitOrder) { cells.Clear(); if (destructible != null && destructible.AlphaTex != null) { target = destructible; tex = target.AlphaTex; width = tex.width; height = tex.height; total = width * height; pixels = tex.GetPixels32(); if (cells.Capacity < total) { cells.Capacity = total; } var threshold = (byte)(target.SplitThreshold * 255.0f); for (var i = 0; i < total; i++) { cells.Add(pixels[i].a >= threshold); } fills.Clear(); var validFillCount = 0; for (var i = 0; i < total; i++) { if (cells[i] == true) { currentFill = new Fill(); fills.Add(currentFill); currentFill.XMin = currentFill.XMax = i % width; currentFill.YMin = currentFill.YMax = i / width; BeginFloodFill(i, currentFill.XMin, currentFill.YMin); // Skip the first floodfill if (currentFill.Count >= target.SplitMinPixels) { currentFill.Valid = true; validFillCount += 1; } } } // Can we split? if (validFillCount > 1) { var firstSet = false; switch (splitOrder) { case D2D_SpriteSplitOrder.KeepLargest: fills.Sort((a, b) => b.Count.CompareTo(a.Count)); break; case D2D_SpriteSplitOrder.KeepSmallest: fills.Sort((a, b) => a.Count.CompareTo(b.Count)); break; } foreach (var fill in fills) { if (fill.Valid == true) { if (firstSet == false) { firstSet = true; Split(destructible, fill, false); } else { var clonedGameObject = D2D_Helper.CloneGameObject(destructible.gameObject, destructible.transform.parent); var clonedDestructible = clonedGameObject.GetComponent <D2D_Destructible>(); Split(clonedDestructible, fill, true); } } } return(true); } if (validFillCount == 0) { D2D_Helper.Destroy(destructible.gameObject); } } return(false); }
private void DestroyCollider() { collider = D2D_Helper.Destroy(collider); }
private void DestroyFixture() { D2D_Helper.Destroy(gameObject); }
private void DestroyChild() { child = D2D_Helper.Destroy(child); }
private void DestroyMaterial() { D2D_Helper.Destroy(clonedMaterial); clonedMaterial = null; }
protected virtual void OnDestroy() { D2D_Helper.Destroy(mesh); }