示例#1
0
    public void LoadScene(string sceneName, LoadCallBackHandler CallBack)
    {
        string       _scenePath = string.Format("{0}{1}", AssetPath, sceneName);
        HandlerParam HP         = new HandlerParam();

        HP.assetName = sceneName;
        HP.paramObj  = null;

        if (Application.isEditor && !isDebug)
        {
            if (CallBack != null)
            {
                CallBack(HP);
            }

            SceneManager.LoadScene(HP.assetName);
            return;
        }

        string url = ResourcePathManager.Instance.GetLoadPath(_scenePath);

        url = Path.ChangeExtension(url, ResourcePathManager.abExtension);
        string         _assetBundleName = Path.ChangeExtension(_scenePath, ResourcePathManager.abExtension).ToLower();
        LoadABCallBack loadABCallBack   = delegate(AssetBundleData assetBundleData)
        {
            HP.m_assetBundleData = assetBundleData;
            if (CallBack != null)
            {
                CallBack(HP);
            }
            SceneManager.LoadScene(HP.assetName);
        };

        LoadAssetBundle.Instance.LoadScene(url, sceneName, _assetBundleName, loadABCallBack);
    }
示例#2
0
    private void LoadAsset <T>(string _assetPath, LoadCallBackHandler loadCallBack, HandlerParam HP) where T : UnityEngine.Object
    {
#if UNITY_EDITOR
        T t = AssetDatabase.LoadAssetAtPath <T>(_assetPath);
        HP.assetObj = t;
        loadCallBack(HP);
#endif
    }
示例#3
0
    //异步加载资源,首先加载依赖项
    public void LoadAssetAsyncBundle(string bundleName, LoadCallBackHandler loadCallBack, HandlerParam HP, bool loadAssets = true, bool isScene = false)
    {
        if (mAssetBundleManifest == null)
        {
            HP.isSucess = false;
            if (loadCallBack != null)
            {
                loadCallBack(HP);
            }
            return;
        }
        bundleName = HP.fullAssetName;
        if (Path.GetExtension(HP.fullAssetName) != ".data")
        {
            bundleName = HP.fullAssetName + ".data";
        }
        bundleName = bundleName.ToLower();

        LoadAssetBundleDependenciesAsync(bundleName);

        BundleLoaderSharedObject blso;
        bool isHave = mBundleLoaderSharedObjectDict.TryGetValue(bundleName, out blso);

        if (!isHave)
        {
            blso = new BundleLoaderSharedObject();
            mBundleLoaderSharedObjectDict.Add(bundleName, blso);
            ResourceCallBackHander resCallBack = ResourceLoadCall;
            if (string.IsNullOrEmpty(bundleName))
            {
                int nn = 0;
            }
            BundleManager.Instance.StartCoroutine(blso.LoadAsync(this, blso, bundleName, loadCallBack, resCallBack, HP, loadAssets));


            return;
        }

        if (blso != null)
        {
            if (blso.mAssetBundle == null)
            {
                return;
            }
            HP.isSucess = true;
            if (isScene == false)
            {
                HP.assetObj = blso.AssetObject(true);
            }
            if (loadCallBack != null)
            {
                loadCallBack(HP);
            }
            return;
        }
    }
示例#4
0
 // 从 Resrouce 文件夹下加载资源
 private void LoadAsset(string _assetPath, LoadCallBackHandler loadCallBack, HandlerParam HP, string spawnName, bool loadAssets)
 {
     UnityEngine.Object obj = LoadObject(_assetPath, loadAssets);
     if (obj == null)
     {
         string fileName = Path.GetFileNameWithoutExtension(_assetPath);
         _assetPath = _assetPath.Replace(fileName, spawnName + "_Default");
         obj        = BundleManager.Instance.LoadObject(_assetPath, true);
     }
     HP.assetObj = obj;
     loadCallBack(HP);
 }
示例#5
0
 // 从 Resrouce 文件夹下加载资源
 private void LoadAsset <T>(string _assetPath, LoadCallBackHandler loadCallBack, HandlerParam HP, bool loadAssets) where T : UnityEngine.Object
 {
     writeDownloadedFileList(_assetPath);
     HP.fullAssetName = _assetPath;
     UnityEngine.Object obj = BundleManager.Instance.LoadObject(_assetPath, loadAssets);
     if (obj == null)
     {
         string fileName = Path.GetFileNameWithoutExtension(_assetPath);
         _assetPath = _assetPath.Replace(fileName, spawnName + "_Default");
         obj        = BundleManager.Instance.LoadObject(_assetPath, true);
     }
     HP.assetObj = obj;
     loadCallBack(HP);
     //AssetBundleManager.Instance.SyncLoadBundleCall(_assetPath, loadCallBack, HP, spawnName, loadAssets);
 }
