I have a requirement which I was not able to resolve by googeling.
I have a couple scripts on gameobjects that define settings for my game, e.g. shoult it connect to Steam or not, am I in developer cheat mode or not, do I use VR or not, etc. I’m doing the setup currently in Editor.
I would like to create different configurations for my game and set them via script, so I can link the setting to a menu entry or button and just set it before building the game.
However, I fail to understand how I can modify editor values of gameobjects.
You could have a Settings ScriptableObject, and a SettingsManager that contains the current settings. Every different configuration would be a new asset, so a SteamSettings etc.
You could add a simple button to the inspector which can apply those ScriptableObject values in the editor.
Make an Editor script for your main script, then use DrawDefaultInspector to draw it as normal, then add a button underneath to apply all the settings, then you can build your game.
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(MyScriptName))]
public class MyScriptNameEditor : Editor {
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if (GUILayout.Button("Apply", GUILayout.Height(20f)))
{
...
}
}
}
Or just use a menu drop down to apply different settings.