cs
复制代码
using Aliyun.OSS;
using Aliyun.OSS.Common;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Unity.EditorCoroutines.Editor;
using UnityEditor;
using UnityEditor.VersionControl;
using UnityEngine;
using UnityEngine.Networking;
public class MakeAB : EditorWindow
{
private static string TALAccessKeyId = "your TALAccessKeyId";
private static string TALAccessKeySecret = "your TALAccessKeySecret";
#if UNITY_ANDROID
private int selectedOption = 2;
#elif UNITY_IOS
private int selectedOption = 3;
#elif UNITY_STANDALONE_WIN
private int selectedOption = 0;
#elif UNITY_STANDALONE_OSX
private int selectedOption = 1;
#endif
private string[] options = new string[] { "Windows", "Mac", "Android", "IOS" };
private static string localABPath;
private static float TALUploadProgress = 0f; // 上传进度
private static string TALUploadProgressText = "0%"; // 进度文本
[MenuItem("Tools/Make AB")]
public static void ShowWindow()
{
//编辑器Make AB窗口紧靠Game窗口
GetWindow<MakeAB>("Make AB", typeof(Editor).Assembly.GetType("UnityEditor.GameView"));
}
private void OnGUI()
{
//文本
GUILayout.Label("未来云设置");
//文本输入框
TALAccessKeyId = EditorGUILayout.TextField("TALAccessKeyId", TALAccessKeyId);
TALAccessKeySecret = EditorGUILayout.TextField("TALAccessKeySecret", TALAccessKeySecret);
//间距
GUILayout.Space(10);
//划线
EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), new Color(0.5f, 0.5f, 0.5f, 0.5f));
GUILayout.Space(10);
//下拉列表
selectedOption = EditorGUILayout.Popup("AB包编译平台", selectedOption, options);
localABPath = "Assets/../AssetBundles/" + options[selectedOption];
//右对齐文本
EditorGUILayout.LabelField("*AB包路径:" + localABPath, new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleRight });
//按钮
if (GUILayout.Button("制作AB包"))
{
//弹窗
bool confirm = EditorUtility.DisplayDialog(
"提示",
$"\n确定打{options[selectedOption]}平台的AB包吗?",
"确定",
"取消"
);
if (confirm)
{
BuildAB(selectedOption);
}
else
{
Debug.Log("取消打包");
}
}
GUILayout.Space(10);
//进度条
GUILayout.BeginHorizontal();
GUILayout.Label("Upload Progress:", GUILayout.Width(110));
Rect rect = GUILayoutUtility.GetRect(200, 20);
EditorGUI.ProgressBar(rect, TALUploadProgress, TALUploadProgressText);
GUILayout.EndHorizontal();
//刷新
Repaint();
}
public void BuildAB(int targetOption)
{
if (!Directory.Exists(localABPath))
{
Directory.CreateDirectory(localABPath);
}
switch (targetOption)
{
case 0:
BuildPipeline.BuildAssetBundles(localABPath, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
break;
case 1:
BuildPipeline.BuildAssetBundles(localABPath, BuildAssetBundleOptions.None, BuildTarget.StandaloneOSX);
break;
case 2:
BuildPipeline.BuildAssetBundles(localABPath, BuildAssetBundleOptions.None, BuildTarget.Android);
break;
case 3:
BuildPipeline.BuildAssetBundles(localABPath, BuildAssetBundleOptions.None, BuildTarget.iOS);
break;
}
Debug.Log("AB包制作完成");
}
}