Exemple #1
0
    bool CreateObject(char type, out EcsEntity entity)
    {
        switch (type)
        {
        case 'o':
        {
            entity = _world.NewEntity();
            entity.Replace(new ObjectType
                {
                    Value = GameObjectEnum.Wall
                });
            return(true);
        }

        case 's':
        {
            entity = _world.NewEntity();
            entity.Get <PlayerTag>();
            entity.Replace(new ObjectType
                {
                    Value = GameObjectEnum.Player
                });
            return(true);
        }

        default:
        {
            entity = default;
            return(false);
        }
        }
    }
Exemple #2
0
 public void SetAimComponent()
 {
     entity.Replace(new AimingComponent()
     {
         AimPosition = Vector3.zero
     });
 }
Exemple #3
0
        public void generateUnit(SettlerData data)
        {
            EcsEntity entity = GameModel.get().createEntity();

            entity.Replace(new UnitNameComponent {
                name = data.name
            })                                                         // TODO add name generator
            .Replace(new AgeComponent {
                age = data.age
            })                                                // TODO add name generator
            .Replace(new UnitMovementComponent {
                speed = 0.06f, step = 0
            })
            .Replace(new UnitVisualComponent())
            .Replace(new UnitJobsComponent {
                enabledJobs = new List <string>()
            })
            .Replace(new NameComponent {
                name = "mockName"
            })
            .Replace(new PositionComponent {
                position = new Vector3Int()
            })
            .Replace(equipmentGenerator.generate())
            .Replace(new UnitComponent());
        }
        public void createDesignation(Vector3Int position, DesignationType type)
        {
            EcsEntity entity = GameModel.get().createEntity();

            entity.Replace(new DesignationComponent {
                type = type
            });
            entity.Replace(new PositionComponent {
                position = position
            });
            if (designations.ContainsKey(position)) // replace previous designation
            {
                cancelDesignation(position);        // cancel previous designation
            }
            designations[position] = entity;
        }
        public static EcsEntity CreateAirplane(this EcsWorld world)
        {
            EcsEntity         entity   = world.NewEntity();
            CategotyComponent category = new CategotyComponent()
            {
                value = Category.Player
            };

            entity.Replace(category);
            //            / Get() returns component on entity. If component not exists -it will be added.
            //ref Component1 c1 = ref entity.Get<Component1>();
            //            ref Component2 c2 = ref entity.Get<Component2>();
            //            // Del() removes component from entity.
            //            entity.Del<Component2>();
            //            // Component can be replaced with new instance of component. If component not exist - it will be added.
            //            var weapon = new WeaponComponent() { Ammo = 10, GunName = "Handgun" };
            //            entity.Replace(weapon);
            //            // With Replace() you can chain component's creation:
            //            var entity2 = world.NewEntity();
            //            entity2.Replace(new Component1 { Id = 10 }).Replace(new Component2 { Name = "Username" });
            //            // Any entity can be copied with all components:
            //            var entity2Copy = entity2.Copy();
            //            // Any entity can be merged / "moved" to another entity (source will be destroyed):
            //            var newEntity = world.NewEntity();
            //            entity2Copy.MoveTo(newEntity); // all components from entity2Copy moved to newEntity, entity2Copy destroyed.
            //                                           // any entity can be destroyed.
            //            entity.Destroy();
            return(entity);
        }
 private void detachTask(EcsEntity unit, EcsEntity task, TaskFinishedComponent finishComponent)
 {
     unit.Del <TaskFinishedComponent>();
     unit.Del <TaskComponent>();
     task.Replace(new TaskFinishedComponent {
         status = finishComponent.status
     });                                                                        // move status to task, it will be handled by TaskStatusSystem
 }
 // bind unit and task entities
 private void assignTask(EcsEntity unit, EcsEntity task)
 {
     unit.Replace(new TaskComponent {
         task = task
     });
     task.Replace(new TaskPerformerComponent {
         performer = unit
     });
 }
        public EcsEntity createTask(Action initialAction)
        {
            EcsEntity task = GameModel.get().createEntity();

            task.Replace(new TaskActionsComponent {
                initialAction = initialAction, preActions = new List <Action>()
            });
            initialAction.task = task;
            return(task);
        }
