コード例 #1
0
        public void AddResources(AssetBundle bundle)
        {
            var textures = bundle.LoadAll(typeof(Texture2D)).OfType <Texture2D>().ToDictionary(t => t.name);

            foreach (var asset in bundle.LoadAll(typeof(TextAsset)).OfType <TextAsset>())
            {
                // this is really the best we can do for now
                if (asset.text.StartsWith("atlas\n") || asset.text.StartsWith("atlas\r\n"))
                {
                    _atlases[asset.name] = new Atlas(asset, textures);
                }
                else if (asset.text.StartsWith("info "))
                {
                    _fonts[asset.name] = new BitmapFont(asset, textures);
                }
                else if (asset.text.StartsWith("strings\n") || asset.text.StartsWith("strings\r\n"))
                {
                    _strings.AddStrings(asset.text);
                }
            }

            foreach (var asset in bundle.LoadAll(typeof(Shader)).OfType <Shader>())
            {
                _shaders.Add(asset.name, asset);
            }
        }
コード例 #2
0
    static int LoadAll(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 1)
        {
            AssetBundle obj = LuaScriptMgr.GetUnityObject <AssetBundle>(L, 1);
            Object[]    o   = obj.LoadAll();
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }
        else if (count == 2)
        {
            AssetBundle obj  = LuaScriptMgr.GetUnityObject <AssetBundle>(L, 1);
            Type        arg0 = LuaScriptMgr.GetTypeObject(L, 2);
            Object[]    o    = obj.LoadAll(arg0);
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: AssetBundle.LoadAll");
        }

        return(0);
    }
コード例 #3
0
    private IEnumerator WaitForAnimationRequest(WWW www)
    {
        yield return(www);

        if (www.error != null)
        {
            yield break;
        }
        yield return(www);

        Logger.trace("<< Loading Animations . . .");
        AssetBundle assetBundle = www.assetBundle;

        UnityEngine.Object[] anims = assetBundle.LoadAll(typeof(AnimationClip));
        for (int i = 0; i < anims.Length; i++)
        {
            GameData.Animations.Add(anims[i] as AnimationClip);
            if (anims[i].name.Contains("running"))
            {
                int           numidx   = anims[i].name.IndexOf("_");
                string        toCreate = anims[i].name.Substring(numidx);
                AnimationClip ac       = UnityEngine.Object.Instantiate(anims[i] as AnimationClip) as AnimationClip;
                ac.name = "move_arm" + toCreate;
                GameData.Animations.Add(ac);
            }
        }
        mStatus         += " ... Animations Loaded!";
        mBundleIsLoading = false;
    }
コード例 #4
0
    private IEnumerator WaitForLowSuitsRequest(WWW www)
    {
        yield return(www);

        if (www.error == null)
        {
            yield return(www);

            Logger.trace("<< Loading Suits . . .");
            AssetBundle          assetBundle = www.assetBundle;
            UnityEngine.Object[] suits       = assetBundle.LoadAll(typeof(GameObject));
            for (int i = 0; i < suits.Length; i++)
            {
                foreach (Exosuit Suit in GameData.MasterSuitList.Values)
                {
                    if (suits[i].name.Contains(Suit.mSuitFileName))
                    {
                        string             textureName = Suit.mSuitFileName + "_sheet_1";
                        AssetBundleRequest abr         = assetBundle.LoadAsync(textureName, typeof(Material));
                        yield return(abr);

                        GameData.setLowPolySuitIsLoaded(texture: abr.asset as Material, suitId: Suit.mSuitId, model: suits[i] as GameObject);
                    }
                }
            }
            mStatus         += " ... Suits Loaded!";
            mBundleIsLoading = false;
        }
    }
