2021. Pavel Rumayncev. Copying or distribution of the materials outside the website is strictly prohibited.
View-Data separation
1. View-Data separation technique
2. About Data element
3. Introducing 'Capitalist' project
4. Scriptable Objects
5. Developing 'Capitalist' project
6. Lesson takeaways
Key takeaways
It's important to develop skill of identifying data models
Data models need to be implemented as separate elements, classes or scriptable objects
Key responsibilities of data models:
Serve as data containers
Provide API for modify and initialize the data
Provide events to notify listeners about data change
Unity's ScriptableObjects can be used for implement data models and provide following benefits:
Change and mock the model's data in Unity Editor and Runtime
It's possible to create custom editors for complex data model
It is not necessary to use ScriptableObjects for data models. it's all about convenience and visibility of real data in the Unity inspector
The purpose of view-data separation
Deal with complexity by splitting the logic into two parts - visual and data
Provide global access to the data (Single place to change)
Abstract from visual representation of the data (view can be 2d / 3d / UI/ with complex animations / A2B / etc., but all this aspects aren't related to the data layer)
Allows multiple Views for single data model
Easily add / remove / change Views
Testability - enables writing of automatic unit tests
Facilitate parallel development - art team works on the Views, programmers on data layer
Scriptable Objects
Scriptable Object(SO) is
Data Container
Unity asset
This means that you can store data within it and it's serializable. From Unity's asset database perspective, Scriptable Objects are regular assets, like Textures, Models, Materials etc. The difference between, for example, Texture asset and SO asset is that Texture asset contains array of color data (one element for every single pixel), when SO asset contains data of any serializable type.
Additionally you can implement logic/API for accessing and modifying the data stored in the SO.
Reading materials
Unity manual - Scriptable Objects
בשיעור הווידאו הזה אני חושף עקרונות חשובים ומורכבים וטכניקות מתקדמות שבהן משתמשים מקצוענים בכל יום. הבנת החומר עשויה להיות מורכבת עבור ג'וניורים ואפילו עבור מפתחים מנוסים. נדרש ניסיון רב על מנת להתפתח ולהבין באופן מלא. אני ישמח לעזור לכם לא רק להבין, אלא גם להסביר כיצד להשתמש בטכניקות אלה בפועל. זה יסייע לכם להתפתח כמפתחי משחקים מקצועיים.
תזמינו שיעור אישי איתי.