I’m trying to make a static class that is callable from anywhere. I want it to let me create an object from that class at a specific location. Here is where I’m at
I though maybe I could create an enumeration and put all the objects in there. Then I could access the objects through a static function. I know I’m doing plenty wrong. Should I even use enums?
An enum is essentially just a named wrapper around an integer value. There’s plenty of language-specific documentation about them if you search around MSDN etc.
Thanks, how would I go about making it so in another code I can type Tools.CreatePrimitive(primitive name, transform). Would i have to make if statements for every object?
I’m making an editor extension that comes with a lot of new primitives. I have it set up so you can create them in the editor from the menu, but I also want the objects to be able to be called through scripts http://forum.unity3d.com/threads/community-asset-idea.257799/
Because enum is basically an integer you can use it to index into an array if you want. So you could make an array containing the actual primitive GameObjects and reference into it with enum values cast to integer.
The more verbose (and uglier) way to do it would be to use a switch or if/else block.
Sorry if I’m being nagging…But how would I specifically make it happen. I would create an array in the class with all the objects. Would the array need to be static or public? Then I make an enum and name all of the corresponding “keywords” for each object in the array. Then would I make a public static function? If so, what argument would I pass through? and what would I put inside the function?
Sorry for asking so many questions! I’m really excited to figure this out
Also, I know I can access the primitives through Resources, which is the folder I have them in. How would I set up a for loop statement that adds all of the objects in the primitive folder to the array, and then possibly the enum? I would love to know because I have A LOT of primitives and it took me near a whole day to type out each primitives’ @MenuItem and static function, even with copying and pasting!
God I feel dumb, So in my CreatePrimitive function, between the brackets, I’ll put
for (obj : GameObject in Resources.Load("PrimitiveFolder"))
{
//And then here I would add that obj to the objArray that I would create right under the Tools class? I don't know how to do this either :(
}
You’re not wasting my time - or anyone else’s time. I’m simply saying you’ll be better served by having a good grasp of the conceptual foundations of programming.
Yeah, I mean I’m really solid at most basic stuff, and then a couple intermediate. I learn whatever comes to me easiest, first. I learned how to communicate between objects way before I understood for loops! the are both pretty basic, but loops are absolute beginner concepts. I am not sure why my brain works that way!