コード例 #5
0
ファイル: ShaderLoader.cs プロジェクト: happylays/tbb2
        public static IEnumerator LoadAllShader(string assetDir, string assetWWWDir, string inAssetDir, string inAssetWWWDir, string assetNetDir)
        {
            string strName = "all.shd";

            if (WWWDownLoaderConfig.CheckResNeedUpdate(strName))
            {
                DownLoadPack downloadPack = WWWDownLoader.InsertDownLoad(strName, assetNetDir + strName, DownLoadAssetType.AssetBundle, null, null, DownLoadOrderType.AfterRunning);
                if (downloadPack != null)
                {
                    while (!downloadPack.AssetReady)
                    {
                        yield return(null);
                    }
                    m_ShaderAsset = downloadPack.Bundle;
                }
                WWWDownLoader.RemoveDownLoad(strName, null);
            }
            else
            {
                IEnumerator itor = LoadAllShader(assetDir, assetWWWDir, inAssetDir, inAssetWWWDir);
                while (itor.MoveNext())
                {
                    yield return(null);
                }
            }

            if (m_ShaderAsset != null)
            {
                m_AllShader = m_ShaderAsset.LoadAll();
            }
            Shader.WarmupAllShaders();
            Messenger.Broadcast(MessangerEventDef.LOAD_ONEASSET_FINISH, MessengerMode.DONT_REQUIRE_LISTENER);
        }
コード例 #6
0
        public override IEnumerator Load()
        {
            SuitAsset Suit       = mInstance.mCurrentLoading as SuitAsset;
            Exosuit   suitToLoad = GameData.getExosuit(Suit.mSuitID);

            myWWW = new WWW(GameData.BUNDLE_PATH + Suit.myFilename);
            // Logger.trace("LoadSuitAsset " + myWWW.url);
            yield return(myWWW);

            if (myWWW.error == null)
            {
                yield return(myWWW);

                if (myWWW == null)
                {
                    Logger.trace("www is null");
                    yield break;
                }
                if (myWWW.assetBundle != null)
                {
                    AssetBundle        assetBundle = myWWW.assetBundle;
                    string             fileName    = suitToLoad.mSuitFileName;
                    AssetBundleRequest abr4        = assetBundle.LoadAsync(fileName + "_" + Suit.mModelType + "_pre", typeof(GameObject));
                    yield return(abr4);

                    GameObject suitModel = abr4.asset as GameObject;
                    if (Suit.mModelType == SuitType.low)
                    {
                        string textureName = fileName + "_sheet_1";
                        abr4 = assetBundle.LoadAsync(textureName, typeof(Material));
                        yield return(abr4);

                        GameData.setLowPolySuitIsLoaded(texture: abr4.asset as Material, suitId: Suit.mSuitID, model: suitModel);
                    }
                    else
                    {
                        object[] arry  = assetBundle.LoadAll();
                        object[] array = arry;
                        foreach (object obj in array)
                        {
                            if (obj is Texture2D)
                            {
                            }
                            abr4 = assetBundle.LoadAsync(fileName + "_mask_1", typeof(Material));
                            yield return(abr4);

                            Material MaskMat = abr4.asset as Material;
                            abr4 = assetBundle.LoadAsync(fileName + "_armor_1", typeof(Material));
                            yield return(abr4);

                            GameData.setHighPolySuitIsLoaded(armor: abr4.asset as Material, suitId: Suit.mSuitID, model: suitModel, mask: MaskMat);
                        }
                    }
                    assetBundle.Unload(unloadAllLoadedObjects: false);
                }
            }
            mInstance.mCurrentLoading = null;
        }
コード例 #7
0
ファイル: AssetLoader.cs プロジェクト: ww386362087/MoyuHero
        IEnumerator DowningEternalBundle(string name, HandleFinishDownLoad finishFun)
        {
            StringBuilder localPath = new StringBuilder();

            localPath.Append(WWW_LOCAL_PATH);
            localPath.Append(name);

            WWW www = new WWW(localPath.ToString());

            while (www.isDone == false)
            {
                yield return(www);
            }

            if (www.error != null)
            {
                LogManager.Log("error = " + www.error);
                LogManager.Log("error when downloading: " + name);
            }

            byte[] decryptedData = AssetManager.Inst.ExecuteDecrypt(name, www.bytes);

            AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData);

            yield return(acr);

            AssetBundle bundle = acr.assetBundle;

            object[] ListSprite = bundle.LoadAll(typeof(UnityEngine.Sprite));
            Sprite   sprite     = null;
            int      size       = ListSprite.Length;

            for (int i = 0; i < size; i++)
            {
                sprite = ListSprite[i] as Sprite;
                if (sprite != null && m_AssetEternalSprite.ContainsKey(sprite.name) == false)
                {
                    m_AssetEternalSprite.Add(sprite.name, sprite);
                    if (m_AssetEternalSprite.Count == m_NeedDownEternalBundle.Count)
                    {
                        isEternalBundleReady = true;
                        GameEventDispatcher.Inst.dispatchEvent(GameEventID.U_EternalSpriteLoaded);
                    }
                }
            }

            bundle.Unload(false);
            www.Dispose();
            if (finishFun != null)
            {
                LogManager.LogToFile("下载完成!!!!!!!!Path:" + localPath.ToString());
                finishFun(www);
            }
            LogManager.LogToFile("下载完成!!!!!!!!Path:" + localPath.ToString());
        }
