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);
    }
}
相关推荐
天人合一peng6 小时前
unity 通过代码修改button及其名字字体的属性
unity·游戏引擎
GLDbalala10 小时前
Unity基于自定义管线实现经典经验光照模型
unity·游戏引擎
心疼你的一切13 小时前
Unity异步编程神器:Unitask库深度解析(功能+实战案例+API全指南)
深度学习·unity·c#·游戏引擎·unitask
呆呆敲代码的小Y15 小时前
【Unity 实用工具篇】 | Book Page Curl 快速实现翻书效果
游戏·unity·游戏引擎·u3d·免费游戏·翻书插件
AC梦1 天前
unity中如何将UI上的字高清显示
ui·unity
小贺儿开发2 天前
Unity3D 智慧城市管理平台
数据库·人工智能·unity·智慧城市·数据可视化
June bug2 天前
【领域知识】休闲游戏一次发版全流程:Google Play + Apple App Store
unity
星夜泊客2 天前
C# 基础:为什么类可以在静态方法中创建自己的实例?
开发语言·经验分享·笔记·unity·c#·游戏引擎
dzj20212 天前
PointerEnter、PointerExit、PointerDown、PointerUp——鼠标点击物体,则开始旋转,鼠标离开或者松开物体,则停止旋转
unity·pointerdown·pointerup
心前阳光2 天前
Unity 模拟父子关系
android·unity·游戏引擎