x


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.

more ▼

asked Jan 16 '12 at 02:27 AM

dago23 gravatar image

dago23
91 3 5 8

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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..

more ▼

answered Jan 16 '12 at 05:27 AM

flamy gravatar image

flamy
3.6k 5 12 38

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

@MenuItem ( "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...

Jan 17 '12 at 05:49 AM jahroy
(comments are locked)
10|3000 characters needed characters left

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", ...
more ▼

answered Jan 16 '12 at 08:26 AM

dago23 gravatar image

dago23
91 3 5 8

(comments are locked)
10|3000 characters needed characters left

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 :)

more ▼

answered Jan 16 '12 at 09:28 PM

dago23 gravatar image

dago23
91 3 5 8

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??!!

Jan 17 '12 at 05:13 AM flamy

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

Jan 17 '12 at 09:44 AM dago23
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x22

asked: Jan 16 '12 at 02:27 AM

Seen: 578 times

Last Updated: Jan 17 '12 at 09:44 AM