Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Kovenant · Oct 10, 2013 at 06:24 AM · gui style

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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
    }
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kovenant · Oct 10, 2013 at 06:56 AM 0
Share

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

avatar image vexe · Oct 10, 2013 at 07:00 AM 1
Share

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.

avatar image Kovenant · Oct 10, 2013 at 07:28 AM 0
Share

Thank you, vexe!

avatar image vexe · Oct 10, 2013 at 07:33 AM 0
Share

Anytime yo! :)

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges