Пример #1
0
        public override void Dispose()
        {
            Unload();

            {
                foreach (ABLoad e in mAbLoadObject)
                {
                    ABLoad abloadTmp = (ABLoad)e;

                    switch (mABDataType)
                    {
                    case ABDataType.Mpq:
                        //((ABLoadMpq)abloadTmp).Dispose();
                        break;

                    case ABDataType.Normal:
                        ((ABLoadFile)abloadTmp).Dispose();
                        break;
                    }
                    abloadTmp = null;
                }
                mAbLoadObject.Clear();
            }

            {
                if (loadAdapter != null)
                {
                    loadAdapter.Dispose();
                }

                loadAdapter = null;
            }

            base.Dispose();
        }
Пример #2
0
	IEnumerator Monster001()
	{
		yield return 1;
		
#if UNITY_IPHONE
		string path = "file://" + Application.dataPath + "/Raw/";
#elif UNITY_STANDALONE_WIN
		string path = "file://" + Application.dataPath + "/StreamingAssets/";
#else
		string path = "jar:file://" + Application.dataPath + "!/assets/";
#endif
				
		Debug.Log(path + "monster001.assetBundles");
		
		ABLoad load = new ABLoad(path + "monster001.assetBundles");
		while(true)
		{
			if (load.bundle.isDone)
				break;
			
			yield return 1;
		}
		
		Debug.Log(load);
        //GameObject res = load.LoadGameObject("monster001");
        GameObject res = load.Load<GameObject>("monster001");
		
		Debug.Log(res);
		
		Instantiate(res);
		
		load.Close();

	}
Пример #3
0
        /// <summary>
        /// 根据bundle的全路径,来加载bundles 
        /// </summary>
        /// <param name="bundlepathname"></param>
        /// <returns></returns>
        public Object[] LoadBundles(string bundlepathname)
        {
            ABLoad load = null;

            if (allbundleloads.ContainsKey(bundlepathname))
            {
                load = (ABLoad)allbundleloads[bundlepathname];

                Debug.Log(bundlepathname);

            }
            else
            {
                string targetPath = bundlepathname;

                // AssetBundle 存储路径
                Debug.Log(targetPath);

                load = new ABLoad(targetPath);

                allbundleloads[bundlepathname] = load;
            }

            Object[] all = load.LoadAll();

            return all;

        }
Пример #4
0
        public override void Unload()
        {
            base.Unload();

            nav      = null;
            lightmap = null;
            asset    = null;
            scene    = null;

            requestGo      = null;
            requestNav     = null;
            requestAsset   = null;
            requestTexture = null;

            {
                foreach (Material e in mMaterialObject.Values)
                {
                    Material m = (Material)e;

                    m = null;
                }
                mMaterialObject.Clear();
            }

            {
                foreach (AssetBundleRequest e in mAssetBundleRequestObject.Values)
                {
                    AssetBundleRequest requestTmp = (AssetBundleRequest)e;

                    requestTmp = null;
                }
                mAssetBundleRequestObject.Clear();
            }

            {
                foreach (ABLoad e in mAbLoadObject)
                {
                    ABLoad abloadTmp = (ABLoad)e;

                    switch (mABDataType)
                    {
                    case ABDataType.Mpq:
                        //((ABLoadMpq)abloadTmp).Unload();
                        break;

                    case ABDataType.Normal:
                        ((ABLoadFile)abloadTmp).Unload();
                        break;
                    }
                }
            }

            if (loadAdapter != null)
            {
                loadAdapter.Unload();
            }
        }
Пример #5
0
        public void Close()
        {
            foreach (ABLoad e in allbundleloads.Values)
            {
                ABLoad ab = (ABLoad)e;
                ab.Dispose();
                ab = null;
            }

            allbundleloads.Clear();
        }
