All Projects → andoowhy → Egocs

andoowhy / Egocs

Licence: other
EgoCS: An Entity (GameObject) Component System framework for Unity3D

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Egocs

Gdk For Unity Fps Starter Project
SpatialOS GDK for Unity FPS Starter Project
Stars: ✭ 119 (-43.6%)
Mutual labels:  ecs, unity, unity3d, entity-component-system
Ecs
LeoECS is a fast Entity Component System (ECS) Framework powered by C# with optional integration to Unity
Stars: ✭ 578 (+173.93%)
Mutual labels:  ecs, unity, unity3d, entity-component-system
Learning Unity Ecs 2
A bunch of small Unity projects where I explore and learn Unity's new ECS and Job System. Updated for the new API.
Stars: ✭ 65 (-69.19%)
Mutual labels:  ecs, unity, unity3d, entity-component-system
Actors.unity
🚀Actors is a framework empowering developers to make better games faster on Unity.
Stars: ✭ 437 (+107.11%)
Mutual labels:  ecs, unity, unity3d, entity-component-system
Firefly
Unity ECS example for special effects
Stars: ✭ 489 (+131.75%)
Mutual labels:  ecs, unity, unity3d
Gdk For Unity
SpatialOS GDK for Unity
Stars: ✭ 296 (+40.28%)
Mutual labels:  ecs, unity, entity-component-system
Entitas Csharp
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
Stars: ✭ 5,393 (+2455.92%)
Mutual labels:  ecs, unity, entity-component-system
Ecs Snake
Simple snake game powered by ecs framework.
Stars: ✭ 41 (-80.57%)
Mutual labels:  ecs, unity, unity3d
Svelto.ecs
Svelto ECS C# Lightweight Data Oriented Entity Component System Framework
Stars: ✭ 605 (+186.73%)
Mutual labels:  ecs, unity, entity-component-system
Voxelman
Unity ECS + C# Job System example
Stars: ✭ 1,086 (+414.69%)
Mutual labels:  ecs, unity, unity3d
Entitas Sync Framework
Networking framework for Entitas ECS. Targeted at turnbased games or other slow-paced genres.
Stars: ✭ 98 (-53.55%)
Mutual labels:  ecs, unity, entity-component-system
Entitas Lite
Entitas-Lite is a No-CodeGenerator branch of Entitas, and also a fast & easy ECS framework for C#/Unity.
Stars: ✭ 106 (-49.76%)
Mutual labels:  ecs, unity, entity-component-system
Ecsrx
A reactive take on the ECS pattern for .net game developers
Stars: ✭ 288 (+36.49%)
Mutual labels:  ecs, unity, unity3d
Endless Runner Entitas Ecs
Runner template for Unity
Stars: ✭ 41 (-80.57%)
Mutual labels:  ecs, unity, entity-component-system
Uecs
Ubpa Entity-Component-System (U ECS) in Unity3D-style
Stars: ✭ 174 (-17.54%)
Mutual labels:  ecs, unity3d, entity-component-system
Ecs
ECS for Unity with full game state automatic rollbacks
Stars: ✭ 151 (-28.44%)
Mutual labels:  ecs, unity, unity3d
Htframework
Unity HTFramework, a rapid development framework of client to the unity.
Stars: ✭ 179 (-15.17%)
Mutual labels:  ecs, unity, unity3d
Vfxgraphtestbed
My testbed for Unity VFX Graph
Stars: ✭ 209 (-0.95%)
Mutual labels:  unity, unity3d
Unitylive2dextractor
Unity Live2D Cubism 3 Extractor
Stars: ✭ 183 (-13.27%)
Mutual labels:  unity, unity3d
Nice Lua
基于xlua的MVVM框架,支持Addressables, 统一渲染管线等Unity新特性
Stars: ✭ 207 (-1.9%)
Mutual labels:  unity, unity3d

EgoCS

An Entity (GameObject) Component System framework for Unity3D, in C#.

Join the chat at https://gitter.im/andoowhy/EgoCS

For more detailed info, please see the EgoCS Wiki.

EgoCS aims to improve upon Unity3D's GameObject / Component relationship by completely decoupling Data and Behaviour, typical in Unity3D Components.

While there isn't a standard Entity Component System (ECS) pattern or reference implementation, EgoCS follows the most popular conventions:

  • Entities (AKA GameObjects) are merely containers for Components (like in Unity3D).
  • Components store data. And unlike Unity3D, Components ONLY store public data:
// Movement.cs
using UnityEngine;

[DisallowMultipleComponent]
public class Movement : MonoBehaviour
{
    public Vector3 velocity = new Vector3( 1.0f, 2.0f, 3.0f );
}
  • Systems run logic & perform updates on GameObjects, and Constraints determine which GameObjects:
// MovementSystem.cs
using UnityEngine;

// MovementSystem updates any GameObject with a Transform & Movement Component
public class MovementSystem : EgoSystem<
	EgoConstraint<Transform, Movement>
