Exemple #1
0
    private void LoadCastleConnection()
    {
        AssetBundle ab = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "castle_connect"));

        if (ab == null)
        {
            Debug.LogError("ab==null");
            return;
        }

        string[] totalName         = ab.GetAllAssetNames();
        CastleConnectionTotal data = (CastleConnectionTotal)ab.LoadAsset(totalName[0]);

        m_CM.m_TotalCastleConnect = data;
        SetDataToStatic(data.m_TotalData);
    }
Exemple #2
0
        public override void success(AssetBundle assetBundle)
        {
            // do not Unload here

            if (assetBundle.isStreamedSceneAssetBundle)
            {
                return;
            }

            foreach (string name in assetBundle.GetAllAssetNames())
            {
                Object     obj  = assetBundle.LoadAsset(name);
                GameObject gobj = Instantiate(obj) as GameObject;
                gobj.transform.SetParent(this.transform, false);
            }
        }
Exemple #3
0
 // 记录bundle里的资源路径,在Editor+Develop模式时可以直接从路径加载文件
 private void GetAssetPathFromBundle(AssetBundle bundle)
 {
     if (ezApplication.runMode == RunMode.Develop)
     {
         foreach (string filePath in bundle.GetAllAssetNames())
         {
             string assetName = Path.GetFileNameWithoutExtension(filePath);
             assetPathDict[GetAssetKey(bundle.name, assetName)] = filePath;
         }
         foreach (string scenePath in bundle.GetAllScenePaths())
         {
             string sceneName = Path.GetFileNameWithoutExtension(scenePath);
             assetPathDict[GetAssetKey(bundle.name, sceneName)] = scenePath;
         }
     }
 }
Exemple #4
0
    public void InitByAssetBundle(AssetBundle ab)
    {
        Debug.LogWarning(">>>>>> InitByAssetBundle =  " + assetBundlePath + " " + ab);

        assetBundle = ab;

        LightmapData data = tempMapDatas[index];

        String[] allAssetNames = assetBundle.GetAllAssetNames();

        if (allAssetNames.Length == 1)
        {
            texture2DlightmapLight = assetBundle.LoadAsset(allAssetNames[0]) as Texture2D;
            data.lightmapColor     = texture2DlightmapLight;
        }
        else
        if (allAssetNames.Length == 2)
        {
            texture2DlightmapColor = assetBundle.LoadAsset(allAssetNames[0]) as Texture2D;
            texture2DlightmapDir   = assetBundle.LoadAsset(allAssetNames[1]) as Texture2D;

            //LightmapData data = new LightmapData();
            data.lightmapColor = texture2DlightmapColor;
            data.lightmapDir   = texture2DlightmapDir;
        }

        if (LightmapSettings.lightmaps == null || LightmapSettings.lightmaps.Length == 0)
        {
            //LightmapData[] tempMapDatas = new LightmapData[count];
            //LightmapSettings.lightmaps = tempMapDatas;
        }

        // tempMapDatas[index] = data;
        LightmapSettings.lightmaps = tempMapDatas;
        //LightmapSettings.lightmaps[index] = data;

        Renderer tempRenderer = GetComponent <Renderer>();

        tempRenderer.lightmapIndex       = index;
        tempRenderer.lightmapScaleOffset = scaleOffset;

        if (LightmapSettings.lightmapsMode != LightmapsMode.NonDirectional)
        {
            //设置原来烘焙时的光照模式,这个不设置正确,默认模式就会只显示光照贴图
            LightmapSettings.lightmapsMode = LightmapsMode.NonDirectional;
        }
    }
