// Update is called once per frame void Update() { Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 mouseWorldDelta = prevMouseWorldPos - mouseWorldPos; prevMouseWorldPos = mouseWorldPos; if (Input.GetMouseButtonDown(0)) { // We sample with a little circle, we could also use a point here // but then we would never be able to drag points because they never truly contact selectedUnit = gridManager.GridInterface.FirstContact(new Circle(mouseWorldPos, 0.1f)); } else if (Input.GetMouseButtonUp(0)) { if (selectedUnit != null) { selectedUnit.EndDrag(); selectedUnit = null; } } if (selectedUnit != null) { selectedUnit.Drag(mouseWorldPos); } }
public void DoContact(DemoUnit unit) { foreach (var c in prevContact) { c.UnmarkAsContacted(); } prevContact.Clear(); foreach (var u in gridManager.GridInterface.ContactWhich(unit.GetShape(), (u) => u != unit)) { prevContact.Add(u); u.MarkAsContacted(); } }
// Update is called once per frame void Update() { Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); var nearest = gridManager.GridInterface.GetNearest(mouseWorldPos); if (prevNearest != null) { prevNearest.UnmarkAsNearest(); } if (nearest != null) { nearest.MarkAsNearest(); prevNearest = nearest; } }
public void Add(DemoUnit unit) { _grid.Add(unit.Key, unit, unit.GetShape()); }