Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Some questions about auto-generated c# class

Discussion in 'Input System' started by ConfusedCactus, Aug 2, 2020.

  1. ConfusedCactus

    ConfusedCactus

    Joined:
    Jul 3, 2018
    Posts:
    19
    I created a input action titled "PlayerControl" and pressed auto-generated c#class.

    So you will see a class like:

    public @PlayerControl()
    {
    }

    1) I am just wonder why there is a @ in front of the class name and what is its function?

    Also you have this function:

     public InputBinding? bindingMask
    {
    get => asset.bindingMask;
    set => asset.bindingMask = value;
    }

    2) Just wonder what does this bit "InputBinding? bindingMask" mean?

    Many thanks for answering!
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    It protects against compilation failing if C# reserved words are used for names (e.g. "return"). The code could check whether the identifier is indeed a reserved word and only use @ then. The current code just always appends the @.

    The ? is for a "nullable" type. InputBinding is a struct so it's not possible to tell the difference between a default-initialized value (
    default(InputBinding)
    ) and a value that has not been set. Thus the "nullable" thing. The default value is
    null
    and thus different from
    default(InputBinding)
    so it's possible to tell a mask that hasn't been set to one that has been set to default values.
     
    ConfusedCactus likes this.