コード例 #8
0
    // Token: 0x06001139 RID: 4409 RVA: 0x001E7244 File Offset: 0x001E5444
    private void Load(byte ID, byte Level)
    {
        if (this.AssetID != 0)
        {
            AssetManager.UnloadAssetBundle(this.AssetID, true);
        }
        this.tmpAssetName.ClearString();
        byte graphic = this.CastleSkinTable.GetRecordByKey((ushort)ID).Graphic;

        if (graphic > 0)
        {
            this.tmpAssetName.IntToFormat((long)graphic, 3, false);
            this.tmpAssetName.AppendFormat("UI/castle_{0}");
        }
        else
        {
            this.tmpAssetName.IntToFormat((long)graphic, 3, false);
            byte b = 1;
            if (Level >= 9 && Level < 17)
            {
                b = 2;
            }
            else if (Level >= 17 && Level < 25)
            {
                b = 3;
            }
            else if (Level >= 25)
            {
                b = 4;
            }
            this.tmpAssetName.IntToFormat((long)b, 1, false);
            this.tmpAssetName.AppendFormat("UI/castle_{0}-{1}");
        }
        AssetBundle assetBundle = AssetManager.GetAssetBundle(this.tmpAssetName, out this.AssetID);

        this.CastleID = ID;
        this.Level    = Level;
        if (assetBundle == null)
        {
            if (this.AssetID != 0)
            {
                AssetManager.UnloadAssetBundle(this.AssetID, true);
            }
            this.AssetID = 0;
            this.LoadDefault(Level);
            this.sprite   = this.defaultSprite;
            this.material = this.defaultMaterial;
            return;
        }
        UnityEngine.Object[] array = assetBundle.LoadAll();
        this.sprite   = (array[1] as Sprite);
        this.material = (array[3] as Material);
    }
コード例 #9
0
ファイル: AssetLoader.cs プロジェクト: ww386362087/MoyuHero
        IEnumerator DowningEditorBundle(string name, HandleFinishDownLoad finishFun)
        {
            StringBuilder localPath = new StringBuilder();

            localPath.Append(WWW_LOCAL_PATH);
            localPath.Append(name);

            WWW www = new WWW(localPath.ToString());

            while (www.isDone == false)
            {
                yield return(www);
            }

            if (www.error != null)
            {
                LogManager.Log("error = " + www.error);
                LogManager.Log("error when downloading: " + name);
            }
            byte[] decryptedData = AssetManager.Inst.ExecuteDecrypt(name, www.bytes);

            AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData);

            yield return(acr);

            AssetBundle bundle = acr.assetBundle;

            if (bundle == null)
            {
                Debug.LogError("!!!Error: DowningEditorBundle() bundle is null:" + name);
                yield return(1);
            }

            object[]           EditorList = bundle.LoadAll(typeof(UnityEngine.Object));
            UnityEngine.Object go         = null;
            for (int i = 0; i < EditorList.Length; i++)
            {
                go = EditorList[i] as UnityEngine.Object;
                if (go != null && m_EditorAssetDynamicBundle.ContainsKey(go.name) == false)
                {
                    m_EditorAssetDynamicBundle.Add(go.name, go);
                }
            }
            bundle.Unload(false);
            www.Dispose();
            if (finishFun != null)
            {
                LogManager.LogToFile("下载完成!!!!!!!!Path:" + localPath.ToString());
                finishFun(www);
            }
        }
