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

    }
}
相关推荐
小春熙子41 分钟前
Unity图形学之Shader结构
unity·游戏引擎·技术美术
Sitarrrr3 小时前
【Unity】ScriptableObject的应用和3D物体跟随鼠标移动:鼠标放置物体在场景中
3d·unity
极梦网络无忧3 小时前
Unity中IK动画与布偶死亡动画切换的实现
unity·游戏引擎·lucene
电子云与长程纠缠4 小时前
UE5.3中通过编辑器工具创建大纲菜单文件夹
java·ue5·编辑器
lucky九年5 小时前
vscode翻译插件
ide·vscode·编辑器
真·Wild·攻城狮6 小时前
【码农日常】Vscode Clangd初始化失败(Win10)
ide·vscode·编辑器
七灵微6 小时前
【测试】【Debug】vscode中同一个测试用例出现重复
ide·vscode·编辑器
逐·風11 小时前
unity关于自定义渲染、内存管理、性能调优、复杂物理模拟、并行计算以及插件开发
前端·unity·c#
_oP_i13 小时前
Unity Addressables 系统处理 WebGL 打包本地资源的一种高效方式
unity·游戏引擎·webgl
代码盗圣16 小时前
GODOT 4 不用scons编译cpp扩展的方法
游戏引擎·godot