Пример #6
0
        /// <summary>
        /// 临时申请的材质的WWW即时释放.
        /// </summary>
        public override void Release(bool force = false)
        {
            base.Release(force);

            //  基础数据不能释放.
            loadAdapter.Release(false);

            if (force)
            {
                mAutoRelease = force;
            }

            if (mAutoRelease && Ref == 0)
            {
                foreach (Material e in mMaterialObject.Values)
                {
                    Material m = (Material)e;

                    m = null;
                }
                mMaterialObject.Clear();

                foreach (AssetBundleRequest e in mAssetBundleRequestObject.Values)
                {
                    AssetBundleRequest requestTmp = (AssetBundleRequest)e;

                    requestTmp = null;
                }
                mAssetBundleRequestObject.Clear();

                foreach (ABLoad e in mAbLoadObject)
                {
                    ABLoad abloadTmp = (ABLoad)e;

                    switch (mABDataType)
                    {
                    case ABDataType.Mpq:
                        //((ABLoadMpq)abloadTmp).Release(force);
                        break;

                    case ABDataType.Normal:
                        ((ABLoadFile)abloadTmp).Release(force);
                        break;
                    }
                    abloadTmp = null;
                }
                mAbLoadObject.Clear();
            }
        }
Пример #7
0
    public ABData(string url, string resname, System.Type type, ABLoad load)
    {
        mLoad = load;
        mUrl = url;
        mResname = resname;
        mType = type;

        Create();

        mRef++;
        mReferenceList.Add(this);

        mCount = 0;
        mProgress = 1;
    }
Пример #8
0
        public static string DumpAllABLoadList()
        {
            string sout = "**********AssetBundleEditor.ABLoad.DumpAllABLoadList********** ";

            sout += "\r\n";

            for (int i = mReferenceList.Count - 1; i >= 0; --i)
            {
                ABLoad load = (ABLoad)mReferenceList[i];
                sout += i.ToString() + "\t";
                sout += load.mType + "\t";
                sout += load.Log() + "\t";
                sout += "\r\n";
            }

            return(sout);
        }
Пример #9
0
        public ABLoad Add(string url, int version, ABDataType abtype)
        {
            string keyName = url + version.ToString();

            ABLoad bl = null;

            switch (abtype)
            {
            case ABDataType.Normal:
                bl = new ABLoadFile(version, true);
                break;

            case ABDataType.Mpq:
                //bl = new ABLoadMpq(version, true);
                break;
            }
            mABLoads[keyName] = bl;

            return(bl);
        }
Пример #10
0
        public ABLoadScene(int version, ABDataType abtype) 
            : base(version)
        {
            mABDataType = abtype;

            switch (abtype)
            {
                case ABDataType.Mpq:
                    loadAdapter = new ABLoadMpq(version, false);
                    break;
                case ABDataType.Normal:
                    loadAdapter = new ABLoadFile(version,false);
                    break;
            }

            loadAdapter.mDontDestroyOnLoad = true;

            mAutoRelease = false;

            //mDontDestroyOnLoad = true;
        }
Пример #11
0
        public ABLoadScene(int version, ABDataType abtype)
            : base(version)
        {
            mABDataType = abtype;

            switch (abtype)
            {
            case ABDataType.Mpq:
                //loadAdapter = new ABLoadMpq(version, false);
                break;

            case ABDataType.Normal:
                loadAdapter = new ABLoadFile(version, false);
                break;
            }

            loadAdapter.mDontDestroyOnLoad = true;

            mAutoRelease = false;

            //mDontDestroyOnLoad = true;
        }
Пример #12
0
    IEnumerator Scene()
    {
        yield return 1;

#if UNITY_IPHONE
		string path = "file://" + Application.dataPath + "/Raw/";
#elif UNITY_STANDALONE_WIN
        string path = "file://" + Application.dataPath + "/StreamingAssets/";
#else
		string path = "jar:file://" + Application.dataPath + "!/assets/";
#endif

        Debug.Log(path + "110101.assetBundles");

        ABLoad load = new ABLoad(path + "110101.assetBundles");
        while (true)
        {
            if (load.bundle.isDone)
                break;

            yield return 1;
        }
        
        //  加载场景
        GameObject res = load.Load<GameObject>("110101");
        Instantiate(res);

        //  加载LightMap
        ArrayList texlist = new ArrayList();// Texture2D

        Object[] objects = load.LoadAll();
        foreach (Object e in objects)
        {
            if (!e.name.StartsWith("LightmapFar-"))
                continue;

            if (e.GetType() == typeof(Texture2D))
                texlist.Add(e);
        }
        texlist.Sort();

        //  数据集数量
        int lmDataSetCount = (texlist.Count + 1) / 2;
        int lmDataIndex = 0;

        LightmapData[] lmDataSet = new LightmapData[lmDataSetCount];

        for (int i = 0; i < texlist.Count; ++i)
        {
            LightmapData lmData = new LightmapData();
            lmData.lightmapFar = (Texture2D)texlist[i];
            if ((++i) != texlist.Count) lmData.lightmapNear = (Texture2D)texlist[i];

            lmDataSet[lmDataIndex] = lmData;
        }

        LightmapSettings.lightmapsMode = LightmapsMode.Dual;
        LightmapSettings.lightmaps = lmDataSet;

        load.Close();

    }
