Is it possible to make a C# script variable changeable in the Editor, without being public?

I have some C# scripts with a bunch of variables that I’d like to be able to change in the editor, to make testing and iterating easier, however I don’t really want to have any of those variables be public since they really shouldn’t be changed by anything within the game itself at runtime.

Though this is generic to a lot of scripts in my game, as an example in my Weapon script I have some variables like reload time, damage, firing speed etc… Now obviously nothing else should be able to ever change those variables, but I’d like to be able to initially set them from the editor so that I can control everything from within Unity itself rather than having to go out to various XML files or whatever to change things.

Is there any good way I can do this? My temporary solution was to have a public and private version of each variable. The public one gets set in the editor, and then on object creation the value is copied to the private version, and the public version is then ignored. That feels pretty awful to me though, doubling the amount of variables in each script and then never even using half of them after the first second.

Is there some proper way to do this, or should I just give in and load in values like this from XML files instead? That certainly feels cleaner, but I’d really like to have everything in the Editor itself.

You can have a custom editor call in to a function in the class itself:

[Thing.cs]
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class Thing : MonoBehaviour {
  [SerializeField] private int count;

#if UNITY_EDITOR
  public void ShowEditGUI() {
    count = EditorGUILayout.IntField("Count",count);
  }
#endif
}

...
[ThingInspector.cs]
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(Thing))]
public class ThingInspector : Editor {
  public override void OnInspectorGUI() {
    (target as Thing).ShowEditGUI();
  }
}