// SETUP PLANET public void PlanetSetup(PlanetStats thisPlanet) { // Initialize Variables // Set a reference to the child objects, Name and Image; planetNameObject = gameObject.transform.Find("Name").gameObject; planetImageObject = gameObject.transform.Find("Image").gameObject; // Get the RectTransform of this planet and it's name object. planetRectTransform = GetComponent <RectTransform>(); nameRectTransform = planetNameObject.GetComponent <RectTransform>(); // Get the starting versions of this Mode's co-ords and scale thisModeX = planetRectTransform.anchoredPosition.x; thisModeY = planetRectTransform.anchoredPosition.y; // Get the pixels per unit of the sprite being used ppu = planetImageObject.GetComponent <Image>().sprite.pixelsPerUnit; // Get reference to this planet's button planetButtonScript = gameObject.GetComponent <ButtonSwitch>(); // Initialize audio controller reference audioObj = AudioController.Instance; // Setup the objects in accordance with the current mode currentMode = GameController.currentMode; if (currentMode == "ScaleMode") { // Set the scale of the planet relative to it's diameter diameterInPixels = thisPlanet.diameter * GameController.pixelsPerKm; thisModeScale = diameterInPixels / ppu; planetImageObject.transform.localScale = new Vector2(thisModeScale, thisModeScale); // Keep the name above the scaled planet nameRectTransform = planetNameObject.GetComponent <RectTransform>(); thisModeNameX = nameRectTransform.anchoredPosition.x; thisModeNameY = nameRectTransform.anchoredPosition.y; nameRectTransform.anchoredPosition = new Vector2(thisModeNameX, thisModeNameY + GameController.textScalar * diameterInPixels); } // Setup the distance mode planet to be standard size else if (gameObject.name == "Distance Planet") { // Reset planetIsMoving bool GameController.planetIsMoving = false; // Set this planet's name text position to the Planet Info version var nameX = nameRectTransform.anchoredPosition.x; nameRectTransform.anchoredPosition = new Vector2(nameX, GameController.infoNameY); // Set this planet's position and scale to the default version planetRectTransform.anchoredPosition = new Vector2(GameController.defaultX, GameController.kmPlanetY); planetImageObject.transform.localScale = new Vector2(GameController.defaultScale, GameController.defaultScale); } else if (currentMode == "DistanceMode") { // Get the reference to the Distance Planet and it's import script distanceObj = DistanceController.distanceObj; distanceImportScript = distanceObj.GetComponent <PlanetImport>(); // Disable the button if this mini planet is the same as Distance Planet if (gameObject.name == distanceImportScript.planet.name) { planetButtonScript.ButtonDisable(); } } // Save vector to variable for future use thisModeNameVector = nameRectTransform.anchoredPosition; }
// Handle the sequence of events for travelling to a new planet IEnumerator TravelToPlanet(GameObject planetObj) { // Tween Distance Planet offscreen to the right float planetTweenTime = 0.5f; float halfPlanetWidth = GameController.defaultScale * ppu * 0.5f; Tween movePlanetX = transform.DOMoveX(Screen.width + halfPlanetWidth, planetTweenTime).SetEase(Ease.InCirc); // Get the stats from each planet PlanetImport planetInfo = GetComponent <PlanetImport>(); PlanetImport planetInfoNew = planetObj.GetComponent <PlanetImport>(); // Get the distance from sun of the two planets var oldKmFromSun = planetInfo.kmFromSun; var newKmFromSun = planetInfoNew.kmFromSun; // Initialize time variables float minTraveltime = planetTweenTime * 2; double timeScaleFactor = 1e3d; // Calculate the distance between new planet and old planet double travelKm = Math.Abs(newKmFromSun - oldKmFromSun); // Calculate wait time based on distance float travelTime = (float)(travelKm / timeScaleFactor); travelTime = Mathf.Max(minTraveltime, travelTime); // Distance Counter // Get reference to Distance Controller script DistanceController kmControl = DistanceController.Instance; // Enable and Reset counter text kmControl.ActivateCounter(); kmControl.ResetCounter(); // Accelerate counting over time from 0 -> calculated distance DOTween.To(() => CountDistance.kmCounter, x => CountDistance.kmCounter = x, travelKm, travelTime).SetEase(Ease.InOutQuart); // Set counter scale to tween to (weighted by travel time) float counterScale = 0.8f + 0.1f * travelTime; // Scale up counter over time DOTween.To(() => CountDistance.myScale, x => CountDistance.myScale = x, counterScale, travelTime).SetEase(Ease.OutBack); // Enable and Reset journey display kmControl.ActivateJourneyDisplay(); kmControl.SetJourneyDisplay(planetInfo.planet.name, planetInfoNew.planet.name); // Scale tween in the Journey Display float journeyScale = 1f; DOTween.To(() => JourneyDisplay.myScale, x => JourneyDisplay.myScale = x, journeyScale, planetTweenTime).SetEase(Ease.OutElastic); // Play travel to planet sound if (travelKm < 1800d) { audioObj.PlaySfx(AudioController.audioTravelShort); } else { audioObj.PlaySfx(AudioController.audioTravelLong); } yield return(movePlanetX.WaitForCompletion()); // Change to new planet planetInfo.planet = planetInfoNew.planet; planetInfo.ImportThisPlanet(); // Put Distance Planet off left of screen gameObject.transform.position = new Vector3(-1000, transform.position.y, 0); yield return(new WaitForSeconds(travelTime - (2 * planetTweenTime))); // Tween new Distance Planet onscreen from the left. movePlanetX = transform.DOMoveX(Screen.width * 0.5f, planetTweenTime).SetEase(Ease.OutCirc); // Fade out travel sound if (audioObj.sfxPlayer.clip == AudioController.audioTravelLong) { audioObj.FadeOutVol(audioObj.sfxPlayer, 1.5f); } yield return(movePlanetX.WaitForCompletion()); GameController.planetIsMoving = false; }