示例#6
0
    public void LoadAssetAsync <T>(string assetName, LoadCallBackHandler CallBack, System.Object paramsArr, bool useType = false, bool loadAssets = true) where T : UnityEngine.Object
    {
        if (string.IsNullOrEmpty(assetName))
        {
            return;
        }
        string _assetPath = string.Format("{0}{1}{2}", AssetPath, assetName, assetExtension);

        HandlerParam HP = new HandlerParam();

        HP.assetName = assetName;
        HP.paramObj  = paramsArr;

        LoadAsyncAsset <T>(_assetPath, CallBack, HP, loadAssets);
    }
示例#7
0
        private void LoadUI(string _name, Action <GameObject> CallBack)
        {
            // 加载UI
            LoadCallBackHandler LoadCallBack = delegate(HandlerParam p_handleParam)
            {
                if (p_handleParam.assetObj == null)
                {
                    return;
                }
                GameObject go = GameObject.Instantiate(p_handleParam.assetObj) as GameObject;
                if (CallBack != null)
                {
                    CallBack(go);
                }
            };

            AssetPool.Instance.UI.LoadAsset <GameObject>(_name, LoadCallBack, null);
        }
示例#8
0
    /// <summary>
    /// 加载资源
    /// </summary>
    /// <typeparam name="T">加载资源类型</typeparam>
    /// <param name="assetName">资源名</param>
    /// <param name="CallBack">加载回调</param>
    /// <param name="paramsArr">加载传递参数</param>
    /// <param name="useType">加载解包时,是否使用类型 T</param>
    public void LoadAsset <T>(string assetName, LoadCallBackHandler CallBack, System.Object paramsArr, bool useType = true, bool isAsync = true) where T : UnityEngine.Object
    {
        if (string.IsNullOrEmpty(assetName))
        {
            Debug.LogWarning("Load AssetName is null " + assetName);
            return;
        }

        string _assetPath = string.Format("{0}{1}{2}", AssetPath, assetName, Extension);

        HandlerParam HP = new HandlerParam();

        HP.assetName = Path.GetFileNameWithoutExtension(assetName);
        HP.paramObj  = paramsArr;

        if (Application.isEditor && !isDebug)
        {
            _assetPath = string.Format("{0}{1}", "Assets/", _assetPath);
            LoadAsset <T>(_assetPath, CallBack, HP);
            return;
        }

        _assetPath = Path.ChangeExtension(_assetPath, ResourcePathManager.abExtension);
        string url = ResourcePathManager.Instance.GetLoadPath(_assetPath);

        url = url.ToLower();
        string _assetBundleName = Path.ChangeExtension(_assetPath, ResourcePathManager.abExtension).ToLower();
        // allassets/prefab/building/dige_ziyuan.unity3d
        // 加载资源回调
        LoadABCallBack loadABCallBack = delegate(AssetBundleData assetBundleData)
        {
            HP.m_assetBundleData = assetBundleData;
            // 异步加载同时调用两次会卡死主线程
            //.m_AssetBundle.LoadAssetAsync<T>(p_handleParam.assetName);
            HP.assetObj = assetBundleData.m_AssetBundle.LoadAsset <T>(HP.assetName);

            if (CallBack != null)
            {
                CallBack(HP);
            }
        };

        Game.Instance.StartCoroutine(LoadAssetBundle.Instance.LoadAsset(url, loadABCallBack, _assetBundleName));
    }
示例#9
0
    /// <summary>
    /// 加载场景资源
    /// </summary>
    /// <typeparam name="T">加载资源类型</typeparam>
    /// <param name="assetName">资源名</param>
    /// <param name="CallBack">加载回调</param>
    /// <param name="paramsArr">加载传递参数</param>
    /// <param name="useType">加载解包时,是否使用类型 T</param>
    public void LoadScene <T>(string assetName, LoadCallBackHandler CallBack, System.Object paramsArr, bool useType = false, bool isAsync = true, bool loadAssets = true) where T : UnityEngine.Object
    {
        string _assetPath = string.Format("{0}{1}{2}", AssetPath, assetName, assetExtension);

        HandlerParam HP = new HandlerParam();

        HP.assetName = assetName;
        HP.paramObj  = paramsArr;

        HP.fullAssetName = _assetPath;

        if (string.IsNullOrEmpty(assetName))
        {
            if (CallBack != null)
            {
                CallBack(HP);
            }
            return;
        }


        BundleManager.Instance.LoadObjectAsync(_assetPath, CallBack, HP, loadAssets, true);
    }