>{
	public override void Start()
	{
		// Create a Cube GameObject
		var cubeEgoComponent = Ego.AddGameObject( GameObject.CreatePrimitive( PrimitiveType.Cube ) );
		cubeEgoComponent.gameObject.name = "Cube";
		cubeEgoComponent.transform.position = Vector3.zero;

		// Add a Movement Component to the Cube
		Ego.AddComponent<Movement>( cubeEgoComponent.gameObject );
	}

	public override void Update()
	{
		// For each GameObject that fits the constraint...
		constraint.ForEachGameObject( ( egoComponent, transform, movement ) =>
		{
			// ...move it by the velocity in its Movement Component
			transform.Translate( movement.velocity * Time.deltaTime );
		} );
	}
}

Following this convention literally, Systems are completely isolated from one another. To allow inter-system communication, EgoCS uses Events and a global Event Queue:

  • Systems can register Event Handlers (methods) for specified Events. Multiple Systems can handle the same Event:
// ExampleSystem.cs
using UnityEngine;

public class ExampleSystem : EgoSystem<
	EgoConstraint<Rigidbody>
>{
	public override void Start()
	{
		// Create a falling cube
		var cubeEgoComponent = Ego.AddGameObject( GameObject.CreatePrimitive( PrimitiveType.Cube ) );
		var cubeGameObject = cubeEgoComponent.gameObject;
		cubeGameObject.name = "Cube";
		cubeGameObject.transform.position = new Vector3( 0f, 10f, 0f );
		Ego.AddComponent<Rigidbody>( cubeGameObject );
		Ego.AddComponent<OnCollisionEnterComponent>( cubeGameObject );

		// Create a stationary floor
		var floorEgoComponent = Ego.AddGameObject( GameObject.CreatePrimitive( PrimitiveType.Cube ) );
		var floorGameObject = floorEgoComponent.gameObject;
		floorGameObject.name = "Floor";
		floorGameObject.transform.localScale = new Vector3( 10f, 1f, 10f );
		Ego.AddComponent<Rigidbody>( floorGameObject ).isKinematic = true;
		Ego.AddComponent<OnCollisionEnterComponent>( floorGameObject );

		// Register Event Handlers
		EgoEvents<CollisionEnterEvent>.AddHandler( Handle );
	}

	void Handle( CollisionEnterEvent e )
	{
		var name1 = e.egoComponent1.gameObject.name;
		var name2 = e.egoComponent2.gameObject.name;
		Debug.Log( name1 + " collided with " + name2 );
	}
}
  • EgoCS provides built-in Events for most MonoBehavior Messages (OnCollisionEnter, OnTriggerExit, etc.), and you can easily create your own custom events:
// ExampleSystem.cs
using UnityEngine;

public class ExampleEvent: EgoEvent
{
    public readonly int num;

	public ExampleEvent( int num )
    {
		this.num = num;
    }
}

public class ExampleSystem : EgoSystem<
	EgoConstraint<Rigidbody>
>{
    public override void Start()
    {
        // Register Event Handlers
        EgoEvents<ExampleEvent>.AddHandler( Handle );

		var e = new ExampleEvent( 42 );
		EgoEvents<ExampleEvent>.AddEvent( e );
    }
    
    void Handle( ExampleEvent e )
    {
        Debug.Log( e.num ); // 42
    }
}
  • Event objects can be created while a System is starting or updating (Ex: Collision, Win, etc). These Events are automatically sent to the back of the Ego Event Queue.
  • Events are handled after all systems have updated.

TL;DR: Changes in Data (Components) will not break logic, and changes in logic (Systems) will not break Data. Maximum decoupling is achieved, and you will never have to write [RequireComponent(...)] *shudder* again.

Installation

Place the "EgoCS" folder anywhere in your project's Assets folder:

cd [project_dir]/Assets/

git clone https://github.com/andoowhy/EgoCS.git EgoCS

Create an empty GameObject in the scene, and give it an appropriate name (Ex: Game Manager or EgoCS).

Attach an EgoInterface Component to this GameObject. This Component is the bridge between Unity3D and EgoCS.

Add your Systems to EgoCS in your EgoInterface's static contructor:

// EgoInterface.cs
using UnityEngine;

public class EgoInterface : MonoBehaviour
{
    static EgoInterface()
    {
        // Add Systems Here:
        EgoSystems.Add(
            new ExampleSystem(),
            new MovementSystem()
        );
    }

    void Start()
    {
        EgoSystems.Start(); 
    }

    void Update()
    {
        EgoSystems.Update();
    }

    void FixedUpdate()
    {
        EgoSystems.FixedUpdate();
    }
}

Debugging

Like with GameObjects and MonoBehaviours, you can easily enable & disable Systems on-the-fly before and during runtime:

Easily Enable / Disable Systems

Limitations

  • Only OnTrigger* and OnCollision* MonoBehaviour Messages are converted into EgoEvents. More to be added.
  • Unity3D v5.3+ Multi Scene Editing not supported (yet)

TODO

  • Example projects
  • Documentation
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].