示例#1
0
        public override void OnLoad()
        {
            PrefabFactory prefabFactory = new PrefabFactory(world.EntityManager);

            gameOver = prefabFactory.CreateSpriteText("Game OVER!");
            gameOver.AddComponent(new GameOverBehaviour());
        }
示例#2
0
 public override void OnComponentAddedToEntity(ECSEntity entity, ECSComponent component)
 {
     if (component != null && component is Renderer)
     {
         AddComponent(new RenderingSystemComponent(component as Renderer, entity.GetComponent <Transform>()));
     }
 }
示例#3
0
        public TComponent GetComponent <TComponent>(ECSEntity ecsEntity)
            where TComponent : ECSComponent
        {
            int typeIndex = typeIndexLookup[typeof(TComponent)];

            return((TComponent)ecsComponentData[ecsEntity.Index, typeIndex]);
        }
示例#4
0
        public override void OnLoad()
        {
            PrefabFactory prefabFactory = new PrefabFactory(world.EntityManager);

            player = prefabFactory.Create(PrefabIds.PLAYER);
            player.GetComponent <Transform>().Position = new Vector2(250, 50);
        }
示例#5
0
        public void SetComponent <TComponent>(ECSEntity ecsEntity, TComponent component)
            where TComponent : ECSComponent
        {
            int typeIndex = typeIndexLookup[typeof(TComponent)];

            ecsComponentData[ecsEntity.Index, typeIndex] = component;
        }
示例#6
0
        public void RemoveComponent <TComponent>(ECSEntity ecsEntity)
            where TComponent : ECSComponent
        {
            int typeIndex = typeIndexLookup[typeof(TComponent)];

            ecsComponentData[ecsEntity.Index, typeIndex] = null;
        }
示例#7
0
 public override void OnEntityDestroyedPre(ECSEntity entity)
 {
     if (HasComponent <CCollider>(entity.EntityID))
     {
         RemoveEntity(entity.EntityID);
     }
 }
示例#8
0
        public bool HasComponent <TComponent>(ECSEntity ecsEntity)
            where TComponent : ECSComponent
        {
            int typeIndex = typeIndexLookup[typeof(TComponent)];

            return(ecsComponentData[ecsEntity.Index, typeIndex] != null);
        }
示例#9
0
 public virtual void OnComponentRemovedFromEntity(ECSEntity entity, ECSComponent component)
 {
     if (Accept(component))
     {
         RemoveComponent(component);
     }
 }
示例#10
0
 public virtual void OnComponentAddedToEntity(ECSEntity entity, ECSComponent component)
 {
     if (Accept(component))
     {
         AddComponent(component);
     }
 }
示例#11
0
        private void InvalidateEntity(ref ECSEntity ecsEntity)
        {
            ecsEntity.IsValid = false;

            for (int i = 0; i < ecsComponentData.GetLength(1); i++)
            {
                ecsComponentData[ecsEntity.Index, i] = null;
            }
        }
示例#12
0
        private ECSEntity CreateInvalidEntity(int index)
        {
            ECSEntity ecsEntity = new ECSEntity {
                Index = index, IsValid = false
            };

            Entities.Add(ecsEntity);
            freeEntities.Add(ecsEntity);
            return(ecsEntity);
        }
示例#13
0
 public virtual void OnEntityRemoved(ECSEntity entity)
 {
     foreach (ECSComponent cmp in entity.GetComponents())
     {
         if (Accept(cmp))
         {
             RemoveComponent(cmp);
         }
     }
 }
示例#14
0
        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);
            }
        }
示例#15
0
        public void Shutdown()
        {
            foreach (ECSEntity entity in Entities)
            {
                ECSEntity ecsEntity = entity;
                DestroyEntity(ref ecsEntity);
            }

            typeIndexLookup  = null;
            systems          = null;
            Entities         = null;
            freeEntities     = null;
            ecsComponentData = null;
        }
示例#16
0
        public ECSEntity CreateEntity()
        {
            while (true)
            {
                if (freeEntities.Count > 0)
                {
                    ECSEntity ecsEntity = freeEntities[0];
                    freeEntities.RemoveAt(0);

                    ValidateEntity(ref ecsEntity);

                    return(ecsEntity);
                }

                IncreaseBuffer(BATCH_SIZE);
            }
        }
示例#17
0
        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);
        }
示例#18
0
 private void ValidateEntity(ref ECSEntity ecsEntity)
 {
     ecsEntity.IsValid         = true;
     Entities[ecsEntity.Index] = ecsEntity;
 }
示例#19
0
        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
        }
示例#20
0
        public bool HasComponent(ECSEntity ecsEntity, Type type)
        {
            int typeIndex = typeIndexLookup[type];

            return(ecsComponentData[ecsEntity.Index, typeIndex] != null);
        }
示例#21
0
 public void DestroyEntity(ECSEntity entity)
 {
     m_componentManager.RemoveAllComponents(entity.EntityID);
 }
示例#22
0
 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);
 }
示例#25
0
 public void DestroyEntity(ref ECSEntity ecsEntity)
 {
     InvalidateEntity(ref ecsEntity);
     Entities[ecsEntity.Index] = ecsEntity;
     freeEntities.Add(ecsEntity);
 }