Refactoring To state Pattern - Grid Placement System P6

Поділитися
Вставка
  • Опубліковано 29 чер 2024
  • In this Unity tutorial we start implementing the Remove Objects logic by first refactoring the code to State Pattern. At the end of this tutorial you will have a grid placement system that you can use in your own project.
    House building system in unity project template:
    courses.sunnyvalleystudio.com...
    Starter Project:
    / 80441380
    Scripts on github:
    github.com/SunnyValleyStudio/...
    Assets used:
    kenney.nl/
    𝗛𝗮𝘃𝗲 𝗮𝗻𝘆 𝗾𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀? 𝗝𝗼𝗶𝗻 𝘁𝗵𝗲 𝗱𝗶𝘀𝗰𝗼𝗿𝗱!
    / discord
    𝗣𝗟𝗘𝗔𝗦𝗘 support the channel:
    / sunnyvalleystudio
    00:00 Why do we need State Pattern
    01:24 Moving instantiation logic to separate script
    07:34 Moving Placement logic to separate script
    16:00 Creating State abstraction
    17:02 Using State Pattern
    #unity3d #gamedevelopment #indiegamedev #sunnyvalleystudio

КОМЕНТАРІ • 18

  • @starfall-studio
    @starfall-studio Рік тому +2

    This is great! Thanks for introducing us to the state pattern. So much cleaner this way. 😄

  • @fyh-zj7jw
    @fyh-zj7jw 11 місяців тому +2

    Great job on the tutorial, thank you so much for all the help your video has given me. I hope to see more quality videos like this in the future (it would be even better with text notes)

  • @vvbgamedevx11
    @vvbgamedevx11 3 місяці тому +1

    Another excellent episode. 👍

  • @usercontent2112
    @usercontent2112 Рік тому +1

    Amazing tutorial!

  • @alex_tahiti
    @alex_tahiti 4 місяці тому +1

    thx!

  • @rens652
    @rens652 7 днів тому +1

    Hiya! Thanks a bunch for this tutorial it's really helping me realize my game project!
    I know it's been a while since you've uploaded this, but I have a few questions that I hope you could answer.
    I'm just getting familiar with state pattern in C# (I come from a frontend background so my intuition about how state is handled is a bit different from what I'm used to), and I was wondering if there was a reason for why the list of placedGameObjects is located in the ObjectPlacer script. My intuition is that because it relates to the state of objects it makes more sense to place it in the GridData component. Why did you choose to place it there?
    Also I'm a bit confused about the naming convention here. Looking at the PlacementState script, when I think of a component called xState, my assumtion here is that state is stored here, but it seems that you are using it in the sense of ''a script that contains functions related to the state of an action'. What is your thought on this matter?
    Thanks again for the video's, It's a great way to start thinking about state in unity and I really enjoyed your style of presenting!

    • @SunnyValleyStudio
      @SunnyValleyStudio  6 днів тому

      Hey! It is placed in ObjectPlacer only because I try to separate "code data" from "visual data". Why? Because when you do any kind of save / load functionality you save what is in PlacedData and load it. Next you can call the ObjectPlacer to again place those objects like we would do when placing an object when just playing a game. It is not something that we need to ever save because we can always recreate it from important data - PlacedData. But that is what I like to do. You do what works for you
      I am using it State pattern. refactoring.guru/design-patterns/state . Its not the same as "Data State". Yeah come to think of it it can be confusing. But I always think of it in terms of State pattern so I didn't think that it might be confused with anything else.

    • @rens652
      @rens652 3 дні тому

      @@SunnyValleyStudio Thanks for your quick response! Makes sense, I'll definitely go over the recourse you linked. I stuck with your architecture and I'm retrieving the data from PlacedData as you suggest here. Cool stuff ✌️🙏

  • @alpha_greninja1944
    @alpha_greninja1944 Місяць тому +1

    How would you import a currency to build these interior structures? i would love to know

    • @SunnyValleyStudio
      @SunnyValleyStudio  Місяць тому

      I guess you would first store the moneyValue somewhere and update the UI based on what is available. Next when you place the object you would subtract the amount from the current value. This would require some modifications to the existing code but it shouldn't be difficult.

  • @PengiiiiGameDev
    @PengiiiiGameDev Рік тому +3

    This is definitely an april fools prank.

    • @177unneh_YT
      @177unneh_YT 4 місяці тому

      Why?

    • @PengiiiiGameDev
      @PengiiiiGameDev 2 місяці тому

      ​@@177unneh_YTlook at the date it was posted, just making a sarcastic joke