private bool isInside(PlatoonBehaviour obj) { bool inside = false; if (!obj.GetComponent <PlatoonBehaviour>().initialized) { return(false); } inside |= obj.GetComponent <PlatoonBehaviour>().units.Any(x => isInside(x.transform.position)); inside |= isInside(obj.GetComponent <PlatoonBehaviour>().icon.transform.GetChild(0).position); return(inside); }
private bool IsInside(PlatoonBehaviour obj) { var platoon = obj.GetComponent <PlatoonBehaviour>(); if (!platoon.IsInitialized) { return(false); } bool inside = false; inside |= platoon.Units.Any(x => IsInside(x.transform.position)); // TODO: This checks if the center of the icon is within the selection box. It should instead check if any of the four corners of the icon are within the box: inside |= IsInside(platoon.Icon.transform.GetChild(0).position); return(inside); }
private bool IsInsideSelectionBox(PlatoonBehaviour obj) { PlatoonBehaviour platoon = obj.GetComponent <PlatoonBehaviour>(); if (!platoon.IsInitialized) { return(false); } Rect selectionBox; // Guarantee that the rect has positive width and height: float rectX = _mouseStart.x > _mouseEnd.x ? _mouseEnd.x : _mouseStart.x; float rectY = _mouseStart.y > _mouseEnd.y ? _mouseEnd.y : _mouseStart.y; selectionBox = new Rect( rectX, rectY, Mathf.Abs(_mouseEnd.x - _mouseStart.x), Mathf.Abs(_mouseEnd.y - _mouseStart.y)); bool inside = false; inside |= platoon.Units.Any( x => selectionBox.Contains( Camera.main.WorldToScreenPoint( x.Transform.position))); // This checks if the icon overlaps with the selection box: Rect platoonLabel = platoon.SelectableRect.rect; // To screen coordinates: platoonLabel.center = platoon.SelectableRect.TransformPoint( platoonLabel.center); platoonLabel.size = platoon.SelectableRect.TransformVector( platoonLabel.size); inside |= selectionBox.Overlaps(platoonLabel); return(inside); }