Unity方便修改产品名和包名的小工具

csharp 复制代码
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;

public class BundleIdentifierEditor : EditorWindow
{
    // 存储选项数据
    private class Option
    {
        public string label;
        public string productName;
        public string bundleIdentifierSuffix; // 仅存储后缀部分
    }

    private const string DefaultPrefix = "com.HappyMaster."; // 固定前缀部分

    // 存储所有选项
    private List<Option> options = new List<Option>();

    // 当前选中的选项
    private Option selectedOption;

    // 初始化窗口
    [MenuItem("Tools/Bundle Identifier Editor")]
    public static void ShowWindow()
    {
        GetWindow<BundleIdentifierEditor>("Bundle Identifier Editor");
    }

    private void OnEnable()
    {
        // 默认选项(可以修改或删除)
        options.Add(new Option { label = "Option 1", productName = "影片播控", bundleIdentifierSuffix = "VideoControl" });
        options.Add(new Option { label = "Option 2", productName = "影片服务端", bundleIdentifierSuffix = "VideoServer" });

        // 默认选中第一个选项
        selectedOption = options[0];
    }

    private void OnGUI()
    {
        GUILayout.Label("选择并修改产品名称和捆绑标识符", EditorStyles.boldLabel);

        // 创建可选的选项
        for (int i = 0; i < options.Count; i++)
        {
            Option option = options[i];
            bool isSelected = selectedOption == option;
            if (GUILayout.Toggle(isSelected, option.label))
            {
                selectedOption = option;
            }
        }

        // 显示当前选中的选项的产品名和捆绑标识符
        if (selectedOption != null)
        {
            GUILayout.Space(10);
            GUILayout.Label("当前选项: " + selectedOption.label, EditorStyles.boldLabel);
            selectedOption.productName = EditorGUILayout.TextField("Product Name", selectedOption.productName);
            selectedOption.bundleIdentifierSuffix = EditorGUILayout.TextField("Bundle Identifier Suffix", selectedOption.bundleIdentifierSuffix);

            // 应用按钮
            if (GUILayout.Button("Apply Changes"))
            {
                ApplyChanges();
            }
        }

        // 添加新选项按钮
        GUILayout.Space(10);
        if (GUILayout.Button("Add New Option"))
        {
            AddNewOption();
        }
    }

    private void ApplyChanges()
    {
        if (selectedOption != null)
        {
            // 拼接默认前缀和用户提供的后缀
            string bundleIdentifier = DefaultPrefix + selectedOption.bundleIdentifierSuffix;

            // 应用到 PlayerSettings
            PlayerSettings.productName = selectedOption.productName;
            PlayerSettings.applicationIdentifier = bundleIdentifier;

            Debug.Log($"Product Name set to: {selectedOption.productName}");
            Debug.Log($"Bundle Identifier set to: {bundleIdentifier}");
        }
    }

    private void AddNewOption()
    {
        // 新建一个选项,使用默认名称和标识符
        Option newOption = new Option
        {
            label = "Option " + (options.Count + 1),
            productName = "NewProduct",
            bundleIdentifierSuffix = "NewProduct"
        };

        // 添加到选项列表
        options.Add(newOption);
    }
}
相关推荐
黄思搏17 小时前
基于标注平台数据的 Unity UI 自动化构建工作流设计与工程实践
ui·unity·蓝湖·vectoui
羊羊20351 天前
开发手札:Unity6000与Android交互
android·unity·android-studio
Zarek枫煜1 天前
C3 编程语言 - 现代 C 的进化之选
c语言·开发语言·青少年编程·rust·游戏引擎
Sator12 天前
Unity AStarPath的踩坑点
unity
榮華2 天前
DOTA全图透视辅助下载DOTA全图科技辅助下载DOTA外挂下载魔兽争霸WAR3全图下载
数据库·科技·游戏·游戏引擎·游戏程序·ai编程·腾讯云ai代码助手
RPGMZ2 天前
RPGMakerMZ 游戏引擎 野外采集点制作
javascript·游戏·游戏引擎·rpgmz·野外采集点
星河耀银海2 天前
Unity基础:摄像机Camera的参数设置与视角控制
unity·游戏引擎·lucene
星河耀银海2 天前
Unity基础:Transform组件的位移、旋转与缩放详解
unity·游戏引擎·lucene
weixin_409383122 天前
godot 击败敌人后增加经验的脚本
游戏引擎·godot
海清河晏1113 天前
数据结构 | 单链表
数据结构·unity·dreamweaver