public void OnGUI() { if (GameLogic.Instace.State != GameLogicState.PlayingShip) { return; } if (centeredLabelStyle == null) { centeredLabelStyle = new GUIStyle(GUI.skin.label); centeredLabelStyle.alignment = TextAnchor.MiddleCenter; centeredBoxStyle = new GUIStyle(GUI.skin.box); centeredBoxStyle.alignment = TextAnchor.MiddleCenter; } InputAreas.ResetInputAreas(); switch (mode) { case ShipInputMode.Move: DrawMoveGUI(); break; } }
private void DrawMoveGUI() { //Draw movement keys if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { InputAreas.AddInputArea(new Rect(0, Screen.height - Screen.height * 0.25f, Screen.width, Screen.height * 0.25f)); GUI.Button(new Rect(0, Screen.height - Screen.height * 0.25f, Screen.width / 4, Screen.height * 0.25f), "Rotate Left"); GUI.Button(new Rect(Screen.width / 4.0f, Screen.height - Screen.height * 0.25f, Screen.width / 4, Screen.height * 0.25f), "Rotate Right"); GUI.Button(new Rect(Screen.width / 2.0f, Screen.height - Screen.height * 0.25f, Screen.width / 2, Screen.height * 0.25f), "Move Forward"); } //Draw switch to avatar button InputAreas.AddInputArea(new Rect(Screen.width - (Screen.width / 8) * 3.0f, 0, Screen.width / 8, Screen.height / 8)); if (GUI.Button(new Rect(Screen.width - (Screen.width / 8) * 3.0f, 0, Screen.width / 8, Screen.height / 8), "LEAVE SHIP")) { int clickedThingIndex = shipView.UniverseView.Universe.FindClosestRenderedThing(shipView.UniverseObject.Position, 30.0f); if (clickedThingIndex >= 0) { GameLogic.Instace.PlayerLeaveShip(shipView.UniverseView.Universe.GetPlanet((ushort)clickedThingIndex)); } } }
private void DrawMoveGUI() { //Draw movement keys if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { InputAreas.AddInputArea(new Rect(0, Screen.height - Screen.height * 0.25f, Screen.width, Screen.height * 0.25f)); GUI.Button(new Rect(0, Screen.height - Screen.height * 0.25f, Screen.width / 4, Screen.height * 0.25f), "Left"); GUI.Button(new Rect(Screen.width / 4.0f, Screen.height - Screen.height * 0.25f, Screen.width / 4, Screen.height * 0.25f), "Right"); GUI.Button(new Rect(Screen.width / 2.0f, Screen.height - Screen.height * 0.25f, Screen.width / 2, Screen.height * 0.25f), "Jump"); } //Draw travel button //InputAreas.AddInputArea(new Rect(Screen.width - (Screen.width / 8) * 2.0f, 0, Screen.width / 8, Screen.height / 8)); //if (GUI.Button(new Rect(Screen.width - (Screen.width / 8) * 2.0f, 0, Screen.width / 8, Screen.height / 8), "TRAVEL")) // mode = AvatarInputMode.TravelToPlanet; //Draw edit button InputAreas.AddInputArea(new Rect(Screen.width - Screen.width / 8, 0, Screen.width / 8, Screen.height / 8)); if (GUI.Button(new Rect(Screen.width - Screen.width / 8, 0, Screen.width / 8, Screen.height / 8), "EDIT")) { mode = AvatarInputMode.Edit; editTool = AvatarInputEditTool.None; } //Draw switch to ship button InputAreas.AddInputArea(new Rect(Screen.width - (Screen.width / 8) * 3.0f, 0, Screen.width / 8, Screen.height / 8)); if (GUI.Button(new Rect(Screen.width - (Screen.width / 8) * 3.0f, 0, Screen.width / 8, Screen.height / 8), "BOARD SHIP")) { GameLogic.Instace.PlayerBoardShip(); } }
private void DrawTravelToPlanetGUI() { //Draw cancel button InputAreas.AddInputArea(new Rect(Screen.width - Screen.width / 8, 0, Screen.width / 8, Screen.height / 8)); if (GUI.Button(new Rect(Screen.width - Screen.width / 8, 0, Screen.width / 8, Screen.height / 8), "EXIT\nTRAVEL")) { mode = AvatarInputMode.Move; } GUI.Box(new Rect(0, Screen.height - 50, Screen.width, 50), "Tap on a planet to travel", centeredBoxStyle); }
private void DrawEditGUI() { //Draw toolbar InputAreas.AddInputArea(new Rect(0, Screen.height - Screen.height * 0.25f, Screen.width, Screen.height * 0.25f)); editTool = (AvatarInputEditTool)GUI.Toolbar(new Rect(0, Screen.height - Screen.height * 0.25f, Screen.width, Screen.height * 0.25f - 50), (int)editTool, EditToolNames); GUI.Box(new Rect(0, Screen.height - 50, Screen.width, 50), EditToolTooltips[(int)editTool], centeredBoxStyle); //Draw cancel button InputAreas.AddInputArea(new Rect(Screen.width - Screen.width / 8, 0, Screen.width / 8, Screen.height / 8)); if (GUI.Button(new Rect(Screen.width - Screen.width / 8, 0, Screen.width / 8, Screen.height / 8), "EXIT\nEDIT")) { mode = AvatarInputMode.Move; } }
public void UpdateTilesModification() { bool modifyTile = false; int tileX = 0; int tileY = 0; if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { if (Input.touchCount == 1 && !InputAreas.IsInputArea(Input.GetTouch(0).position)) { modifyTile = GetTileCoordinatesUnderTouch(out tileX, out tileY); } } else { if (Input.GetMouseButton(0) && !InputAreas.IsInputArea(Input.mousePosition)) { modifyTile = GetTileCoordinatesUnderMouse(out tileX, out tileY); } } switch (editTool) { case AvatarInputEditTool.Add: if (modifyTile) { avatarView.ParentView.TilemapCircle.SetTile(tileX, tileY, 1); } break; case AvatarInputEditTool.Remove: if (modifyTile) { avatarView.ParentView.TilemapCircle.SetTile(tileX, tileY, 0); } break; case AvatarInputEditTool.MoveCamera: UniverseViewCamera.Instance.UpdateMove(); break; } }
public void UpdateClickOnPlanetToTravel(UniverseView universeView) { bool clickTravel = false; Vector2 clickPosition = Vector2.zero; if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { if (!travelInput) { if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began && !InputAreas.IsInputArea(Input.GetTouch(0).position)) { travelInput = true; travelInputStartPosition = Input.GetTouch(0).position; } else { travelInput = false; } } else { if (Input.touchCount == 1) { if (Input.GetTouch(0).phase == TouchPhase.Ended) { if ((travelInputStartPosition - Input.GetTouch(0).position).magnitude < 10) { clickTravel = true; clickPosition = Input.GetTouch(0).position; } travelInput = false; } } else { travelInput = false; } } } else { if (!travelInput) { if (Input.GetMouseButtonDown(0) && !InputAreas.IsInputArea(Input.mousePosition)) { travelInput = true; travelInputStartPosition = Input.mousePosition; } else { travelInput = false; } } else { if (Input.GetMouseButtonUp(0)) { if ((travelInputStartPosition - (Vector2)Input.mousePosition).magnitude < 10) { clickTravel = true; clickPosition = Input.mousePosition; } travelInput = false; } else if (!Input.GetMouseButton(0)) { travelInput = false; } } } if (clickTravel) { Vector2 worldPos = Camera.main.ScreenToWorldPoint(clickPosition); Vector2 worldPosTolerance = Camera.main.ScreenToWorldPoint(clickPosition + Vector2.right * (Screen.dpi > 0 ? Screen.dpi : 72) / 2.54f); //1 cm tolerance int clickedThingIndex = universeView.Universe.FindClosestRenderedThing(worldPos, (worldPos - worldPosTolerance).magnitude); if (clickedThingIndex >= 0) { PlanetView targetPlanetView = universeView.GetPlanetView((ushort)clickedThingIndex); if (universeView.avatarView.UniverseObject.parent != targetPlanetView.TilemapCircle) { GameLogic.Instace.TravelToPlanet(targetPlanetView); } } } }