protected void MoveCameraByTouches(float timeStep) { const float touchSensitivity = 0.2f; RayQueryResult?raycastResult = null; var input = Input; if (UIClicked || m_Loading) { return; } if (Input.MouseMove.LengthSquared > 0) { if (InputRaycastCollided(Input.MousePosition, out raycastResult)) { m_CurrentHoveredTile = InterpretRaycastResult(raycastResult.Value); if (m_CurrentHoveredTile != m_lastHoveredTile) { if (m_CurrentHoveredTile != null) { m_CurrentHoveredTile.Hovered = true; Debug.WriteLine("Hovered: " + m_CurrentHoveredTile.Node.Name); } if (m_lastHoveredTile != null) { m_lastHoveredTile.Hovered = false; } m_lastHoveredTile = m_CurrentHoveredTile; } } else { if (m_lastHoveredTile != null) { m_lastHoveredTile.Hovered = false; } m_CurrentHoveredTile = null; m_lastHoveredTile = null; } } if (Input.GetMouseButtonPress(MouseButton.Left)) { if (InputRaycastCollided(Input.MousePosition, out raycastResult)) { m_CurrentSelectedTile = InterpretRaycastResult(raycastResult.Value); if (m_CurrentSelectedTile != m_lastSelectedTile) { m_CurrentSelectedTile.Selected = true; if (m_lastSelectedTile != null) { m_lastSelectedTile.Selected = false; } m_lastSelectedTile = m_CurrentSelectedTile; CloseBuildingUpgradeMenu(); CloseBuildingSelectionMenu(); if (m_CurrentSelectedTile.HasBuildingBuilt()) { OpenBuildingUpgradeMenu(m_CurrentSelectedTile.Building as Building); } else if (m_CurrentSelectedTile.IsBuildable) { OpenBuildingSelectionMenu(); } } } else { CloseBuildingUpgradeMenu(); CloseBuildingSelectionMenu(); if (m_CurrentSelectedTile != null) { m_CurrentSelectedTile.Selected = false; } } } if (Input.GetMouseButtonDown(MouseButton.Right)) { // TODO: screen to world sync move const float mouseSensitivity = .01f; var mouseMove = Input.MouseMove; float cameraX = -mouseSensitivity * mouseMove.X; float cameraY = mouseSensitivity * mouseMove.Y; cameraNode.Position = cameraNode.LocalToWorld(new Vector3(cameraX, cameraY, 0f)); Debug.WriteLine("Camera " + cameraY + " " + cameraX); } if (input.NumTouches == 1) { TouchState state = input.GetTouch(0); if (state.Delta.X != 0 || state.Delta.Y != 0) { var camera = cameraNode.GetComponent <Camera>(); if (camera == null) { return; } float cameraX = -TouchMovementFactor * state.Delta.X * DT; float cameraY = TouchMovementFactor * state.Delta.Y * DT; cameraNode.Position = cameraNode.LocalToWorld(new Vector3(cameraX, cameraY, 0f)); //cameraNode.Position = new Vector3(cameraNode.Position.X + cameraX, cameraNode.Position.Y + cameraY, cameraNode.Position.Z); Debug.WriteLine("Camera " + cameraY + " " + cameraX); } else if (state.Delta == IntVector2.Zero && InputRaycastCollided(state.Position, out raycastResult)) { m_CurrentSelectedTile = InterpretRaycastResult(raycastResult.Value); if (m_CurrentSelectedTile != m_lastSelectedTile) { m_CurrentSelectedTile.Selected = true; if (m_lastSelectedTile != null) { m_lastSelectedTile.Selected = false; } m_lastSelectedTile = m_CurrentSelectedTile; CloseBuildingUpgradeMenu(); CloseBuildingSelectionMenu(); if (m_CurrentSelectedTile.HasBuildingBuilt()) { OpenBuildingUpgradeMenu(m_CurrentSelectedTile.Building as Building); } else if (m_CurrentSelectedTile.IsBuildable) { OpenBuildingSelectionMenu(); } } } else { CloseBuildingUpgradeMenu(); CloseBuildingSelectionMenu(); if (m_CurrentSelectedTile != null) { m_CurrentSelectedTile.Selected = false; } } } }
/// <summary> /// Move camera for 3D samples /// </summary> protected void SimpleMoveCamera3D(float timeStep, float moveSpeed = 10.0f) { RayQueryResult?raycastResult = null; if (UIClicked || m_Loading) { return; } if (Input.MouseMove.LengthSquared > 0) { if (InputRaycastCollided(Input.MousePosition, out raycastResult)) { m_CurrentHoveredTile = InterpretRaycastResult(raycastResult.Value); if (m_CurrentHoveredTile != m_lastHoveredTile) { if (m_CurrentHoveredTile != null) { m_CurrentHoveredTile.Hovered = true; Debug.WriteLine("Hovered: " + m_CurrentHoveredTile.Node.Name); } if (m_lastHoveredTile != null) { m_lastHoveredTile.Hovered = false; } m_lastHoveredTile = m_CurrentHoveredTile; } } else { if (m_lastHoveredTile != null) { m_lastHoveredTile.Hovered = false; } m_CurrentHoveredTile = null; m_lastHoveredTile = null; } } if (Input.GetMouseButtonPress(MouseButton.Left)) { if (InputRaycastCollided(Input.MousePosition, out raycastResult)) { m_CurrentSelectedTile = InterpretRaycastResult(raycastResult.Value); if (m_CurrentSelectedTile != m_lastSelectedTile) { m_CurrentSelectedTile.Selected = true; if (m_lastSelectedTile != null) { m_lastSelectedTile.Selected = false; } m_lastSelectedTile = m_CurrentSelectedTile; CloseBuildingUpgradeMenu(); CloseBuildingSelectionMenu(); if (m_CurrentSelectedTile.HasBuildingBuilt()) { OpenBuildingUpgradeMenu(m_CurrentSelectedTile.Building as Building); } else if (m_CurrentSelectedTile.IsBuildable) { OpenBuildingSelectionMenu(); } } } else { CloseBuildingUpgradeMenu(); CloseBuildingSelectionMenu(); if (m_CurrentSelectedTile != null) { m_CurrentSelectedTile.Selected = false; } } } if (Input.GetMouseButtonDown(MouseButton.Right)) { // TODO: screen to world sync move const float mouseSensitivity = .01f; var mouseMove = Input.MouseMove; float cameraX = -mouseSensitivity * mouseMove.X; float cameraY = mouseSensitivity * mouseMove.Y; cameraNode.Position = cameraNode.LocalToWorld(new Vector3(cameraX, cameraY, 0f)); Debug.WriteLine("Camera " + cameraY + " " + cameraX); } if (Input.MouseMoveWheel != 0) { MainCamera.OrthoSize += Input.MouseMoveWheel; /*MainCamera.NearClip = -1000;*/ //TODO } }