public override void OnUpdate(GameTime gameTime) { if (!_levelLoaded) { return; } base.OnUpdate(gameTime); _pausePhysics = true; if (Keyboard.GetState().IsKeyDown(Keys.LeftControl) && Keyboard.GetState().IsKeyDown(Keys.S) && !_saveAction) { _saveAction = true; GameWorldManager.Instance.SaveState(); _level = PrefabRepository.Instance.GetLevelPrefab(@"Content\Levels\" + _levelName + ".eql"); _level.SetState(GameWorldManager.Instance.GetState()); _level.SerializeLevel(); HintManager.Instance.SpawnHint("Saved " + _levelName, new Vector2(200, 200), 5000, 13); } else if (Keyboard.GetState().IsKeyUp(Keys.S) || Keyboard.GetState().IsKeyUp(Keys.LeftControl)) { _saveAction = false; } if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.D)) { if (!_actionToggleDebugView) { _debugViewState = !_debugViewState; _actionToggleDebugView = true; } } if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.D)) { _actionToggleDebugView = false; } if (_inputAggregator.HasEvent(UISButton.G, true)) { _debugViewGrid = !_debugViewGrid; } // debug view segments _debugViewGridstep = UnitsConverter.ToSimUnits(1f); if (_inputAggregator.HasEvent(UISButton.LeftControl) || _inputAggregator.HasEvent(UISButton.RightControl)) { _debugViewGridstep *= 2f; } else if (_inputAggregator.HasEvent(UISButton.LeftShift) || _inputAggregator.HasEvent(UISButton.RightShift)) { _debugViewGridstep *= 0.1f; } }
public void MoveProcess(GameTime dt) { if (_selectedEntity != null && _dragging) { Vector3 m3D = SceneManager.Instance.IntersectScreenRayWithPlane(_selectedEntity.GetPosition().Z); Vector3 newPosition = new Vector3(m3D.X, m3D.Y, _selectedEntity.GetPosition().Z) - _relative; if (!newPosition.Equals(_selectedEntity.GetPosition())) { if (_inputAggregator.HasEvent(UISButton.LeftControl) || _inputAggregator.HasEvent(UISButton.RightControl)) { newPosition = TransformUtility.SnapToGridXY(newPosition, OperationBigIncrement); } else if (_inputAggregator.HasEvent(UISButton.LeftShift) || _inputAggregator.HasEvent(UISButton.RightShift)) { newPosition = TransformUtility.SnapToGridXY(newPosition, OperationSmallIncrement); } else { newPosition = TransformUtility.SnapToGridXY(newPosition, 1f); } _selectedEntity.SetPosition(newPosition); } } if (_selectedEntity != null && _state.Equals(EditorState.Selected)) { Vector3 move = Vector3.Zero; float snapStep = 1f; if (_inputAggregator.HasEvent(UISButton.Up)) { move += Vector3.UnitY; } else if (_inputAggregator.HasEvent(UISButton.Down)) { move -= Vector3.UnitY; } if (_inputAggregator.HasEvent(UISButton.Left)) { move -= Vector3.UnitX; } else if (_inputAggregator.HasEvent(UISButton.Right)) { move += Vector3.UnitX; } if (_inputAggregator.HasEvent(UISButton.Minus)) { move -= Vector3.UnitZ; } else if (_inputAggregator.HasEvent(UISButton.Plus)) { move += Vector3.UnitZ; } if (_inputAggregator.HasEvent(UISButton.LeftControl) || _inputAggregator.HasEvent(UISButton.RightControl)) { move *= OperationBigIncrement; snapStep = OperationBigIncrement; } else if (_inputAggregator.HasEvent(UISButton.LeftShift) || _inputAggregator.HasEvent(UISButton.RightShift)) { move *= OperationSmallIncrement; snapStep = OperationSmallIncrement; } if (!move.Equals(Vector3.Zero)) { if (_inputAggregator.HasEvent(UISButton.Q)) { move *= 5; } if (_moveTime < 0) { _moveTime = dt.TotalGameTime.TotalMilliseconds; _selectedEntity.SetPosition(TransformUtility.SnapToGridXY(_selectedEntity.GetPosition() + move, snapStep)); _lastSelectedZ = _selectedEntity.GetPosition().Z; } else if (dt.TotalGameTime.TotalMilliseconds - _moveTime > MoveDelay || Keyboard.GetState().IsKeyDown(Keys.Q)) { _selectedEntity.SetPosition(TransformUtility.SnapToGridXY(_selectedEntity.GetPosition() + move, snapStep)); _lastSelectedZ = _selectedEntity.GetPosition().Z; } } else { _moveTime = -1; } } }