x


public enum

hi im still really confused on how i get a specific selection, sorry to be a pain but i learn as i work, here is my sample code, is there also a way to make a sub menu bit like the component menu and how would this be done if easier

#pragma strict
    @script ExecuteInEditMode()

public enum menuListA
{aa = 0,ab = 1,ac = 2,}
public enum menuListB
{ad = 3,ae = 4,af = 5,ag = 6,ah = 7,}

var menuA : menuListA;
var menuB : menuListB;

function Update(){

    if(menuA == menuListA.aa){

         Debug.Log("menuB = 5 to 7"); // this is the bit im really stuck on getting menu b to only a few options
    }

}
more ▼

asked May 29 '12 at 11:49 PM

reptilebeats gravatar image

reptilebeats
1.2k 57 108 137

Just for clarification - are you talking about a Unity Editor menu?

May 30 '12 at 12:09 AM whydoidoit

yes for the editor in java as my script is actually for game stuff

May 30 '12 at 12:14 AM reptilebeats

i cant seem to work it out i need to say only show 1 to3 and for something else only show 3 to 5, or i would rather have target = list a but if i select this then target = list b

May 30 '12 at 12:17 AM reptilebeats

Oh, just added an answer - and now I'm not sure I'm answering the right question! Sorry if that isn't what you are after...

May 30 '12 at 12:23 AM whydoidoit

well its to do with the editor but not really anything to do with the question

May 30 '12 at 12:29 AM reptilebeats
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

The only way to do this is by using a custom Editor subclass for your entire object. You are then free to present the UI any way you like. The simplest would be just to use DrawDefaultInspector, then add an error message if the settings violate whatever rules you want to enforce (eg. not AddComponent and Gameobject).

BTW, it seems you're using the first enum item purely to get text in the menu. It is probably cleaner to just have a "None" option, and ensure that the name of the variable is meaningful:

enum Action { None, AddComponent, Destroy }
enum Target { None, Rigidbody, Gameobject }

var action : Action;
var performActionOn : Target;
more ▼

answered May 30 '12 at 01:08 AM

Waz gravatar image

Waz
6.5k 23 33 71

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

x131

asked: May 29 '12 at 11:49 PM

Seen: 1000 times

Last Updated: May 30 '12 at 06:32 PM