Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

EditorPrefs pre-defined magic strings

Discussion in 'Documentation' started by Baste, Jun 29, 2016.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,224
    The EditorPrefs class allows us to modify some properties of the Unity Editor that's not modifiable anywhere else, but this isn't documented anywhere.

    As an example, the property "kAutoRefresh" controls the editor's autoRefersh property:

    ThisIsTheOne.jpg

    Toggled like this:

    Code (csharp):
    1. EditorPrefs.SetBool("kAutoRefresh", true/false);
    I'm assuming that the other toggles there (and a bunch of other properties) are controlled by EditorPrefs. It'd be really nice if all of the properties that are available to the user either were written down somewhere, or (preferably) were exposed in a more intuitive way.

    There's also the (very slight) possibility that a user might use "kAutoRefresh" or another, pre-used variable name for their own editor script, which would Break Things and Be Bad.
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,561
    There are a few simple things you can do if you want to "reverse engineer" the editor like that:

    1. Use a decompiler, such as Reflector, DotPeek or any other tool that allows you to decompile managed (C#) code.

    Look for all usages of EditorPrefs.SetXXXX and EditorPrefs.GetXXXX. This should get you all the different keys that the editor uses, as well as the exact scenario in which it is used (should be pretty straightforward to understand what each value does).

    Note that it may be a pretty lengthy process (there are probably many different usages).

    2. Using MonoDevelop and a few function breakpoints, setup as shown in this image:
    upload_2016-7-4_0-41-47.png

    since MonoDevelop allows setting up function breakpoints, even for code you don't have (e.g: UnityEditor), you can set up breakpoints for the EditorPrefs methods and have each breakpoint that fires print a simple message (see on the right).

    Voila! you get many different keys that the editor uses. Note that in this case, you are missing the "context" - that is, what the actual key means... :)
     
  3. Alex_May

    Alex_May

    Joined:
    Dec 29, 2013
    Posts:
    198
    Hi all - documentation of these is possible but low priority right now. If you can't use the above (very clever) method, please see this tool: https://github.com/CapnRat/Unity-Utilities which may help you.
     
    liortal and Baste like this.