Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by webster · Jan 16, 2013 at 01:46 AM · uieditorwizard

Need help with Editor script

Hey all,

I'm needing to make an editor script which a) starts automatically to init some stuff when I open my project (possible?) b) accepts some input (I know how to make a Wizard, is that the only option?) and c) periodically runs something (like Update, doesn't have to be every frame though).

Is that all possible?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by numberkruncher · Jan 16, 2013 at 01:59 AM

a) starts automatically to init some stuff when I open my project (possible?)

Yes this is possible:

 using UnityEngine;
 using UnityEditor;

 [InitializeOnLoad]
 public static class SomeEditorScript {

     static SomeEditorScript() {
         // Do your stuff here...
     }

 }

See: http://docs.unity3d.com/Documentation/Manual/RunningEditorCodeOnLaunch.html

b) accepts some input (I know how to make a Wizard, is that the only option?)

You can create your own custom interfaces by creating your very own editor windows. As of the time of writing you cannot automatically display a window when your script first loads, but you can add a custom menu item which displays your interface:

 using UnityEngine;
 using UnityEditor;

 public static class SomeEditorWindow : EditorWindow {

     [MenuItem("Your Stuff/Some Editor Window")]
     static void Show() {
         GetWindow<SomeEditorWindow>();
     }

     void OnEnable() {
         title = "My Editor Window";
     }

     void OnGUI() {
         GUILayout.Label("Place your controls here!");

         if (GUILayout.Button("Foo")) {
             // Do something here!
             GUIUtility.ExitGUI();
         }
     }

 }

See: http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow.html

c) periodically runs something (like Update, doesn't have to be every frame though).

There are several ways to do this depending upon what you are trying to achieve. The most generic solution is to attach an event handler as demonstrated below. This will frequently invoke your custom event handler. You can manually limit how often your logic is executed using the .NET DateTime class.

 void SomeFunctionToInitializeEvent() {
     EditorApplication.update += delegate {
         // Do your stuff here!
     };
 }

 // or alternatively you can use this syntax:

 void SomeFunctionToInitializeEvent() {
     EditorApplication.update += new CallbackFunction(MyEventHandler);
 }

 void MyEventHandler() {
     // Do your stuff here!
 }

See: http://docs.unity3d.com/Documentation/ScriptReference/EditorApplication-update.html

The following documentation includes references to other callbacks that may be of use to you: http://docs.unity3d.com/Documentation/ScriptReference/EditorApplication.html

It is also worth noting that you can use the Update message in your custom EditorWindow which is called at regular intervals so long as the window is open.

I hope that this is of help to you.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image webster · Jan 16, 2013 at 02:11 AM 0
Share

$$anonymous$$any thanks

avatar image numberkruncher · Jan 16, 2013 at 02:17 AM 0
Share

@web No problem, glad that I could help :-) Happy coding!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem scale ui custom font text 0 Answers

One button doesn't cycle through an array when pressed. 1 Answer

Perform action on save/load in editor 2 Answers

Custom Asset Icons? 2 Answers

Editor script - any callback when target is first instantiated? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges