what is meaning of GUI

I am reading the manual of unity, and I don’t understand the meaning of GUI.
It says that the GUI class is the interface for Unity’s GUI with manual positioning, what does it mean it is the interface for unity’s GUI.

GUI == Graphical User Interface.

In the early days of Unity it only had one UI system, IMGUI, or Immediate Mode Graphical User Interface. The GUI class was one of the classes with which to do this for runtime.

When it says ‘interface’ it’s means an interface in the programming API sense. It’s an API with which to draw manually positioned UI.

1 Like

I would like to expand on the ‘interface’ thing as this is a word I’ve noticed over my years people struggle with in programming, especially in OOP (object oriented paradigm/programming).

An “interface” just means “the way in which you interact with a thing”. It’s the literal definition:
interface - noun - a point where two systems, subjects, organizations, etc. meet and interact.

You’re going to run into this word in a lot of places.

GUI - graphical user interface - we’re talking about how a user interfaces/interacts with the system, it is graphical in nature. This is in opposition to more legacy systems where the CLI was more common (or even older where it was potentially punch cards or other things).

CLI - command line interface - we’re talking about how a user interfaces/interacts with the system via a command line

API - application programming interface - we’re talking about how one may program against an application/program/library

class interface - the public members of a class with which you interact with an object of that class type

the interface keyword - in C# there is a special ‘interface’ keyword like:

public interface ISomeContractName
{
    string SomeProperty { get; }
    void DoThing();
}

Which you may implement as:

public class MyClass : MonoBehaviour, ISomeContractName
{
    public string SomeProperty => this.name;
    public void DoThing()
    {
        this.gameObject.SetActive(false);
    }
}

This interface is intended to define the public members of a potential object. This way multiple classes can all implement the same interface and then be treated similarly. This is referred to as “polymorphism” in OOP. The idea that 2 like objects can be treated similar. Where “like” means they have the same members, which is called the “class interface”.

So basically the interface keyword allows you to define a class interface explicitly. This is sometimes called a ‘contract’ because you’re explicitly writing down what makes them the same. This is as opposed to dynamic languages where we just rely on “duck typing” (if it looks like a duck, quacks like a duck, then it’s a duck) to share interfaces. C# is not dynamic but instead is “strongly typed” so therefore we use “interfaces” to define shared “interfaces”…

Yeah, that’s a LOT of different uses of the word interface. And you’re going to run into that word being use in event MORE ways than I listed (someone may very well respond with more examples).

I just wanted to cover that here real quick cause well I was taking a quick break while something built and figured I’d type that up.

So yeah basically when you see:

They’re very confusing saying that there is a class out there called GUI:

Which you use (interface with) to draw GUI elements for the user to interact (interface) with in Unity.

2 Likes

then this means unity GUI iinteracts with manual positioning.
Then what is manual positioning?

It’s UI that you position manually.

When it says ‘with manual positioning’, it doesn’t mean with some system called ‘manual positioning’, it’s just UI… that you position, manually.

Manual positioning means that you manually / explicitly state where on the screen a certain GUI element should appear. For example

void OnGUI()
{
    if (GUI.Button(new Rect(100,50,100,20), "Test Button"))
    {
        Debug.Log("You pressed the test button");
    }
    GUI.Label(new Rect(200,250,150,30), "Some text");
}

Apart from manual positioning, Unity also has an automatic layout system which distributes the available space according to certain rules. For more information in the IMGUI, you may want to read my IMGUI crash course which was originally an answer to another question :slight_smile:

1 Like

thank you so much