private void CreateListItemAsynchronously(DynamicAchievementManager.Achievement itemName, string description, int reward, AssetReference sprite, bool unlocked) { var achievementItemGameObject = Instantiate(DisplayItemAddressableAsGameObject, Display).GetComponentInChildren <AchievementListItem>(); var achievementItemGameObjectTransform = achievementItemGameObject.transform; achievementItemGameObjectTransform.SetParent(Display); achievementItemGameObjectTransform.localScale = Vector3.one; _achievementListItems.Add(itemName, new AchievementItemStruct(achievementItemGameObject.Background, achievementItemGameObject.ReturnNameDisplay, achievementItemGameObject.ReturnDescriptionDisplay, achievementItemGameObject.ReturnRewardDisplay, achievementItemGameObject.ReturnGraphic, unlocked)); _achievementListItems[itemName].NameDisplay.text = StringUtilities.AddSpacesBeforeCapitals(itemName.ToString()); _achievementListItems[itemName].DescriptionDisplay.text = description; _achievementListItems[itemName].RewardDisplay.text = reward.ToString(); if (unlocked) { SetUnlockedState(itemName); } AssetReferenceLoader.LoadAssetReferenceAsynchronously <Sprite>(sprite, (returnSprite) => { _achievementListItems[itemName].Graphic.sprite = returnSprite; achievementItemGameObject.RemoveClassFromObject(); if (sprite.Asset) { AssetReferenceLoader.UnloadAssetReference(sprite); //TODO: cant unload sprites in use } }); }
private void SetUnlockedState(DynamicAchievementManager.Achievement achievement) { if (!ListCreated) { return; //Sometimes an achievement for opening the app x times will try to set this before the list is created. } _achievementListItems[achievement].Background.color = UnLockedColour; }
private static void OnAchievementUnlocked(DynamicAchievementManager.Achievement achievement) { if (_activeAchievements >= _maximumNumberOfActiveAchievements) { DelayedDynamicAchievementsQueue.Enqueue(achievement); return; } PopAchievement(achievement); }
private static void PopAchievement(DynamicAchievementManager.Achievement achievement) { var assetReference = DynamicAchievementManager.ReturnSpriteAssetReference(achievement); _activeAchievements++; AssetReferenceLoader.LoadAssetReferenceAsynchronously <Sprite>(assetReference, (returnVariable) => { var popUp = PopUps.Dequeue(); popUp.transform.SetSiblingIndex(_maximumNumberOfActiveAchievements - 1); popUp.Show(returnVariable, StringUtilities.AddSpacesBeforeCapitals(achievement.ToString()), DynamicAchievementManager.ReturnDescription(achievement), DynamicAchievementManager.ReturnReward(achievement), () => { _activeAchievements--; PopUps.Enqueue(popUp); popUp.gameObject.SetActive(false); }); AssetReferenceLoader.UnloadAssetReference(assetReference); Instance.StartCoroutine(Instance.HandleDelayedAdditions()); }); }
private void OnAchievementUnlocked(DynamicAchievementManager.Achievement achievement) { SetUnlockedState(achievement); SetRewardDisplay(); }