Search Unity

Script Editor Creator?

Discussion in 'Scripting' started by Studio_Akiba, Mar 1, 2015.

  1. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Are there any easy alternatives to creating editors for scripts?
    I have noticed many scripts having editors recently, and we would like to add editors to our own scripts, but they seem very complicated and no-one here has had any experience with them, our main question I suppose is:
    Are there any applications, plugins or assets that would allow us to easily create or "generate" a Unity Editor for each of our scripts?
     
  2. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
  3. seldom

    seldom

    Joined:
    Dec 4, 2013
    Posts:
    118
    It's unclear what you are asking about. Editors are made for certain tasks, not for scripts. All the editors you see on the asset store are written from scratch, there is no way to automatically generate one. If that doesn't answer your question, maybe you can rephrase it?
     
  4. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    We have submitted the first version of one of our defining features to the asset store, personally I would like to have a custom editor for it for the next versions, I have taken a swing at making an editor for it, it ended disastrously.
    As stated above, we are mostly a graphics company, and have little in the way of programmers, none that have had specific experience with editors, and as I am the only one pushing for this, it is up to me to bring the first version to the table.
     
  5. seldom

    seldom

    Joined:
    Dec 4, 2013
    Posts:
    118
    What is the editor window supposed to do? As long as you only want to expose some parameters to the user, you should be able to get it done even as non-programmer.
     
  6. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Essentially just have a button to add a trigger object with 2 specific scripts on (of a specific size (1,2,1)) at the editor cameras pivot point, a button to add a specific script to the selected object, from there I would probably be able to figure out the rest as I go along, we have a little while until we are planning the next version of our asset.
     
  7. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    244
    I've heavily commented one of my editors and put some examples. It should be very easy to edit this to your liking. :)

    Editors are basically broken into 3 parts.
    1. Create variables to be used/shown in editor.
    2. Define them by pulling the values from the original class.
    3. Display them in whatever fasion you want, and add any logic/buttons you need.

    Edit: Below is for custom inspector functionality. To have an actual separate editor window for your script is a much larger/slower process. Hopefully this will be all you need.
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. //Put original class name here, with editor class name below. CanEditMultipleObjects is optional
    5. //This file must also be in a folder called 'Editor' or it won't work.
    6. [CustomEditor(typeof(ObjectTools)), CanEditMultipleObjects]
    7. public class ObjectToolsEditor : Editor {
    8.  
    9.     //List all variables the editor should use here.
    10.     //They are created as SerializedProperty objects, define below.
    11.     public SerializedProperty
    12.         type,
    13.         vec3,
    14.         vec3b,
    15.         check,
    16.         num,
    17.         numb,
    18.         numc;
    19.  
    20.     //Define them here. This pulls the values from the class, and brings them into the editor
    21.     //These are all serialized objects. So if 'vec3' used to be a vector3, here it is now a serialized object.
    22.     //Info on how to use it below.
    23.     void OnEnable () {
    24.         type = serializedObject.FindProperty ("type");
    25.         vec3 = serializedObject.FindProperty ("vec3");
    26.         vec3b = serializedObject.FindProperty ("vec3b");
    27.         check = serializedObject.FindProperty ("check");
    28.         num = serializedObject.FindProperty("num");
    29.         numb = serializedObject.FindProperty("numb");
    30.         numc = serializedObject.FindProperty("numc");
    31.     }
    32.  
    33.     //Now that the variables are defined, we can finally show the layout.
    34.     public override void OnInspectorGUI() {
    35.         serializedObject.Update (); // Updates all values
    36.  
    37.  
    38.         //Feel free to display ANY values in this function in any order or to use buttons (google em)
    39.         // EditorGUILayout.PropertyField(type); is all you need to do to display a value.
    40.         // to get the actual value to be used in logic, use type.boolValue for example.
    41.         // If you want to show the property in a specific way, check out the EditorGUILayout class!
    42.         // Below is an example of my editor layout.
    43.  
    44.  
    45.         //'type' is normally an enum. So it will display a drop down list for type.
    46.         //The editor automatically displays the proper field for the variable passed in.
    47.         EditorGUILayout.PropertyField(type);
    48.  
    49.         //Creates a separator, to make the content look nicer
    50.         EditorGUILayout.Separator();
    51.  
    52.         //Because 'type' is a serialized object in the editor, we make
    53.         //a new _type enum variable, and get the enum value from 'type'
    54.         ObjectTools.Type _type = (ObjectTools.Type)type.intValue;
    55.  
    56.  
    57.         switch(_type) {
    58.         case ObjectTools.Type.Rotate:
    59.             //the type enum (drop down) is set to 'Rotate'.
    60.             //Here I only display the vec3 variable, with the title "Rotate by"
    61.             EditorGUILayout.PropertyField(vec3, new GUIContent("Rotate by"));
    62.             break;
    63.         case ObjectTools.Type.Move:
    64.             //the type enum (drop down) is set to 'Move'.
    65.  
    66.             //Display vector3 property with title "Move to"
    67.             EditorGUILayout.PropertyField(vec3, new GUIContent("Move to"));
    68.  
    69.             //Display float property with title "Move to"
    70.             EditorGUILayout.PropertyField(num, new GUIContent("Over time"));
    71.  
    72.             //Display bool property with title "Easing"
    73.             EditorGUILayout.PropertyField(check, new GUIContent("Easing"));
    74.  
    75.             //Display a slider between 0-1
    76.             EditorGUILayout.Slider(numb, 0f, 1f, new GUIContent("Start at progress %"));
    77.  
    78.             //gets the boolean value from check (since check is normally a boolean,
    79.             //but it's created as a serialized object above
    80.             if(check.boolValue){
    81.                 //if check is checked (the easing above) it will display this property.
    82.                 EditorGUILayout.PropertyField(numc,new GUIContent("Ease Time"));
    83.             }
    84.             break;
    85.         }
    86.  
    87.         serializedObject.ApplyModifiedProperties (); // Saves all values
    88.     }
    89. }
     
    Last edited: Mar 1, 2015
  8. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    this all looks incredibly complicated to me, as I said, I am a graphics artist, we only have one programmer and he is part-time and hasn't got any experience with editors.
     
  9. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    244
    It "Looks" complicated, but it's super simple.

    That's the first editor I've ever made. I literally found one on line and changed some things around and found it to be quite easy. He can do the same with mine. As a bonus i put in super descriptive comments. Let him read the comments and give it a try.

    Literally 10 or so minutes to read through and just put in your own values.
     
  10. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Continually restating your not a programmer wont make it any easier. There is no visual way to desgine editor uis you have to do all of this in code with the editor GUI stuff.

    It will be a easy task for a programmer of any experience level so just get your programmer to do it once he has time.