"func : WindowFunction" into a variable??

Hello,

I am searching a method to put a function name into a variable with C#

For exemple with Melscript (into Maya) we can deal with a string variable keeping the name of the function.
If you want to call it you can use the “eval” function and it gives something like the following :

string $myfunc = "SAMA_Script_A()" ;
eval ($myfunc);

Well with C#, a colleague spoke to me about the the “FuncDelegate” thing.
Did some research but I am into a complete misunderstanding.

Now what I am making is the following :

I work with the GUI.Window function :

static function Window (id : int, clientRect : Rect, func : WindowFunction, text : String) : Rect

In my code I am using it into another function to build many other windows using the same “template” :

	void Create_Window_A (float pos_X, int buttonCount, string Window_Content)
	{
		GUI.Window(0, new Rect(pos_X, Button_Pos_Y, Button_Scale_X * buttonCount, Button_Scale_Y), Window_Content, "test", GUI.skin.FindStyle("Window"));
		
	}

Window_Content is the function building the content of my window.

Well, for now that is a string variable because I am years of light to understand how to deal with.

Then does someone know how to travel a function with variable into function entry to use it into GUI.Window with C#?? :face_with_spiral_eyes::face_with_spiral_eyes:

Thank you much for your help… :frowning:

well i am not sure how this GUI.Window work , but to pass a fct as argument in another you can do that way ( i am pretty sure there is maybe other clever way but at last that may give you an idea

using UnityEngine;
using System.Collections;

public class DelegateExemple : MonoBehaviour
{
	// create function pointer
	delegate void MyDelegate();
	MyDelegate myDelegate;
	
	void Start()
	{
		// assign a function to the delegate, method signature should match !
		myDelegate = ComeFromDelegate;
		
		// call dumb fct..
		SomeFunctionWaitingForDelegateType(myDelegate);
	}
	
	// a stupid function to test ...
	void SomeFunctionWaitingForDelegateType(MyDelegate myFunctionDelegate)
	{
		myFunctionDelegate();
	}
	
	// that will be our function stored in our delegate
	void ComeFromDelegate()
	{
		Debug.Log("I was the delegate function bouh !!!!!!");	
	}
}

voila démerde toi maintenant ^^…

oh by the way looking at doc example , it seem you just need to path the fct name if this one is in same script…

okkkkk!!! I understand better!

I just did some test.
The delagate tips works, but still getting issue with the GUI.Window.

2 errors always come back :

Assets/Application/Sama_Scripts/Menu_Browser_A.cs(142,21): error CS1502: The best overloaded method match for `UnityEngine.GUI.Window(int, UnityEngine.Rect, UnityEngine.GUI.WindowFunction, string, UnityEngine.GUIStyle)' has some invalid arguments

Assets/Application/Sama_Scripts/Menu_Browser_A.cs(142,21): error CS1503: Argument `#3' cannot convert `Menu_Browser_A.MyDelegate' expression to type `UnityEngine.GUI.WindowFunction'

It starts to be a little bit deep for what I would like to do…
Then I will maybe do it in a simple way writing each time the GUI.Window thing…

I keep what I done with your tips, and maybe later, with more skill, I’ll find a way to make it works with the delegate!!

Really thank you for helping me to understand the concept of “delagate”!