Autorun

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<csharp> using UnityEngine; using UnityEditor; // from the excellent http://answers.unity3d.com/questions/45186/can-i-auto-run-a-script-when-editor-launches-or-a.html /// /// Ex...")
 
m
Line 1: Line 1:
 +
Save this script as Autorun.cs in your Editor folder:
 
<csharp>
 
<csharp>
 
using UnityEngine;
 
using UnityEngine;

Revision as of 17:59, 1 October 2011

Save this script as Autorun.cs in your Editor folder: <csharp> using UnityEngine; using UnityEditor; // from the excellent http://answers.unity3d.com/questions/45186/can-i-auto-run-a-script-when-editor-launches-or-a.html

/// /// Execute some code exactly once, whenever the project is opened, recompiled, or run. /// [InitializeOnLoad] public class Autorun {

   static Autorun()
   {
       EditorApplication.update += RunOnce;
   }
   static void RunOnce()
   {
       Debug.Log("RunOnce!");
       EditorApplication.update -= RunOnce;

// do something here. You could open an EditorWindow, for example.

   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox