private void UpdateIcon() { PlanetNameData planetNameData = Services.ResourceService.PlanetNameRepository.GetPlanetNameData( Services.GetService <IPlanetService>().CurrentPlanet.Id ); iconImage.overrideSprite = Services.ResourceService.GetSprite(planetNameData.ui_icon); }
public void Setup(ShipModuleInfo module) { this.module = module; ModuleNameData moduleNameData = Services.ResourceService.ModuleNameRepository.GetModuleNameData(module.Id); moduleNameText.text = Services.ResourceService.Localization.GetString(moduleNameData.name); switch (module.State) { case ShipModuleState.Opened: { currencyIconImage.Deactivate(); currencyText.Deactivate(); planetImage.Deactivate(); buyButton.Deactivate(); } break; case ShipModuleState.Available: { currencyIconImage.Activate(); currencyText.Activate(); planetImage.Deactivate(); buyButton.Activate(); } break; case ShipModuleState.Locked: { currencyIconImage.Activate(); currencyText.Activate(); planetImage.Activate(); buyButton.Activate(); } break; } currencyIconImage.overrideSprite = Services.ResourceService.GetCurrencySprite(module.CurrencyType); currencyText.text = BosUtils.GetCurrencyString(Currency.Create(module.CurrencyType, module.Price)); PlanetNameData planetNameData = Services.ResourceService.PlanetNameRepository.GetPlanetNameData(module.Data.PlanetId); if (planetNameData != null) { planetImage.overrideSprite = Services.ResourceService.GetSpriteByKey(planetNameData.icon); } else { planetImage.overrideSprite = Services.ResourceService.Sprites.FallbackSprite; } buyButton.SetListener(() => { var status = Services.GetService <IShipModuleService>().BuyModule(module.Id); switch (status) { case ModuleTransactionState.Success: { Services.SoundService.PlayOneShot(SoundName.buyUpgrade); Setup(module); } break; case ModuleTransactionState.NotEnoughCurrency: { if (module.CurrencyType == CurrencyType.Coins) { Services.ViewService.Show(ViewType.CoinRequiredView, new ViewData { UserData = (int)module.Price }); } } break; } }); IShipModuleService moduleService = Services.GetService <IShipModuleService>(); updateTimer.Setup(0.5f, (deltaTime) => { ModuleTransactionState moduleTransactionState; if (moduleService.IsAllowBuyModule(module.Id, out moduleTransactionState)) { buyButton.interactable = true; } else if (moduleTransactionState == ModuleTransactionState.NotEnoughCurrency && module.CurrencyType == CurrencyType.Coins) { buyButton.interactable = true; } else { buyButton.interactable = false; } }, true); MoveObject(module); }
void LateUpdate() { Vector3 camPos = Camera.mainCamera.transform.position; _DataList.Clear(); if (guiManager.ShowPlanets()) { foreach (Star star in StarPicker.Stars) { List <Exoplanet> planets = star.Planets; if (guiManager.ShowOnlyWithPlanets() && star.Planets.Count == 0) { continue; } Vector3 starPos = new Vector3(star.X, star.Y, star.Z) * Scaler.Scale; float distance3D = Vector3.SqrMagnitude(camPos - starPos); float planetFilter = guiManager.GetPlanetFilter(); if (guiManager.ShowOnlyWithPlanets()) { planetFilter *= 10; } if (distance3D < planetFilter * planetFilter * Scaler.Scale) { Bounds bounds = new Bounds(starPos, Vector3.one); if (GeometryUtility.TestPlanesAABB(GeometryUtility.CalculateFrustumPlanes(Camera.main), bounds) == false) { continue; } Vector3 screenPos3D = Camera.mainCamera.WorldToScreenPoint(starPos); screenPos3D.y = Screen.height - screenPos3D.y; if (screenPos3D.z < 0) { continue; } float distance = Vector3.Distance(starPos, camPos); Vector2 screenPos = new Vector2(screenPos3D.x, screenPos3D.y); NameData newData = new NameData(); newData.ScreenPos = screenPos; newData.Star = star; newData.Distance = distance; _DataList.Add(newData); } } } _PlanetDataList.Clear(); if (PickedStar != null && PickedStar.Planets.Count > 0) { for (int i = 0; i < Sun.Instance._Planets.Length; i++) { Transform planetTransform = Sun.Instance._Planets[i]; Exoplanet planet = PickedStar.Planets[i]; Vector3 planetPos = planetTransform.position; float distance3D = Vector3.SqrMagnitude(camPos - planetPos); //if (distance3D < guiManager.GetPlanetFilter() * guiManager.GetPlanetFilter() * Scaler.Scale) { Bounds bounds = new Bounds(planetPos, Vector3.one); if (GeometryUtility.TestPlanesAABB(GeometryUtility.CalculateFrustumPlanes(Camera.main), bounds) == false) { continue; } Vector3 screenPos3D = Camera.mainCamera.WorldToScreenPoint(planetPos); screenPos3D.y = Screen.height - screenPos3D.y; if (screenPos3D.z < 0) { continue; } float distance = Vector3.Distance(planetPos, camPos); Vector2 screenPos = new Vector2(screenPos3D.x, screenPos3D.y); PlanetNameData newData = new PlanetNameData(); newData.ScreenPos = screenPos; newData.Planet = planet; newData.Distance = distance; _PlanetDataList.Add(newData); } } } }
private void Setup() { if (moduleService == null) { moduleService = Services.GetService <IShipModuleService>(); } if (module == null) { module = moduleService.GetModule(moduleId); } if (moduleNameData == null) { moduleNameData = Services.ResourceService.ModuleNameRepository.GetModuleNameData(moduleId); } nameText.text = Services.ResourceService.Localization.GetString(moduleNameData.name); iconImage.overrideSprite = Services.ResourceService.GetSpriteByKey(moduleNameData.icon); currencyIconImage.overrideSprite = Services.ResourceService.GetCurrencySprite(module.Data.Currency); currencyText.text = BosUtils.GetCurrencyString(module.Data.Currency); ModuleTransactionState status; bool isAllowedToBuy = moduleService.IsAllowBuyModule(moduleId, out status); if (isAllowedToBuy) { requirementText.text = string.Empty; buyButton.interactable = true; } else { switch (status) { case ModuleTransactionState.NotEnoughCurrency: { requirementText.text = string.Empty; currencyText.text = BosUtils.GetCurrencyString(module.Data.Currency, "#FF0000"); buyButton.interactable = false; } break; case ModuleTransactionState.NotValidState: { var planetData = Services.ResourceService.Planets.GetPlanet(module.Data.PlanetId); if (planetData == null) { Debug.LogError($"not found planet for upgrade level => {module.Data.PlanetId}"); return; } PlanetNameData planetNameData = Services.ResourceService.PlanetNameRepository.GetPlanetNameData(planetData.Id); requirementText.text = string.Format(Services.ResourceService.Localization.GetString("fmt_module_requirement"), Services.ResourceService.Localization.GetString(planetNameData.name)); buyButton.interactable = false; buyText.color = Color.grey; } break; } } buyButton.SetListener(() => { var buyStatus = moduleService.BuyModule(moduleId); if (buyStatus == ModuleTransactionState.Success) { Services.GetService <ISoundService>().PlayOneShot(SoundName.Poof); buyParticles?.Play(); } else { Services.GetService <ISoundService>().PlayOneShot(SoundName.click); } }); switch (module.State) { case ShipModuleState.Opened: { checkObject.Activate(); buyButton.Deactivate(); requirementText.text = string.Empty; } break; default: { checkObject.Deactivate(); buyButton.Activate(); } break; } }