public void Init(UniverseObject universeObject, UniverseView universeView) { this.universeView = universeView; this.universeObject = universeObject; universeObject.Listener = this; parentView = universeView.GetPlanetView(universeObject.parent); UpdatePosition(); }
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); } } } }
public virtual void OnParentChanged(TilemapCircle parent) { parentView = universeView.GetPlanetView(universeObject.parent); UpdatePosition(); }