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);
    }
}
相关推荐
爱搞虚幻的阿恺2 天前
Niagara粒子系统-超炫酷的闪电特效(加餐 纸牌螺旋上升效果)
游戏·游戏引擎
_Li.2 天前
Simulink - 6DOF (Euler Angles)
人工智能·算法·机器学习·游戏引擎·cocos2d
weixin_424294672 天前
Unity 调用Steamworks API 的 SteamUserStats.RequestCurrentStats()报错
unity·游戏引擎·steamwork
HoFunGames2 天前
Unity小地图,Easy Minimap System MT-GPS插件
unity·游戏引擎
wy3258643642 天前
Unity 新输入系统InputSystem(基本操作)
unity·c#·游戏引擎
WarPigs2 天前
着色器multi_compile笔记
unity·着色器
ECHO飞跃 0122 天前
Unity2019 本地推理 通义千问0.5-1.5B微调导入
人工智能·深度学习·unity·llama
Unity游戏资源学习屋2 天前
【Unity UI资源包】GUI Pro - Casual Game 专为休闲手游打造的专业级UI资源包
ui·unity
冰凌糕2 天前
Unity3D Shader 顶点法线外扩实现描边效果
unity
星和月2 天前
Untiy使用说明
c#·游戏引擎