Exemple #5
0
        // Loads all the source code found in bundle as Text Assets & adds to Sources list
        private bool LoadSourceCodeFromModBundle()
        {
            try
            {
                if (sources == null)
                {
                    sources = new List <Source>();
                }

                foreach (string assetName in AssetBundle.GetAllAssetNames())
                {
                    bool isSource      = false;
                    bool isPrecompiled = false;

                    if (assetName.EndsWith(".cs.txt", StringComparison.Ordinal))
                    {
                        isSource      = true;
                        isPrecompiled = false;
                    }
                    else if (assetName.EndsWith(".dll.bytes", StringComparison.Ordinal))
                    {
                        isSource      = true;
                        isPrecompiled = true;
                    }

                    if (isSource)
                    {
                        var newSource = GetAsset <TextAsset>(assetName);
                        if (newSource)
                        {
                            sources.Add(new Source()
                            {
                                sourceTxt     = newSource,
                                isPreCompiled = isPrecompiled
                            });
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Debug.LogError(ex.Message);
                return(false);
            }
        }
Exemple #6
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);
		}
Exemple #7
0
        /// <summary>
        /// Returns the bundle at the specified path, loading it if neccessary.
        /// Unloads previously loaded bundles if neccessary when dealing with variants.
        /// </summary>
        /// <returns>Returns the loaded bundle, null if it could not be loaded.</returns>
        /// <param name="path">Path of bundle to get</param>
        private AssetBundle LoadBundle(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            string bundleName = Path.GetFileNameWithoutExtension(path);

            // Check if we have a record for this bundle
            AssetBundleRecord record = this.GetLoadedBundleRecordByName(bundleName);
            AssetBundle       bundle = null;

            if (null != record)
            {
                // Unload existing bundle if variant names differ, otherwise use existing bundle
                if (!record.path.Equals(path))
                {
                    this.UnloadBundle(bundleName);
                }
                else
                {
                    bundle = record.bundle;
                }
            }

            if (null == bundle)
            {
                // Load the bundle
                bundle = AssetBundle.LoadFromFile(path);
                if (null == bundle)
                {
                    return(null);
                }

                m_loadedAssetBundles[bundleName] = new AssetBundleRecord(path, bundle);

                // Load the bundle's assets
                string[] assetNames = bundle.GetAllAssetNames();
                foreach (string name in assetNames)
                {
                    bundle.LoadAsset(name);
                }
            }

            return(bundle);
        }
        private void CachePaths()
        {
            m_fileStructure = new Dictionary <string, List <string> >();
            m_cachedEntries = new Dictionary <string, Object>();

            foreach (var entry in RefAssetBundle.GetAllAssetNames())
            {
                var fullpath = entry.Replace('/', Path.DirectorySeparatorChar);

                var assetsString = $"assets{Path.DirectorySeparatorChar}";
                if (fullpath.StartsWith(assetsString))
                {
                    fullpath = fullpath.Substring(assetsString.Length, fullpath.Length - assetsString.Length);
                }

                //SL.Log("Caching entry " + fullpath);

                var obj = RefAssetBundle.LoadAsset(entry);

                m_cachedEntries.Add(fullpath, obj);

                var splitPath = fullpath.Split(Path.DirectorySeparatorChar);

                string key = "";
                if (splitPath.Length > 1)
                {
                    for (int i = 0; i < splitPath.Length - 1; i++)
                    {
                        if (!string.IsNullOrEmpty(key))
                        {
                            key += Path.DirectorySeparatorChar;
                        }

                        key += splitPath[i];
                    }
                }

                if (!m_fileStructure.ContainsKey(key))
                {
                    m_fileStructure.Add(key, new List <string>());
                }

                m_fileStructure[key].Add(Path.GetFileName(fullpath));

                //SL.Log($"added to file structure under directory '{key}', file '{Path.GetFileName(fullpath)}'");
            }
        }
        internal static void LoadShaderBundles()
        {
            string bundleFileName;

            switch (Application.platform)
            {
            case RuntimePlatform.OSXPlayer:
                bundleFileName = "kkshaders.osx";
                break;

            case RuntimePlatform.LinuxPlayer:
                bundleFileName = "kkshaders.osx";
                break;

            default:
                bundleFileName = "kkshaders.windows";
                break;
            }
            string bundlePath = KSPUtil.ApplicationRootPath + "GameData/KerbalKonstructs/Shaders/" + bundleFileName;

            AssetBundle shadersBundle = null;

            try
            {
                shadersBundle = AssetBundle.LoadFromFile(bundlePath);
                if (shadersBundle == null)
                {
                    Log.Normal("Failed to load shader asset file: " + bundlePath);
                    return;
                }
                foreach (string shadername in shadersBundle.GetAllAssetNames())
                {
                    LoadAndRegisterShader(shadersBundle, shadername);
                }
            }
            catch (System.Exception exeption)
            {
                Log.Error("Error loading Shader assetbundle " + exeption);
            }
            finally
            {
                if (shadersBundle != null)
                {
                    shadersBundle.Unload(false);
                }
            }
        }
Exemple #10
0
        public override IEnumerator Load(UrlDir.UrlFile urlFile, FileInfo file)
        {
            // KSP-PartTools built AssetBunldes are in the Web format,
            // and must be loaded using a WWW reference; you cannot use the
            // AssetBundle.CreateFromFile/LoadFromFile methods unless you
            // manually compiled your bundles for stand-alone use
            string path = urlFile.fullPath.Replace('\\', '/');
            WWW    www  = CreateWWW(path);

            //not sure why the yield statement here, have not investigated removing it.
            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                MonoBehaviour.print("Error while loading AssetBundle model: " + www.error + " for url: " + urlFile.url + " :: " + path);
                yield break;
            }
            else if (www.assetBundle == null)
            {
                MonoBehaviour.print("Could not load AssetBundle from WWW - " + www);
                yield break;
            }

            AssetBundle bundle = www.assetBundle;

            //TODO clean up linq
            string             modelName = bundle.GetAllAssetNames().FirstOrDefault(assetName => assetName.EndsWith("prefab"));
            AssetBundleRequest abr       = bundle.LoadAssetAsync <GameObject>(modelName);

            while (!abr.isDone)
            {
                yield return(abr);
            }                      //continue to yield until the asset load has returned from the loading thread
            if (abr.asset == null) //if abr.isDone==true and asset is null, there was a major error somewhere, likely file-system related
            {
                MonoBehaviour.print("ERROR: Failed to load model from asset bundle!");
                yield break;
            }
            GameObject model = GameObject.Instantiate((GameObject)abr.asset);//make a copy of the asset

            //modelDebugOutput(model);
            setupModelTextures(urlFile.root, model);
            this.obj        = model;
            this.successful = true;
            //this unloads the compressed assets inside the bundle, but leaves any instantiated models in-place
            bundle.Unload(false);
        }
