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);
    }
}
相关推荐
叶帆1 天前
【YFIOs】用C#开发硬件之设备上云
开发语言·unity·c#
久数君1 天前
AI三维建模工具“造形家”:地理场景三维化的高效解决方案
unity·glb·ai算法·ai三维建模工具·地图框选·造形家·城市建筑模型
会思考的猴子2 天前
Unity VFX 属性 Postion 和 TargetPostion
unity
hai3152475432 天前
九章编程法 · 猜数字游戏 (GW-BASIC 重构版) *
人工智能·microsoft·游戏引擎·游戏程序
心前阳光2 天前
Unity资源导入之自动化资源导入
unity·自动化·游戏引擎
心前阳光2 天前
Unity之2021.3.45f2c1发布安卓程序遇到的问题
android·unity·游戏引擎
纪纯2 天前
PicoVR Unity Integration SDK 3.4 常用交互API
unity·游戏引擎·vr·pico
龙智DevSecOps解决方案2 天前
3A 游戏优化技术栈:如何打通引擎级分析工具与 DevOps 持续集成管线?
unity·性能优化·游戏开发·技术美术·perforce·unrealengine
葛兰岱尔2 天前
从 SolidWorks 到 Three.js,从 Inventor 到 Unity——制造业CAD模型“几何-语义一体化“转换,不再是天方夜谭!
开发语言·javascript·unity
鼎艺创新科技2 天前
三维电子沙盘中OSGB倾斜摄影数据的加载与渲染
游戏引擎·cocos2d