예제 #1
0
    private IEnumerator PreLoad(eAssetType type, System.Action <GameObject> callback)
    {
        GameObject go = null;

        if (_loadType == eLoadType.Resources)
        {
            go = Resources.Load <GameObject>(string.Format("Prefab/{0}", type.ToString()));
        }
        else if (_loadType == eLoadType.PackageAssetBundle)
        {
            var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, type.ToString().ToLower()));
            if (myLoadedAssetBundle == null)
            {
                Debug.LogError("asset bundle load failed!");
                yield break;
            }
            go = myLoadedAssetBundle.LoadAsset <GameObject>(type.ToString());
        }
        else if (_loadType == eLoadType.AmazonS3)
        {
            string uri = string.Format("{0}/{1}", amazon_s3_url, type.ToString().ToLower());

            UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(uri, 0);
            yield return(request.SendWebRequest());

            AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);
            go = bundle.LoadAsset <GameObject>(type.ToString());
        }

        if (go == null)
        {
            Debug.LogError("resource is null!");
        }

        callback?.Invoke(go);
        yield break;
    }
예제 #2
0
    public IEnumerator InstantiateGameObjectAsync(eAssetType _assetType, string assetName, System.Action <GameObject> callback)
    {
        // This is simply to get the elapsed time for this phase of AssetLoading. // 어셋 로드 시작 시각을 세팅
        float startTime = Time.realtimeSinceStartup;

        Object prefab;

        if (ResourceLoadType == eResourceLoadType.UnityEditor)
        {
            #region 리소스 폴더 로드 방식
            prefab = Get(_assetType, assetName);
            #endregion
        }
        else
        {
            #region 어셋번들 로드 방식
            string assetBundleName = _assetType.ToString().ToLower();
            // Load asset from assetBundle. //어셋을 비동기로 로드함
            AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject));
            if (request == null)
            {
                yield break;
            }
            yield return(StartCoroutine(request));

            // Get the asset. //비동기 로드가 끝난후 어셋을 게임오브젝트 타입으로 로드함
            prefab = request.GetAsset <GameObject>();
            #endregion
        }

        GameObject go;
        if (prefab != null)
        {
            go = (GameObject)Instantiate(prefab); //생성
            callback(go);
        }

        // Calculate and display the elapsed time.
        float elapsedTime = Time.realtimeSinceStartup - startTime;
        Debug.Log(assetName + (prefab == null ? " was not" : " was") + " loaded successfully in " + elapsedTime + " seconds");
    }