Exemple #11
0
        private static void SetLoaderReady(LoaderInfo loaderInfo, AssetBundle assetBundle)
        {
            var loadedAsset = assetBundle.LoadAsset <GameObject>(loaderInfo.objectName);

            if (loadedAsset == null)
            {
                var sb = new StringBuilder();
                foreach (var asset in assetBundle.GetAllAssetNames())
                {
                    sb.AppendLine(asset);
                }
                Log("Failed to load asset. Does the asset(", loaderInfo.objectName, ") exist in the specified bundle(", loaderInfo.path, ") ? But found:", sb.ToString());
                return;
            }
            loaderInfo.onAssetLoaded(loadedAsset);
            loaderInfo.isReady = true;
        }
Exemple #12
0
        /// <summary>
        /// 添加资源包
        /// </summary>
        /// <param name="path"></param>
        /// <param name="bundle"></param>
        public void Add(string path, AssetBundle bundle)
        {
            if (string.IsNullOrEmpty(path) || bundle == null)
            {
                return;
            }
            _assetBundles[path] = bundle;

            string[] assetNames = bundle.GetAllAssetNames();
            if (assetNames != null && assetNames.Length > 0)
            {
                for (var i = 0; i < assetNames.Length; i++)
                {
                    _assetPaths[assetNames[i]] = path;
                }
            }
        }
        private static IEnumerable <string> EnumerateIcons(AssetBundle editorAssetBundle, string iconsPath)
        {
            foreach (var assetName in editorAssetBundle.GetAllAssetNames())
            {
                if (assetName.StartsWith(iconsPath, StringComparison.OrdinalIgnoreCase) == false)
                {
                    continue;
                }
                if (assetName.EndsWith(".png", StringComparison.OrdinalIgnoreCase) == false &&
                    assetName.EndsWith(".asset", StringComparison.OrdinalIgnoreCase) == false)
                {
                    continue;
                }

                yield return(assetName);
            }
        }
