Skip to content

Framework

James McGhee edited this page Feb 13, 2019 · 1 revision

Serializable

Systems Core defines serializable bridge classes for common Unity structures and classes that are not typically serializable. These structures are designed to facilitate save and load of such data and include implicit conversions to the related Unity type.

  • Serializable Color converts to and from Unity Color and Vector 4
  • Serializable Quaternion converts to and from Unity Quaternion and Vector 4
  • Serializable Rect Transform converts to and from Unity RectTransform and Transform
  • Serializable Transform converts to and from Unity Transform
  • Serializable Vector 2 converts to and from Vector 2
  • Serializable Vector 2 Int converts to and from Vector 2
  • Serializable Vector 3 converts to and from Vector 2 and 3
  • Serializable Vector 4 converts to and from Vector 2, 3 and 4
  • Serializable Data Library Indexed collection of string keyed, object values

Scriptable

Systems Core defines Unity Scriptable Objects for most primitive types (string, float, etc.). Unity structures such as Color and Vectors and event systems (Unity Event with and without parameters) are also available and the Scriptable system includes base classes and inspectors for easy extension and integration with existing code. The concept is that most if not all occurrences of data types meant for designers to populate at design-time e.g. public float (example); can be replaced with public FloatReference (example) enabling the designer to choose between constant or scriptable input values e.g. ‘type it in’ or ‘reference it from elsewhere’. Or Using scriptable expressions for common and player data makes it faster and easier to maintain symmetry in design, carry data between scenes or even game sessions and enables designers to define save data, save it and load it with no engineer required via the Data Library File Manager.

Modular

Components and behaviours have been designed to server designers and developers as puzzles pieces. Each component developed for a specific discrete task without dependency or awareness of the wider system. The modularity concept insures behaviours are easily tailored to your games specific needs, reduces the work impact of changing code by isolating functionality and capitalizes on reuse of both data (scriptable objects) and functionality (modular behaviours). Systems Core provides a set of basic components and developer tools for easy extension with additional components available in Heathen Systems UIX and Heathen Systems Extensions with more expected as Heathen Engineering continues to mature the framework.

Using Serializable Types

Heathen Systems Core serializable variants of Vector2, Quaternion and others are meant for use on objects that must be serializable. The stock Unity equivalent of these type are not traditionally serializable (e.g. binary serializable). Each type includes implicit operators and where required UnityEvent variants to support there use in as seamless a manner as possible along side the native Unity types they represent.

Note that serializable variants do not include the native functionality of there Unity counter parts e.g. SerializableQuaternion cannot perform rotations for you it can however be assigned to a UnityEngine.Quaternion to create a quaternion rotation that can carry with it the x, y, z and w matrix values it was serialized with. Because scriptable variables must support binary serialization (to enable file saves) there underlying data type is the serializable variant of the related Unity type … e.g. Vector2Variable has a base type of SerializableVector2 … the base type is the value that will be reported on change events. E.g. UnityEvent<SerializableVector2> not UnityEvent<Vector2>.

In most cases a serializable value will implicitly convert the required Unity type such as when assigning variables

public Vector2 MyVector = new SerializableVector2();

The above statement does compile and yields the desired results. Understanding what is happing is key to good performance; in this case a new SerializableVector2 is being initialized then converted to a Vector2 which creates a new Vector2. This example is not performant but does illustrate the case. Similarly, equivalency tests undergo the same conversion where the Unity native type causes the serializable variant to first be converted (generating a new Unity value of that type) before performing the conversion. It is recommended to only use Serializable types as data storage and to cache their Unity type values for use in any logic tests or processes where more than a single read is required.

Extras

Heathen Systems Core includes a collection of UnityEvent derived classes that will draw proper inspectors when used e.g. instead of UnityEvent<string> use UnityStringEvent. These are simple wrappers an add no functionality above the typical UnityEvent<type> declaration other than displaying correctly in the editor. A thread safe console logger (ConsoleLogger) has been provided and can be accessed by ConsolLogger.Log(string message) as a static method. Additional interfaces, delegates and attribute properties have been provided including [ShowOnly] and [EnumFlags] to improve the quality of default inspectors.

Using Scriptable Types

Scriptable Objects are a standard feature of Unity though often underutilized. Unity Learn has a freely available tutorial on the subject available in a basic (https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/scriptable-objects/) and intermediate (https://unity3d.com/learn/tutorials/topics/scripting/ability-system-scriptable-objects/) presentation.

Heathen Systems Core defines common use scriptable objects representing simple data types, lists and events and provides companion behaviours to help designers leverage scriptable objects via the inspector just as they would any other field.

For developers Heathen Systems Core provides Interfaces, abstract classes and base classes along with custom inspectors and property drawers to insure fast seamless integration of custom objects and logic with Unity and Systems Core.

To create a new scriptable object right click in your project and select Create, along the top of the menu you will find categories of scriptable objects defined by Systems Core.

Create > Variables > [The data type you want]

Using Modular Behaviours

Heathen Systems Core behaviours work like any other mono behaviour and can be added to game objects to build up functionality. All Heathen Systems Core behaviours leverage Variable References in place of primitive value fields this allows the designer to choose rather they will type in a constant value or reference a Scriptable Object Variable to provide the value to the behaviour.

(menu) buttons appear beside Variable Reference fields and can be clicked to change the fields mode.

  • Constant: Works like a primative field allowing the designer to directly type in a value or use the standard inspector controls such as the color picker.
  • Static: Works the same as Constant but at runtime will ignore updates to its value that aren't directly assigned to its Constant Value. This is useful to selectivly prevent references from being updated by procedural events but shouldn't inhibit designers or developers from setting the value deliberately.
  • Variable: In variable mode the field displays an object picker filtered for the appropriately typed Scriptable Object Variable. e.g. this lets you drag and drop to reference a variable you created in your asset folder.

The property drawer for Variable Reference is generic and will draw any class that inherits from Variable Reference in this manner. Note that the inspector does assume that the Reference has a public ConstantValue; member and a public DataVariable Variable; member. These will be used to draw the controls and calculate the changes in size. The property drawer also handles child values and list values and always displays string values as multi lined. Additional component behaviours are available in other Heathen Engineering assets which leverage the Heathen Systems Core. Systems Core is provided with all such Unity Asset packs.

Clone this wiki locally