Entitas-CSharp "blueprints", depends on OdinInspector
- Unity3d 2017.1.2f1
- Entitas 0.47.9 releases
- Sirenix.Odin 1.0.6.0 asset store
For use in your own project:
- Ensure Entitas and other dependencies are installed
- Copy EntProto folder into Assets
- Remove EntProto/Examples folder
- Done
For testing examples:
- Create new Unity project
- Install dependencies
- Copy Preferences.properties into root of project
- Copy EntProto folder into Assets
- Open and run example scene
If you don't have Odin plugin it's possible to use other plugin that serializes List<IComponent> by changing few lines of code. FullInspector has Free license GPLv3 for example.
OdinSerializer was open sourced some time ago under Apache 2.0 license.
- Inherit EnityProto
- Inherit BaseProtoHolder, expose [SerializeField] with your entity prototypes, fill them in editor, pass them into Prototypes in Awake
- Place inherited ProtoHolder script on top of Unity's Edit->ProjectSettings->ScriptExecutionOrder
- Call BaseProtoHolder Clone and ApplyTo methods at runtime
Code part of these steps can be seen in example scripts GameProtoHolder.cs, GameController.cs
- List<IComponent> allows creating entity
- It's possible to change entity completely by removing some components and adding other components, that's why there are Remove, Self and Shared fields
- If Remove, Self and Shared fields have duplicates only top ones are processed other are skipped.
- There is a more robust way to create entities without use of blueprints - using static create methods and configuration files more info
- Serialization. Carefully study Serializer's limitations for platform support etc.
- Refactoring. After renaming component class, "blueprints" lose these comoponents silently. Serializer may have solution for this, for example OdinSerializer uses
[BindTypeNameToType]
attribute. - Version Control. Creating entities through source code usually is more suitable for diff tools. Serializer may have pretty print option to solve this
- Cloning. Unlike simple create functions, this method clones fields, which requires implementing IAfterCopy for any object that is non plain old data
Good usage of blueprints might be experimenting and prototyping with further transition into code.