The power of Editor scripts

Discussion in 'iOS Development' started by n0mad, Nov 30, 2009.

  1. n0mad

    n0mad

    Member

    Joined:
    Jan 27, 2009
    Messages:
    3,731
    Sorry, I couldn't hold myself to share with you the awesomeness that is Editor scripting.

    I don't know if other engines provide such a tool, but the ability to hack every step in the importing process is incredibly powerful.

    Just an example :
    Basically, I have fighting characters, with precise data like frame time, hit power for each move, collision time, etc..

    2 monthes ago, before I jumped into editor scripts, I had to enter myself all those datas in each fighter's class, and moreover enter manually all the split animations in the import settings... I got more than 60 anims per char .. A pain in the ass.

    Cherry on the cake : I'm using mirrored models for right side fighters. So if I don't want to hit my overall FPS by 50% with a negative X scale, I'd had to mirror all the anims manually in my 3D too, and name them properly in unity import settings... 120 x 8 x 3 forms to enter... Depressing.

    To make it short : now with classes like ModelImport, all I have to do is drag n drop any FBX in the editor, and bam, job's done.
    Datas are written to my classes, mirrors are generated automatically by a script, and anim split by diggin a simple .txt file that I update each time I'm producing a new anim.

    To an extent, we can imagine huge factorizing for some more complex applications, like automating avatar models creation from an external database.

    I wrote this thread because according to forum threads, I can't see that Editor scripts are that much popular. They should, because they can save a truckload of time, which is vital on iPhone production ;)
  2. arzi

    arzi

    Member

    Joined:
    Apr 6, 2009
    Messages:
    153
    I use some editor scripting too. We're making a tilebased game, so I made a tile editor inside Unity with editor scripts. It basically catches the mouse buttons, and then spawns prefabs to the scene. Additionally it allows to pick a tile from the scene as the selection and remove tiles, which makes the editing quite convenient.
    The tiles are also created by a script that takes a model and splits all its submodels into separate prefabs, adds needed components and so on.

    So yes, I do wholeheartedly agree that editor scripting is a really powerful tool, although irritatingly buggy in Unity iPhone. But when used with care (remember those backups) it can speed up the development a lot.
  3. n0mad

    n0mad

    Member

    Joined:
    Jan 27, 2009
    Messages:
    3,731
    The way you are using editor scripts sounds awesome. Clic-and-go state of mind is priceless for game studios.

    Furthermore, what bugs are you speaking of, in Unity's particular iPhone version ?
  4. arzi

    arzi

    Member

    Joined:
    Apr 6, 2009
    Messages:
    153
    The EditorGUI class doesn't work at all. The ordinary GUI methods can still be used, but it doesn't include all the useful editor elements. Creating prefabs with CreateAsset can mess up the whole project, and there are some crash bugs but I can't remember the details for those.
  5. rozgo

    rozgo

    New Member

    Joined:
    Feb 7, 2008
    Messages:
    158
    Same here.

    My game is heavily adventure based with several powerups. I have a Cheat Menu with several options to set the character at several stages in the game. I can also turn on and off all the items and powerups independently.

    One of the most useful scripts I have in my workflow is one that automatically generates optimized collision colliders as an AssetPostprocessor step.

    Actually, I wished editor scripting was more powerful. Blender (beta) is a step in the right direction. I still have to take a look at Unity's 2.6 features on this regard.

    Have to agree with Nomad 100%, editor scripts are extremely useful and probably underrated.

    EDIT: Main Unity editor features look a lot more powerful, very nice.
  6. tonyd

    tonyd

    New Member

    Joined:
    Jun 2, 2009
    Messages:
    1,224
    Editor scripting does appear to be powerful, but needs better documentation, IMO.

    Even after reading the manual page, it still took me a lot of trial and error to get a simple editor script to work.

    And I have experienced a few editor related crashes as well. It looks like Unity created a second assets folder, and could no longer find my scripts!
  7. the_gnoblin

    the_gnoblin

    Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    Yeah, Editor scripts are absolutely cool.

    But they, indeed, lack the documentation :).
    I wish all the API was documented a bit more detailed, or even allow moderated adding of examples by users.
  8. n0mad

    n0mad

    Member

    Joined:
    Jan 27, 2009
    Messages:
    3,731
    I have to agree, Editor classes documentation is too vague.

    It lacks of examples and logical links between functions. Actually it's not that hard to produce an efficient automatizer in a short time, but it does involve some trial and error.

    Come on Unity people, communicate more about it, it will save the cheer leader ;)
  9. mudloop

    mudloop

    New Member

    Joined:
    May 3, 2009
    Messages:
    1,082
    I haven't used Editor scripts yet, but I'm doing something similar in my new game - I'm using Adobe Flash as a level editor, and I wrote a jsfl script (Flash's equivalent to editor scripting) to export my levels to C# classes, which I then dump into my Unity project. So while I don't use Unity editor scripting (yet), I agree that editor scripting in general can be very useful.
  10. Yann

    Yann

    Member

    Joined:
    Oct 20, 2007
    Messages:
    423
  11. n0mad

    n0mad

    Member

    Joined:
    Jan 27, 2009
    Messages:
    3,731
    That's an excellent initiative Yann :)

    I guess the only reason why I didn't noticed this thread is once again because I didn't know how perful was Editor scripting, back in May ...

    I'll share my automatic animation splitter as soon as it fully works (planned to be next days).

    Clever Editor scripts can open a brand new world for indies, or even studios.

    Another example that came to mind : with the MonoScript class, you could even generate a whole runtime class in a single click, depending on which object you drag and drop on the scene.

    There should even be an Editor Scripting sub forum, imho.
  12. BogdanDude

    BogdanDude

    Member

    Joined:
    Jun 18, 2009
    Messages:
    74
    I just made this script because of the limited capabilities of Unity to merge scene objects from one scene file to another.

    This could prove great for doing environment scene layouts. Basically, you can replace any number of objects in your scene with another prefab in your project. So whenever you feel like updating some objects in your scene, or if you accidentally messed up some prefabs, just use this script :)

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4.  
    5. public class ReplaceSelectionWithPrefab : ScriptableWizard
    6. {
    7.     public GameObject prefab;
    8.     public bool includeChildren = false;
    9.     public bool excludePrefabs = false;
    10.     public bool deleteSelectedObjects = true;
    11.     public bool copyPosition = true;
    12.     public bool copyRotation = true;
    13.     public bool copyScale = true;
    14.  
    15.     private SelectionMode modePrefs;
    16.    
    17.  
    18.     [MenuItem("Custom/Replace Selection with Prefab %r")]
    19.     static void DoSet()
    20.     {
    21.         ScriptableWizard.DisplayWizard("Replace Selection with Prefab", typeof(ReplaceSelectionWithPrefab), "Set");
    22.  
    23.     }
    24.  
    25.     void OnWizardUpdate()
    26.     {
    27.         helpString = "Duplicate the selected prefab and place it around the scene to the position of the selected objects. Tick Include Children to also place the Prefab at the position of the children of selected objects or tick Exclude Prefabs if you don't want instanced objects (from prefabs) to be changed. Tick DeleteSelectedObjects to delete the original selection after placing the prefab. The new objects are nicely placed in the same hierarchy as the old ones.";
    28.     }
    29.  
    30.  
    31.     void OnWizardCreate()
    32.     {
    33.  
    34.         if (includeChildren || excludePrefabs)
    35.  
    36.             modePrefs = (SelectionMode.ExcludePrefab | SelectionMode.Editable | SelectionMode.Deep);
    37.         else
    38.             modePrefs = (SelectionMode.Editable);
    39.  
    40.         Object[] objs = Selection.GetFiltered(typeof(GameObject), modePrefs);
    41.  
    42.         foreach (GameObject go in objs)
    43.         {
    44.  
    45.      
    46.  
    47.             clone.name = prefab.name;
    48.             clone.transform.parent = go.transform.parent;
    49.             if (copyPosition)
    50.             {
    51.                 clone.transform.localPosition = go.transform.localPosition;
    52.             }
    53.             if (copyRotation)
    54.             {
    55.                 clone.transform.localRotation = go.transform.localRotation;
    56.             }
    57.             if (copyScale)
    58.             {
    59.                 clone.transform.localScale = go.transform.localScale;
    60.             }
    61.                
    62.  
    63.         }
    64.         if (deleteSelectedObjects)
    65.         {
    66.             foreach (GameObject go in objs)
    67.             {
    68.                 DestroyImmediate(go.gameObject);
    69.             }
    70.         }
    71.  
    72.     }
    73. }
    74.  
  13. n0mad

    n0mad

    Member

    Joined:
    Jan 27, 2009
    Messages:
    3,731
    Hello,

    I finally finished mine, a mirrored animationClip generator.

    Unfortunately, I came to realize that it's so dependant on each character rig that I couldn't succeed with producing a generic script.

    So all I could do was a methods guideline.

    Hope it helps,

    Cheers
  14. DaveA

    DaveA

    Member

    Joined:
    Apr 15, 2009
    Messages:
    270
  15. Fishypants

    Fishypants

    Member

    Joined:
    Jan 25, 2009
    Messages:
    344
    I myself have just discovered this feature, which I believe on its own rises Unity FAR above the competition.

    I am an avid Maya user, and write custom scripts for my team at work, so this editor customization is pretty much an exact clone of how Maya works, so I totally appreciate it.

    I'm falling in love with Unity more and more each day. :D