Load() public method

public Load ( string name ) : System.Object
name string
return System.Object
Esempio n. 1
0
 static public int Load(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(string)))
         {
             UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l);
             System.String           a1;
             checkType(l, 2, out a1);
             UnityEngine.Object ret = self.Load(a1);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, 2, typeof(string), typeof(System.Type)))
         {
             UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l);
             System.String           a1;
             checkType(l, 2, out a1);
             System.Type a2;
             checkType(l, 3, out a2);
             UnityEngine.Object ret = self.Load(a1, a2);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Esempio n. 2
0
    static int Load(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.AssetBundle), typeof(string)))
            {
                UnityEngine.AssetBundle obj = (UnityEngine.AssetBundle)ToLua.ToObject(L, 1);
                string             arg0     = ToLua.ToString(L, 2);
                UnityEngine.Object o        = obj.Load(arg0);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.AssetBundle), typeof(string), typeof(System.Type)))
            {
                UnityEngine.AssetBundle obj = (UnityEngine.AssetBundle)ToLua.ToObject(L, 1);
                string             arg0     = ToLua.ToString(L, 2);
                System.Type        arg1     = (System.Type)ToLua.ToObject(L, 3);
                UnityEngine.Object o        = obj.Load(arg0, arg1);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.AssetBundle.Load"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 3
0
 /// <summary>
 /// 创建
 /// </summary>
 /// <param name="decryptedData"></param>
 /// <returns></returns>
 IEnumerator LoadBundle(byte[] decryptedData)
 {
     AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData);
     yield return acr;
     assetBundel = acr.assetBundle;
     Instantiate(assetBundel.Load("Cube"));
 }
 static public int Load(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l);
             System.String           a1;
             checkType(l, 2, out a1);
             var ret = self.Load(a1);
             pushValue(l, ret);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l);
             System.String           a1;
             checkType(l, 2, out a1);
             System.Type a2;
             checkType(l, 3, out a2);
             var ret = self.Load(a1, a2);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 private UnityEngine.Object LoadFromBundle(AssetBundle bundle, string name)
 {
     #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
     return bundle.Load(name);
     #else
     return bundle.LoadAsset(name);
     #endif
 }
    /// <summary>
    /// 初始化
    /// </summary>
    void initialize() {
        string uri = string.Empty;
        //------------------------------------Shared--------------------------------------
        uri = Util.DataPath + "shared.assetbundle";
        Debug.LogWarning("LoadFile::>> " + uri);

        shared = AssetBundle.CreateFromFile(uri);
        shared.Load("Dialog", typeof(GameObject));
        ioo.gameManager.OnResourceInited();    //回调游戏管理器,执行后续操作 
    }
Esempio n. 7
0
    public IEnumerator LoadBundle()
    {
        ImBusy = true;
            string url = "file:///"+Path.GetFullPath(ResPath);
            MessageServiceClass.MessageProcessing("Loadin bundle from "+url);
            WWW www = WWW.LoadFromCacheOrDownload(url, version);
            yield return www;
            MessageServiceClass.MessageProcessing("Bundle resources are loaded from "+ url);

            assetBundle = www.assetBundle;
            CircleGameObjPref = assetBundle.Load("circle") as GameObject;
            for (int i = 0;i <4; i++){
                BundleResourceTextures2d[i] = assetBundle.Load (BundleTexturesNames[i]) as Texture2D;

            }// int i = 0;i <4; i++

           	assetBundle.Unload(false);
            ImBusy = false;
    }
    public IEnumerator LoadAssetsFromBundle(AssetBundle bundle, string[] names)
    {
        objects = new List<Object>();

        foreach (var name in names)
        {
            Object obj = bundle.Load(name);
            TryAddAsset(name, obj, objects);
        }
        yield return null;
    }
        /// <summary>
        /// 初始化
        /// </summary>
        public void initialize(Action func) {
            byte[] stream;
            string uri = string.Empty;
            //------------------------------------Shared--------------------------------------
            uri = Util.DataPath + "shared.assetbundle";
            Debug.LogWarning("LoadFile::>> " + uri);

            stream = File.ReadAllBytes(uri);
            shared = AssetBundle.CreateFromMemoryImmediate(stream);
#if UNITY_5
        shared.LoadAsset("Dialog", typeof(GameObject));
#else
            shared.Load("Dialog", typeof(GameObject));
#endif
            if (func != null) func();    //资源初始化完成,回调游戏管理器,执行后续操作 
        }
Esempio n. 10
0
    /**
        (3):AssetBundle

        关于AssetBundle的介绍已经有很多了。简而言之就是把prefab或者二进制文件封装成AssetBundle文件(也是一种二进制)。
        但是也有硬伤,就是在移动端无法更新脚本。下面简单的总结下:
        1:是Unity3D定义的一种二进制类型。
        2:最好将prefab封装成AseetBundle,不过上面不是才说了在移动端无法更新脚本吗?
            那从Assetbundle中拿到的Prefab上挂的脚本是不是就无法运行了?也不一定,只要这个prefab上挂的是本地脚本,就可以。
        3:使用WWW类来下载。

     * */
    IEnumerator loadAssetBundle()
    {
        AssetBundle AssetBundleCsv = new AssetBundle();

        //读取放入StreamingAssets文件夹中的bundle文件
        string str = Application.streamingAssetsPath + "/" + "Test.bundle";
        WWW www = new WWW(str);
        www = WWW.LoadFromCacheOrDownload(str, 0);

        AssetBundleCsv = www.assetBundle;
        string path = "Test";
        TextAsset test = AssetBundleCsv.Load(path, typeof(TextAsset)) as TextAsset;
        string result = test.ToString();

        yield return null;
    }
        /// <summary>
        /// 初始化
        /// </summary>
        public void initialize(Action func) {
            if (AppConst.ExampleMode) {
                byte[] stream;
                string uri = string.Empty;
                //------------------------------------Shared--------------------------------------
                uri = Util.DataPath + "shared" + AppConst.ExtName;
                Debug.LogWarning("LoadFile::>> " + uri);

                stream = File.ReadAllBytes(uri);
                shared = AssetBundle.LoadFromMemory(stream);
#if UNITY_5
        shared.LoadAsset("Dialog", typeof(GameObject));
#else
                shared.Load("Dialog", typeof(GameObject));
#endif
            }
            if (func != null) func();    //资源初始化完成,回调游戏管理器,执行后续操作 
        }