Пример #13
0
    public IEnumerator CallBackSync(ABLoad mAB, string url, string resname, System.Type type, ABDataType abtype)
    {
        //Debuger.Log("AssetBundleUti.CallBack " + System.IO.Path.GetFileName(url) + " " + resname + " " + type.ToString());
        
        Count++;

        callbackerror = string.Empty;
        bCallback = true;

        do
        {
            if (!mAB.Create(url))
            {   
                callbackerror = "ABLoad Create Error " + url;
                bCallback = false;

                break;
            }

            yield return StartCoroutine(mAB.Waiting());
		
            //Debuger.Log("Waiting End ");

            while (true)
            {
                if (mAB.IsWWW())
                    break;

                yield return null;
            }
		
            //Debuger.Log("Error " + mAB.Error());

		    if (mAB.Error())
		    {
                //Debuger.LogError(mAB.GetErrorMsg());
                callbackerror = mAB.GetErrorMsg();
                bCallback = false;

                break;
		    }
		    else
		    {
	            if (typeof(AudioClip) == type)
	            {
	                AudioClip ac = mAB.Load(resname);
	
                    //Debuger.Log(resname + " " + ac.length + " " + ac.samples + " " + ac.isReadyToPlay + " " + ac.channels);
                    //Debuger.Log(ac.isReadyToPlay);
	
	                if (ac != null)
	                {
	                    while (true)
	                    {
	                        if (ac.isReadyToPlay)
	                            break;

                            yield return null;
                        }

                        ac.name = resname;
	                    mAB.Pair(resname, ac, type);
	
	                    //  返回
                        if (OnFinishLoading != null)
                        {
                            //Debuger.Log("AssetBundleUti.OnFinishLoading " + System.IO.Path.GetFileName(url) + " " + resname + " " + type.ToString());

                            OnFinishLoading(url, resname, type, true);
                        }
	
	                }
	                else
	                {
	                    Debuger.LogError("Load " + resname + " in " + url);

                        callbackerror = mAB.GetErrorMsg();
                        bCallback = false;

                        break;
	                }
	            }
	            else
	            {
                    AssetBundle ab = mAB.GetAb();
                    if (ab == null)
                    {
                        callbackerror = "AssetBundle == null";
                        bCallback = false;

                        break;
                    }

                    AssetBundleRequest request = ab.LoadAsync(resname, type);
                    if (request == null)
                    {
                        callbackerror = "LoadAsync AssetBundleRequest == null";
                        bCallback = false;

                        break;
                    }

	                while (true)
	                {
	                    if (request.isDone)
	                        break;

                        yield return null;
                    }

                    mAB.Pair(resname, request.asset, type);
	
	                //  返回
                    if (OnFinishLoading == null)
                    {
                        //Debuger.Log("AssetBundleUti.OnFinishLoading " + System.IO.Path.GetFileName(url) + " " + resname + " " + type.ToString());
                        callbackerror = "OnFinishLoading == null";
                        bCallback = false;

                        break;
                    }

                    OnFinishLoading(url, resname, type, true);
	            }
		    }

        }
        while (false);

        if (!bCallback)
        {
            Debuger.LogError("Error " + mAB.Error() + " callbackerror: " + callbackerror);

            MessageBox(callbackerror + " \r\n " + OnFinishLoading.ToString());

            OnFinishLoading(url, resname, type, false, callbackerror);

            if (mAB != null)
            {
                mAB.Dispose();
                mAB = null;
            }
        }
        else
        {
            releaseQueue.Enqueue(mAB);
        }

        Count--;

        if (Count <= 0)
        {
            Count = 0;
            releaseAllBundles();
        }
    }
