Exemplo n.º 1
0
 public override void AssetsLoadedSuccessful(UGAssetsBundle bundle)
 {
     if(flag){
         _body = LoadResource("Characters/U_Character/U_Character_REF_FB");
         _body.transform.position = new Vector3(30f,0f,45f);
     }else
     {
         if(bundle.assetbundle != null)
         {
             Object obj;
             if(string.IsNullOrEmpty(willLoadAssetName)|| willLoadAssetName == "Empty")
                 obj = bundle.assetbundle.mainAsset;
             else
                 obj = bundle.assetbundle.Load(willLoadAssetName);
             if(obj == null)
             {
                 Debug.LogError(" 资源包中没有名为"+willLoadAssetName+"的资源");
             }else
             {
                 _body = Instantiate(obj) as GameObject;
             }
         }else
         {
             Debug.LogError("LoadAsset Failed !!");
         }
     }
 }
Exemplo n.º 2
0
 public void ReplaceUGAssetsBundle(string key,UGAssetsBundle nugAssets)
 {
     UnloadeUGAssetsBundle(key);
         AddUGAssetsBundle(key,nugAssets);
 }
Exemplo n.º 3
0
 public void AddUGAssetsBundle(string key,UGAssetsBundle ugAssets)
 {
     if(!_bundleDic.ContainsKey(key))
     _bundleDic.Add(key,ugAssets);
 }
Exemplo n.º 4
0
    public bool LoadAsset( )
    {
        if(!UGBundlePoolManager.instance().ContainsUGAssetsBundle(assetsPackage))
        {

            RuntimePlatform run_platform = Application.platform;

            //不同平台下StreamingAssets的路径是不同的,这里需要注意一下。
            string PathURL  = "";

            if(run_platform == RuntimePlatform.Android)
            {
                PathURL =  "jar:file://" + Application.dataPath + "!/assets/";
            }
            else if(run_platform == RuntimePlatform.IPhonePlayer)
            {
                PathURL = Application.dataPath + "/Raw/";
            }
            else if(run_platform == RuntimePlatform.OSXEditor || run_platform == RuntimePlatform.WindowsEditor)
            {
                PathURL = "file://" + Application.dataPath + "/StreamingAssets/";
            }

            PathURL = PathURL+assetsPackage + ".unity3d";

            //			if(File.Exists(PathURL))
            //			{
            print("AssetBundle path: "+PathURL + "  \n Gloable:" + Global.PathURL);
            StartCoroutine( this.LoadFromCacheOrDownload(PathURL));

            Debug.Log(" StartCoroutine Done!!!! ");

            if(ugAssets != null)
            {
                ugAssets.Keep();
                AssetsLoadedSuccessful(ugAssets);
                return true;
            }else
            {
                return false;
            }

        }else
        {
            Debug.Log(" This Assets had Loaded!! ");

            ugAssets = UGBundlePoolManager.instance().TryGetUGAssetsBundle(assetsPackage);
            if(ugAssets != null)
            {
                ugAssets.Keep();
                AssetsLoadedSuccessful(ugAssets);
                return true;
            }
            else
            {
                AssetsLoadedFailed();
                return false;
            }
        }
    }
Exemplo n.º 5
0
 //属性
 public abstract void AssetsLoadedSuccessful(UGAssetsBundle bundle);
Exemplo n.º 6
0
    private IEnumerator LoadFromCacheOrDownload(string path)
    {
        //		print(" AssetVersion : " + Global.Version);
        // 载入 AssetBundle

        WWW www =  WWW.LoadFromCacheOrDownload(path,Global.Version);

        if(string.IsNullOrEmpty(www.error))
        {
            if(Caching.IsVersionCached(path,Global.Version))
            {
                Debug.LogWarning("这个版本的资源已经缓存了!!! :" + www.error+"wo");

                if(UGBundlePoolManager.instance().ContainsUGAssetsBundle(assetsPackage))
                {
                    ugAssets = UGBundlePoolManager.instance().TryGetUGAssetsBundle(assetsPackage);
                }else
                {
                    ugAssets = new UGAssetsBundle(www.assetBundle);
                    ugAssets.AssetsName = assetsPackage;
                    UGBundlePoolManager.instance().AddUGAssetsBundle(assetsPackage,ugAssets);
                }

            }else
            {
                ugAssets = new UGAssetsBundle(www.assetBundle);
                ugAssets.AssetsName = assetsPackage;

                if(UGBundlePoolManager.instance().ContainsUGAssetsBundle(assetsPackage))
                {
                    UGBundlePoolManager.instance().ReplaceUGAssetsBundle(assetsPackage,ugAssets);
                }else
                {
                    UGBundlePoolManager.instance().AddUGAssetsBundle(assetsPackage,ugAssets);
                }
            }
        }else
        {
            Debug.LogError("UGBody: "+www.error);
        }

        //等待载入完成
        yield return www;
    }