Exemple #14
0
    public static void ReadNewPalOlAb()
    {
        string      bundlePath = AssetDatabase.GetAssetPath(Selection.activeObject);
        AssetBundle bundle     = AssetBundle.LoadFromFile(bundlePath);

        if (bundle == null)
        {
            Debug.LogError("Can not find bundle " + bundlePath);
        }
        var list = bundle.GetAllAssetNames();

        foreach (var item in list)
        {
            Debug.Log(item);
        }
        bundle.Unload(true);
    }
        protected void AsyncLoadModelCallBack(object context, AssetBundle asset)
        {
            _3dObj = Object.Instantiate(asset.LoadAsset(asset.GetAllAssetNames()[0])) as GameObject;
            if (_3dObj == null)
            {
                return;
            }

            // GameObjectEntity 需要先false,再true 才有效果
            // GameObjectEntity 才会进入EntityManager
            _3dObj.SetActive(false);

            Transform transform = _3dObj.GetComponent <Transform>();

            transform.position = _position;
            transform.Rotate(0, 0, 0);
            transform.localScale = new Vector3(1, 1, 1);

            _3dObj.AddComponent <GameObjectEntity>();
            var moveComponent = _3dObj.AddComponent <MoveComponent>();

            moveComponent.AttachRole(this);

            var roleComponent = _3dObj.AddComponent <RoleUpdateComponent>();

            roleComponent.AttachRole(this);

            _3dObj.SetActive(true);

            if (_sn == GameMain.GetInstance().MainPlayer.Sn)
            {
                GameMain.GetInstance().MainPlayer.SetGameObject(_3dObj);
                _3dObj.name = "MainPlayer";
                Object.DontDestroyOnLoad(_3dObj);

                CameraFollowBehaviour cTrack = Camera.main.gameObject.GetComponent <CameraFollowBehaviour>();
                if (cTrack != null)
                {
                    cTrack.Target = _3dObj.GetComponent <Transform>();
                }
            }
            else
            {
                _3dObj.name = "Sync_" + _name;
            }
        }
    public void CheckABInfo(AssetBundle ab, string abName)
    {
        EditorSettings.serializationMode = SerializationMode.ForceText;
        string[] names        = ab.GetAllAssetNames();
        string[] dependencies = AssetDatabase.GetDependencies(names);
        string[] allDepen     = dependencies.Length > 0 ? dependencies : names;
        Dictionary <string, UnityEngine.Object> assetMap = new Dictionary <string, UnityEngine.Object>();

        for (int i = 0; i < allDepen.Length; ++i)
        {
            UnityEngine.Object obj = ab.LoadAsset(allDepen[i]);
            if (obj != null && assetTypeList.Contains(obj.GetType()))
            {
                TryAddAssetToMap(obj.name, allDepen[i], abName, GetObjectType(obj));
            }
        }
    }
        /// <summary>
        /// 加载图集资源,仅支持 unity atlas方案
        /// </summary>
        /// <param name="texName"></param>
        /// <returns></returns>
        public Object LoadTextureFormAtlas(string texName)
        {
            //默认一个ab中只有一个atlas,
            var allAssetNames = AssetBundle.GetAllAssetNames();
            var atlas         = this.AssetBundle.LoadAsset <SpriteAtlas>(allAssetNames.Last());

            if (atlas)
            {
                texName = Path.GetFileName(texName);
                var sp = atlas.GetSprite(texName);
                return(sp);
            }
            else
            {
                return(null);
            }
        }
Exemple #18
0
        public static ContentManifest GetContentManifestFromAssetBundle(AssetBundle assetBundle)
        {
            string[]        allAssetNames = assetBundle.GetAllAssetNames();
            ContentManifest result        = null;

            for (int i = 0; i < allAssetNames.Length; i++)
            {
                string fileName = Path.GetFileName(allAssetNames[i]);
                if (string.Equals(fileName, "ContentManifest.txt", StringComparison.OrdinalIgnoreCase))
                {
                    TextAsset textAsset = assetBundle.LoadAsset <TextAsset>(allAssetNames[i]);
                    result = new ContentManifest(textAsset);
                    break;
                }
            }
            return(result);
        }
        void CheckAssetBundle(AssetBundle assetBundle, string assetsUri)
        {
            if (assetBundle == null)
            {
                HandleCheckError("AssetBundle with URI '" + assetsUri + "' could not be loaded");
            }
#if (DEBUG)
            else
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "Mod Assets URI: " + assetsUri);
                foreach (string asset in assetBundle.GetAllAssetNames())
                {
                    DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "Asset: " + asset);
                }
            }