Esempio n. 12
0
    /// <summary>
    /// 创建面板
    /// </summary>
    IEnumerator StartCreatePanel(string name, AssetBundle bundle, string text = null) {
        name += "Panel";
        GameObject prefab = bundle.Load(name) as GameObject;
        yield return new WaitForEndOfFrame();
        if (Parent.FindChild(name) != null || prefab == null) {
            yield break;
        }
        GameObject go = Instantiate(prefab) as GameObject;
        go.name = name;
        go.layer = LayerMask.NameToLayer("Default");
        go.transform.parent = Parent;
        go.transform.localScale = Vector3.one;
        go.transform.localPosition = Vector3.zero;

        yield return new WaitForEndOfFrame();
        go.AddComponent<BaseLua>().OnInit(bundle);

        Debug.Log("StartCreatePanel------>>>>" + name);
    }
Esempio n. 13
0
 /// <summary>
 /// Add a UI package from two assetbundles with a optional main asset name.
 /// </summary>
 /// <param name="desc">A assetbunble contains description file.</param>
 /// <param name="res">A assetbundle contains resources.</param>
 /// <param name="mainAssetName">Main asset name.</param>
 /// <returns>UIPackage</returns>
 public static UIPackage AddPackage(AssetBundle desc, AssetBundle res, string mainAssetName)
 {
     string source = null;
     #if UNITY_5
     if (mainAssetName != null)
     {
         TextAsset ta = desc.LoadAsset<TextAsset>(mainAssetName);
         if (ta != null)
             source = ta.text;
     }
     else
     {
         string[] names = desc.GetAllAssetNames();
         foreach (string n in names)
         {
             if (n.IndexOf("@") == -1)
             {
                 TextAsset ta = desc.LoadAsset<TextAsset>(n);
                 if (ta != null)
                 {
                     source = ta.text;
                     if (mainAssetName == null)
                         mainAssetName = Path.GetFileNameWithoutExtension(n);
                     break;
                 }
             }
         }
     }
     #else
     if (mainAssetName != null)
     {
         TextAsset ta = (TextAsset)desc.Load(mainAssetName, typeof(TextAsset));
         if (ta != null)
             source = ta.text;
     }
     else
     {
         source = ((TextAsset)desc.mainAsset).text;
         mainAssetName = desc.mainAsset.name;
     }
     #endif
     if (source == null)
         throw new Exception("FairyGUI: invalid package.");
     if (desc != res)
         desc.Unload(true);
     return AddPackage(source, res, mainAssetName);
 }
    private IEnumerator DownloadAssetBundle(string asset, string bundleName, int version)
    {
        loadedAsset = null;

        // Wait for the Caching system to be ready
        while (!Caching.ready)
        {
            yield return null;
        }

        string url = baseURL + bundleName;

        // Start the download
        using (WWW www = WWW.LoadFromCacheOrDownload(url, version))
        {
            yield return www;
            if (www.error != null)
            {
                throw new System.Exception("AssetBundle - WWW download:" + www.error);
            }
            thisAssetBundle = www.assetBundle;

            //load the specified asset into memory
            loadedAsset = thisAssetBundle.Load(asset, typeof(GameObject));

            www.Dispose();

            isDone = true;
        }
    }
Esempio n. 15
0
    public static GameObject LoadAsset(AssetBundle bundle, string name)
    {
#if UNITY_5
        return bundle.LoadAsset(name, typeof(GameObject)) as GameObject;
#else
        return bundle.Load(name, typeof(GameObject)) as GameObject;
#endif
    }
Esempio n. 16
0
    IEnumerator Load()
    {
        string filePath = string.Empty;
        if(GooglePlayDownloader.RunningOnAndroid()){

            if(mainPath == null){
                needServerDownload = true;

                message = "MainFile still not found!";
                Debug.Log(message);

            }

            if(needServerDownload){
                filePath = ServerURL + "/" + AssetBundleName + ".unity3d";
            } else {
                filePath = "jar:file://" + mainPath;
                filePath += "!/"+AssetBundleName+".unity3d";
            }

        } else {
            filePath = "file://" + Application.dataPath;
            filePath += "/"+AssetBundleName+".unity3d";

        }

        message = "FilePath: " + filePath;
        Debug.Log(message);

        www = WWW.LoadFromCacheOrDownload(filePath,AssetVersionNumber);
        yield return www;
        bundle = www.assetBundle;
        loadedAssets.Clear();
        foreach(var name in PrefabNames){
            GameObject go = bundle.Load(name, typeof(GameObject)) as GameObject;
            loadedAssets.Add(name, go);
        }

        if(loadingScreen != null && loadingScreen.renderer != null)
            loadingScreen.renderer.enabled = false;

        Application.LoadLevel(ChangeToScene);
    }