コード例 #1
0
 private void Awake()
 {
     _instance = this;
     //localAssetLoader = new AssetBundleLoader();
     localAssetLoader = new ResourceLoader();
     netAssetLoader   = new AssetLoader();
 }
コード例 #2
0
    private IEnumerator LoadAsync <T>(string path, Action <T> callback) where T : Object
    {
        isLoading = true;
        CacheObject co;

        if (callback != null && dicCacheObject.TryGetValue(path, out co) && co != null)
        {
            callback(co.obj as T);
            co.time   = Time.time;
            isLoading = false;
            yield break;
        }
        if (path.IndexOf("http://") >= 0 || path.IndexOf(Application.streamingAssetsPath) >= 0)
        {
            loader = netAssetLoader;
        }
        else
        {
            loader = localAssetLoader;
        }
        yield return(loader.LoadAssetAsync <T>(path, (res) => {
            AddCache(path, res);
            callback(res);
            Debug.Log("加载数据:" + path);
        }));

        isLoading = false;
    }
コード例 #3
0
    // 根据资源选择加载器
    private IAssetsLoader AdapterLoader(string strResName)
    {
        IAssetsLoader loader = null;

        // todo 根据资源打包的配置确定资源被打包的方式,选择不同的加载器
        loader = LoaderEditorLoad.Instance;
        return(loader);
    }
コード例 #4
0
    /// <summary>
    /// 获取GameObject资源实体
    /// </summary>
    /// <param name="strName"></param>
    /// <param name="handleOnComplete"></param>
    /// <param name="handleOnProgress"></param>
    /// <returns></returns>
    public bool GetInstance(string strName, Action <string, Object> handleOnComplete, Action <float> handleOnProgress)
    {
        if (string.IsNullOrEmpty(strName) == true)
        {
            return(false);
        }
        // 适配加载器
        m_AssetsLoader = AdapterLoader(strName);
        if (m_AssetsLoader == null)
        {
            return(false);
        }
        // 加载
        m_AssetsLoader.LoadAsset(strName, (objectGo) =>
        {
            if (objectGo == null && handleOnComplete != null)
            {
                handleOnComplete(strName, null);
                return;
            }

            GameObject go = GameObject.Instantiate(objectGo) as GameObject;
            Int32 guid    = -1;
            if (go != null)
            {
                guid = go.GetInstanceID();
            }
            m_InstanceMap.Add(guid, strName);
            if (handleOnComplete != null)
            {
                handleOnComplete(strName, go);
            }
        }, handleOnProgress);

        return(true);
    }