• AssetBundle流程备份


    资源Bundle创建,这里Assets下手动创建StreamingAssets文件夹

    using UnityEngine;
    using System.Collections;
    using UnityEditor;
    
    public class CreateAssetBundlesMain{
       
        [MenuItem("Custom Editor/Create AssetBundles Main")]
    
        static void CreateMain()
        {
            Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
    
            foreach(Object obj in SelectedAsset)
            {
                string sourcePath = AssetDatabase.GetAssetPath(obj);
                string targetPath = Application.dataPath + "/StreamingAssets/" + obj.name + ".assetbundle";
                if(BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies, BuildTarget.StandaloneWindows ))
                {
                    Debug.Log(obj.name + "资源打包成功");
                }
                else
                {
                    Debug.Log(obj.name + "资源打包失效");
                }
            }
    
            AssetDatabase.Refresh();
        }
    }
    using UnityEngine;
    using System.Collections;
    using UnityEditor;
    
    public class CreateAssetBundlesAll {
    
        [MenuItem("Custom Editor/Create AssetBundles All")]
    
        static void CreatAll()
        {
            Caching.CleanCache();
    
            string Path = Application.dataPath + "/StreamingAssets/All.assetbundle";
    
            Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
    
            foreach(object obj in SelectedAsset)
            {
                Debug.Log("AssetBundle name:" + obj);
            }
    
            if(BuildPipeline.BuildAssetBundle(null, SelectedAsset, Path, BuildAssetBundleOptions.CollectDependencies, BuildTarget.StandaloneWindows))
            {
                AssetDatabase.Refresh();
            }
            else
            {
    
            }
        }
    }
    using UnityEngine;
    using System.Collections;
    using UnityEditor;
    
    public class CreateSceneAll{
    
        [MenuItem("Custom Editor/Create AssetBundles Scene")]
    
        static void CreateScene()
        {
            Caching.CleanCache();
            string Path = Application.dataPath + "/StreamingAssets/MyScene.unity3d";
            string[] levels = { "Assets/Scene/Level1.unity" , "Assets/Scene/Level2.unity" };
    
            BuildPipeline.BuildStreamedSceneAssetBundle(levels, Path, BuildTarget.StandaloneWindows, BuildOptions.UncompressedAssetBundle);
            AssetDatabase.Refresh();
        }
    }

    资源的引用

    using UnityEngine;
    using System.Collections;
    
    public class RunScript : MonoBehaviour
    {
        //不同平台StreamingAssets路径有差异
        public static readonly string PathURL =
    #if UNITY_ANDROID
            "jar:file://" + Application.dataPath + "!/assets/";
    #elif UNITY_IPHONE
            Application.dataPath + "/Raw/";
    #elif UNITY_STANDLONE_WIN || UNITY_EDITOR
            "file://" + Application.dataPath + "/StreamingAssets/";
    #else
        string.Empty;
    #endif
    
        void OnGUI()
        {
            if(GUILayout.Button("Main Assetbundle"))
            {
                StartCoroutine(LoadMain(PathURL + "GameObject1.assetbundle"));
                StartCoroutine(LoadMain(PathURL + "GameObject2.assetbundle"));
            }
            if(GUILayout.Button("All Assetbundle"))
            {
                StartCoroutine(LoadAll(PathURL + "All.assetbundle"));
            }
    
            if(GUILayout.Button("Load Scene"))
            {
                StartCoroutine(LoadScene());
            }
        }
    
        private IEnumerator LoadMain(string path)
        {
            WWW bundle = new WWW(path);
            yield return bundle;
    
            yield return Instantiate(bundle.assetBundle.mainAsset);
            bundle.assetBundle.Unload(false);
        }
    
        private IEnumerator LoadAll(string path)
        {
            WWW bundle = new WWW(path);
            yield return bundle;
    
            Object obj1 = bundle.assetBundle.LoadAsset("GameObject1");
            Object obj2 = bundle.assetBundle.LoadAsset("GameObject2");
    
            yield return Instantiate(obj1);
            yield return Instantiate(obj2);
    
            bundle.assetBundle.Unload(false);
        }
    
        private IEnumerator LoadScene()
        {
            AssetBundle ab = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/MyScene.unity3d");
            yield return ab;
            Application.LoadLevel("Level2");
        }
    }

    资源层级截图

     

     http://blog.csdn.net/lyh916/article/details/49815871

    http://www.xuanyusong.com/archives/2405

  • 相关阅读:
    MYSQL函数 Cast和convert的用法详解
    MySQL5.7.9(GA)的安装
    TMS Scripter importtool的使用
    MySQL 高可用架构在业务层面的应用分析
    UNIGUI:How to redirect and close session?
    HTML URL 编码:请参阅:http://www.w3school.com.cn/tags/html_ref_urlencode.html
    js 解决函数加载的问题
    必备函数
    Action 分离
    JavaScript.Remove
  • 原文地址:https://www.cnblogs.com/JimmyCode/p/7064543.html
Copyright © 2020-2023  润新知