コード例 #10
0
    // Token: 0x0600140F RID: 5135 RVA: 0x002343CC File Offset: 0x002325CC
    public void LoadChallegeFrame()
    {
        if (DataManager.StageDataController._stageMode != StageMode.Dare)
        {
            return;
        }
        CString cstring = StringManager.Instance.StaticString1024();

        cstring.StringToFormat("ChallegeFrame");
        cstring.AppendFormat("UI/{0}");
        AssetBundle assetBundle = AssetManager.GetAssetBundle(cstring, out this.ChallegeAssKey);

        UnityEngine.Object[] array = assetBundle.LoadAll();
        if (assetBundle == null)
        {
            return;
        }
        UnityEngine.Object[] array2 = assetBundle.LoadAll(typeof(Sprite));
        cstring.ClearString();
        cstring.StringToFormat("ChallegeFrame");
        cstring.AppendFormat("{0}_m");
        this._ChallegeMaterial = (assetBundle.Load(cstring.ToString(), typeof(Material)) as Material);
        for (int i = 0; i < array2.Length; i++)
        {
            Sprite sprite = array2[i] as Sprite;
            if (!(sprite == null))
            {
                cstring.ClearString();
                int startIndex = sprite.name.Length - 3;
                Debug.Log(sprite.name.Substring(startIndex));
                int num;
                if (int.TryParse(sprite.name.Substring(startIndex), out num) && num < this.ChallegeFrame.Length)
                {
                    this.ChallegeFrame[num] = sprite;
                }
            }
        }
    }
コード例 #11
0
ファイル: BundleLoadManager.cs プロジェクト: llchaha/SomeTips
 public void unloadBundle(bool guaranteeFutureLoading)
 {
     if (assetBundle)
     {
         isUnloaded = true;
         //如果参数为true则预加载所有资源
         if (guaranteeFutureLoading)
         {
             objects = new List <Object>(assetBundle.LoadAll());
         }
         //卸载AssetBundle(仅Bundle部分)
         DownloadManager.Instance.DisposeBundle(assetBundleName);
     }
 }
コード例 #12
0
    /// <summary>
    /// 加载lua bundle
    /// </summary>
    /// <returns></returns>
    private IEnumerator loadLuaBundle(bool domain, LuaFunction onLoadedFn)
    {
        string keyName = "";
        string luaP    = CUtils.GetAssetFullPath("font.u3d");
        //Debug.Log("load lua bundle" + luaP);
        WWW luaLoader = new WWW(luaP);

        yield return(luaLoader);

        if (luaLoader.error == null)
        {
            byte[]      byts = CryptographHelper.Decrypt(luaLoader.bytes, DESHelper.instance.Key, DESHelper.instance.IV);
            AssetBundle item = AssetBundle.CreateFromMemoryImmediate(byts);

//            item = luaLoader.assetBundle;
#if UNITY_5
            TextAsset[] all = item.LoadAllAssets <TextAsset>();
            foreach (var ass in all)
            {
                keyName = Regex.Replace(ass.name, @"\.", "");
                //Debug.Log("cache : " + keyName);
                luacache[keyName] = ass;
            }
#else
            UnityEngine.Object[] all = item.LoadAll(typeof(TextAsset));
            foreach (var ass in all)
            {
                keyName = Regex.Replace(ass.name, @"\.", "");
                Debug.Log(keyName + " complete");
                luacache[keyName] = ass as TextAsset;
            }
#endif
            //Debug.Log("loaded lua bundle complete" + luaP);
//            luaLoader.assetBundle.Unload(false);
            item.Unload(false);
            luaLoader.Dispose();
        }

        DoUnity3dLua();
        if (domain)
        {
            DoMain();
        }

        if (onLoadedFn != null)
        {
            onLoadedFn.call();
        }
    }
コード例 #13
0
    public void setSfxSoundFromAssetBundle(AssetBundle ab)
    {
        if (ab == null)
        {
            return;
        }

        UnityEngine.Object[] obs = ab.LoadAll(typeof(AudioClip));

        foreach (UnityEngine.Object o in obs)
        {
            _bundleSfxDic.Add(o.name, o as AudioClip);

            _sfxDic.Add(o.name, o as AudioClip);
        }
    }
