How to use the Setup Trick in Unity

How to use the Setup Trick in Unity

#gamedevelopment?,?#unity3d?,?#csharp?,?#3d?,?#programming?,?#gaming


Foreword

Sometimes I am watching videos of Nick Chapsas, a Youtube content creator for C# and .Net. The topic of one of his videos is called The setup trick that .Net libraries use.

I recently applied this idea to one of my Typescript projects, where I needed to prepare some classes that will be used by other developers in the future. However, since my newsletter is currently focused on Unity, I will introduce you to the idea using MonoBehaviours.

Design

In Figure 1 you can see a class which contains typical attributes of different character classes of a roleplaying game. For the sake of simplicity, the fields are all marked as public. The most important part here is the options parameter inside the constructor!

As you can see, this parameter is not used in the Farmer script. If you now add the Farmer script to any GameObject in your scene, you will see in the Unity Inspector that all fields contain their default values.

Es wurde kein Alt-Text für dieses Bild angegeben.
Figure 1

However, if you add the Warrior or Mage script (see Figures 2 and 3) to any GameObject instead, you will notice that some attributes have different values.

Es wurde kein Alt-Text für dieses Bild angegeben.
Figure 2


Es wurde kein Alt-Text für dieses Bild angegeben.
Figure 3

Final Words

I have only described one use case within Unity projects today. But there are several others. So I highly recommend to watch the Youtube video for inspiration.

The setup trick is usually worthwhile when there are a large number of configuration options and implementing many method overloads does not seem reasonable.


That's it for today.

What do you think about?the Setup Trick? Have you used it before or do you have concerns about its usefulness? Or do you think that I have forgotten an important aspect, then feel free to leave a comment.

And if you are interested in topics like?#gamedesign, project organization or software design patterns, don't forget to press the?Follow?button on?my profile page?or add me as a contact. Not convinced yet? Well, maybe you will be once you read some of my?other articles.

要查看或添加评论,请登录

Lars Wobus的更多文章

  • Brief introduction of my main game mechanics

    Brief introduction of my main game mechanics

    As some readers of my newsletter already know, I'm currently developing a turn-based strategy game, among many other…

  • UI & UX design from a Programmer's Perspective

    UI & UX design from a Programmer's Perspective

    As some people already know, I'm currently developing a strategy game as part of my second master's degree at the…

  • Asset and Project Management for Indie Game Developers

    Asset and Project Management for Indie Game Developers

    This week, I want to talk about Miro, which my tutors and comillitons recommended to me some time ago. It's an online…

  • Unfinished Unity Projects (Round 2)

    Unfinished Unity Projects (Round 2)

    #Unity #3D #Blender Foreword Welcome back to episode 20 of my newsletter. For this particular episode, I thought we'd…

  • Greyboxing in Blender

    Greyboxing in Blender

    Hello fellow game devs and hobbyists and welcome back to the next episode of my newsletter. This time I will talk about…

  • The importance of a core gameplay loop

    The importance of a core gameplay loop

    The need for a good gameplay loop can be summed up in one sentence. If the main game mechanics are flawed or not…

    1 条评论
  • Data Analysis before, during and after Live Events

    Data Analysis before, during and after Live Events

    #marketing - #games - #gaming - #gamedevelopment - #videogames On Friday, April 14, 2023, I visited the game festival…

  • Paper Prototyping in Game Development

    Paper Prototyping in Game Development

    Foreword Last week one of the instructors at the University of Applied Science in Dresden said that he insists that I…

  • Data Driven Marketing - About Touchpoints and Customer Journey

    Data Driven Marketing - About Touchpoints and Customer Journey

    Foreword In the past, it was enough to advertise new products widely to boost sales. But that is no longer sufficient!…

  • Market Research for Game Developers

    Market Research for Game Developers

    Foreword Only a few people already know that I have started a second master study on the subject of Games and XR…

社区洞察

其他会员也浏览了