BioMotionLab / TUX

A framework for experiments in Unity and VR
https://biomotionlab.github.io/TUX/
Other
29 stars 4 forks source link

Automatically set API Compatibility Level and Scripting Runtime Version #34

Closed A-Ivan closed 2 years ago

A-Ivan commented 3 years ago

Hi,

I wrote a script (below) to help with the setup of bmITUX. In the instructions it is noted that the the API Compatibility Level needs to be set to .NET 4.0 and Scripting Runtime Version needs to be set to .Net 4.x Equivalent.

To make this automatic, and because sometimes Unity changes where these settings are placed in the editor, I created the script below. This may be helpful to others:

You just need to add this script, called "AutomaticallyConfigureSettings", to your Assets folder in Unity, I suggest a "Scripts" folder to make it more organized.

In the Unity Editor, a Menu option will appear, called "bmITUX", with a suboption called "Initial Setup For bmITUX Use", clicking on this option will automatically setup both the API Compatibility level and the Scripting Runtime version. Note, it takes around 5 seconds for the Unity Editor to update these settings (at least on my computer).

image

using UnityEngine;
using UnityEditor;

public class AutomaticallyConfigureSettings : MonoBehaviour
{
    [MenuItem("bmITUX/Initial Setup For bmITUX Use")]
    private static void SetSettingsComputer()
    {
        // Sets the Build Target Group to be the current build target group (required) and the API Compatibility Level to be .NET 4.6
        PlayerSettings.SetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup, ApiCompatibilityLevel.NET_4_6);

        // Only set the Scripting Runtime Version if the Unity version is 2019 (as scripting runtime version was deprecated as of 2020)
        if (Application.unityVersion.Contains("2019"))
        {
            PlayerSettings.scriptingRuntimeVersion = ScriptingRuntimeVersion.Latest;
        }

        Debug.Log("API Compatibility set to .NET 4.x and Scripting Runtime Version set to .Net 4.x Equivalent. Setup complete.");
    }
}

@AdamBebko , not sure if it works, as this setup may be required before using the "Script Helper Tool", but if not, this automatic setup may be something interesting to use as an explicit option or an implicit (background) part of this tool (check before if the API has already been set, if not then set it and then continue with the setup (design file, runner, etc.)).

AdamBebko commented 3 years ago

This is excellent! I will include it in the next version, with an attribution to you in this class. Thanks so much for contributing!

Adam

A-Ivan commented 3 years ago

Great, glad to be of help. You're welcome. Ivan

A-Ivan commented 3 years ago

@AdamBebko In the Standalone VR issue I create an updated version of the script I provided here. That one may be better to use/build on.

AdamBebko commented 2 years ago

This version of the script is modified slightly and included in v3. Thanks again! I decided not to use the expanded version, since I have no way to test it and I won't be directly supporting the standalone headsets.

I do plan on adding a section in the docs about standalone headsets with a caveat that it's user-submitted and untested.

A-Ivan commented 2 years ago

Great. You're welcome, I'm glad I could be of help.

I think having that section for the standalone headsets, even if it is not officially supported, will help users. As they at least have a direction of what to do to help them.