Esempio n. 1
0
 public void Load()
 {
     loading = true;
     if (!string.IsNullOrEmpty(name) && name != "empty")
     {
         string path = string.Empty;
         path = CDirectory.MakeCachePath(name);
         if (!File.Exists(path))
         {
             path = CDirectory.MakeOtherStreamingPath(name);
         }
         if (this.name.EndsWith(".txt"))
         {
             this.text = new StringBuilder(File.ReadAllText(path));
         }
         else
         {
             this.asset_bundle = AssetBundle.CreateFromFile(path);
         }
         //this.complete = true;
     }
     if (!string.IsNullOrEmpty(name))
     {
         this.complete = true;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// AssetBundle.LoadAsset() を実行してプレハブを生成します。
        /// </summary>
        /// <param name="assetBundlePath">アセットバンドルのパス名</param>
        /// <param name="assetBundleName">アセットバンドル名</param>
        /// <returns>新しく生成されたインスタンスを返します。</returns>
        public static GameObject OnInstantiateWithAssetBundle(string assetBundlePath, string assetBundleName)
        {
            GameObject go = null;

            try
            {
                // アセットバンドルに含まれるリストの取得
#if UNITY_5_3_OR_NEWER || UNITY_5_3
                AssetBundle bundle = AssetBundle.LoadFromFile(assetBundlePath + "/" + assetBundleName);
#else
                AssetBundle bundle = AssetBundle.CreateFromFile(assetBundlePath + "/" + assetBundleName);
#endif
                string[] bundleNameArray = bundle.GetAllAssetNames();
                if (0 < bundleNameArray.Length)
                {
                    go = bundle.LoadAsset <GameObject>(bundleNameArray[0]);
                }
                bundle.Unload(false);
            }
            catch (System.Exception)
            {
                Debug.LogError("AssetBundle.LoadAsset() failed.");
                return(null);
            }

            return(go);
        }
Esempio n. 3
0
    private void Load(string path)
    {
        if (GameSetting.isEditorModel)
        {
            loadingList.Add(path);
            string fullpath = FullPath(path);
            loadedList[path] = Resources.LoadAssetAtPath(fullpath, typeof(Object));
            loadingList.Remove(path);
        }
        else
        {
            loadingList.Add(path);

            string fullpath = FullPath(path);

            /*
             * WWW bundle = WWW.LoadFromCacheOrDownload(fullpath, 1);
             * AssetBundle asset = bundle.assetBundle;
             */
            AssetBundle asset = AssetBundle.CreateFromFile(fullpath);

            loadedList[path] = asset.Load(GetAssetName(path), typeof(Object));
            StartCoroutine(UnloadAssetBundle(asset));
            //bundle = null;

            loadingList.Remove(path);
        }
    }
Esempio n. 4
0
    AnimationClipEx GetPostureData(_SourceItemData item)
    {
        AnimationClipEx postureClip = null;

        if (!poseTable.ContainsKey(item))
        {
            AssetBundle ab = AssetBundle.CreateFromFile(item.isTempLoaded ? item.TempLocalPath : item.DecorationLocalPath);

            postureClip = ab.Load("anime") as AnimationClipEx;

            if (postureClip != null)
            {
                poseTable.Add(item, postureClip);
                Debug.Log("Clip is " + (postureClip.animationClip == null) + "?\n" + postureClip.ToString());
            }
            else
            {
                Debug.Log("AssetBundle Load \"anime\" is back NULL!!!");
            }

            ab.Unload(false);
        }
        else
        {
            postureClip = poseTable[item];
        }
        return(postureClip);
    }
Esempio n. 5
0
    static void LoadM0001MOdel()
    {
        if (!EditorApplication.isPlaying)
        {
            return;
        }

        AssetBundle bundle = AssetBundle.CreateFromFile("test.assetbundle");
        Object      obj    = bundle.Load("Assets/Model/m_0010_model.fbx");

        if (obj)
        {
            Instantiate(obj);
        }

        obj = bundle.Load("Assets/m_0010.prefab");
        if (obj)
        {
            Instantiate(obj);
        }

        obj = bundle.Load("m_0010");
        if (obj)
        {
            Instantiate(obj);
        }
    }
Esempio n. 6
0
        protected override IEnumerator LoadFromPackage()
        {
            //兼容低版本API
#if UNITY_4 || UNITY_4_6 || UNITY_5_1 || UNITY_5_2
            _bundle = AssetBundle.CreateFromFile(_assetBundleSourceFile);
            yield return(null);
#else
            _assetBundleSourceFile = bundleManager.pathResolver.GetBundleSourceFile(bundleName, false);
            AssetBundleCreateRequest req = AssetBundle.LoadFromFileAsync(_assetBundleSourceFile);
            yield return(req);

            _bundle = req.assetBundle;
#endif
            if (loadAsset)
            {
#if UNITY_5 || UNITY_2018
                string[] names = _bundle.GetAllAssetNames();
                if (names.Length > 0)
                {
                    AssetBundleRequest req2 = _bundle.LoadAssetAsync(names[0]);
                    yield return(req2);

                    loadedAsset = req2.asset;
                }
#else
                loadedAsset = _bundle.mainAsset;
#endif
            }
            this.Complete();
        }
Esempio n. 7
0
    private IEnumerator LoadAsset(string resourceName, Action <AssetBundle> onResourceLoadedCallback)
    {
        // Create the request
        OnDemandResourcesRequest request = OnDemandResources.PreloadAsync(new string[] { "resource_tag" });

        // Wait until request is completed
        yield return(request);

        // Check for errors
        if (request.error != null)
        {
            throw new Exception("ODR request failed: " + request.error);
        }

        // Get path to the resource and use it. Note that at the moment the only API
        // that can load ODR or sliced resources is AssetBundle.CreateFromFile()
        string path = "res://" + resourceName;

        AssetBundle bundle = AssetBundle.CreateFromFile(path);

        onResourceLoadedCallback(bundle);

        // Call Dispose() when resource is no longer needed. This will release a pin on ODR resource.
        request.Dispose();
    }
        /// <summary>
        /// 载入素材
        /// </summary>
        public AssetBundle LoadBundle(string name)
        {
            string      uri    = Util.DataPath + name.ToLower() + AppConst.ExtName;
            AssetBundle bundle = AssetBundle.CreateFromFile(uri); //关联数据的素材绑定

            return(bundle);
        }
Esempio n. 9
0
        UObj RefAssetBundle(string filename)
        {
            UObj obj = lstRefAsset.Get(filename);

            if (obj == null)
            {
                //TODO : 后期合成真实的本地路劲
                string path = ResourceSetting.ConvertToABPath(filename);

                ///
                /// WWW.LoadFromCacheOrDownload 这个方法建议大家以后不要再用了
                /// 因为是异步方法,而且还占用内存。
                ///

                AssetBundle asset = AssetBundle.CreateFromFile(path);
                obj = asset.Load(filename);

                //释放Compressed资源
                asset.Unload(false);

                //加入引用列表的同时,释放资源
                releaseRes(lstRefAsset.Add(filename, obj));
            }

            return(obj);
        }
Esempio n. 10
0
        IEnumerator AsyncAb(string filename, Action <UObj, string> finished)
        {
            yield return(null);

            bool cached = false;
            UObj obj    = lstRefAsset.Get(filename);

            cached = obj != null;

            if (!cached)
            {
                //TODO : 后期合成真实的本地路劲
                string      path  = ResourceSetting.ConvertToABPath(filename);
                AssetBundle asset = AssetBundle.CreateFromFile(path);

                AssetBundleRequest request = asset.LoadAsync(filename, typeof(UObj));
                yield return(request);

                //加入引用列表的同时,释放资源
                releaseRes(lstRefAsset.Add(filename, request.asset));
                obj = request.asset;
            }

            if (finished != null)
            {
                finished(obj, filename);
            }
        }
Esempio n. 11
0
    static int CreateFromFile(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 1)
        {
            string      arg0 = LuaScriptMgr.GetLuaString(L, 1);
            AssetBundle o    = AssetBundle.CreateFromFile(arg0);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 2)
        {
            string      arg0 = LuaScriptMgr.GetLuaString(L, 1);
            int         arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            AssetBundle o    = AssetBundle.CreateFromFile(arg0, arg1);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: AssetBundle.CreateFromFile");
        }

        return(0);
    }
Esempio n. 12
0
        protected override void FinishDownload()
        {
            error = request.error;
            if (error != null)
            {
                return;
            }

            var path   = "res://" + assetBundleName;
            var bundle = AssetBundle.CreateFromFile(path);

            if (bundle == null)
            {
                error = string.Format("Failed to load {0}", path);
                request.Dispose();
            }
            else
            {
                assetBundle = new LoadedAssetBundle(bundle);
                // At the time of unload request is already set to null, so capture it to local variable.
                var localRequest = request;
                // Dispose of request only when bundle is unloaded to keep the ODR pin alive.
                assetBundle.unload += () =>
                {
                    localRequest.Dispose();
                };
            }

            request = null;
        }
        private void setUpComponents()
        {
            if (mesh == null)
            {
                mesh = gameObject.AddComponent <MeshFilter>().mesh;
            }
            if (gameObject.GetComponent <MeshRenderer>() == null)
            {
                var renderer = gameObject.AddComponent <MeshRenderer>();

                renderer.enabled           = false;
                renderer.shadowCastingMode = ShadowCastingMode.Off;
                renderer.receiveShadows    = false;

                AssetBundle AB       = AssetBundle.CreateFromFile(KSPUtil.ApplicationRootPath + "/GameData/KerbalWeatherSystems/Resources/mapoverlay");
                string[]    names    = AB.GetAllAssetNames();
                var         material = new Material(AB.LoadAsset <Shader>(AB.GetAllAssetNames()[0]));


                var color = Color.white;
                color.a        = 1.0f;
                material.color = color;

                renderer.material = material;
            }
        }
Esempio n. 14
0
        protected virtual void Awake()
        {
            string bundlePath = EngineerGlobals.AssemblyPath;

            s_Images  = AssetBundle.CreateFromFile(bundlePath + "/images");
            s_Prefabs = AssetBundle.CreateFromFile(bundlePath + "/prefabs");
        }
        private void Awake()
        {
            string path = KSPUtil.ApplicationRootPath + "GameData/SurfaceExperimentPackage/Resources";

            images  = AssetBundle.CreateFromFile(path + "/sep_images.ksp");
            prefabs = AssetBundle.CreateFromFile(path + "/sep_prefab.ksp");
        }
Esempio n. 16
0
        /// <summary>
        /// Starts the mod. Called from Injector.
        /// </summary>
        public static void Start()
        {
            string logPath = GetPath("clientLog.txt");

            if (!Logger.SetupLogger(logPath))
            {
                FatalError($"Cannot setup logger. Log file path: {logPath}");
                return;
            }

            Logger.SetAutoFlush(true);

            Game.Hooks.PlayMakerActionHooks.Install();

            string assetBundlePath = GetPath("../../data/mpdata");

            if (!File.Exists(assetBundlePath))
            {
                FatalError("Cannot find mpdata asset bundle.");
                return;
            }

            assetBundle = AssetBundle.CreateFromFile(assetBundlePath);

            var go = new GameObject("Multiplayer GUI Controller");

            go.AddComponent <UI.MPGUI>();

            go = new GameObject("Multiplayer Controller");
            go.AddComponent <MPController>();
        }
Esempio n. 17
0
    private void LoadConfig(string path)
    {
        AssetBundle assetBundle = AssetBundle.CreateFromFile(path);

        if (assetBundle == null)
        {
            return;
        }
        TextAsset textAsset = assetBundle.mainAsset as TextAsset;

        string[] array = textAsset.text.Split(new char[]
        {
            '|'
        });
        assetBundle.Unload(true);
        XPlatform._defaultLoginServer       = array[0];
        XPlatform._androidQQLoginServer     = array[1];
        XPlatform._androidWeChatLoginServer = array[2];
        XPlatform._iOSQQLoginServer         = array[3];
        XPlatform._iOSWeChatLoginServer     = array[4];
        XPlatform._iOSGuestLoginServer      = array[5];
        XPlatform._versionServer            = array[6];
        XPlatform._hostUrl   = array[7];
        XPlatform._isPublish = bool.Parse(array[8]);
        XPlatform._testDefaultLoginServer       = array[9];
        XPlatform._testAndroidQQLoginServer     = array[10];
        XPlatform._testAndroidWeChatLoginServer = array[11];
        XPlatform._testiOSQQLoginServer         = array[12];
        XPlatform._testiOSWeChatLoginServer     = array[13];
        XPlatform._testiOSGuestLoginServer      = array[14];
        XPlatform._testVersionServer            = array[15];
    }
 // Token: 0x0600177E RID: 6014 RVA: 0x000588F4 File Offset: 0x00056AF4
 public IDownloader CreateDownloaderForJob(Job job)
 {
     if (File.Exists(job.Path))
     {
         FileInfo fileInfo = new FileInfo(job.Path);
         bool     flag     = fileInfo.Length == (long)job.ByteLength;
         if (flag)
         {
             AssetBundle assetBundle = AssetBundle.CreateFromFile(Path.GetFullPath(job.Path).Replace('\\', '/'));
             if (assetBundle)
             {
                 return(new FileDispatch.Downloader
                 {
                     bundle = assetBundle
                 });
             }
         }
     }
     Debug.LogWarning("Missing Bundle " + job.Path);
     if (job.ContentType != ContentType.Assets || job.TypeOfAssets == typeof(NavMesh))
     {
         return(this.wwwFallback.CreateDownloaderForJob(job));
     }
     return(null);
 }
Esempio n. 19
0
    public static AssetBundle GetAssetBundle(string name, long stamper = 0L)
    {
        AssetManager.SOB.Length = 0;
        AssetManager.AssRef assRef;
        if (stamper > 0L && !AssetManager.AssetMap.TryGetValue(name.ToUpperInvariant().GetHashCode(), out assRef))
        {
            using (FileStream fileStream = new FileStream(AssetManager.SOB.AppendFormat("{0}/{1}", AssetManager.persistentDataPath, name).ToString(), FileMode.OpenOrCreate))
            {
                using (StreamReader streamReader = new StreamReader(fileStream))
                {
                    long num;
                    if (long.TryParse(streamReader.ReadLine(), out num) && stamper <= num)
                    {
                        AssetManager.SetAssetBundle(name.ToUpperInvariant().GetHashCode(), num, true);
                    }
                    else
                    {
                        AssetManager.SetAssetBundle(name.ToUpperInvariant().GetHashCode(), stamper, false);
                    }
                }
            }
        }
        StringBuilder stringBuilder = new StringBuilder();

        if (!AssetManager.AssetMap.TryGetValue(name.ToUpperInvariant().GetHashCode(), out assRef) || !assRef.Internal)
        {
            stringBuilder.AppendFormat("{0}!assets/{1}.unity3d", Application.dataPath, name);
        }
        else
        {
            stringBuilder.AppendFormat("{0}/{1}.unity3d", AssetManager.persistentDataPath, name);
        }
        return(AssetBundle.CreateFromFile(stringBuilder.ToString()));
    }
    public static AssetBundle LoadAB(string abPath)
    {
        if (abDic.ContainsKey(abPath) == true)
        {
            return(abDic[abPath]);
        }
        if (manifest == null)
        {
            AssetBundle manifestBundle = AssetBundle.CreateFromFile(AssetBundleConfig.ASSETBUNDLE_PATH + AssetBundleConfig.ASSETBUNDLE_FILENAM);
            manifest = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest");
        }
        if (manifest != null)
        {
            // 2.获取依赖文件列表
            string[] cubedepends = manifest.GetAllDependencies(abPath);

            for (int index = 0; index < cubedepends.Length; index++)
            {
                //Debug.Log(cubedepends[index]);
                // 3.加载所有的依赖资源
                LoadAB(cubedepends[index]);
            }

            // 4.加载资源
            abDic[abPath] = AssetBundle.CreateFromFile(AssetBundleConfig.ASSETBUNDLE_PATH + abPath);

            return(abDic[abPath]);
        }
        return(null);
    }
Esempio n. 21
0
 // Token: 0x06000160 RID: 352 RVA: 0x00016254 File Offset: 0x00014454
 public static AssetBundle GetAssetBundle(CString Name, out int Key)
 {
     Key = Name.GetHashCode(true);
     AssetManager.AssRef value;
     if (!AssetManager.AssetMap.TryGetValue(Key, out value) || !value.Asset || value.RefCount == 0)
     {
         CString cstring = StringManager.Instance.StaticString1024();
         if (!value.Internal)
         {
             cstring.StringToFormat(Application.dataPath);
             cstring.StringToFormat(Name);
             cstring.AppendFormat("{0}!assets/{1}.unity3d");
         }
         else
         {
             cstring.StringToFormat(AssetManager.persistentDataPath);
             cstring.StringToFormat(Name);
             cstring.AppendFormat("{0}/{1}.unity3d");
         }
         value.Set(AssetBundle.CreateFromFile(cstring.ToString()));
     }
     value.RefCount++;
     AssetManager.AssetMap[Key] = value;
     return(value.Asset);
 }
Esempio n. 22
0
        /// <summary>
        /// Starts the mod. Called from Injector.
        /// </summary>
        public static void Start(string commandLine)
        {
            if (!SetupLogger())
            {
                return;
            }

            ParseCommandLine(commandLine);

            Logger.SetAutoFlush(true);

            Game.Hooks.PlayMakerActionHooks.Install();

            string assetBundlePath = GetPath("../../data/mpdata");

            if (!File.Exists(assetBundlePath))
            {
                FatalError("Cannot find mpdata asset bundle.");
                return;
            }

            assetBundle = AssetBundle.CreateFromFile(assetBundlePath);

            var go = new GameObject("Multiplayer GUI Controller");

            go.AddComponent <UI.MPGUI>();

            go = new GameObject("Multiplayer Controller");
            go.AddComponent <MPController>();

            UI.Console.RegisterCommand("quit", (string[] args) => {
                Application.Quit();
            });
        }
Esempio n. 23
0
    Texture2D GetItemTexture(_SourceItemData item)
    {
        Texture2D itemTex;// = itemObjTable[item];

        //-------------------------------------------------------------
        if (itemTexTable == null)
        {
            itemTexTable = new Dictionary <_SourceItemData, Texture2D>();
        }

        if (!itemTexTable.ContainsKey(item))
        {//.title + name)){// || !itemObjTable[item.title + name]
            AssetBundle ab = AssetBundle.CreateFromFile(item.isTempLoaded ? item.TempLocalPath : item.DecorationLocalPath);

            itemTex = ab.mainAsset as Texture2D;//Object.Instantiate()

            if (itemTex != null)
            {
                /*itemTex.wrapMode = TextureWrapMode.Clamp;*/
                itemTexTable.Add(item, itemTex);
            }
            else
            {
                Debug.Log("_TextureLoader.GetItemTexture : itemTex is Null !");
            }
            ab.Unload(false);
        }
        else
        {
            itemTex = itemTexTable[item];
        }
        return(itemTex);
    }
Esempio n. 24
0
    private int EnumerateDRMContentFiles(string contentDir)
    {
        int num = 0;

        PSVitaDRM.ContentOpen(contentDir);
        string text = "addcont0:" + contentDir;

        OnScreenLog.Add("Found content folder: " + text);
        string[] files = Directory.GetFiles(text);
        OnScreenLog.Add(" containing " + files.Length + " files");
        string[] array = files;
        foreach (string text2 in array)
        {
            OnScreenLog.Add("  " + text2);
            num++;
            if (text2.Contains(".unity3d"))
            {
                AssetBundle val    = AssetBundle.CreateFromFile(text2);
                Object[]    array2 = val.LoadAllAssets();
                OnScreenLog.Add("  Loaded " + array2.Length + " assets from asset bundle.");
                val.Unload(false);
            }
        }
        PSVitaDRM.ContentClose(contentDir);
        return(num);
    }
Esempio n. 25
0
 public BundleLoader(string path)
 {
     assetBundle = AssetBundle.CreateFromFile(path);
     if (assetBundle == null)
     {
         throw new System.Exception();
     }
 }
    /// <summary>
    /// 载入素材
    /// </summary>
    public AssetBundle LoadBundle(string name)
    {
        AssetBundle bundle = null;
        string      uri    = Util.DataPath + name.ToLower() + ".assetbundle";

        bundle = AssetBundle.CreateFromFile(uri); //关联数据的素材绑定
        return(bundle);
    }
 public IEnumerator LoadBundleFromFileUncompressed(string path)
 {
     CheckFileExists(path);
     bundle = AssetBundle.CreateFromFile(path);
     CheckBundle(bundle);
     Debug.Log("loaded bundle: " + path);
     yield return(null);
 }
Esempio n. 28
0
    private static int CreateFromFile(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        AssetBundle bundle = AssetBundle.CreateFromFile(LuaScriptMgr.GetLuaString(L, 1));

        LuaScriptMgr.Push(L, bundle);
        return(1);
    }
    //load obj
    public void LoadGameObject()
    {
        AssetBundle ab = AssetBundle.CreateFromFile(objSavePath);
        GameObject  go = gameObjectFromAssetsBundle(ab);

        Instantiate(go);
        ab.Unload(false);
    }
Esempio n. 30
0
 private void LoadAssetBundle(string file)
 {
     if (mBundle != null)
     {
         Dispose();
     }
     mBundle = AssetBundle.CreateFromFile(file);
 }