Unity 通过editor脚本设置project setting属性

本文介绍如何在Unity中创建自定义编辑器脚本,通过菜单项修改Player Settings中的配置选项,包括公司名称、GPU Skinning等,并展示了如何通过代码设置特定于Android平台的多线程渲染。

新建unity 工程,创建Editor 目录,并在目录下创建editor脚本,添加如下代码

using UnityEditor;
using System.Reflection;
using System;
using System.Reflection.Emit;
public class ModifySettings
{
    [MenuItem("Custom/ ModifySettings")]
    private static void ModifySettings()
    {
        //设置属性
        UnityEditor.PlayerSettings.companyName = "XXXX";
        UnityEditor.PlayerSettings.gpuSkinning = !UnityEditor.PlayerSettings.gpuSkinning;
        //下边这个属性比较特别 与平台有关 直接设置在编辑器下看不到变化
        //UnityEditor.PlayerSettings.MTRendering = !UnityEditor.PlayerSettings.MTRendering;
        //通过这个方法设置 平台相关属性
        UnityEngine.Debug.Log(UnityEditor.PlayerSettings.MTRendering);
        UnityEditor.PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, UnityEditor.PlayerSettings.MTRendering);
        //可以通过vs中直接查看这个类的属性,如果vs不工作,可以用如下代码反射查看属性
        /**
        Type t = typeof(UnityEditor.PlayerSettings);
        foreach (PropertyInfo pi in t.GetProperties())
        {
            UnityEngine.Debug.Log(pi.Name);
        }
        **/
        //UnityEditor.PlayerSettings.OtherSettings.Mu
    }
}
<think>好的,我现在需要帮助用户找到在Unity中启用“Fast but no Exceptions”最高设置的相关代码。首先,我得回忆一下Unity设置方式。用户提到的这个选项应该和异常处理有关,可能是在Player Settings里的某个地方。 根据用户提供的引用,iOS开发中这个设置会影响异常处理,启用后游戏运行更快但崩溃时没有堆栈跟踪。Unity通常使用C#,而C#默认会处理异常,但可能在发布时需要调整IL2CPP的选项。 接下来,我需要确定如何在Unity中配置这个选项。IL2CPP有一个“Script Call Optimization”设置,选项包括“Slow and Safe”和“Fast but No Exceptions”。用户需要的是后者,并且可能想知道如何通过代码脚本设置。 不过,Unity的大部分项目设置不能在运行时通过代码直接修改,通常需要在Player Settings里手动设置。但用户可能希望自动化流程,比如使用编辑器脚本。这时候,可能需要通过修改PlayerSettings.SetIl2CppCompilerConfiguration方法,或者调整相关的API级别。 另外,iOS的优化设置可能涉及Xcode项目,但Unity通常允许在构建时配置这些选项。需要确认是否有对应的API可以设置IL2CPP的异常处理模式。查阅Unity文档的话,可能会找到PlayerSettings.SetIl2CppCompilerConfiguration和ApiCompatibilityLevel相关的设置。 总结步骤:首先,手动在Player Settings里找到IL2CPP的Script Call Optimization设置为Fast but No Exceptions。其次,如果需通过脚本,使用Editor脚本调用PlayerSettings.SetIl2CppCompilerConfiguration,可能还需要设置API兼容级别为.NET 4.x或.NET Standard 2.0,因为旧版本可能不支持。 需要验证这些步骤是否正确,比如检查Unity的API文档,确保代码片段有效。同时提醒用户编辑器脚本要放在Assets/Editor目录下,并且只能在编辑模式下运行。</think>在Unity中启用"Fast but No Exceptions"最高设置需要配置IL2CPP编译器选项,可通过以下两种方式实现: 一、通过编辑器界面设置: 1. 菜单栏选择 File > Build Settings 2. 点击Player Settings按钮 3. 在Other Settings > Configuration下 4. 将Script Call Optimization设置为"Fast but No Exceptions" 二、通过C#编辑器脚本实现自动化配置: ```csharp #if UNITY_EDITOR using UnityEditor; public class BuildSettingsConfigurator : MonoBehaviour { [MenuItem("Build/Apply Fast Exceptions Setting")] public static void SetFastNoExceptions() { // 设置IL2CPP编译器配置 PlayerSettings.SetIl2CppCompilerConfiguration( BuildTargetGroup.iOS, Il2CppCompilerConfiguration.Master); // 启用快速异常模式 PlayerSettings.SetIl2CppCodeGeneration( BuildTargetGroup.iOS, Il2CppCodeGeneration.OptimizeSpeed); // 设置API兼容级别(必要前提) PlayerSettings.SetApiCompatibilityLevel( BuildTargetGroup.iOS, ApiCompatibilityLevel.NET_4_6); } } #endif ``` 注意要点: 1. 该配置主要影响iOS/Android平台的IL2CPP编译[^1] 2. 需要Unity 2018.3+版本支持 3. 需在Build Settings中启用IL2CPP后端 4. 建议在Project Settings > Player > Other Settings中将"Scripting Backend"设置为IL2CPP 5. 编辑器脚本需要放在Assets/Editor目录下
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值