Пример #14
0
        public override void Dispose()
        {
            Unload();

            {
                foreach (ABLoad e in mAbLoadObject)
                {
                    ABLoad abloadTmp = (ABLoad)e;

                    switch (mABDataType)
                    {
                        case ABDataType.Mpq:
                            ((ABLoadMpq)abloadTmp).Dispose();
                            break;
                        case ABDataType.Normal:
                            ((ABLoadFile)abloadTmp).Dispose();
                            break;
                    }
                    abloadTmp = null;
                }
                mAbLoadObject.Clear();
            }

            {
                if (loadAdapter != null)
                    loadAdapter.Dispose();

                loadAdapter = null;
            }

            base.Dispose();
        }
Пример #15
0
        public void CleanABByScene()
        {
            ////foreach (KeyValuePair<string, ABLoad> e in mABLoads)
            ////{
            ////    ABLoad bl = (ABLoad)mABLoads[e.Key];
            ////    if (!bl.IsDontDestroyOnLoad())
            ////    {
            ////        bl.Dispose();
            ////        bl = null;

            ////        mABLoads.Remove(e.Key);
            ////    }
            ////}
            ////mABLoads.Clear();
            ////mABLoads = null;


            {
                List <string> listABLoadOrders = new List <string>(mABLoads.Keys);
                List <ABLoad> listABLoad       = new List <ABLoad>(mABLoads.Values);
                for (int i = 0; i < listABLoad.Count; i++)
                {
                    ABLoad bl = (ABLoad)listABLoad[i];
                    if (!bl.IsDontDestroyOnLoad())
                    {
                        bl.Dispose();
                        bl = null;
                    }

                    //  根据序号去删除.
                    mABLoads.Remove(listABLoadOrders[i]);
                }
                listABLoadOrders.Clear();
                listABLoad.Clear();
                listABLoadOrders = null;
                listABLoad       = null;
            }

            {
                List <string>      listABLoadOrders = new List <string>(mABLoadScenes.Keys);
                List <ABLoadScene> listABLoad       = new List <ABLoadScene>(mABLoadScenes.Values);
                for (int i = 0; i < listABLoad.Count; i++)
                {
                    ABLoadScene bl = (ABLoadScene)listABLoad[i];
                    if (!bl.IsDontDestroyOnLoad())
                    {
                        bl.Dispose();
                        bl = null;
                    }

                    //  根据序号去删除.
                    mABLoadScenes.Remove(listABLoadOrders[i]);
                }
                listABLoadOrders.Clear();
                listABLoad.Clear();
                listABLoadOrders = null;
                listABLoad       = null;
            }

            ////foreach (KeyValuePair<string, ABLoadScene> e in mABLoadScenes)
            ////{
            ////    ABLoadScene bl = (ABLoadScene)mABLoadScenes[e.Key];
            ////    if (!bl.IsDontDestroyOnLoad())
            ////    {
            ////        bl.Dispose();
            ////        bl = null;

            ////        mABLoadScenes.Remove(e.Key);
            ////    }

            ////}
            ////mABLoadScenes.Clear();
            ////mABLoadScenes = null;
        }