Exemple #9
0
        public void Init()
        {
            GL.ClearColor(Color4.LightSkyBlue);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Texture2D);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

            world   = new EcsWorld();
            systems = new EcsSystems(world)
                      .Add(new RenderSystem())
                      .Add(new CameraSystem())
                      .Inject(window)
                      .Inject(this);

            systems.Init();

            EcsEntity playerEntity = world.NewEntity();

            playerEntity.Replace(new CameraComponent(new Vector3(0, 5, 5), -90.0f, -45.0f, 60));

            EcsEntity groundEntity = world.NewEntity();

            groundEntity.Replace(new TransformationComponent()
            {
                Position = new Vector3(0, 0, 0),
                Rotation = new Quaternion(0, 0, 0),
                Scale    = new Vector3(1, 1, 1)
            });

            groundEntity.Replace(new RenderComponent()
            {
                geometry = ResourceManager.GetResource <Geometry>("GROUND_GEOMETRY"),
                shader   = ResourceManager.GetResource <Shader>("GROUND_SHADER"),
                diffuse  = ResourceManager.GetResource <Texture>("GROUND_TEXTURE")
            });

            MainMenu                = new MainMenu(window);
            window.Resize          += (e) => MainMenu.Resize(e.Width, e.Height);
            MainMenu.OnButtonClick += HandleMainMenuButton_Click;
        }
        public EcsEntity generateItem(string typeName, string materialName, Vector3Int position, EcsEntity entity)
        {
            ItemType type = ItemTypeMap.getItemType(typeName);

            if (type == null)
            {
                Debug.LogError("Type " + typeName + " not found.");
            }
            Material_ material = MaterialMap.get().material(materialName);

            entity.Replace(new ItemComponent {
                material = material.id, type = typeName, materialString = material.name, volume = 1, weight = material.density * 1
            });
            entity.Replace(new PositionComponent {
                position = position
            });
            entity.Replace(new NameComponent());
            // entity.Replace(new ItemVisualComponent());
            return(entity);
        }
        private void createSpriteForItem(EcsEntity entity)
        {
            ItemComponent       item           = entity.Get <ItemComponent>();
            ItemVisualComponent visual         = new ItemVisualComponent();
            Vector3             spritePosition = ViewUtil.fromModelToScene(entity.pos());

            visual.go = Object.Instantiate(itemPrefab, spritePosition + new Vector3(0, 0, -0.1f), Quaternion.identity);
            visual.go.transform.SetParent(GameView.get().mapHolder);
            visual.spriteRenderer        = visual.go.GetComponent <SpriteRenderer>();
            visual.spriteRenderer.sprite = createSprite(ItemTypeMap.getItemType(item.type));
            entity.Replace(visual);
        }
 public void putItemToMap(EcsEntity item, Vector3Int position)
 {
     validateForPlacing(item);
     if (!itemsOnMap.ContainsKey(position))
     {
         itemsOnMap.Add(position, new List <EcsEntity>());
     }
     itemsOnMap[position].Add(item);
     all.Add(item);
     item.Replace(new PositionComponent {
         position = position
     });
 }
Exemple #13
0
 private EcsEntity?createTaskForDesignation(DesignationComponent designation, PositionComponent position)
 {
     // TODO create job component
     if (designation.type.JOB.Equals(JobsEnum.MINER.name))
     {
         Debug.Log("mining task created.");
         EcsEntity taskEntity = GameModel.get().taskContainer.createTask(new DigAction(position.position, designation.type));
         taskEntity.Replace(new TaskJobComponent {
             job = JobsEnum.MINER.name
         });
         return(taskEntity);
     }
     // switch (designation.type.NAME) {
     //     case "cutting stairs": {
     //         return null;
     //     }
     //     case "cutting downstairs": {
     //         return null;
     //     }
     //     case "cutting ramp": {
     //         return null;
     //     }
     //     case "digging channel": {
     //         return null;
     //     }
     //     case "chopping trees": {
     //         return null;
     //     }
     //     case "cutting plants": {
     //         return null;
     //     }
     //     case "harvesting plants": {
     //         return null;
     //     }
     //     case "building": {
     //         return null;
     //     }
     //     case "hoeing": {
     //         return null;
     //     }
     //     case "planting": {
     //         return null;
     //     }
     // }
     return(null);
 }
Exemple #14
0
        private void Start()
        {
            world   = new EcsWorld();
            systems = new EcsSystems(world);
            systems.Add(new ValuePrintSystem())
            .Add(new LinkIncrementSystem())
            .Init();

            EcsEntity entity1 = world.NewEntity();

            entity2 = world.NewEntity();
            entity1.Replace(new LinkComponent {
                link = entity2
            });
            entity2.Replace(new ValueComponent {
                value = 0
            });
        }
Exemple #15
0
 public void Run()
 {
     foreach (var i in filter)
     {
         EcsEntity designation = filter.GetEntity(i);
         if (!validateDesignation(designation))
         {
             continue;
         }
         EcsEntity?task = createTaskForDesignation(filter.Get1(i), filter.Get2(i));
         if (task.HasValue)
         {
             designation.Replace(new TaskComponent {
                 task = task.Value
             });
             GameModel.get().taskContainer.addTask(task.Value);
         }
     }
 }
        private void createSprite(EcsEntity entity)
        {
            DesignationComponent designation = entity.Get <DesignationComponent>();
            PositionComponent    position    = entity.Get <PositionComponent>();
            // create sprite on scene
            GameObject     go             = PrefabLoader.create("designation", GameView.get().mapHolder);
            SpriteRenderer spriteRenderer = go.GetComponent <SpriteRenderer>();
            Sprite         sprite         = IconLoader.get("designation/" + designation.type.SPRITE_NAME);

            spriteRenderer.sprite = sprite;

            float width = go.GetComponent <RectTransform>().rect.width;
            float scale = width / sprite.rect.width * sprite.pixelsPerUnit;

            spriteRenderer.transform.localScale = new Vector3(scale, scale, 1);

            go.transform.localPosition = getSpritePosition(position, designation);
            // add visual component
            entity.Replace(new DesignationVisualComponent {
                spriteRenderer = spriteRenderer
            });
        }
 private void Fire(ref EcsEntity entity)
 {
     entity.Replace(new ShootingEvent());
 }
Exemple #18
0
 public static void Add <T>(this EcsEntity entity, T component) where T : struct
 {
     entity.Replace(component);
 }
 public void Add <T>(T component) where T : struct
 {
     entity.Replace(component);
 }
Exemple #20
0
 void IConvertToEntity.Convert(EcsEntity entity)
 {
     entity.Replace(value);
 }