打包场景,模型,资源包。。。

[MenuItem("CreateScene/打包场景")]
    static void CreateSceneALL()
    {
        Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
        foreach (Object obj in SelectedAsset)
        {
            //取得当前选择场景文件路径
            string myPath = AssetDatabase.GetAssetPath(obj);
            //去掉路径前部分得到文件名
            string path = myPath.Replace("Assets/", "");
            //替换文件扩展名
            path = path.Replace("unity", "unity3d");
            //清楚缓存
            Caching.ClearCache();
            //拼接出打包之后文件存放路径(和场景文件同目录下)
            string Path = Application.dataPath + "/" + path;
            string[] array = path.Split('.');
            for (int i = 0; i < array.Length; i++)
            {
                Debug.Log(array[i]);
            }
            string[] levels = { myPath };
            //打包场景
            BuildPipeline.BuildPlayer(levels, Path, BuildTarget.WebGL, BuildOptions.BuildAdditionalStreamedScenes);
        }

        //刷新编辑器
        AssetDatabase.Refresh();
    }
    [MenuItem("CreateScene/打包模型")]
    static void CreatePrefabs()
    {
        //取得当前选择场景文件路径
        string myPath = AssetDatabase.GetAssetPath(Selection.activeObject);
        //去掉路径前部分得到文件名
        string path = myPath.Replace("Assets/", "");
        //替换文件扩展名
        //path = path.Replace("prefab", "assetbundle");
        //清楚缓存
        Caching.ClearCache();
        //拼接出打包之后文件存放路径(和场景文件同目录下)
        string Path = Application.dataPath + "/" + path;
        if (Path.Length != 0)
        {
            // 选择的要保存的对象  
            Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
            AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
            buildMap[0].assetBundleName = Path;
            buildMap[0].assetNames = new string[] { Path };
            //打包  
            //BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, Path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.StandaloneWindows);
           // BuildPipeline.BuildAssetBundles(Application.dataPath+ "/ResourcesPrefab", buildMap);
            BuildPipeline.BuildAssetBundles(Application.dataPath + "/Prefab", 0, EditorUserBuildSettings.activeBuildTarget);
        }
        //刷新编辑器
        AssetDatabase.Refresh();
    }


using UnityEngine;
using System.Collections;
using UnityEditor;

public class createABundle : MonoBehaviour {

    [MenuItem("Framework/Build WebGL Resource", false, 101)]
    public static void BuildWebGLResource()
    {
        Caching.ClearCache();
        string streamPath = Application.streamingAssetsPath + "/scene/";
        BuildPipeline.BuildAssetBundles(streamPath, BuildAssetBundleOptions.None, BuildTarget.WebGL);
        AssetDatabase.Refresh();
    }

    [MenuItem("Framework/SetAssetBundleNameExtension")]  //将选定的资源进行统一设置AssetBundle名
    static void SetBundleName()
    {
        Object[] selects = Selection.objects;
        foreach (Object item in selects)
        {
            string path = AssetDatabase.GetAssetPath(item);
            AssetImporter asset = AssetImporter.GetAtPath(path);
            asset.assetBundleName = item.name;//设置Bundle文件的名称
            asset.assetBundleVariant = "unity3d";//设置Bundle文件的扩展名
            asset.SaveAndReimport();
        }
        AssetDatabase.Refresh();
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值