protected virtual void OnAreaChange(SelectionTracker.OnAreaChangeArgs args) { Vector2Int startPosition = Utils.WorldToGrid(args.startMousePosition); Vector2Int currentPosition = Utils.WorldToGrid(args.currentMousePosition); int width = Mathf.Abs(currentPosition.x - startPosition.x) + 1; int height = Mathf.Abs(currentPosition.y - startPosition.y) + 1; Vector2Int start = startPosition; fidt17.Utils.IntRectangle rect; if (width >= height) { Vector2Int end = new Vector2Int(currentPosition.x, startPosition.y); rect = new fidt17.Utils.IntRectangle(start, end); } else { Vector2Int end = new Vector2Int(startPosition.x, currentPosition.y); rect = new fidt17.Utils.IntRectangle(start, end); } if (args.dragEnded) { CreateJobs(); } if (_selectionArea?.CompareTo(rect) == false || _selectionArea == null) { _selectionArea = rect; GetNewPlans(); } }
protected virtual void OnAreaChange(SelectionTracker.OnAreaChangeArgs args) { if (_selectionArea?.CompareTo(args.rectangle) == false || _selectionArea == null) { _selectionArea = args.rectangle; GetNewTrees(); } if (args.dragEnded) { CreateJobs(); } }
protected virtual void OnAreaChange(SelectionTracker.OnAreaChangeArgs args) { if (_selectionArea?.CompareTo(args.rectangle) == false || _selectionArea == null) { _selectionArea = args.rectangle; DrawSelectionArea(args.startMousePosition, args.currentMousePosition); } if (args.dragEnded) { StockpileCreator.CreateStockpileOnTiles(GetTilesInArea()); GameObject.Destroy(_area?.gameObject); } }
protected void DrawSelectionArea(Vector2 start, Vector2 end) { if (_area == null) { _area = Factory.Create("SelectionArea", new Vector2Int((int)start.x, (int)start.y)).GetComponent <Transform>(); Color color = Color.white; ColorUtility.TryParseHtmlString(ColorHex, out color); color.a = 60.0f / 255.0f; _area.GetChild(0).GetComponent <SpriteRenderer>().color = color; } start = Utils.WorldToGrid(start); end = Utils.WorldToGrid(end); var rect = new fidt17.Utils.IntRectangle(Utils.ToVector2Int(start), Utils.ToVector2Int(end)); _area.position = new Vector3(rect.Start.x - 0.5f, rect.Start.y - 0.5f, 0); float width = rect.End.x - rect.Start.x + 1; float height = rect.End.y - rect.Start.y + 1; _area.localScale = new Vector3(width, height, 1); }
public bool CompareTo(IntRectangle otherRect) => this.Start == otherRect.Start && this.End == otherRect.End;