Unity | 编辑器开发

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包制作完成");

    }
}
相关推荐
Unity大海1 小时前
诠视科技Unity SDK开发环境配置、项目设置、apk打包。
科技·unity·游戏引擎
浅陌sss7 小时前
Unity中 粒子系统使用整理(一)
unity·游戏引擎
维度攻城狮11 小时前
实现在Unity3D中仿真汽车,而且还能使用ros2控制
python·unity·docker·汽车·ros2·rviz2
为你写首诗ge14 小时前
【Unity网络编程知识】FTP学习
网络·unity
1alisa16 小时前
Sublime Text for Mac v4【注册汉化版】代码编辑器
macos·编辑器·sublime text
神码编程17 小时前
【Unity】 HTFramework框架(六十四)SaveDataRuntime运行时保存组件参数、预制体
unity·编辑器·游戏引擎
菲fay18 小时前
Unity 单例模式写法
unity·单例模式
mzak19 小时前
vscode集成deepseek实现辅助编程(银河麒麟系统)【详细自用版】
linux·vscode·编辑器·银河麒麟·deepseek
一个程序员(●—●)19 小时前
编辑器检视器面板深度扩展2+编辑器菜单栏扩展
编辑器
火一线19 小时前
【Framework-Client系列】UIGenerate介绍
游戏·unity