Unload() public method

public Unload ( ) : void
return void
Beispiel #1
0
    //加载资源,传入prefabPath, type(type可以不传。)
    public UnityEngine.Object LoadAsset(string prefabPath, Type type = null)
    {
        //转换路径
        prefabPath = NormalizePath(prefabPath);
#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor)
        {
            if (type == null)
            {
                type = typeof(UnityEngine.Object);//如果没有指定类型,其实就是任意类型,Object是其他类型的基类,所以什么类型都行。
            }
            //加载prefabPath路径下的资源对象。调用资源数据库的指定路径加载资源接口去加载对象.
            var obj = AssetDatabase.LoadAssetAtPath(prefabPath, type);
            if (obj == null)
            {
                Debug.LogErrorFormat("the asset {0} not exist in the editor!", prefabPath);
            }
            return(obj);
        }
#endif
        //不是unity编辑器的话,就要先获取AssetBundle的路径了。
        string abPath = GetAssetBundlePath(prefabPath);
        //然后调用assetbundle 的加载器去加载指定路径的对象。
        var ab = abLoader.Load(abPath);//这个最后是调用AssetBundle.LoadFromFile接口去加载的.

        //加载了对象,还要加载资源?
        UnityEngine.Object asset = null;
        if (type == null)
        {
            //AssetBundle的LoadAsset接口
            asset = ab.LoadAsset(prefabPath);//没有类型的
        }
        else
        {
            asset = ab.LoadAsset(prefabPath, type);//有类型的
        }
        if (asset == null)
        {
            abLoader.Unload(abPath);//加载失败了,要卸载掉.
            Debug.LogErrorFormat("Asset: Async Load Error, assetPath = {0}, abPath = {1}, type = {2}", prefabPath, abPath, type);
        }
        else
        {
            loadedAsset[asset] = abPath;
            int n = 0;
            refCount.TryGetValue(asset, out n);
            ++n;//引用+1
            refCount[asset] = n;
            //Debug.LogFormat("Asset: Sync Load Done, asset={0}", asset.ToString());
        }
        return(asset);
    }
Beispiel #2
0
 /// <summary>
 /// Method from unloading asset model (and its bundle) from app
 /// </summary>
 public void Unload()
 {
     if (this.Bundle != null)
     {
         //Unloading bundle from app
         AssetBundleLoader.Unload(this.Bundle);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 释放
 /// </summary>
 public void Release()
 {
     if (m_loader != null)
     {
         m_loader.Unload();
         m_loader = null;
     }
 }
Beispiel #4
0
 public void Release()
 {
     if (loader != null)
     {
         loader.Unload();
         loader = null;
     }
     UIPackage.RemovePackage(packageId);
     package = null;
 }
Beispiel #5
0
        /// <summary>
        /// 获取资源信息完成
        /// </summary>
        private void OnGetResInfoCompleted(string abPath, string assetName, GameObject obj, Action callback)
        {
            if (obj != null)
            {
                Transform parent = ParseParentAttr();

                _root = GameObject.Instantiate(obj, parent).GetComponent <RectTransform>();

                if (_root != null)
                {
                    _rootCanvas = _root.GetComponent <CanvasGroup>();

                    if (_rootCanvas == null)
                    {
                        _rootCanvas = _root.gameObject.AddComponent <CanvasGroup>();
                    }

                    OnCreate();

                    _created = true;

                    _presenter?.OnCreateCompleted();
                }
                else
                {
                    throw new Exception($"<Ming> ## Uni Exception ## Cls:{this.GetType().Name} Func:Create Info:Instantiate failed !");
                }

                callback?.Invoke();
            }
            else
            {
                throw new Exception($"<Ming> ## Uni Exception ## Cls:{this.GetType().Name} Func:Create Info:Load res failed !");
            }

            AssetBundleLoader?.Unload(abPath, false);
        }
    // todo: patch lootdistribution jsonmapper to insert my own loot data, patch entitycell deserializer to insert new entities into new cells, patch worldentityinfo to make loot work correctly, patch PDAData to insert my own pda entries
    public static void Patch()
    {
        if (!Directory.Exists("Mods"))
        {
            Debug.Log("ModLoader: Folder \"Mods\" not found! Creating...");
            Directory.CreateDirectory("Mods");
            return;
        }

        MainThread = Thread.CurrentThread;
        var instance = HarmonyInstance.Create("com.railway.modloader");

        DLLFinder.FindDLLs("Mods");



        Application.runInBackground = true;

        AlternativeSerializer.RegisterCustomSerializer(-5, typeof(ScaleFixer), new ScaleFixerSerializer());

        DLLFinder.PrepatchDLLs();
        AssetBundleLoader.Unload();
        TechTypePatcher.Patch(instance);



        DLLFinder.PatchDLLs();


        CustomResourceManager.Patch(instance);
        ProtobufSerializerPatcher.Patch(instance);
        CustomSpriteManager.Patch(instance);
        CraftDataPatchHelper.Patch();
        LootPatcher.Patch(instance);
        WorldEntityInfoPatcher.Patch(instance);
        DLLFinder.PostPatchDLLs();
    }