コード例 #14
0
ファイル: AssetLoader.cs プロジェクト: ww386362087/MoyuHero
        IEnumerator DownloadShopAssedBundle(string name)
        {
            StringBuilder localPath = new StringBuilder();

            localPath.Append(WWW_LOCAL_PATH);
            localPath.Append(name);

            WWW www = new WWW(localPath.ToString());

            while (www.isDone == false)
            {
                yield return(www);
            }

            if (www.error != null)
            {
                LogManager.Log("error = " + www.error);
                LogManager.Log("error when downloading: " + name);
            }

            byte[] decryptedData = AssetManager.Inst.ExecuteDecrypt(name, www.bytes);

            AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData);

            yield return(acr);

            m_ShopAssetList = new List <Sprite>();

            AssetBundle bundle = acr.assetBundle;

            object[] ListSprite = bundle.LoadAll(typeof(UnityEngine.Sprite));
            Sprite   sprite     = null;
            int      size       = ListSprite.Length;

            for (int i = 0; i < size; i++)
            {
                sprite = ListSprite[i] as Sprite;
                if (sprite != null && !m_ShopAssetList.Contains(sprite))
                {
                    m_ShopAssetList.Add(sprite);
                }
            }
            bundle.Unload(false);
            www.Dispose();

            GameEventDispatcher.Inst.dispatchEvent(GameEventID.UI_ShopAdAssetDownload);
        }
コード例 #15
0
ファイル: MyTest.cs プロジェクト: midgithub/AssetBundle
    IEnumerator DownloadAndCache()
    {
        // Wait for the Caching system to be ready
        while (!Caching.ready)
        {
            yield return(null);
        }

        using (WWW www = WWW.LoadFromCacheOrDownload("https://googledrive.com/host/0B0zQPJH0W58oRVpsUXUyUS13OFk/", 1))
        {
            yield return(www);


            if (www.error != null)
            {
                throw new System.Exception("WWW download had an error:" + www.error);
            }

            AssetBundle bundle = www.assetBundle;

            //string AssetName = "pre_cryWolfLogo.prefab";
            string AssetName = "";
            if (AssetName == "")
            {
                //	Instantiate(bundle.mainAsset);
                Object [] objs = bundle.LoadAll();
                foreach (Object ob in objs)
                {
                    System.Type objType = ob.GetType();
                    System.Reflection.PropertyInfo objProperty = objType.GetProperty("name");
                    string objName = "null";
                    if (objProperty != null)
                    {
                        objName = (string)objProperty.GetValue(ob, null);
                    }
                    Debug.Log("Object  Type = " + objType.Name + ", Name=" + objName);
                }
            }
            else
            {
                Instantiate(bundle.Load(AssetName));
            }
            // Unload the AssetBundles compressed contents to conserve memory
            bundle.Unload(false);
        }
    }
コード例 #16
0
    public void loadAllTextureFromBundle(AssetBundle ab)
    {
        if (ab == null)
        {
            return;
        }

        UnityEngine.Object[] obs = ab.LoadAll(typeof(Texture));

        if (obs != null)
        {
            foreach (UnityEngine.Object o in obs)
            {
                _texture[o.name] = (Texture)o;
            }
        }
    }
        /// <summary>
        /// Registers all prefabs in the asset bundle that does have a NetworkView component.
        /// This makes sure they can be instantiated later with
        /// <see cref="O:uLink.Network.Instantiate">uLink.Network.Instantiate</see>
        /// </summary>
        /// <param name="assetBundle">The asset bundle that you want to register its prefabs.</param>
        /// <param name="replaceIfExists">if <c>true</c> then prefabs with the same name will be replaced by the new ones in the asset bundle.</param>
        /// <remarks>
        /// This is a convenience method that calls <see cref="O:uLink.NetworkInstantiator.AddPrefab"/>
        /// for all prefabs in the asset bundle that has a network view component.
        /// <para>
        /// It is common for developers to minimize the download time for the Unity game at startup by putting
        /// some prefabs in asset bundles and then download the asset bundles when needed in the game.
        /// We recommend writing code that downloads the asset bundle, loads the prefabs, registers them with this method,
        /// and finally makes the calls to <see cref="O:uLink.Network.Instantiate">uLink.Network.Instantiate</see>.
        /// If it is an authoritative server the call to <see cref="O:uLink.Network.Instantiate">uLink.Network.Instantiate</see>
        /// has to be done on the server.
        /// </para>
        /// </remarks>
        public static void AddAssetBundle(AssetBundle assetBundle, bool replaceIfExists)
        {
#if UNITY_4
            var prefabs = assetBundle.LoadAll(typeof(GameObject)) as GameObject[];
#else
            var prefabs = assetBundle.LoadAllAssets <GameObject>();
#endif

            foreach (var prefab in prefabs)
            {
                var views = NetworkInstantiatorUtility.GetComponentsInChildren <NetworkView>(prefab.transform);
                if (views.Count != 0)
                {
                    Add(prefab.GetName(), _CreateDefault(prefab, views), replaceIfExists);
                }
            }
        }