#endif
        }
    /// <summary>
    /// 读取Lua热更文件
    /// </summary>
    /// <returns></returns>
    IEnumerator LoadLuaFile()
    {
        string path = "file://" + string.Format(Application.persistentDataPath + "/Assetbundle/lua.unity3d");;
        WWW    www  = new WWW(path);

        yield return(www);

        AssetBundle luaAsset = www.assetBundle;

        foreach (string name in luaAsset.GetAllAssetNames())
        {
            Debug.LogWarning(">>>>>>>>>>>>>>Name = " + name);
        }
        LuaFileUtils.Instance.AddSearchBundle(luaAsset.name, luaAsset);

        LuaMain();
    }
Exemple #21
0
    public T LoadResource <T>(string resourceName) where T : Object
    {
        string assetBundleName = resourceName + ".unity3d";

        AssetBundle resAssetBundle = null;

        if (!m_LoadAssetBundleDict.TryGetValue(assetBundleName, out resAssetBundle))
        {
            //加载依赖
            string[] dependences = m_AssetBundleManifest.GetAllDependencies(assetBundleName);
            for (int i = 0; i < dependences.Length; i++)
            {
                string dependenceName = dependences[i];

                LoadAssetBundle(dependenceName);
            }

            //加载ab
            resAssetBundle = LoadAssetBundle(assetBundleName);
        }

        if (resAssetBundle != null)
        {
            resourceName = resourceName.ToLower();

            string[] assetBundleNames = resAssetBundle.GetAllAssetNames();
            for (int index = 0; index < assetBundleNames.Length; index++)
            {
                string assetBunldNameWithoutExtension = assetBundleNames[index];
                int    extensionIndex = assetBunldNameWithoutExtension.LastIndexOf('.');
                if (extensionIndex != -1)
                {
                    assetBunldNameWithoutExtension = assetBunldNameWithoutExtension.Substring(0, extensionIndex);
                }

                if (assetBunldNameWithoutExtension.EndsWith(resourceName))
                {
                    //实例化
                    T instance = resAssetBundle.LoadAsset <T>(assetBundleNames[index]);
                    return(instance);
                }
            }
        }

        return(null);
    }
Exemple #22
0
    public static void hackAB()
    {
        if (ab != null)
        {
            releaseAB();
        }
        string str = EditorUtility.OpenFilePanel("open", "/", "");

        try
        {
            ab = AssetBundle.LoadFromFile(str);
            Debug.LogError(ab.GetAllAssetNames());
            Object[] os = ab.LoadAllAssets();
            foreach (Object go in os)
            {
                Debug.Log(go);
                if (go is GameObject)
                {
                    GameObject m = GameObject.Instantiate(go, null) as GameObject;
                    m.name += "_x";
                    PrefabUtility.CreatePrefab("Assets/00/" + m.name + ".prefab", m);
                }
                else if (go is Material)
                {
                    Material m = new Material(go as Material);
                    m.name += "_x";
                    AssetDatabase.CreateAsset(m, "Assets/" + m.name + ".mat");
                }
                else if (go is AnimationClip)
                {
                    AnimationClip m = go as AnimationClip;
                    m.name += "_x";
                    AssetDatabase.AddObjectToAsset(m, "Assets/" + m.name + ".anim");
                }
            }
        }
        catch (System.Exception e)
        {
            if (ab != null)
            {
                releaseAB();
            }
            Debug.LogError(e.ToString());
        }
    }
