private void BuildBoxColliders(IList <BoxColliderInfo> boxColliders) { if (boxColliders == null) { return; } IList <BoxCollider2D> colliderComponents = GetComponents <BoxCollider2D>().ToList(); var diff = boxColliders.Count - colliderComponents.Count; if (diff > 0) { for (var i = 0; i < diff; i++) { colliderComponents.Add(gameObject.AddComponent <BoxCollider2D>()); } } else if (diff < 0) { for (var i = colliderComponents.Count - 1; i >= boxColliders.Count; i--) { Destroy(colliderComponents[i]); colliderComponents.RemoveAt(i); } } for (var i = 0; i < boxColliders.Count; i++) { var currentComponent = colliderComponents[i]; currentComponent.offset = ApiMappings.Vector2FromPosition(boxColliders[i].Position); currentComponent.size = ApiMappings.Vector2FromPosition(boxColliders[i].Size); } }
private void BuildEdgeColliders(IList <Position> colliderPoints) { var colliderRoot = GetComponent <EdgeCollider2D>(); colliderRoot.points = colliderPoints.Select(pos => ApiMappings.Vector2FromPosition(pos)).ToArray(); }