Closed YacineFenina closed 8 years ago
Hi there,
I'm not sure what you mean by "I don't need to call my get propertie at each begining of the game" Anything you do in the editor, stays in the editor. It won't actually run in the game when you build it.
You could just pass [Popup] the function name that returns an array/list of the method names you want to populate the results with. i.e.
string[] GetFunctionNames() { return typeof(Something).GetMethods().Select(x -> x.Name).ToArrray(); }
[Popup("GetFunctionNames")] public string FunctionName;
Does that not work for you?
You could tell Popup to update the list (call your function again to get the list of options) every frame or manually via a 'U' button.
Actually, that's exactly what I'm doing. I just put a Debug message in my "GetFunctionNames", and it is displayed at the beginning of the game . It means that the function is called at the begining of my game.
What do you mean by "beginning of the game"? When you first enter playmode? Well yes because Unity will create new editor objects so it will repaint everything and call Popup's OnGUI function. What behavior are you looking for? What do you want to happen?
You mean that it is only called because I'm in editor ?
I want that my popup menu fill once. When I launch the game, I have selected my function and I just want to be able to execute this one ! I don't need any search.
Yes once you select the function from the editor, it will be stored in your string (which I assume you have serialized, i.e. public or marked with [SerializeField] or what-have-you). If you run the game "in-editor" by hitting playmode, Popup's OnGUI will be called to populate the list again because you're still in-editor. It shouldn't mess up the value you chose in your string.
If you build and run the game however (not in-editor), then GetFunctionNames should never be called because there's no Unity editor anymore, just the game running. If that makes sense. You could give it a try by putting a lot in GetFunctionNames and seeing if it gets called.
Ok ! Great ! That's was my question ! :) Do you know where I can find this type of information about intern logic of unity ?
Not sure what information or logic you mean exactly. Could you elaborate a bit more so I can better answer?
Things like, what unity is doing during execution. For instance as you say : unity will rebuild new editor object when hitting play mode.
Things like that ...
Anyway, thanks for your answer it totally answers to my question ! :+1:
I think this might help: http://docs.unity3d.com/Manual/ExecutionOrder.html there's more stuff on the left side if you scroll. And http://blogs.unity3d.com/2014/06/24/serialization-in-unity/ - Another useful tip is to use ILSpy and inspect Unity's managed DLLs, I learned a lot just by reading their codes. You'll find them in YourUnityInstallDirectory/Editor/Data/Managed/ - Just experiment, be curios and hack things and you'll build up experience quite fast. Good luck!
Hi,
I'm trying to use [Popup] attribute to create a list of method that I can call after. I don't need to call my get propertie at each begining of the game, but I notice your plugin does !
What I'm doing : Get a list of methodInfo and extract the name of the method. Then, I intend to use reflexion. Do you know a better way to display method of a Type in inspector ? Do I have to do a custom editor ?
Thanks again for your work.
I wish you a very merry christmas !