Exemple #23
0
 public override T Get <T>()
 {
     if (mAB == null || FileName.IsEmptyOrNull())
     {
         return(null);
     }
     if (typeof(T) == typeof(AssetBundle))
     {
         return(mAB as T);
     }
     FileName = FileName.ToLower();
     string[] assetsNames = mAB.GetAllAssetNames();
     for (int i = 0; i < assetsNames.Length; i++)
     {
         if (IsContains(assetsNames[i], FileName))
         {
             LogIColor("Get:{0}", LogColor.Green, assetsNames[i]);
             string strVal = assetsNames[i].Substring(assetsNames[i].IndexOf(FileName));
             string check  = assetsNames[i].Substring(0, assetsNames[i].IndexOf(FileName));
             int    iIdx   = strVal.LastIndexOf(".");
             if (-1 != iIdx)
             {
                 strVal = strVal.Substring(0, iIdx);
             }
             if (strVal == FileName && (check.IsEmptyOrNull() || check.EndsWith("/")))
             {
                 if (typeof(T) == typeof(GameObject))
                 {
                     var kObj = GameObject.Instantiate(mAB.LoadAsset <T>(assetsNames[i]));
                     if (kObj != null)
                     {
                         kObj.name = kObj.name.Replace("(Clone)", "");
                     }
                     return(kObj);
                 }
                 else
                 {
                     return(mAB.LoadAsset <T>(assetsNames[i]));
                 }
             }
         }
     }
     Log.E("No Get:{0}", FileName);
     return(null);
 }
    // Use this for initialization
    void Start()
    {
        string currentTestFolder = "TestLoadDependedAssetBundle/";
        string mainManifestName  = currentTestFolder.Trim('/');

        //AssetImporter assetA = AssetImporter.GetAtPath(AssetResourceRootPath + currentTestFolder + "A.prefab");
        Asset assetA = new Asset {
            assetBundleName = "a_testloaddependedassetbundle"
        };
        UICamera uiCamera = GameObject.FindObjectOfType <UICamera>();



        AssetBundle mainManifestAssetBundle = AssetBundle.LoadFromFile(BundleOutputRootPath + currentTestFolder + mainManifestName);
        // Note: must assign "AssetBundleManifest"
        AssetBundleManifest mainManifest = mainManifestAssetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");

        mainManifestAssetBundle.Unload(false);

        AssetBundle assetABundle = AssetBundle.LoadFromFile(BundleOutputRootPath + currentTestFolder + assetA.assetBundleName);

        foreach (string name in assetABundle.GetAllAssetNames())
        {
            GameObject gameObj = assetABundle.LoadAsset(name) as GameObject;
            NGUITools.AddChild(uiCamera.gameObject, gameObj);
            Debug.Log("assetABundle.LoadAsset " + assetABundle.LoadAsset(name));
        }
        assetABundle.Unload(false);

        // just load depended asset bundle, don't need assign, and don't care order
        int loaded = 0;

        foreach (string name in mainManifest.GetAllDependencies(assetA.assetBundleName))
        {
            AssetBundle dependedAssetBundle = AssetBundle.LoadFromFile(BundleOutputRootPath + currentTestFolder + name);
            // Note: if want to do unload bundle, must do LoadAllAssets
            dependedAssetBundle.LoadAllAssets();
            dependedAssetBundle.Unload(false);
            // can't do unload, or mapping will lose
            if (loaded++ > 0)
            {
                break;
            }
        }
    }
Exemple #25
0
    IEnumerator webReq(string urlLink)
    {
        if (anim == 1)
        {
            anim = 0;
        }
        if (urlLink == "https://drive.google.com/uc?export=download&id=1udOxYcO_IlJigSNC-s38kCFl946z-pUF")
        {
            anim      = 1;
            offset    = 0.5f;
            offsetRot = 5;
        }
        UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(urlLink);

        yield return(www.SendWebRequest());

        if (www.isNetworkError)
        {
            Debug.Log("Network error");
        }
        else
        {
            AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
            if (bundle != null)
            {
                if (go != null)
                {
                    go.SetActive(false);
                }
                string rootAssetPath = bundle.GetAllAssetNames()[0];
                Debug.Log("numele fisier" + rootAssetPath);
                m_RegionPrefab = (GameObject)bundle.LoadAsset(rootAssetPath);
                go             = Instantiate(m_RegionPrefab, m_SessionOrigin.trackablesParent);
                bundle.Unload(false);
                go.SetActive(true);
                rotatiedefault = m_RegionPrefab.transform.localRotation;
                pozitiedefault = m_RegionPrefab.transform.localPosition;
                flag           = 1 - flag;
            }
            else
            {
                Debug.LogError("Not a valid asset bundle");
            }
        }
    }
