Player/enemy variables (HP, shield, etc.).In the particular case of Single-Player CCG Kit, we use scriptable object for the following things: While they are most commonly used for configuration data, we can actually exploit them to represent many other gameplay concepts. Scriptable Objects are Unity assets that live in your project and can be used to store any kind of data. Unite Austin 2017 - Game Architecture with Scriptable ObjectsĪt the core of this architecture is the idea of using Scriptable Objects to manage all (or most) of the data in your game.Unite 2016 - Overthrowing the MonoBehaviour Tyranny in a Glorious Scriptable Object Revolution.If you are not familiar with it, we recommend watching the following videos: The kit follows a ScriptableObject-based architecture. Var vehicleBehaviour = vehicle.Monetization with Unity Ads and Unity IAPĭeploying the kit to a Digital Ocean droplet Var vehicle = GameObject.CreatePrimitive( PrimitiveType.Cube) Var vehicleBehaviour = vehicle.AddComponent() Var vehicle = GameObject.CreatePrimitive( PrimitiveType.Sphere) Step 2 - Create some example vehicles in the current scene VehicleTypeInfo cruiser = AssetDatabase.LoadAssetAtPath("Assets/VehicleTypeCruiser.asset") Ĭruiser = ScriptableObject.CreateInstance() ĪssetDatabase.CreateAsset(cruiser, "Assets/VehicleTypeCruiser.asset") Wagon = ScriptableObject.CreateInstance() ĪssetDatabase.CreateAsset(wagon, "Assets/VehicleTypeWagon.asset") Create and save ScriptableObject because it doesn't exist yet If (m_VehicleType & m_VehicleType.m_MaxSpeed ("Assets/VehicleTypeWagon.asset") Use parameter from the ScriptableObject to control the behaviour of the Vehicle ![]() M_CurrentSpeed += m_Acceleration * ltaTime M_Acceleration = Random.Range(0.05f, m_VehicleType.m_MaxAcceration) Public void Initialize(VehicleTypeInfo vehicleType) Reference to the ScriptableObject asset In PlayMode it accelerates up to the maximum speed permitted by its type Snippet of a MonoBehaviour that would control motion of a specific vehicle. ![]() Public class VehicleInstance : MonoBehaviour The first script of the example implements a class derived from ScriptableObject. It isĪlso good for performance, especially in cases where the size of the shared data is substantial. This design makes it convenient to tweak vehicle behaviour in a central location. Type, rather than keeping its own redundant copy of each parameter. ![]() Each instance of the vehicle in the game would have a reference to the asset corresponding to its The following example demonstrates a typical use of a ScriptableObject: different types of vehicle parameters are represented in the fields of a VehicleTypeInfo class, derived from ScriptableObject.Įach type of vehicle would have its own asset file, with the parameter values set appropriately for the type. However, this class doesn't support the null-conditional operator ( ?.) and the null-coalescing operator ( ?). For example, it returns true for a "obj = null" check. A ScriptableObject in this state acts as if it is null. See Script Serialization for details.Ĭlasses that include big arrays, or other potentially large data, should be declared with the PreferBinarySerialization attribute, because YAML is not an efficient representation for that sort of data.Īfter a ScriptableObject is destroyed, the C# object remains in memory until garbage is collected. The C# fields of a ScriptableObject are serialized exactly like fields on a MonoBehaviour. When a ScriptableObject is referenced from a field on a MonoBehaviour, the ScriptableObject is automatically loaded, so a script can simply use the value of the field to reach it. If a ScriptableObject has not been saved to an asset, and it is referenced from an object in a scene, Unity serializes it directly into the scene file.įor ScriptableObjects that have only a single persistent instance within a project, use the ScriptableSingleton base class.Īccess previously saved objects using AssetDatabase, for example AssetDatabase.LoadAssetAtPath. You can also generate ScriptableObjects as an output from a ScriptedImporter. You can save ScriptableObjects to asset files either from the Editor UI (see CreateAssetMenuAttribute), or by calling AssetDatabase.CreateAsset from a script. Instantiate ScriptableObject objects with CreateInstance. Use ScriptableObjects to centralise data in a way that can be conveniently accessed from scenes and assets within a project.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |