private void DestroyPolygonColliders() { if (polygonColliders != null) { D2D_Helper.Destroy(polygonColliders.gameObject); polygonColliders = null; } }
private void UpdateColliders() { if (ColliderType != D2D_SpriteColliderType.None) { var cellTransform = default(Transform); switch (ColliderType) { case D2D_SpriteColliderType.Edge: { DestroyAutoPolygonCollider(); DestroyPolygonColliders(); if (edgeColliders == null) { edgeColliders = D2D_Helper.CreateGameObject("Edge Colliders", transform).AddComponent<D2D_EdgeColliders>(); edgeColliders.RebuildAllColliders(AlphaTex); } cellTransform = edgeColliders.transform; } break; case D2D_SpriteColliderType.Polygon: { DestroyAutoPolygonCollider(); DestroyEdgeColliders(); if (polygonColliders == null) { polygonColliders = D2D_Helper.CreateGameObject("Polygon Colliders", transform).AddComponent<D2D_PolygonColliders>(); polygonColliders.RebuildAllColliders(AlphaTex); } cellTransform = polygonColliders.transform; } break; case D2D_SpriteColliderType.AutoPolygon: { DestroyPolygonColliders(); DestroyEdgeColliders(); if (autoPolygonCollider == null) { autoPolygonCollider = D2D_Helper.CreateGameObject("Auto Polygon Collider", transform).AddComponent<D2D_AutoPolygonCollider>(); autoPolygonCollider.RebuildCollider(AlphaTex); } cellTransform = autoPolygonCollider.transform; } break; } if (cellTransform != null) { var cellScale = Vector3.one; var cellOffset = Vector3.zero; if (sprite != null && MainTex != null && AlphaTex != null) { cellScale = D2D_Helper.Reciprocal(PixelsToUnits) * D2D_Helper.Divide(MainTex.width, MainTex.height, AlphaTex.width, AlphaTex.height); cellOffset = sprite.bounds.min; cellOffset.z = 0.0f; } if (cellTransform.localPosition != cellOffset) { cellTransform.localPosition = cellOffset; } if (cellTransform.localScale != cellScale) { cellTransform.localScale = cellScale; } } } else { DestroyAutoPolygonCollider(); DestroyPolygonColliders(); DestroyEdgeColliders(); } }