public override void OnLoad() { PrefabFactory prefabFactory = new PrefabFactory(world.EntityManager); gameOver = prefabFactory.CreateSpriteText("Game OVER!"); gameOver.AddComponent(new GameOverBehaviour()); }
public override void OnComponentAddedToEntity(ECSEntity entity, ECSComponent component) { if (component != null && component is Renderer) { AddComponent(new RenderingSystemComponent(component as Renderer, entity.GetComponent <Transform>())); } }
public TComponent GetComponent <TComponent>(ECSEntity ecsEntity) where TComponent : ECSComponent { int typeIndex = typeIndexLookup[typeof(TComponent)]; return((TComponent)ecsComponentData[ecsEntity.Index, typeIndex]); }
public override void OnLoad() { PrefabFactory prefabFactory = new PrefabFactory(world.EntityManager); player = prefabFactory.Create(PrefabIds.PLAYER); player.GetComponent <Transform>().Position = new Vector2(250, 50); }
public void SetComponent <TComponent>(ECSEntity ecsEntity, TComponent component) where TComponent : ECSComponent { int typeIndex = typeIndexLookup[typeof(TComponent)]; ecsComponentData[ecsEntity.Index, typeIndex] = component; }
public void RemoveComponent <TComponent>(ECSEntity ecsEntity) where TComponent : ECSComponent { int typeIndex = typeIndexLookup[typeof(TComponent)]; ecsComponentData[ecsEntity.Index, typeIndex] = null; }
public override void OnEntityDestroyedPre(ECSEntity entity) { if (HasComponent <CCollider>(entity.EntityID)) { RemoveEntity(entity.EntityID); } }
public bool HasComponent <TComponent>(ECSEntity ecsEntity) where TComponent : ECSComponent { int typeIndex = typeIndexLookup[typeof(TComponent)]; return(ecsComponentData[ecsEntity.Index, typeIndex] != null); }
public virtual void OnComponentRemovedFromEntity(ECSEntity entity, ECSComponent component) { if (Accept(component)) { RemoveComponent(component); } }
public virtual void OnComponentAddedToEntity(ECSEntity entity, ECSComponent component) { if (Accept(component)) { AddComponent(component); } }
private void InvalidateEntity(ref ECSEntity ecsEntity) { ecsEntity.IsValid = false; for (int i = 0; i < ecsComponentData.GetLength(1); i++) { ecsComponentData[ecsEntity.Index, i] = null; } }
private ECSEntity CreateInvalidEntity(int index) { ECSEntity ecsEntity = new ECSEntity { Index = index, IsValid = false }; Entities.Add(ecsEntity); freeEntities.Add(ecsEntity); return(ecsEntity); }
public virtual void OnEntityRemoved(ECSEntity entity) { foreach (ECSComponent cmp in entity.GetComponents()) { if (Accept(cmp)) { RemoveComponent(cmp); } } }
public override void OnEntityRemoved(ECSEntity entity) { Transform transform = entity.GetComponent <Transform>(); Renderer renderer = entity.GetComponent <Renderer>(); RenderingSystemComponent renderingSystemComponent = FindComponent(transform, renderer); if (renderingSystemComponent != null) { RemoveComponent(renderingSystemComponent); } }
public void Shutdown() { foreach (ECSEntity entity in Entities) { ECSEntity ecsEntity = entity; DestroyEntity(ref ecsEntity); } typeIndexLookup = null; systems = null; Entities = null; freeEntities = null; ecsComponentData = null; }
public ECSEntity CreateEntity() { while (true) { if (freeEntities.Count > 0) { ECSEntity ecsEntity = freeEntities[0]; freeEntities.RemoveAt(0); ValidateEntity(ref ecsEntity); return(ecsEntity); } IncreaseBuffer(BATCH_SIZE); } }
public ECSEntity SetupEntity(ECSEntity e, string archetype) { ECSDebug.Assert(m_parser != null, "Cannot create Entity from Archetype > JSON not provided!"); JSONNode archetypeData = m_parser.GetArchetypeData(archetype); string baseArchetype = m_dataLocator.GetBaseArchetype(archetypeData); if (baseArchetype != null) { archetypeData = m_parser.OverwriteBaseArchetypeData(m_parser.GetArchetypeData(baseArchetype).AsObject, archetypeData.AsObject); } Bag <ECSComponent> components = m_parser.ParseComponentData(archetypeData); ComponentPreProcessing(archetype, components); m_componentManager.AddComponents(e.EntityID, components); return(e); }
private void ValidateEntity(ref ECSEntity ecsEntity) { ecsEntity.IsValid = true; Entities[ecsEntity.Index] = ecsEntity; }
private static void Main(string[] args) { Game.CreateWindow(800, 600, "LELEngine"); // Load Default Scene Game.Mono.LoadDefaultScene(); // Setup scene for debug GameObject cam = Game.Mono.ActiveScene.CreateGameObject("MainCamera"); GameObject CameraRig = Game.Mono.ActiveScene.CreateGameObject("CameraRig"); GameObject lightRig = Game.Mono.ActiveScene.CreateGameObject("LightRig"); GameObject light = Game.Mono.ActiveScene.CreateGameObject("LDirectional"); // Setup light light.transform.SetParent(lightRig.transform); light.transform.localRotation = Quaternion.Identity; light.transform.localPosition = new Vector3(0, 0, -200); light.transform.scale = Vector3.One * 10; light.AddComponent <DirectionalLight>(); lightRig.transform.position = Vector3.Zero; lightRig.transform.rotation = QuaternionHelper.Euler(10, 40, 0); // Setup sun sphere MeshRenderer m = light.AddComponent <MeshRenderer>(); m.SetMaterial("Sun.material"); m.SetMesh("sphere.obj"); // Setup camera CameraRig.AddComponent <CameraController>(); Camera c = cam.AddComponent <Camera>(); cam.transform.SetParent(CameraRig.transform); CameraRig.transform.position = Vector3.Zero; CameraRig.transform.rotation = QuaternionHelper.Euler(0, 180, 0); cam.transform.localPosition = new Vector3(0, 4, -15f); cam.transform.localRotation = Quaternion.Identity; c.FoV = 70; c.FarClip = 1000f; c.NearClip = 0.1f; // Setup lighting Lighting.Ambient.Color = Color4.LightGreen; Lighting.Ambient.Strength = 0.3f; Lighting.Directional.Color = Color4.AntiqueWhite; Lighting.Directional.Strength = 1f; Lighting.Specular.Strength = 1f; Lighting.Specular.Shine = 32f; foreach (GameObject go in Game.Mono.ActiveScene.SceneGameObjects) { if (go.Name == "Floor") { MeshRenderer mr = go.AddComponent <MeshRenderer>(); mr.SetMaterial("Cube.material"); mr.SetMesh("quad.obj"); mr.transform.rotation = QuaternionHelper.Euler(0, 0, 90); mr.transform.scale = Vector3.One * 500; mr.transform.position = new Vector3(0, -10, 10f); } } // Create ShipGraphics GameObject shipGraphics = Game.Mono.ActiveScene.CreateGameObject("ShipGraphics"); shipGraphics.transform.rotation = Quaternion.Identity; shipGraphics.transform.scale = Vector3.One * 5f; //Create ShipController GameObject shipController = Game.Mono.ActiveScene.CreateGameObject("ShipController"); shipController.transform.rotation = Quaternion.Identity; shipGraphics.transform.SetParent(shipController.transform); shipGraphics.transform.localPosition = Vector3.Zero; shipGraphics.transform.localRotation = QuaternionHelper.Euler(-90, 180, 0); MeshRenderer shipGraphicsMR = shipGraphics.AddComponent <MeshRenderer>(); shipGraphicsMR.SetMaterial("Axe.material"); shipGraphicsMR.SetMesh("axe.obj"); PlayerShipControl shipControllerPSC = shipController.AddComponent <PlayerShipControl>(); Game.Mono.InitializeECSScope(Assembly.GetExecutingAssembly()); ECSManager manager = Game.Mono.ECSManager; ECSEntity ecsEntity = manager.CreateEntity(); manager.SetComponent(ecsEntity, new FrameRateCounterComponent()); Game.Mono.Run(); // Main function is frozen until game window closes }
public bool HasComponent(ECSEntity ecsEntity, Type type) { int typeIndex = typeIndexLookup[type]; return(ecsComponentData[ecsEntity.Index, typeIndex] != null); }
public void DestroyEntity(ECSEntity entity) { m_componentManager.RemoveAllComponents(entity.EntityID); }
protected override void Execute(ECSEntity ecsEntity, ref FrameRateCounterComponent component1) { Console.Title = $@"LELEngine - FPS: {Time.frameRate:0} Render: {Time.renderDeltaTime}ms"; }
public void DestroyEntity(ECSEntity entity) { ECSDebug.LogWarning("EntityFactory was not provided.. Using " + GetType().Name); }
public ECSEntity SetupEntity(ECSEntity e, string archetype) { ECSDebug.LogWarning("EntityFactory was not provided.. Using " + GetType().Name); return(e); }
public void DestroyEntity(ref ECSEntity ecsEntity) { InvalidateEntity(ref ecsEntity); Entities[ecsEntity.Index] = ecsEntity; freeEntities.Add(ecsEntity); }