Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

The power of Editor scripts

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

  1. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    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

    Joined:
    Apr 6, 2009
    Posts:
    154
    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

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    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

    Joined:
    Apr 6, 2009
    Posts:
    154
    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

    Joined:
    Feb 7, 2008
    Posts:
    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

    Joined:
    Jun 2, 2009
    Posts:
    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

    Joined:
    Jan 10, 2009
    Posts:
    722
    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

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    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

    Joined:
    May 3, 2009
    Posts:
    1,107
    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

    Joined:
    Oct 20, 2007
    Posts:
    432
  11. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    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

    Joined:
    Jun 18, 2009
    Posts:
    89
    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.             GameObject clone = EditorUtility.InstantiatePrefab(prefab) as GameObject;
    48.             clone.name = prefab.name;
    49.             clone.transform.parent = go.transform.parent;
    50.             if (copyPosition)
    51.             {
    52.                 clone.transform.localPosition = go.transform.localPosition;
    53.             }
    54.             if (copyRotation)
    55.             {
    56.                 clone.transform.localRotation = go.transform.localRotation;
    57.             }
    58.             if (copyScale)
    59.             {
    60.                 clone.transform.localScale = go.transform.localScale;
    61.             }
    62.                
    63.  
    64.         }
    65.         if (deleteSelectedObjects)
    66.         {
    67.             foreach (GameObject go in objs)
    68.             {
    69.                 DestroyImmediate(go.gameObject);
    70.             }
    71.         }
    72.  
    73.     }
    74. }
    75.  
     
  13. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    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

    Joined:
    Apr 15, 2009
    Posts:
    310
  15. Fishypants

    Fishypants

    Joined:
    Jan 25, 2009
    Posts:
    444
    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