private void OnCollisionEnter2D(Collision2D coll) { switch (coll.gameObject.name) { case "chara(Clone)": { var rigid2D = GetComponent <Rigidbody2D>(); rigid2D.AddForce(Vector2.up * 200); var collider = GetComponent <Collider2D>(); Destroy(collider); var spriteRenderer = GetComponent <SpriteRenderer>(); spriteRenderer.sortingOrder = 1; var resourceName = "Assets/BundledResources/Resources/PreloadOnShop/"; var itemKind = Random.Range(0, 4); switch (itemKind) { case 0: { resourceName = resourceName + "maguro.png"; break; } case 1: { resourceName = resourceName + "tamago.png"; break; } case 2: { resourceName = resourceName + "salmon.png"; break; } case 3: { resourceName = resourceName + "ebi.png"; break; } } // get resource contained bundle name from shared onMemoryAsstList. var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (Sprite t) => { spriteRenderer.sprite = t; spriteRenderer.transform.localScale = new Vector2(0.4f, 0.4f); } )); break; } } }
public void GetEbi() { var buttonImage = GameObject.Find("DetailButton").GetComponent <Image>(); buttonImage.color = Color.gray; detailButton.transform.SetParent(canvas.transform, true); var resourceName = "Assets/BundledResources/Resources/OnDemandOnShop/ebi.png"; var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (Sprite s) => { buttonImage.color = Color.white; buttonImage.sprite = s; } )); }
private IEnumerator GetScenePreloadList() { // 1. load " Title" scene preloadList from web. var www2 = new WWW(Settings.RESOURCE_URLBASE + "preload_title.json"); yield return(www2); // got preload list for "Title" scene. let's preload it. var preloadListForTitle = JsonUtility.FromJson <PreloadList>(www2.text); preloadList = new List <string>(preloadListForTitle.preloadBundleNames); // 2.start preload. foreach (var bundleName in preloadListForTitle.preloadBundleNames) { // get target bundle's crc from shared onMemoryBundleList. var crc = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.bundleName == bundleName) .FirstOrDefault().crc; /* * start preload. * set preloadIsDone -> true when all preloads are over. */ StartCoroutine(AssetBundleLoader.PreloadBundle( bundleName, crc, (string preloadedBundleName) => { preloadList.Remove(preloadedBundleName); if (!preloadList.Any()) { /* * all preloaded assets are cached. */ preloadIsDone = true; var resourceName = "Assets/BundledResources/Resources/PreloadOnTitle/Image.prefab"; var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); // use cached asset for title. StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (GameObject titleImagePrefab) => { var prefabImageObj = Instantiate(titleImagePrefab); var canvas = GameObject.Find("Canvas"); // set canvas lighter. var canvasPanel = canvas.transform.FindChild("Panel"); canvasPanel.GetComponent <Image>().color = Color.white; // add buttons. { var goToGameButton = Instantiate(Resources.Load <GameObject>("goToGame")); goToGameButton.transform.SetParent(canvas.transform, false); goToGameButton.GetComponent <Button>().onClick.AddListener( delegate { GoToGame(); } ); var goToShopButton = Instantiate(Resources.Load <GameObject>("goToShop")); goToShopButton.transform.SetParent(canvas.transform, false); goToShopButton.GetComponent <Button>().onClick.AddListener( delegate { GoToShop(); } ); } prefabImageObj.transform.SetParent(canvas.transform, false); } )); } } )); } }
private IEnumerator GetScenePreloadList() { var www2 = new WWW(Settings.RESOURCE_URLBASE + "preload_game.json"); yield return(www2); var preloadListForGame = JsonUtility.FromJson <PreloadList>(www2.text); preloadList = new List <string>(preloadListForGame.preloadBundleNames); var preloadedCount = 0; foreach (var bundleName in preloadListForGame.preloadBundleNames) { var crc = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.bundleName == bundleName) .FirstOrDefault().crc; /* * start preload. * set preloadIsDone -> true when all preloads are over. */ StartCoroutine(AssetBundleLoader.PreloadBundle( bundleName, crc, (string preloadedBundleName) => { preloadList.Remove(preloadedBundleName); if (!preloadList.Any()) { // create character. var resourceName0 = "Assets/BundledResources/Resources/PreloadOnGame/chara.prefab"; var containedBundleData0 = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName0)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName0, containedBundleData0, (GameObject p) => { hero = Instantiate(p) as GameObject; hero.AddComponent <MyCharaController>(); preloadedCount++; if (preloadedCount == 3) { preloadIsDone = true; } } )); // set stage images. var resourceName1 = "Assets/BundledResources/Resources/PreloadOnGame/block.png"; var containedBundleData1 = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName1)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName1, containedBundleData1, (Sprite t) => { var stage = GameObject.Find("stage"); stage.GetComponent <SpriteRenderer>().sprite = t; var stage1 = GameObject.Find("stage (1)"); stage1.GetComponent <SpriteRenderer>().sprite = t; var stage2 = GameObject.Find("stage (2)"); stage2.GetComponent <SpriteRenderer>().sprite = t; preloadedCount++; if (preloadedCount == 3) { preloadIsDone = true; } } )); // get sushibox gameobject. var resourceName2 = "Assets/BundledResources/Resources/PreloadOnGame/box.prefab"; var containedBundleData2 = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName2)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName2, containedBundleData2, (GameObject b) => { sushiBox = b; preloadedCount++; if (preloadedCount == 3) { preloadIsDone = true; } } )); } } )); } }
private IEnumerator GetScenePreloadList() { var www2 = new WWW(Settings.RESOURCE_URLBASE + "preload_shop.json"); yield return(www2); var preloadListForShop = JsonUtility.FromJson <PreloadList>(www2.text); preloadList = new List <string>(preloadListForShop.preloadBundleNames); foreach (var bundleName in preloadListForShop.preloadBundleNames) { var crc = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.bundleName == bundleName) .FirstOrDefault().crc; /* * start preload. */ StartCoroutine(AssetBundleLoader.PreloadBundle( bundleName, crc, (string preloadedBundleName) => { preloadList.Remove(preloadedBundleName); if (!preloadList.Any()) { /* * all preloaded assets are cached. */ // MenuChara { var resourceName = "Assets/BundledResources/Resources/PreloadOnShop/menu.png"; var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (Sprite s) => { var menuBgImage = GameObject.Find("MenuChara").GetComponent <Image>(); menuBgImage.color = Color.white; menuBgImage.sprite = s; } )); } // buttons images. { var resourceName = "Assets/BundledResources/Resources/PreloadOnShop/maguro.png"; var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (Sprite s) => { var buttonImage = GameObject.Find("Button0").GetComponent <Image>(); buttonImage.color = Color.white; buttonImage.sprite = s; } )); } { var resourceName = "Assets/BundledResources/Resources/PreloadOnShop/tamago.png"; var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (Sprite s) => { var buttonImage = GameObject.Find("Button1").GetComponent <Image>(); buttonImage.color = Color.white; buttonImage.sprite = s; } )); } { var resourceName = "Assets/BundledResources/Resources/PreloadOnShop/salmon.png"; var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (Sprite s) => { var buttonImage = GameObject.Find("Button2").GetComponent <Image>(); buttonImage.color = Color.white; buttonImage.sprite = s; } )); } { var resourceName = "Assets/BundledResources/Resources/PreloadOnShop/ebi.png"; var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (Sprite s) => { var buttonImage = GameObject.Find("Button3").GetComponent <Image>(); buttonImage.color = Color.white; buttonImage.sprite = s; } )); } } } )); } }
public IEnumerator GetAllAssetListAndPreloadList() { while (!Caching.ready) { yield return(null); } // delete all cache before running. Caching.CleanCache(); // 1. load whole bundle list from web. var www1 = new WWW(Settings.RESOURCE_URLBASE + "bundle_list.json"); yield return(www1); // deserialize & allocate on memory(should save into local in actual use.) JsonUtility.FromJsonOverwrite(www1.text, AssetBundleLoader.onMemoryBundleList); // 2. load "Boot" scene PreloadList from web. var www2 = new WWW(Settings.RESOURCE_URLBASE + "preload_" + "boot" + ".json"); yield return(www2); // got preload list for "Boot" scene. let's preload it. var preloadListForLoad = JsonUtility.FromJson <PreloadList>(www2.text); preloadList = new List <string>(preloadListForLoad.preloadBundleNames); // 3. start preload bundles. foreach (var bundleName in preloadListForLoad.preloadBundleNames) { // get target bundle's crc from shared onMemoryBundleList. var crc = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.bundleName == bundleName) .FirstOrDefault().crc; /* * start preload. * set preloadIsDone -> true when all preloads are over. */ StartCoroutine(AssetBundleLoader.PreloadBundle( bundleName, crc, (string preloadedBundleName) => { preloadList.Remove(preloadedBundleName); if (!preloadList.Any()) { /* * all preloaded assets are cached. */ preloadIsDone = true; /* * ready loading bar. * instantiate prefab which is already downloaded. */ var resourceName = "Assets/BundledResources/Resources/PreloadOnBoot/ProgressBar.prefab"; var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (GameObject loadingBarPrefab) => { var loadingBarObj = Instantiate(loadingBarPrefab); // add loadingBar object to canvas. var canvas = GameObject.Find("Canvas"); loadingBarObj.transform.SetParent(canvas.transform, false); // hold progress image. loadingBarProgressImage = loadingBarObj.transform.Find("ProgressBar").GetComponent <Image>() as Image; } )); /* * start on-demand loading. * hand model & button texture. * * model & texture will appear after downloading some AssetBundle. */ StartOndemandLoading(); } } )); } }
private void StartOndemandLoading() { // use this resource name for this button's texture. var canvas = GameObject.Find("Canvas"); // add button to GUI. { var buttonObj = new GameObject("DoneButton", typeof(RectTransform)); buttonObj.transform.SetParent(canvas.transform, false); buttonObj.AddComponent <CanvasRenderer>(); var buttonImage = buttonObj.AddComponent <Image>(); buttonImage.rectTransform.anchoredPosition = new Vector2(124, -250); buttonImage.rectTransform.sizeDelta = new Vector2(420, 116); var buttonTextObj = new GameObject("DoneButtonText", typeof(RectTransform)); buttonTextObj.transform.SetParent(buttonObj.transform, false); buttonTextObj.AddComponent <CanvasRenderer>(); var buttonText = buttonTextObj.AddComponent <Text>(); buttonText.font = Resources.GetBuiltinResource <Font>("Arial.ttf"); buttonText.rectTransform.sizeDelta = new Vector2(420, 60); buttonText.text = "loading button texture..."; buttonText.fontSize = 38; buttonText.alignment = TextAnchor.MiddleCenter; buttonText.color = Color.black; var button = buttonObj.AddComponent <Button>(); button.onClick.AddListener( delegate { Debug.LogError("now loading on demand..."); } ); var resourceName = "Assets/BundledResources/Resources/OnDemandOnBoot/GoToNextButton/sushi.jpg"; // get resource contained bundle name from shared onMemoryAsstList. var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); var bundleName = containedBundleData.bundleName; onDemandLoadingBundleNames.Add(bundleName); // load button image. StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (Sprite t) => { buttonText.text = string.Empty; buttonImage.sprite = t; button.onClick.RemoveAllListeners(); button.onClick.AddListener( delegate { Application.LoadLevelAsync("Title"); } ); onDemandLoadingBundleNames.Remove(bundleName); } )); } // load hand model { var resourceName = "Assets/BundledResources/Resources/OnDemandOnBoot/Hand/hand.prefab"; var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); var bundleName = containedBundleData.bundleName; onDemandLoadingBundleNames.Add(bundleName); onDemandLoadingMax = onDemandLoadingBundleNames.Count; // load hand prefab then StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (GameObject hand) => { var handObj = Instantiate(hand); handObj.transform.SetParent(canvas.transform, false); handObj.AddComponent <HandRotation>(); onDemandLoadingBundleNames.Remove(bundleName); } )); } // load title image { var resourceName = "Assets/BundledResources/Resources/PreloadOnTitle/Image.prefab"; var containedBundleData = AssetBundleLoader.onMemoryBundleList.bundles .Where(bundle => bundle.resources.Contains(resourceName)) .FirstOrDefault(); var bundleName = containedBundleData.bundleName; onDemandLoadingBundleNames.Add(bundleName); onDemandLoadingMax = onDemandLoadingBundleNames.Count; // load title image prefab then StartCoroutine(AssetBundleLoader.DownloadBundleThenLoadAsset( resourceName, containedBundleData, (GameObject titlePrefab) => { onDemandLoadingBundleNames.Remove(bundleName); } )); } }