public void Initialize() { if (!isInitialized) { lastViewStoreVersion = 0; listSongItemViews = new List <SongItemView>(20); currentItemList = new Dictionary <GameObject, SongItemView>(20); itemScrollList.onInitializeItem += OnSongItemNeedInitialized; //get all song item view Transform scrolllist = itemScrollList.transform; int numItem = scrolllist.childCount; for (int i = 0; i < numItem; i++) { SongItemView v = scrolllist.GetChild(i).GetComponent <SongItemView>(); if (v != null) { v.OnSongSelected += OnSongItemClicked; v.OnTryToBuySong += OnTryToBuySong; currentItemList.Add(v.gameObject, v); listSongItemViews.Add(v); } } isInitialized = true; } }
private void RefreshScoreRecord(SongItemView songItem) { int crown = 0, star = 0; //set highscore star = HighScoreManager.Instance.GetHighScore(songItem.Model.storeID, ScoreType.Star); crown = HighScoreManager.Instance.GetHighScore(songItem.Model.storeID, ScoreType.Crown); //print("Item: " + songItem.Model.storeID + " crown: " + crown + " star: " + star); if (crown > 0) { songItem.SetNumCrowns(crown); } else { songItem.SetNumStars(star); } }
private void OnTryToBuySong(SongItemView song) { if (ProfileHelper.Instance.CurrentDiamond >= song.Model.pricePrimary) { ProfileHelper.Instance.ListBoughtSongs.Add(song.Model.storeID); ProfileHelper.Instance.CurrentDiamond -= song.Model.pricePrimary; AnalyticsHelper.Instance.LogBuyInGameItem("Song" + song.Model.storeID, 1, song.Model.pricePrimary); AchievementHelper.Instance.LogAchievement("numSongPlayed"); if (song.Model.starsToUnlock == 0) { AnalyticsHelper.Instance.LogBuyPremiumSong(song.Model.name); } song.RefreshView(); } else { SceneManager.Instance.OpenPopup(ProjectConstants.Scenes.IAP); } }
private void SpawnSongsItem() { var listHotSongs = GameManager.Instance.StoreData.listHotSongs; var listNewSongs = GameManager.Instance.StoreData.listNewSongs; if (songItems == null) { songItems = new List <SongItemView>(); } for (int i = 0; i < listHotSongs.Count; i++) { SongItemView item = Instantiate(prefabSongItem); listHotSongItems.Add(item); item.Index = i + 1; item.Model = listHotSongs[i]; item.OnSongSelected += OnSongItemClicked; item.OnTryToBuySong += OnTryToBuySong; item.transform.SetParent(songContainer, false); item.transform.localScale = Vector3.one; songItems.Add(item); } for (int j = 0; j < listNewSongs.Count; j++) { SongItemView item = Instantiate(prefabSongItem); listNewSongItems.Add(item); item.Index = listHotSongs.Count + j + 1; item.Model = listNewSongs[j]; item.OnSongSelected += OnSongItemClicked; item.OnTryToBuySong += OnTryToBuySong; item.transform.SetParent(songContainer, false); item.transform.localScale = Vector3.one; //print(string.Format("Created new song item, status = {0}", item.Model.type)); songItems.Add(item); } Transform emptyTf = Instantiate(prefabEmpty).transform; emptyTf.transform.SetParent(songContainer, false); emptyTf.transform.localScale = Vector3.one; }