- Home /
Adding functions to GUI./GUILayout.?
I'm currently working on a custom GUI skin. I want to take it a step further and add my own functions to GUI. / GUILayout.
Is there a way, for example, adding like GUILayout.Knob/.ProgressBar and so forth?
Answer by vexe · Oct 10, 2013 at 06:44 AM
You can't mess with the Built-in classes' code. But you can extend them by using extension methods
, but you can't add static extension methods, so you can't do stuff like GUI.MyThing
But how about you put them in your own GUI Utility class?
MyGUILayout.Knob
, MyGUI.ProgressBar
, etc
public class MyGUILayout
{
public static RETURN_TYPE Knob(INPUT_PARAMS)
{
// implement your function
}
}
I saw a tutorial on it somewhere but I can't find it again.. The script made it capable to type Transform.ResetPosition or something.. so I think it's possible to add stuff to the built-in classes actually :)
Yes you can add an extension method, but you can't add a static extension method so you can't access it like GUILayout.$$anonymous$$y$$anonymous$$ethod
But, if you want to add extra functionality to a class that you could have an instance of, like the Transform
class, you could do this:
public static class TransformExtensions
{
public static void ResetPosition(this Transform t)
{
t.position = Vector3.zero;
}
}
Now you can do stuff like:
myTransform.ResetPosition();
I think you saw it here?
Yes, you could have an instance of the GUI class, and thus add an extension method into it, but the instance's gonna be useless because the GUI
class is full of static functions which you can't call from an instance.
So you CAN do:
public static class GUIExtensions
{
public static RETURN_TYPE $$anonymous$$nob(this GUI g, INPUT_PARA$$anonymous$$S)
{
// implement your knob here
}
}
And then:
GUI g = new GUI();
g.$$anonymous$$nob();
But guess what? You can't do g.Button
, or g.Label
, etc cause all of these are static functions, and needs to be accessed in the form of: CLASS.FUNCTION
, so GUI.Button
, GUI.Label
, etc.
Your answer

Follow this Question
Related Questions
Progress bar moving texture? 3 Answers
GUI help || Information 1 Answer
GUI - Permanent Selection 1 Answer
GUIStyled button changes after being clicked 1 Answer
Timer With GUI 0 Answers