示例#10
0
    public void LoadObjectAsync(string bundleName, LoadCallBackHandler loadCallBack, HandlerParam HP, bool loadAssets, bool isScene = false)
    {
#if UNITY_EDITOR
        if (LoadBundle)
        {
            mAssetLoader.LoadAssetAsyncBundle(bundleName, loadCallBack, HP, loadAssets, isScene);
            return;
        }

        UnityEngine.Object obj = null;

        obj = UnityEditor.AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(string.Format("Assets/Arts/{1}", bundleName));
        if (obj != null)
        {
            HP.assetObj = obj;
            loadCallBack(HP);
            return;
        }

        loadCallBack(HP);
#else
        mAssetLoader.LoadAssetAsyncBundle(bundleName, loadCallBack, HP, loadAssets, isScene);
#endif
    }
示例#11
0
    // 加载所有数据表
    public void LoadAllTable()
    {
        List <string> tableNameList = new List <string>();

        string[] tableFiles = new string[] { };

        for (int i = 0; i < (int)TableType.None; ++i)
        {
            string tableName = TableDefine.GetTableName((TableType)i);
            tableNameList.Add(tableName);
        }

        LoadCallBackHandler LoadTableCallBack = (handlerParam) =>
        {
            TextAsset textAsset = (TextAsset)handlerParam.assetObj;
            GetTableData(handlerParam.assetName, textAsset);
        };

        for (int i = 0; i < tableNameList.Count; ++i)
        {
            // 读取数据表
            AssetPool.Instance.TableData.LoadAsset <TextAsset>(tableNameList[i], LoadTableCallBack, new System.Object[] { tableNameList[i] });
        }
    }
    public IEnumerator LoadAsync(BundleLoader bundleloader, BundleLoaderSharedObject blso, string bundleResName, LoadCallBackHandler loadCallBack, ResourceCallBackHander resCallBack, HandlerParam HP, bool loadAssets)
    {
        mBundleName = bundleResName;
        AssetBundleCreateRequest bundleRequest;
        string path = BundleLoader.LoadBundleAsyncFromSDCard(mBundleName);

        if (File.Exists(path))
        {
            bundleRequest = AssetBundle.LoadFromFileAsync(path);
            yield return(bundleRequest);

            mAssetBundle = bundleRequest.assetBundle;
        }

        if (mAssetBundle == null)
        {
                        #if UNITY_ANDROID && !_TEST
            if (BundleLoader.mStreamBundleList.Contains(mBundleName))
                        #endif
            {
                bundleRequest = BundleLoader.LoadBundleAsyncFromStreamingAssets(mBundleName);
                yield return(bundleRequest);

                mAssetBundle = bundleRequest.assetBundle;
            }

#if UNITY_ANDROID
            if (mAssetBundle == null)
            {
                bundleRequest = BundleLoader.LoadBundleAsyncFromApkStreamingAssets(mBundleName);
                yield return(bundleRequest);

                mAssetBundle = bundleRequest.assetBundle;
            }
#endif

            if (mAssetBundle == null)
            {
                // DebugConsole.sendmsgServer(mBundleName + "not loaded!");
                bundleloader.RemoveAssetBundle(mBundleName);
                BundleManager.Instance.StartCoroutine(BundleLoader.LoadBundleFromWWW(bundleResName));
            }
        }

        int startIdx = mBundleName.LastIndexOf("/");
        int endIdx   = mBundleName.LastIndexOf(".");
        try
        {
            assName = mBundleName.Substring(startIdx + 1, endIdx - startIdx - 1);
        }
        catch (System.Exception e)
        {
        }

        if (loadAssets && loadCallBack != null)
        {
            mMainObject = mAssetBundle.LoadAsset(assName);
        }

        if (resCallBack != null)
        {
            resCallBack(blso, bundleResName, mAssetBundle, loadCallBack, HP, loadAssets);
        }
    }
示例#13
0
 //资源异步加载回调
 private void ResourceLoadCall(object blso, string bundleResName, UnityEngine.Object obj, LoadCallBackHandler loadCallBack, HandlerParam HP, bool loadAssets)
 {
     if (obj != null)
     {
         HP.isSucess = true;
         HP.assetObj = ((BundleLoaderSharedObject)blso).AssetObject(loadAssets);
         if (loadCallBack != null)
         {
             loadCallBack(HP);
         }
     }
     else
     {
         HP.isSucess = false;
         if (loadCallBack != null)
         {
             loadCallBack(HP);
         }
     }
 }
示例#14
0
 private void LoadAsyncAsset(string _assetPath, LoadCallBackHandler loadCallBack, HandlerParam HP, string pp, bool loadAssets)
 {
     LoadObjectAsync(_assetPath, loadCallBack, HP, loadAssets);
 }