コード例 #18
0
    // Token: 0x0600113A RID: 4410 RVA: 0x001E73AC File Offset: 0x001E55AC
    private void LoadDefault(byte Level)
    {
        if (this.defaultSprite != null)
        {
            return;
        }
        byte b = 0;

        this.tmpAssetName.ClearString();
        this.tmpAssetName.IntToFormat((long)b, 3, false);
        byte b2 = 1;

        if (Level >= 9 && Level < 17)
        {
            b2 = 2;
        }
        else if (Level >= 17 && Level < 25)
        {
            b2 = 3;
        }
        else if (Level >= 25)
        {
            b2 = 4;
        }
        this.tmpAssetName.IntToFormat((long)b2, 1, false);
        this.tmpAssetName.AppendFormat("UI/castle_{0}-{1}");
        AssetBundle assetBundle = AssetManager.GetAssetBundle(this.tmpAssetName, out this.AssetID);

        if (assetBundle == null)
        {
            if (this.AssetID != 0)
            {
                AssetManager.UnloadAssetBundle(this.AssetID, true);
            }
            this.AssetID           = 0;
            this.defaultSprite     = GUIManager.Instance.BuildingData.GetBuildSprite(13, 0);
            this.defaultMaterial   = GUIManager.Instance.MapSpriteMaterial;
            this.defaultMaterialUI = GUIManager.Instance.MapSpriteUIMaterial;
            return;
        }
        UnityEngine.Object[] array = assetBundle.LoadAll();
        this.defaultSprite     = (array[1] as Sprite);
        this.defaultMaterial   = (array[3] as Material);
        this.defaultMaterialUI = (array[4] as Material);
    }
コード例 #19
0
    // Use this for initialization
    void Start()
    {
        if (true == m_LoadFromLocal)
        {
            m_Unity3DURL = m_LocalURLTag + m_LocalDirectory + m_LocalAssetBundleName;
        }
        else
        {
            // use m_Unity3DURL as parameter
        }
        Debug.Log(m_Unity3DURL);

        if (0 == m_Unity3DURL.Length)
        {
            return;
        }


        WWW download = WWW.LoadFromCacheOrDownload(m_Unity3DURL, 0);

        if (null == download)
        {
            Debug.LogError("null == download");
        }
        else
        {
            // Try mark this line
            m_AssetBundle = download.assetBundle;

            if (null == m_AssetBundle)
            {
                Debug.Log("null == assetBundle");
            }
            else
            {
                Debug.Log("null != assetBundle");
                Object[] objs = m_AssetBundle.LoadAll();
                Debug.Log("objNumbers" + objs.Length);
                foreach (Object obj in objs)
                {
                    Debug.Log(obj.name);
                }
            }
        }
    }
コード例 #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="bundle"></param>
 internal void SetAssetBundle(AssetBundle bundle)
 {
     m_bundle = bundle;
     if (bundle == null)
     {
         throw new System.NullReferenceException("Asset " + m_Parameter.Path + " Is Null!");
     }
     Object[] tem = m_bundle.LoadAll();
     foreach (Object o in tem)
     {
         objects.Add(o);
     }
     if (m_Parameter.UnFile)
     {
         m_bundle.Unload(false);
     }
     m_AssetManager.CompleteLoad(this);
 }
コード例 #21
0
        public IEnumerator LoadAsset()
        {
            WWW www = WWW.LoadFromCacheOrDownload(WorldEditor.AssetPath, 1);

            yield return(www);

            if (www.error != null)
            {
                RustBuster2016.API.Hooks.LogData("WorldEditor", "www: " + www.error);
                //return;
            }
            bundle = www.assetBundle;
            www.Dispose();
            ourobject = new GameObject();
            Spawner   = ourobject.AddComponent <LoadObjectFromBundle>();
            UnityEngine.Object.DontDestroyOnLoad(ourobject);

            foreach (UnityEngine.Object item in bundle.LoadAll())
            {
                if (item.name.ToLower().Contains("mat") || item.name.ToLower().Contains("avatar") || item.name.ToLower().Contains("img"))
                {
                    continue;
                }
                GameObject           go = new GameObject();
                LoadObjectFromBundle lo = go.AddComponent <LoadObjectFromBundle>();
                // Test if we can create the object. If not, it's probably not a prefab so we don't need it.
                bool b = lo.Create(item.name, new Vector3(0, 0, 0), new Quaternion(0, 0, 0, 0), new Vector3(1, 1, 1));
                if (!b)
                {
                    UnityEngine.Object.Destroy(go);
                    continue;
                }
                UnityEngine.Object.Destroy(lo.ObjectInstantiate);
                UnityEngine.Object.Destroy(go);

                if (!WorldEditor.Instance.Prefabs.Contains(item.name))
                {
                    WorldEditor.Instance.Prefabs.Add(item.name);
                }
            }

            LoadAllSetObjects();
            WorldEditor.Instance.Editor = WorldEditor.Instance.MainHolder.AddComponent <Editor>();
        }