Пример #16
0
        public override IEnumerator Waiting()
        {
            float begintime = Time.realtimeSinceStartup;

            yield return(loadAdapter.Waiting());

            Debuger.Log("Waiting End ");

            while (true)
            {
                if (loadAdapter.IsWWW())
                {
                    break;
                }

                yield return(null);
            }

            //    _Waiting();
            //}

            //private void _Waiting()
            //{
            ErrorMsg = loadAdapter.GetErrorMsg();

            if (string.IsNullOrEmpty(ErrorMsg))
            {
                {
                    Pair(mResName, loadAdapter.GetAb().LoadAsset(mResName + ABLoadScene.GameObject, typeof(GameObject)), typeof(GameObject));
                }

                {
                    Pair(ABLoadScene.Lightmap, loadAdapter.GetAb().LoadAsset(ABLoadScene.Lightmap, typeof(Texture2D)), typeof(Texture2D));
                }

                {
                    Pair(mResName + ABLoadScene.Material, loadAdapter.GetAb().LoadAsset(mResName + ABLoadScene.Material, typeof(StringPrefab)), typeof(StringPrefab));
                }

                {
                    Pair(ABLoadScene.Nav, loadAdapter.GetAb().LoadAsset(mResName + ABLoadScene.Nav, typeof(GameObject)), typeof(GameObjectNav));
                }

                {
                    if (asset != null)
                    {
                        foreach (StringPrefabMaterial e in asset.material)
                        {
                            //Debuger.Log("assetbundlePath " + e.assetbundlePath);

                            float counttime = Time.realtimeSinceStartup;
#if 异步
                            AssetBundleRequest R = (AssetBundleRequest)mAssetBundleRequestObject[e.assetbundlePath];
#else
                            Material R = (Material)mMaterialObject[e.assetbundlePath];
#endif
                            if (R == null)
                            {
                                string fileurl = System.IO.Path.GetDirectoryName(mUrl) + "/" + e.assetbundlePath;

                                ABLoad loadAdapterTmp = null;

                                switch (mABDataType)
                                {
                                case ABDataType.Mpq:
                                    //loadAdapterTmp = new ABLoadMpq(mVersion);
                                    break;

                                case ABDataType.Normal:
                                    loadAdapterTmp = new ABLoadFile(mVersion);
                                    break;
                                }

                                loadAdapterTmp.Create(fileurl);

                                {
                                    yield return(loadAdapterTmp.Waiting());

                                    while (true)
                                    {
                                        if (loadAdapterTmp.IsWWW())
                                        {
                                            break;
                                        }

                                        yield return(null);
                                    }
                                }

                                if (string.IsNullOrEmpty(loadAdapterTmp.GetErrorMsg()))
                                {
                                    bool success = true;

                                    do
                                    {
                                        if (loadAdapterTmp.GetAb() == null)
                                        {
                                            Debuger.LogError("loadAdapterTmp.GetAb() == null" + " fileurl: " + fileurl + " mUrl: " + mUrl);

                                            success = false;

                                            ErrorMsg = "loadAdapterTmp.GetAb() == null";

                                            break;
                                        }

                                        //string resname = System.IO.Path.GetFileName(e.meshrendererGameObject);

                                        //Debuger.Log("3 " + resname);

#if 异步
                                        AssetBundleRequest requestMat = loadAdapterTmp.GetAb().LoadAsync(e.assetname, typeof(Material));

                                        mAssetBundleRequestObject[e.assetbundlePath] = requestMat;

                                        while (true)
                                        {
                                            if (requestMat.isDone)
                                            {
                                                break;
                                            }

                                            yield return(null);
                                        }

                                        //Debuger.Log("4 " + request);

                                        if (requestMat.asset == null)
                                        {
                                            Debuger.LogError("requestMat.asset == null" + " fileurl: " + fileurl + " mUrl: " + mUrl);

                                            ErrorMsg = "requestMat.asset == null";

                                            success = false;

                                            break;
                                        }
#else
                                        Material m = (Material)loadAdapterTmp.GetAb().LoadAsset(e.assetname, typeof(Material));

                                        mMaterialObject[e.assetbundlePath] = m;
#endif
                                        mAbLoadObject.Add(loadAdapterTmp);
                                    }while (false);

                                    if (!success)
                                    {
                                        loadAdapterTmp.Dispose();

                                        loadAdapterTmp = null;
                                    }
                                }
                                else
                                {
                                    Debuger.LogError(loadAdapterTmp.GetErrorMsg() + " fileurl: " + fileurl + " mUrl: " + mUrl);

                                    ErrorMsg = loadAdapterTmp.GetErrorMsg();
                                }
                            }

                            R = null;

                            Debuger.Log("\t\tAssetBundleEditor.ABLoadScene " + (Time.realtimeSinceStartup - counttime).ToString("f5") + " File: " + e.assetbundlePath);
                        }
                    }
                    else
                    {
                        ErrorMsg = "asset == null";

                        Debuger.LogError("asset == null");
                    }
                }
            }

            Debuger.Log("AssetBundleEditor.ABLoadScene " + (Time.realtimeSinceStartup - begintime).ToString("f5") + " Count: " + asset.material.Length);
        }
Пример #17
0
    public virtual void Destory()
    {
        if (mLoad != null)
        {
            mLoad = null;
        }
        if (_ABLoadGoMono != null)
        {
            _ABLoadGoMono.Clear();
            GameObject.DestroyImmediate(_ABLoadGoMono);
            _ABLoadGoMono = null;
        }

        if (_gameobject != null)
        {
            _gameobject.SetActive(false);
            GameObject.DestroyImmediate(_gameobject);
            _gameobject = null;
        }
        _gameobject = null;
        _audioclip  = null;
        _mat        = null;
        _texture2d  = null;
    }