Save System (aka Serialization) - Items & Inventory (pt.19)

Поделиться
HTML-код
  • Опубликовано: 20 сен 2024
  • In this episode we start the implementation of a saving system (aka serialization) using C#'s BinaryFormatter.
    ► Next Video (Part 19.5): • Save System (cont.) - ...
    ◄ Previous Video (Part 18): • Infinite Scrollable In...
    ► Items & Inventory Playlist: • Items & Inventory
    ► Character Stats Playlist: • Character Stats
    💾 Source Code: bitbucket.org/...
    💬 Discord Server: / discord
    Resources:
    ✔ Download UI: www.mediafire.c...
    ✔ Download Icons: opengameart.or...
    In this tutorial series we learn how to implement an inventory system and items in Unity, typical of an RPG: With items, tooltips, equipping items by right click or drag and drop and applying stats to your character.
    We'll try to maintain a clean code architecture, with minimal dependencies between classes. The SOLID set of principles is a good thing to keep in mind.
    Items are made using ScriptableObjects. Classes are linked together using C# events. And we'll learn the intricacies of Unity's UI components such as Layout Group, Layout Element, Content Size Fitter, Text, Image, and more.
    ● SOLID principles: en.wikipedia.o...
    ● SOLID Unity keynote: • Unite Austin 2017 - S....
    ● Introduction to Scriptable Objects: unity3d.com/le...
    Music by TeknoAXE
    Burnt to a Crisp - • Burnt to a Crisp or Bl...

Комментарии • 16

  • @ivanodak7
    @ivanodak7 5 лет назад +2

    First of all thank you for the series, learned a lot, and this saved my time trying to implement this kind of inventory system. Was wondering about coding tho, example in this one you changed private fields to public ones, was wondering from a programming point of view, why wouldn't you use properties ? Or create getters/setters? Is there any particular reason to just use public? Just asking out of curiosity.

  • @diagadumah6073
    @diagadumah6073 5 лет назад +1

    I love this series man! Thank you so much for all of the work you've put in to it!
    You mentioned you have some ideas for an ability system I think? And you mentioned wanting to monetize some of your content, which I 100% agree with. Maybe you could put an ability system up on the asset store (paid), but also have an option to pay for a tutorial series like this one. That way people could either, get the finished asset from the asset store, or write the code themselves step by step like this. I would totally pay for a tutorial series on abilities. XD
    Thanks again, and looking forward to the next video!

    • @Kryzarel
      @Kryzarel  5 лет назад +1

      Ability/Spell System is absolutely in the works. Most of it is actually done already, but I still want to make a few improvements before releasing it. It will definitely be a paid asset, I am very confident on its quality.
      I'm not a huge fan of paid tutorials, I would rather keep those free on RUclips :)
      (Maybe with the option of supporting the channel through Patreon in the future ^^)
      On that front, not sure how to consolidate a paid asset with tutorials on the same topic without people feeling like they paid for something they could just make for free by watching some videos. On the other hand, the amount of time it takes for a proper tutorial video compared to just developing is orders of magnitude more. So for a system as complex as the Spell System, the tutorial series would probably need to be an extremely simplified version of the full asset anyway, so I guess it would balance out :P

    • @diagadumah6073
      @diagadumah6073 5 лет назад

      @@Kryzarel Hey quick question, I don't suppose you have any plans to show how we could have the weapon slots accept different types of weapons? Main example would be you have a 1-hand weapon type, a 2-hand weapon type, and a shield type. Both slots could accept 1-hand weapons, a 2-hand weapon would "occupy" both slots, and a shield would only be accepted by the "off hand" slot, sort of thing? If you haven't any plans to do that, that's cool, I was just curious, because I am sort of slamming my head against a wall with that right now lol :) Thanks again for your reply to my earlier message. :D

  • @micaiahstevens8840
    @micaiahstevens8840 5 лет назад +1

    T Objects are one of the coolest generic things you can do, it bring a whole new level to code.
    I am confused on the Read and Write for the FileReadWrite, while both functions use as its function generic you only seem to use T in the Read and not the Write method.
    This is use in the FileSaveIO classes for the read and write implementations.
    I always found this weird, any hints as to why it works like that? I always assumed you would need to specific the T in the Write as well and probably explains why I had problems making my own like this.

    • @Kryzarel
      @Kryzarel  5 лет назад +1

      For the write method, we didn't even need to use generics, it could just receive an argument of type "object", which is the base class for literally everything in C#. The BinaryFormatter actually receives a parameter of this type. But I prefer using generics anyway since it makes the code clearer to read, in my opinion.
      For the read method, we only need to use the generic T type to cast the object that we read from the file. The BinaryFormatter Deserialize() once again returns something of type "object" and we need to cast it to the specific type that we want.

    • @micaiahstevens8840
      @micaiahstevens8840 5 лет назад

      Thanks was more a question on the grammar involved. For one function you use a T and its required for the other one you use a T and its its not required, makes it confusion as to why. (You as the programmer, C# expert! )
      Keep up the amazing job, I can't wait to show you how inovled my inventory is largely in part thanks to you!

    • @Kryzarel
      @Kryzarel  5 лет назад

      Awesome, will be looking forward to seeing that :D

  • @seanasdf1425
    @seanasdf1425 5 лет назад +1

    This series has been fantastic! I only have one small hiccup and it's completely unrelated to your code but if maybe you can help me get a workaround that'd be great! My game is using a raycast to hit for a walkable layer and enemies which I was taught to do on a separate script for my camera. It appears with your canvas, it requires the Graphic Raycaster Script to be ticked and that causes my system to stop working! I'm a tinkerer with unity at best but I hope it's something simple haha. If you got any tips they'd be greatly appreciated!

  • @masisaries
    @masisaries 5 лет назад +1

    Just wanted you to know that your implementation isn't Mac Friendly. You need to use Path.Combine() where you would want to combine things with the proper file separators as on windows its "/" but on Mac it is "\" using Path.Combine() will use whatever is appropriate for the OS automatically.

    • @danielhornkvern1055
      @danielhornkvern1055 4 года назад

      so you should replace "/" with "Path.Combine()" ? or how would you write this line: string filePath = baseSavePath + "/" + path + ".dat";

  • @minhnguyenvan2092
    @minhnguyenvan2092 5 лет назад

    Why we don't save the ItemContainer correctly to the binary file, stead of create many new class!!
    Like:
    In ItemSaveIO.cs: "void SaveItems(ItemContainer, string);" "ItemContainer LoadItems(string);"
    Or why not use "SaveCharacter(Character, string)"; "Character LoadCharacter(string);"
    I confused!

  • @HINCO38
    @HINCO38 2 года назад

    to add more modifiers to the items, in addition to dexterity, strength, intelligence, endurance, you need to do a mega class, whatever it is?

  • @iggythemad8701
    @iggythemad8701 5 лет назад

    Hey Kryz! Im having huge trouble implementing the save system. It just doesnt work. I even downloaded your project, and it works fine in yours, but if I import it to mine, it just doesnt D:

  • @fielddark4196
    @fielddark4196 3 года назад

    this inventory I can put it in a database?