コード例 #22
0
    private IEnumerator WaitForWeaponsRequest(WWW www)
    {
        yield return(www);

        if (www.error == null)
        {
            yield return(www);

            AssetBundle          assetBundle  = www.assetBundle;
            UnityEngine.Object[] weaponsArray = assetBundle.LoadAll(typeof(GameObject));
            for (int i = 0; i < weaponsArray.Length; i++)
            {
                Logger.trace("<< Weapon Loaded: " + weaponsArray[i].name);
                GameData.Weapons.Add(weaponsArray[i] as GameObject);
            }
            mStatus         += " ... Weapons Loaded!";
            mBundleIsLoading = false;
        }
    }
コード例 #23
0
    private IEnumerator loadItem(string asset)
    {
        WWW www = new WWW(asset);

        yield return(www);

        AssetBundle bundle = www.assetBundle;

        Debug.Log(bundle.GetHashCode());

        Object[] objs = bundle.LoadAll();

        foreach (Object obj in objs)
        {
            Debug.Log(obj.GetHashCode());
        }
        //SingleStringHolder holder = bundle.mainAsset as SingleStringHolder;
        Debug.Log(true);
    }
コード例 #24
0
ファイル: FileHelper.cs プロジェクト: zuojiashun/hugula
        /// <summary>
        ///
        /// </summary>
        /// <param name="ab"></param>
        /// <param name="luaFn"></param>
        public static void UnpackConfigAssetBundleFn(AssetBundle ab, LuaFunction luaFn)
        {
            callBackFn = luaFn;
#if UNITY_5
            UnityEngine.Object[] all = ab.LoadAllAssets();
#else
            UnityEngine.Object[] all = ab.LoadAll();
#endif
            foreach (UnityEngine.Object i in all)
            {
                if (i is TextAsset)
                {
                    TextAsset a = (TextAsset)i;
                    if (callBackFn != null)
                    {
                        callBackFn.call(a.name, a.text);
                    }
                }
            }
        }
コード例 #25
0
    static void LoadLocalBundle()
    {
        if (!EditorApplication.isPlaying)
        {
            return;
        }

        AssetBundle bundle = AssetBundle.CreateFromFile("test.assetbundle");

        Object[] objs = bundle.LoadAll();
        foreach (Object obj in objs)
        {
            GameObject go = obj as GameObject;
            if (go)
            {
                Debug.Log(go.name);
                Instantiate(go);
            }
            //Instantiate(obj);
        }
    }
コード例 #26
0
ファイル: LuaHelper.cs プロジェクト: beasonshu/hugula
    /// <summary>
    /// 刷新shader
    /// </summary>
    /// <param name="assetBundle"></param>
    public static void RefreshShader(AssetBundle assetBundle)
    {
#if UNITY_5
        UnityEngine.Material[] materials = assetBundle.LoadAllAssets <Material>();
#else
        UnityEngine.Object[] materials = assetBundle.LoadAll(typeof(Material));  //LoadAll<Material>();
#endif
        foreach (UnityEngine.Object m in materials)
        {
            Material mat        = m as Material;
            string   shaderName = mat.shader.name;
            Shader   newShader  = Shader.Find(shaderName);
            if (newShader != null)
            {
                mat.shader = newShader;
            }
            else
            {
                Debug.LogWarning("unable to refresh shader: " + shaderName + " in material " + m.name);
            }
        }
    }
