public void Update() { // Check for movement input float scrollSpeed = 100f; var dragDistance = Time.DeltaTime * scrollSpeed; if (SDLEvent.KeyState(SDL_Keycode.SDLK_a)) { _position.X -= dragDistance; } if (SDLEvent.KeyState(SDL_Keycode.SDLK_d)) { _position.X += dragDistance; } if (SDLEvent.KeyState(SDL_Keycode.SDLK_w)) { _position.Y += dragDistance; } if (SDLEvent.KeyState(SDL_Keycode.SDLK_s)) { _position.Y -= dragDistance; } }
private void UpdateDragging() { /* * // If over UI, do nothing * if (EventSystem.current.IsPointerOverGameObject()) * { * return; * } */ // Clear the drag-area markers while (_dragPreviewGameObjects.Count > 0) { var go = _dragPreviewGameObjects[0]; _dragPreviewGameObjects.RemoveAt(0); SimplePool.Despawn(go); } if (_mode != MouseMode.Build) { return; } // Start Drag if (SDLEvent.MouseButtonWentDown(SDL.SDL_BUTTON_LEFT)) { _dragStartPosition = _currentFramePosition; _isDragging = true; } else if (_isDragging == false) { _dragStartPosition = _currentFramePosition; } if (SDLEvent.MouseButtonWentUp(SDL.SDL_BUTTON_RIGHT) || SDLEvent.KeyUp(SDL.SDL_Keycode.SDLK_ESCAPE)) { // The RIGHT mouse button came up or ESC was pressed, so cancel any dragging. _isDragging = false; } //if (_bmc.IsObjectDraggable() == false) //{ // _dragStartPosition = _currentFramePosition; //} var startX = Mathf.FloorToInt(_dragStartPosition.X + 0.5f); var endX = Mathf.FloorToInt(_currentFramePosition.X + 0.5f); var startY = Mathf.FloorToInt(_dragStartPosition.Y + 0.5f); var endY = Mathf.FloorToInt(_currentFramePosition.Y + 0.5f); if (endX < startX) { var temp = endX; endX = startX; startX = temp; } if (endY < startY) { var temp = endY; endY = startY; startY = temp; } // Put one marker at the mouse position for testing //var cursor = SimplePool.Spawn(_circleCursorPrefab, new Vector2<float>(_currentFramePosition.X, _currentFramePosition.Y), 0); //cursor.Sprite.Centered = true; //cursor.Name = "mousepos"; //_dragPreviewGameObjects.Add(cursor); // Display dragged area for (var x = startX; x <= endX; x++) { for (var y = startY; y <= endY; y++) { var t = World.Instance.GetTileAt(x, y); if (t != null) { var actionTile = true; // If shift is being held, just action the perimeter if (SDLEvent.KeyState(SDL.SDL_Keycode.SDLK_LSHIFT) || SDLEvent.KeyState(SDL.SDL_Keycode.SDLK_RSHIFT)) { actionTile = (x == startX || x == endX || y == startY || y == endY); } if (actionTile) { //if (_bmc.BuildMode == BuildMode.Furniture) //{ // ShowFurnitureSpriteAtTile(_bmc.BuildModeObjectType, t); //} //else //{ var go = SimplePool.Spawn(_circleCursorPrefab, new Vector2 <float>(x, y), 0); // go.transform.SetParent(this.transform, true); _dragPreviewGameObjects.Add(go); //} } } } } // End Drag if (_isDragging && SDLEvent.MouseButtonWentUp(SDL.SDL_BUTTON_LEFT)) { _isDragging = false; for (var x = startX; x <= endX; x++) { for (var y = startY; y <= endY; y++) { var actionTile = true; // If shift is being held, just action the perimeter if (SDLEvent.KeyState(SDL.SDL_Keycode.SDLK_LSHIFT) || SDLEvent.KeyState(SDL.SDL_Keycode.SDLK_RSHIFT)) { actionTile = (x == startX || x == endX || y == startY || y == endY); } if (actionTile) { var t = World.Instance.GetTileAt(x, y); if (t != null) { // _bmc.DoBuild(t); } } } } } }