• 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 dago23 · Jan 16, 2012 at 02:27 AM · extend

Create Predefined Script from Menu

Hi There.

When I create a new script, I click "Assets->create->c# Script" for example, then the new script is added. Is there a way to extend this create-menu for custom scripts/items?? Let's pretend there is a custom script derived from MonoBehaviour, called MyMonoBehaviour. Is there a way to create a new script derived from MyMonoBehaviour by the create-menu?? How can I extend this menu to do so?

To clearify, I mean this menu: create menu

Thanks for any help. Greets.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by flamy · Jan 16, 2012 at 05:27 AM

seems clear that you are looking for this..... this is an editor script. all editor scripts should be kept inside a folder called Editor and should be inherited for one of the editor classes.... For more info on editor scripts search unify (unity wiki) also you can have a look at this page..

Comment
Add comment · Show 1 · 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 jahroy · Jan 17, 2012 at 05:49 AM 0
Share

Yes, you can do the following to add to your picture (javascript):

 @$$anonymous$$enuItem ( "Assets/Create/Execute my Funky Script" )

 static function doFunkyStuff ()
 {
     print("You just chose a menu item!");
 }

If you place that script in a folder named Editor, you will see the menu item once the script compiles.

You can do anything you want with editor scripts:

You can add components, initialize variables, assign assets to scripts, etc...

avatar image
0

Answer by dago23 · Jan 16, 2012 at 08:26 AM

Thanks, but the question was more about, how to create a custom item, that behaves like an item in "Assets->create".

So that I click "Assets->create->New MyCostomItem". Then a new item is added to the project tree, whit a unique name like "NewMyCostomItem". Similar to "Assets->create->New C# Script". Which adds a new c# Script with a unique name "NewBehviourScript" (or "NewBehaviourScript1"....)

Is there any way to do that? Exactly I want to do that:

  • I have a custom BehaviourScript derived from MonoBehaviour, called "MyMonoBehaviour".

  • People that want to use this new BehaviourScript, should be able to add it like a normal c# script by "Assets->create->New MyMonoScript"

  • this adds a new c# Script which is by default derived from "MyMonoBehaviour" and gets a unique name: "NewMyMonoScript" or "NewMyMonoScript1" or "NewMyMonoScript2", ...

Comment
Add comment · 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
0

Answer by dago23 · Jan 16, 2012 at 09:28 PM

Is there really now way to do that?

So what about a Workaround: If I add a component, is there a way to generate a unique name when the component is added? Is there an event that tells me that a component was added? I then could use that event to create a unique name by myself?

Any help is appreciated :)

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 flamy · Jan 17, 2012 at 05:13 AM 0
Share

creating unique component (of script) means you are creating a new script file and adding it to the GameObject.. it is possible but y would someone have to do it??!!

avatar image dago23 · Jan 17, 2012 at 09:44 AM 0
Share

It's hard to tell. I need it because there are other scripts which should work with the provided script. And for some reason it needs to be unique.

So, if there's a way to do that, can you give me an example or a link or some more explanation??

Thanks

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Extending editor without script on GameObject? 1 Answer

Extend a line between two Vectors by a distance 0 Answers

Storing Data and Access Efficiency 0 Answers

Windows Unity Aplicaction on Extend Screen 0 Answers

Extending a class 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