Exemple #26
0
        public static AssetBundle LoadAssetBundle(string name)
        {
            Assembly    assembly = Assembly.GetCallingAssembly();
            AssetBundle ab       = AssetBundle.LoadFromStream(assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{name}"));

#if DEBUG
            foreach (var s in assembly.GetManifestResourceNames())
            {
                Plugin.Log.LogInfo("Resource: " + s);
            }
            foreach (var s in ab.GetAllAssetNames())
            {
                Plugin.Log.LogInfo("Asset in bundle: " + s);
            }
#endif

            return(ab);
        }
Exemple #27
0
 public static void PrintAssets(string name)
 {
     try
     {
         WWW         iteratorVariable0 = new WWW("file:///" + Application.dataPath + name);
         AssetBundle iteratorVariable1 = iteratorVariable0.assetBundle;
         string[]    names             = iteratorVariable1.GetAllAssetNames();
         for (int i = 0; i < names.Length; i++)
         {
             Debug.Log(names[i]);
         }
         iteratorVariable1.Unload(true);
     }
     catch (System.Exception ex)
     {
         Debug.Log(ex.ToString());
     }
 }
    public static int GetAllAssetNames(IntPtr l)
    {
        int result;

        try
        {
            AssetBundle assetBundle   = (AssetBundle)LuaObject.checkSelf(l);
            string[]    allAssetNames = assetBundle.GetAllAssetNames();
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, allAssetNames);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Exemple #29
0
    IEnumerator LoadAssetsFromBundle(AssetBundle assetBundle)
    {
        var bundleAssets = assetBundle.GetAllAssetNames();
        var assetQueue   = new Queue <string>(bundleAssets);

        while (assetQueue.Count > 0)
        {
            string             assetName = assetQueue.Dequeue();
            AssetBundleRequest request   =
                assetBundle.LoadAssetAsync <Sprite>(assetName);
            yield return(request);

            Sprite newSprite = (Sprite)request.asset;
            Debug.Log("Finished load of " + assetName);
            gameAssetManager.AddSpriteAsset(assetName, newSprite);
        }
        SetReady();
    }
Exemple #30
0
 // handle story and comic in the same bundle
 public void loadAllPages()
 {
     if (!this.loaded)
     {
         AssetBundle bundle = DataManager.readAssetBundles(DataManager.bundlePath(this.bundleName));
         this.bundleName = bundle.name;
         this.pages      = new List <Sprite>();
         foreach (string asetName in bundle.GetAllAssetNames())
         {
             if (asetName.Contains(this.comicDirectory))
             {
                 this.pages.Add(bundle.LoadAsset <Sprite>(asetName));
             }
         }
         bundle.Unload(false);
         this.loaded = true;
     }
 }
	// Use this for initialization
	void Start () {
		string assetsBundlePath = Application.streamingAssetsPath + "/bundle/";

		if(bundle != null)
			bundle.Unload(false);
		bundle = AssetBundle.LoadFromFile(assetsBundlePath + "bundle");

		string[] allAssetNames = bundle.GetAllAssetNames();
		foreach(var assetName in allAssetNames){
			print("AssetName: " + assetName);
			AssetBundleManifest assetBundleManifest = bundle.LoadAsset(assetName) as AssetBundleManifest;
			string[] allAssetBundles = assetBundleManifest.GetAllAssetBundles();
			foreach(var assetBundle in allAssetBundles){
				print("AssetBundleName: " + assetBundle);
				bundle = AssetBundle.LoadFromFile(assetsBundlePath + assetBundle);
				GameObject go = bundle.LoadAsset(assetBundle) as GameObject;
				Instantiate(go);
			}

		}

	}
	static void BuildAllAssetBundles ()
	{
		assetBundleManifest = BuildPipeline.BuildAssetBundles ("Assets//StreamingAssets/bundle");
		AssetDatabase.Refresh();
		string[] allAssetBundles = assetBundleManifest.GetAllAssetBundles();
		foreach(var assetBundle in allAssetBundles){
			print("AssetBundleName: " + assetBundle);
//			string[] allDependencies = assetBundleManifest.GetAllDependencies(assetBundle);
//			foreach(var dependencie in allDependencies){
//				print("DependAssetBundleName: " + dependencie);
//			}
//			string[] directDependencies = assetBundleManifest.GetDirectDependencies(assetBundle);
//			foreach(var direct in directDependencies){
//				print("DirectDependAssetBundleName: " + direct);
//			}

			string assetsBundlePath = Application.streamingAssetsPath + "/bundle/" + assetBundle;

			if(bundle != null)
				bundle.Unload(true);
			bundle = AssetBundle.LoadFromFile(assetsBundlePath);

			string[] allAssetNames = bundle.GetAllAssetNames();
			foreach(var assetName in allAssetNames){
				print("AssetName: " + assetName);
//				string[] assetPath = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundle, assetName);
//				foreach(var aPath in assetPath){
//					print("AssetPath: " + aPath);
//					string[] dependencie = AssetDatabase.GetDependencies(aPath);
//					foreach(var dep in dependencie){
//						print("Dependencie: " + dep);
//					}
//				}
			}
		}

	}