コード例 #27
0
    private static int LoadAll(IntPtr L)
    {
        int num = LuaDLL.lua_gettop(L);

        if (num == 1)
        {
            AssetBundle          assetBundle = (AssetBundle)LuaScriptMgr.GetUnityObjectSelf(L, 1, "AssetBundle");
            UnityEngine.Object[] o           = assetBundle.LoadAll();
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }
        if (num == 2)
        {
            AssetBundle          assetBundle2 = (AssetBundle)LuaScriptMgr.GetUnityObjectSelf(L, 1, "AssetBundle");
            Type                 typeObject   = LuaScriptMgr.GetTypeObject(L, 2);
            UnityEngine.Object[] o2           = assetBundle2.LoadAll(typeObject);
            LuaScriptMgr.PushArray(L, o2);
            return(1);
        }
        LuaDLL.luaL_error(L, "invalid arguments to method: AssetBundle.LoadAll");
        return(0);
    }
コード例 #28
0
    public static int LoadAll(IntPtr l)
    {
        int result;

        try
        {
            int num = LuaDLL.pua_gettop(l);
            if (num == 1)
            {
                AssetBundle          assetBundle = (AssetBundle)LuaObject.checkSelf(l);
                UnityEngine.Object[] a           = assetBundle.LoadAll();
                LuaObject.pushValue(l, true);
                LuaObject.pushValue(l, a);
                result = 2;
            }
            else if (num == 2)
            {
                AssetBundle assetBundle2 = (AssetBundle)LuaObject.checkSelf(l);
                Type        type;
                LuaObject.checkType(l, 2, out type);
                UnityEngine.Object[] a2 = assetBundle2.LoadAll(type);
                LuaObject.pushValue(l, true);
                LuaObject.pushValue(l, a2);
                result = 2;
            }
            else
            {
                LuaObject.pushValue(l, false);
                LuaDLL.pua_pushstring(l, "No matched override function to call");
                result = 2;
            }
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
コード例 #29
0
        public IEnumerator LoadAsset()
        {
            WWW www = WWW.LoadFromCacheOrDownload(WorldEditorServer.AssetPath, 1);

            yield return(www);

            if (www.error != null)
            {
                Logger.LogError("[WorldEditorServer] Failure to load www: " + www.error);
            }
            bundle = www.assetBundle;
            www.Dispose();
            ourobject = new GameObject();
            Spawner   = ourobject.AddComponent <LoadObjectFromBundle>();
            UnityEngine.Object.DontDestroyOnLoad(ourobject);

            foreach (UnityEngine.Object item in bundle.LoadAll())
            {
            }

            LoadAllSetObjects();
            bundle.Unload(false);
        }
コード例 #30
0
    private static int LoadAll(IntPtr L)
    {
        switch (LuaDLL.lua_gettop(L))
        {
        case 1:
        {
            UnityEngine.Object[] o = ((AssetBundle)LuaScriptMgr.GetUnityObjectSelf(L, 1, "AssetBundle")).LoadAll();
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }

        case 2:
        {
            AssetBundle          bundle2    = (AssetBundle)LuaScriptMgr.GetUnityObjectSelf(L, 1, "AssetBundle");
            System.Type          typeObject = LuaScriptMgr.GetTypeObject(L, 2);
            UnityEngine.Object[] objArray2  = bundle2.LoadAll(typeObject);
            LuaScriptMgr.PushArray(L, objArray2);
            return(1);
        }
        }
        LuaDLL.luaL_error(L, "invalid arguments to method: AssetBundle.LoadAll");
        return(0);
    }
コード例 #31
0
ファイル: LuaHelper.cs プロジェクト: FlameskyDexive/hugula
    /// <summary>
    /// 刷新shader
    /// </summary>
    /// <param name="assetBundle"></param>
    public static void RefreshShader(AssetBundle assetBundle)
    {
        #if UNITY_5
        UnityEngine.Material[] materials = assetBundle.LoadAllAssets<Material>();

        #else
        UnityEngine.Object[] materials = assetBundle.LoadAll(typeof(Material));  //LoadAll<Material>();
        #endif

        //foreach (UnityEngine.Object m in materials)
        for(int i = 0;i<materials.Length;i++)
        {
            Material mat = materials[i];
            string shaderName = mat.shader.name;
            Shader newShader = Shader.Find(shaderName);
            if (newShader != null)
            {
                mat.shader = newShader;
            }
            else
            {
                Debug.LogWarning("unable to refresh shader: " + shaderName + " in material " + mat.name);
            }
        }
    }