public bool ToTransforms(Transform[] transforms) { _hoverPoint = null; _hoverComponent = null; var components = transforms.Select(x => x.GetComponent <TurretComponent>()).Where(x => x != null); foreach (TurretComponent component in components) { ComponentAttachmentPoint point = component.GetNearestComponentAttachmentPoint(transform.position, _root.GetSize(), true); if (point != null) { _hoverPoint = point; _hoverComponent = component; } } if (_hoverPoint != null) { transform.position = (Vector3)_hoverComponent.AttachmentToWorldPosition(_hoverPoint) + Vector3.back; transform.rotation = _hoverComponent.AttachmentToWorldRotation(_hoverPoint); } return(false); }
public bool ToPosition(Vector2 position, Quaternion rotation) { _hoverPoint = null; _hoverComponent = null; int size = (int)_root.GetSize(); if (size == 1) { position = new Vector2(Mathf.Round(position.x - 0.5f) + 0.5f, Mathf.Round(position.y - 0.5f) + 0.5f); } else { position = new Vector2( Mathf.Round(position.x / size) * size, Mathf.Round(position.y / size) * size ); } transform.position = position; transform.rotation = rotation; return(CanPlace(transform.position, size / 2f)); }