u3d 场景资源打包

搞了一天终于搞定u3d的场景打包,这样就可以不用修改太多程序,把资源放在外部修改了。好处多多

但是本来很简单的东西搞了一天,google来的说作为场景scene。unity 文件 打包成 unityd,结果一直都不行(时间就花在这里了,我相信他)

后来问了别人,别人说看文档,是打包frefab,我一次,一下就行 了,我去

下面是打包的代码

using UnityEngine;
using System.Collections;
using UnityEditor;

public class assetPack : Editor
{
//打包单个
[MenuItem("Custom Editor/Create AssetBunldes Main")]
static void CreateAssetBunldesMain ()
{
    //获取在Project视图中选择的所有游戏对象
    Object[] SelectedAsset = Selection.GetFiltered (typeof(Object), SelectionMode.DeepAssets);

//遍历所有的游戏对象
    foreach (Object obj in SelectedAsset)
    {
    //本地测试:建议最后将Assetbundle放在StreamingAssets文件夹下,如果没有就创建一个,因为移动平台下只能读取这个路径
    //StreamingAssets是只读路径,不能写入
    //服务器下载:就不需要放在这里,服务器上客户端用www类进行下载。
    string targetPath = Application.dataPath + "/StreamingAssets/" + obj.name + ".assetbundle";
    if (BuildPipeline.BuildAssetBundle (obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies)) {
    Debug.Log(obj.name +"资源打包成功");
    }
    else
    {
    Debug.Log(obj.name +"资源打包失败");
    }
    }
    //刷新编辑器
    AssetDatabase.Refresh ();  

}

[MenuItem("Custom Editor/Create AssetBunldes ALL")]
static void CreateAssetBunldesALL ()
{

    Caching.CleanCache ();

    string Path = Application.dataPath + "/StreamingAssets/ALL.assetbundle";

    Object[] SelectedAsset = Selection.GetFiltered (typeof(Object), SelectionMode.DeepAssets);

    foreach (Object obj in SelectedAsset)
    {
        Debug.Log ("Create AssetBunldes name :" + obj);
    }

        //这里注意第二个参数就行
        if (BuildPipeline.BuildAssetBundle (null, SelectedAsset, Path, BuildAssetBundleOptions.CollectDependencies)) {
        AssetDatabase.Refresh ();
    } else
    {

    }
}

[MenuItem("Custom Editor/Create Scene")]
static void CreateSceneALL ()
{
    //清空一下缓存
    Caching.CleanCache();
    string Path = Application.dataPath + "/eScene.unity3d";
    string[] levels = { "Assets/myScene.unity" };
    //打包场景
    BuildPipeline.BuildPlayer( levels, Path,BuildTarget.StandaloneWindows, BuildOptions.BuildAdditionalStreamedScenes);
    AssetDatabase.Refresh ();
}

[MenuItem("Custom Editor/Save Scene")]
static void ExportScene()
{
    // 打开保存面板,获得用户选择的路径
    string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");

    if (path.Length != 0)
    {
        // 选择的要保存的对象
        Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
        string[] scenes = { "Assets/myScene.unity" };
        //打包
        BuildPipeline.BuildPlayer(scenes, path, BuildTarget.StandaloneWindows, BuildOptions.BuildAdditionalStreamedScenes);
    }
    AssetDatabase.Refresh();
}
[MenuItem("Custom Editor/Save Scene2")]
static void ExportResource()
{
    // Bring up save panel
    string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
    if (path.Length != 0)
    {
        // Build the resource file from the active selection.
        Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
        BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path,
                          BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
        Selection.objects = selection;
    }
}
}

下面是加载的代码

using UnityEngine;
using System.Collections;

public class loadScene : MonoBehaviour
{

    // Use this for initialization
    void Start ()
    {
        StartCoroutine(loadScenee());

    }

    // Update is called once per frame
    void Update () {

    }

    IEnumerator loadScenee()
    {
        string path;
        path = "file://" + Application.dataPath + "/StreamingAssets/eScene.unity3d";
        Debug.Log(path);
        WWW www = new WWW(path);
        yield return www;
        AssetBundle bundle = www.assetBundle;
        //GameObject go = bundle.Load("gCube",typeof(GameObject)) as GameObject;

        GameObject ObjScene = Instantiate(www.assetBundle.mainAsset) as GameObject;
        bundle.Unload(false);

    }
}

