码迷,mamicode.com
首页 > 编程语言 > 详细

Unity 4.x 资源打包

时间:2018-06-02 11:34:37      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:eof   from   enc   工程   window   ane   selection   red   resource   

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 资源打包

标签:eof   from   enc   工程   window   ane   selection   red   resource   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!