c0ffeeartc / EntProto

Entitas-CSharp "blueprints", depends on OdinInspector

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EntProto

Entitas-CSharp "blueprints", depends on OdinInspector


Depends on and tested with

Installation

For use in your own project:

  1. Ensure Entitas and other dependencies are installed
  2. Copy EntProto folder into Assets
  3. Remove EntProto/Examples folder
  4. Done

For testing examples:

  1. Create new Unity project
  2. Install dependencies
  3. Copy Preferences.properties into root of project
  4. Copy EntProto folder into Assets
  5. 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.

Usage

  1. Inherit EnityProto
  2. Inherit BaseProtoHolder, expose [SerializeField] with your entity prototypes, fill them in editor, pass them into Prototypes in Awake
  3. Place inherited ProtoHolder script on top of Unity's Edit->ProjectSettings->ScriptExecutionOrder
  4. Call BaseProtoHolder Clone and ApplyTo methods at runtime

Code part of these steps can be seen in example scripts GameProtoHolder.cs, GameController.cs

Main concepts (theory)

  • 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.

Reasons to not use prototypes aka blueprints

  • 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.

About

Entitas-CSharp "blueprints", depends on OdinInspector

License:MIT License


Languages

Language:C# 100.0%