diff --git a/README.md b/README.md index 03dbf8f..2439f1a 100644 --- a/README.md +++ b/README.md @@ -35,12 +35,12 @@ public class MovementSystem : EgoSystem 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; + var cube = Ego.AddGameObject( GameObject.CreatePrimitive( PrimitiveType.Cube ) ).gameObject; + cube.name = "Cube"; + cube.transform.position = Vector3.zero; // Add a Movement Component to the Cube - Ego.AddComponent( cubeEgoComponent.gameObject ); + Ego.AddComponent( cube ); } public override void Update() @@ -68,18 +68,18 @@ public class ExampleSystem : EgoSystem public override void Start() { // Create a falling cube - var cubeEgoComponent = Ego.AddGameObject( GameObject.CreatePrimitive( PrimitiveType.Cube ) ); - cubeEgoComponent.gameObject.name = "Cube"; - Ego.AddComponent( cubeEgoComponent.gameObject ); - cubeEgoComponent.transform.position = new Vector3( 0f, 10f, 0f ); - Ego.AddComponent( cubeEgoComponent.gameObject ); + var cube = Ego.AddGameObject( GameObject.CreatePrimitive( PrimitiveType.Cube ) ).gameObject; + cube.name = "Cube"; + Ego.AddComponent( cube ); + cube.transform.position = new Vector3( 0f, 10f, 0f ); + Ego.AddComponent( cube ); // Create a stationary floor - var floorEgoComponent = Ego.AddGameObject( GameObject.CreatePrimitive( PrimitiveType.Cube ) ); - floorEgoComponent.gameObject.name = "Floor"; - floorEgoComponent.transform.localScale = new Vector3( 10f, 1f, 10f ); - Ego.AddComponent( floorEgoComponent.gameObject ).isKinematic = true; - Ego.AddComponent( floorEgoComponent.gameObject ); + var floor = Ego.AddGameObject( GameObject.CreatePrimitive( PrimitiveType.Cube ) ).gameObject; + floor.name = "Floor"; + floor.transform.localScale = new Vector3( 10f, 1f, 10f ); + Ego.AddComponent( floor ).isKinematic = true; + Ego.AddComponent( floor ); // Register Event Handlers EgoEvents.AddHandler( Handle ); @@ -100,33 +100,33 @@ public class ExampleSystem : EgoSystem // ExampleSystem.cs using UnityEngine; +public class ExampleEvent: EgoEvent +{ + public readonly int num; + + public EgoEvent( int num ) + { + this.num = num; + } +} + public class ExampleSystem : EgoSystem { public override void Start() { - // Create a falling cube - var cubeEgoComponent = Ego.AddGameObject( GameObject.CreatePrimitive( PrimitiveType.Cube ) ); - cubeEgoComponent.gameObject.name = "Cube"; - Ego.AddComponent( cubeEgoComponent.gameObject ); - cubeEgoComponent.transform.position = new Vector3( 0f, 10f, 0f ); - Ego.AddComponent( cubeEgoComponent.gameObject ); - - // Create a stationary floor - var floorEgoComponent = Ego.AddGameObject( GameObject.CreatePrimitive( PrimitiveType.Cube ) ); - floorEgoComponent.gameObject.name = "Floor"; - floorEgoComponent.transform.localScale = new Vector3( 10f, 1f, 10f ); - Ego.AddComponent( floorEgoComponent.gameObject ).isKinematic = true; - Ego.AddComponent( floorEgoComponent.gameObject ); - // Register Event Handlers - EgoEvents.AddHandler( Handle ); + EgoEvents.AddHandler( Handle ); + } + + public override void Update() + { + var e = new ExampleEvent( 42 ); + EgoEvents.AddEvent( e ); } - void Handle( CollisionEnterEvent e ) + void Handle( ExampleEvent e ) { - var name1 = e.egoComponent1.gameObject.name; - var name2 = e.egoComponent2.gameObject.name; - Debug.Log( name1 + " collided with " + name2 ); + Debug.Log( e.num ); // 42 } } ```