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

    }
}
相关推荐
WebCandy42 分钟前
Github Copilot:已免费,速回归!!!
编辑器·github·copilot·ai编程
乐闻x2 小时前
VSCode 插件开发实战(九): 不同插件之间如何通信
ide·vscode·编辑器
乐闻x2 小时前
VSCode 插件开发实战(十): 环境变量Env设置与管理
ide·vscode·编辑器
机器懒得学习2 小时前
打造高效的 LaTeX 公式编辑器
编辑器
超龄魔法少女20 小时前
[Unity] ShaderGraph动态修改Keyword Enum,实现不同效果一键切换
unity·技术美术·shadergraph
蔗理苦21 小时前
2024-12-24 NO1. XR Interaction ToolKit 环境配置
unity·quest3·xr toolkit
花生糖@21 小时前
Android XR 应用程序开发 | 从 Unity 6 开发准备到应用程序构建的步骤
android·unity·xr·android xr
向宇it21 小时前
【从零开始入门unity游戏开发之——unity篇02】unity6基础入门——软件下载安装、Unity Hub配置、安装unity编辑器、许可证管理
开发语言·unity·c#·编辑器·游戏引擎
徐小夕@趣谈前端21 小时前
可视化大屏编辑器, 开源!
编辑器
天天进步20151 天前
TipTap编辑器:现代化的富文本编辑解决方案
编辑器