全做记忆

u3d 场景资源打包

时间: 2024-08-06 00:52:27

u3d 场景资源打包的相关文章

u3d外部资源 打包与加载的问题

被坑了一下午,调bug,u3d外部加载资源一会可以,一会不行,始终找不到问题,最后快下班的时候,重新试了一下,原来是资源打包之前的文件名,和之后的加载资源名必须一样 [MenuItem("Custom Editor/Build AssetBundle From Selection Twice")] static void ExportResourceNoTrack() { // Bring up save panel string path = EditorUtility.SaveFi

Unity资源打包之Assetbundle

转  Unity资源打包之Assetbundle 本文原创版权归 csdn janeky 所有,转载请详细注明原创作者及出处,以示尊重! 作者:janeky 原文:http://blog.csdn.net/janeky/article/details/17652021 如果这篇文章对你有帮助,敬请关注作者<Unity手游之路>系列教程. 在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制成预设Prefab,打包成场景.今天我们来一起学习官方推荐的As

u3d 加密资源并缓存加载

// C# Example // Builds an asset bundle from the selected objects in the project view. // Once compiled go to "Menu" -> "Assets" and select one of the choices // to build the Asset Bundle using UnityEngine; using UnityEditor; using

Unity手游之路&lt;十一&gt;资源打包Assetbundle

http://blog.csdn.net/janeky/article/details/17652021 在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制成预设Prefab,打包成场景.今天我们来一起学习官方推荐的Assetbundle,它是Unity(Pro)提供的资源打包策略.利用AssetBundle,可以将几乎所有的资源都打包封装,便于客户端更新下载新的资源. (转载请注明原文出处http://blog.csdn.net/janeky/art

资源打包Assetbundle .

在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制成预设Prefab,打包成场景.今天我们来一起学习官方推荐的Assetbundle,它是Unity(Pro)提供的资源打包策略.利用AssetBundle,可以将几乎所有的资源都打包封装,便于客户端更新下载新的资源. (转载请注明原文出处http://blog.csdn.net/janeky/article/details/17652021) 创建AssetBundle 1.创建一个空的Prefab,命

将SWF文件用作资源打包

使用Flash开发网页游戏少不了与各种美术资源打交道.对于静态资源的那就是各种图片,对于会动的资源可以考虑直接做成swf.制作成swf的美术资源又可以分为两种:一种是直接将关键帧罗列在主时间轴上,那么当程序使用Loader类加载完swf文件后,就可以直接addChild在显示列表上:另一种是将美术资源封装成影片剪辑(MovieClip),并为AS3导出类,这样在程序中可以用类似new XXX的方式将美术资源创建出来. 弊端然而,这种使用swf的方式有一个非常大的弊端,就是会重复创建位图,导致内存

unity3d 资源打包加密

资源打包脚本,放到Assets\Editor 文件夹下 using UnityEngine; using System.Collections; using UnityEditor; using System.IO; public class assetPack : Editor { [MenuItem("Custom Editor/Save Scene2")] static void ExportResource() { // Bring up save panel string p

characterCustomezition的资源打包代码分析

using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; class CreateAssetbundles { // This method creates an assetbundle of each SkinnedMeshRenderer // found in any selected character fbx, and adds any materials that

【Cocos2d-Js基础教学(5)资源打包工具的使用及资源的异步加载处理】

[转载]http://www.cnblogs.com/zisou/p/cocos2dx-js5.html   TexturePacker是纹理资源打包工具,支持Cocos2dx的游戏资源打包. 如果用过的同学可以直接看下面的资源的异步加载处理 首先为什么用TexturePacker? 1,节省图片资源实际大小 2,减少我们游戏中大量资源带来的内存负荷 3,方便游戏对纹理资源的内存管理 游戏开发到后期,我们或许都会遇到的瓶颈就是需要对游戏包进行"瘦身"和内存优化.那么使用TextureP