Esempio n. 1
0
        protected override void OnUpdate()
        {
            Vector3 position = GameUtilities.MouseToTerrainPosition();

            Vector2 gridPosition = gridSystem.WorldToGrid(position);

            bool isEmpty = gridSystem.IsEmpty((int)gridPosition.x, (int)gridPosition.y);

            // Debug.Log($"{isEmpty} : {gridPosition}");

            Vector3 gridWorldPosition = gridSystem.CellToWorld(gridPosition);

            // Debug.Log($"P: {position} => {gridWorldPosition}");

            RenderPreview(gridWorldPosition, isEmpty);

            if (Mouse.current.leftButton.IsPressed()) // LMouseClick
            {
                if (!isEmpty)
                {
                    Debug.Log("Cell is not empty!");
                    return;
                }

                this.Enabled = false;
                Build(gridWorldPosition, gridPosition);
                return;
            }

            // To-do: Validate that both buttons aren't pressed...
            // if so, do nothing or cancel

            if (Mouse.current.rightButton.IsPressed()) // RMouseClick
            {
                this.Enabled = false;
                return;
            }
        }