首页 > 编程语言 > 详细

Unity 4.x 资源打包

时间:2018-06-02 10:53:56      阅读:273      评论:0      收藏:0      [点我收藏+]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class ExportAssetBundles : MonoBehaviour
{
    //在Unity编辑器中添加菜单
    [MenuItem("Assets/Build AssetBundle From Selection")]
    static void ExportResource()
    {
        //打开保存面板
        string path = EditorUtility.SaveFilePanel("Save Resource", string.Empty, "New Resource", "assetbundle");
        if (path.Length > 0)
        {
            //选择要打包的对象
            Object[] selections = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);

            //打包
            BuildPipeline.BuildAssetBundle(Selection.activeObject, selections, path, BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.CollectDependencies, BuildTarget.StandaloneWindows);
        }
    }

    [MenuItem("Assets/Save Scene")]
    static void ExportScene()
    {
        string path = EditorUtility.SaveFilePanel("Save Resource", string.Empty, "New Resource", "unity3d");

        if (path.Length > 0)
        {
            Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);

            //具体到工程中,需要动态设置
            string[] scenes = { "Assets/Scene1.unity" };

            BuildPipeline.BuildPlayer(scenes, path, BuildTarget.StandaloneWindows, BuildOptions.BuildAdditionalStreamedScenes);
        }
    }
}

  

Unity 4.x 资源打包

原文:https://www.cnblogs.com/luguoshuai/p/9124207.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!