public void LoadItem(ScriptableStoreItem item) { AssetBundleAssetLoader itemBundleLoader = new AssetBundleAssetLoader(item.bundle); itemBundleLoader.behaviorToRunCoroutines = this; itemBundleLoader.hasShippedVersion = false; itemBundleLoader.autoDownloadNewVersion = true; Hash128 hash = manifest.GetAssetBundleHash(item.bundle.assetBundleName); itemBundleLoader.hardcodedServerBundleHash = hash; itemBundleLoader.useHardcodedHash = true; itemBundleLoader.onAssetLoaded.AddListener((Object asset) => { Debug.Log("Item ready: " + item.descriptiveName + ", asset: " + asset.name); itemsAsset[item.GetThisPlatformId()] = asset; itemsDownloaded[item.GetThisPlatformId()] = true; // Mark it as downloaded right now for consistency onStoreItemReady.Invoke(item, asset); if (state.CurrentState == State.LOADING_DOWNLOADED_ITEMS) { itemsToLoad--; // CHECKING all items downloaded if (itemsToLoad == 0) { SetStoreReady(); } } }); itemBundleLoader.LoadBundleAndAsset(); // can load from cache if available, or download it }
StoreItemUI GetItemUI(ScriptableStoreItem item) { foreach (StoreItemUI itemUI in uiItems) { if (itemUI.item == item) { return(itemUI); } } return(null); }
void OnStoreItemReady(ScriptableStoreItem item, Object asset) { // event is called at startup for downloaded items, then when bought&downloaded if (store.state.CurrentState == TreeviewStore.State.LOADING_DOWNLOADED_ITEMS) { //add asset items to Library } else { // hide item buy loading StoreItemUI itemUI = GetItemUI(item); itemUI.RefreshState(); //add asset items to Library } }
void OnStoreItemReady(ScriptableStoreItem item, Object asset) { // event is called at startup for downloaded items, then when bought&downloaded //add asset items to Library ScriptableLibrary lib = asset as ScriptableLibrary; // item asset is a library itself, and can contain several objects foreach (ScriptableLibraryObject scriptLibObj in lib.libObjects) { Debug.Log("STORE scriptableLibraryObject: " + scriptLibObj.displayName); LibraryObject libObj = new LibraryObject(); libObj.prefab = scriptLibObj.prefab; libObj.displayName = scriptLibObj.displayName; libObj.thumbnail = scriptLibObj.thumbnail; storeObjects.Add(libObj); // each item is appended - } ResetLibraryObjects(); }
//// Update is called once per frame //void Update () { //} public void Populate(StorePanel store, ScriptableStoreItem item) { this.store = store; this.item = item; nameLabel.text = item.descriptiveName; if (item.thumbnail != null) { image.sprite = item.thumbnail; } buyBt.onClick.AddListener(() => { store.store.BuyItem(item); }); downloadBt.onClick.AddListener(() => { store.store.LoadItem(item); }); RefreshState(); }
public void BuyItem(ScriptableStoreItem item) { //TODO:: use IAP }