コード例 #1
0
    /*
     * @brief 加载资源
     * @param path 资源路径
     * @param callback 回调函数
     */
    public static byte[] LoadLuaAsset(string path)
    {
        // Windows 平台分隔符为 '/', OS 平台 路径分隔符为 '\', 此处是一个大坑
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            path = path.Replace('\\', '/');
        }

#if UNITY_EDITOR
        Object obj = null;
        //lua ab包地址
        path = PathManager.LuaPath + "/" + path;
        //编辑器模式下 资源获取
        obj = UnityEditor.AssetDatabase.LoadMainAssetAtPath(path);
        TextAsset text = (TextAsset)obj;
        if (null != text)
        {
            return(text.bytes);
        }
        return(null);
#else
        string filename = DownLoadCommon.GetLuaHotFullName(path);
        if (File.Exists(filename))
        {
            try
            {
                string res = File.ReadAllText(filename);
                return(System.Text.Encoding.UTF8.GetBytes(res));
            }catch (System.Exception e)
            {
                Debug.Log("LoadLuaAsset=====3>>" + e.ToString());
            }
        }

        Object        obj2       = null;
        string        fileNameEx = System.IO.Path.GetFileNameWithoutExtension(path);
        ZTAssetBundle bundle     = ZTAssetBundleManager.GetInstance().LoadAssetBundleAndDependencies("luascript");
        //加载assetBundleManifest文件
        if (null != bundle)
        {
            obj2 = bundle.GetAsset(fileNameEx);
        }
        TextAsset text2 = (TextAsset)obj2;
        if (null != text2)
        {
            return(text2.bytes);
        }

        return(null);
#endif
    }
コード例 #2
0
    /// <summary>
    /// 异步加载资源
    /// </summary>
    public void LoadAssetInBundleSync(string assetbundlename, string assetname, System.Action <Object> callback, System.Type type = null)
    {
        if (assetbundlename == null)
        {
            callback(null);
        }
        if (MainManifest == null)
        {
            callback(null);
        }
        ZTAssetBundle ab = LoadAssetBundleAndDependencies(assetbundlename);

        StartCoroutine(ab.GetAssetSync(assetname, callback, type));
    }
コード例 #3
0
    /// <summary>
    /// 获取 缓存中的 ab包
    /// </summary>
    ZTAssetBundle LoadInCahce(string assetbundlename)
    {
        ZTAssetBundle ab = null;

        if (this._assetbundlePermanent.ContainsKey(assetbundlename))
        {
            ab = this._assetbundlePermanent[assetbundlename];
        }
        else if (this._assetbundleTemporary.ContainsKey(assetbundlename))
        {
            ab = this._assetbundleTemporary[assetbundlename];
        }
        return(ab);
    }
コード例 #4
0
    /// <summary>
    ///   释放指定的AssetBundle
    /// </summary>
    public void UnloadAssetBundle(string assetbundlename)
    {
        ZTAssetBundle ab = null;

        if (this._assetbundlePermanent.TryGetValue(assetbundlename, out ab))
        {
            this._assetbundlePermanent.Remove(assetbundlename);
        }
        else if (this._assetbundleTemporary.TryGetValue(assetbundlename, out ab))
        {
            this._assetbundleTemporary.Remove(assetbundlename);
        }
        ab.Destroy();
    }
コード例 #5
0
    /// <summary>
    ///   加载AssetBundle
    /// </summary>
    ZTAssetBundle LoadZTAssetBundle(string assetbundlename)
    {
        if (assetbundlename == null || MainManifest == null)
        {
            return(null);
        }

        ZTAssetBundle ab = LoadInCahce(assetbundlename);

        if (null != ab)
        {
            return(ab);
        }

        ab = new ZTAssetBundle(assetbundlename);
        SaveInCahce(assetbundlename, ab);

        return(ab);
    }
コード例 #6
0
 /// <summary>
 /// 根据预定义 存储ab包
 /// </summary>
 void SaveInCahce(string assetbundlename, ZTAssetBundle ab)
 {
     this._assetbundleTemporary.Add(assetbundlename, ab);
 }