private void createToggles(GameObject row, EcsEntity unit) { GameObject togglePrefab = Resources.Load <GameObject>(togglePath); RectTransform unitName = row.transform.GetChild(0).GetComponent <RectTransform>(); float startX = unitName.rect.width + unitName.localPosition.x; float iconWidth = togglePrefab.GetComponent <RectTransform>().rect.width; for (var i = 0; i < JobsEnum.jobs.Length; i++) { Job job = JobsEnum.jobs[i]; GameObject toggle = Instantiate(togglePrefab, row.transform, false); toggle.transform.localPosition = new Vector3(startX + iconWidth * i, 0, 0); Toggle toggleComponent = toggle.GetComponentInChildren <Toggle>(); toggleComponent.isOn = unit.Get <UnitJobsComponent>().enabledJobs.Contains(job.name); toggleComponent.onValueChanged.AddListener(value => { if (value) { unit.Get <UnitJobsComponent>().enabledJobs.Add(job.name); } else { unit.Get <UnitJobsComponent>().enabledJobs.Remove(job.name); } }); } }
protected override void CreateEntity() { EcsEntity flyingEnemyEntity = SingleTone.mainworld.NewEntity(); flyingEnemyEntity.Get <Enemy>(); flyingEnemyEntity.Get <Flying>(); ref Defence DefenceComponent = ref flyingEnemyEntity.Get <Defence>();
public static void AddDefaultUnitComponents(this EcsEntity unitEntity, GameObject unitObject, int health) { unitEntity.Set <AttackComponent>().InitializeComponent(unitEntity.Get <UnitComponent>().Tag.ToString().ToUnitType()); //unitEntity.Set<DefenseComponent>().InitializeComponent(UnitType.Warrior); unitEntity.Set <HealthComponent>().InitializeComponent(health); unitEntity.Set <HealthBarComponent>().InitializeComponent(unitObject); unitEntity.Set <MovementComponent>().InitializeComponent(unitObject); unitEntity.Set <NavMeshComponent>(); unitEntity.Get <NavMeshComponent>().Agent = unitObject.GetComponent <NavMeshAgent>(); }
private void _Show() { content.SetActive(true); if (_entity.Has <IsSceneInactiveComponent>()) { _entity.Del <IsSceneInactiveComponent>(); } _entity.Get <IsSceneActiveComponent>(); _entity.Get <SceneBecomeActiveComponent>(); }
protected override void CreateEntity() { EcsEntity bulletTowerEntity = SingleTone.mainworld.NewEntity(); bulletTowerEntity.Get <CanShootFlying>(); bulletTowerEntity.Get <CanShootWalking>(); bulletTowerEntity.Get <Tower>(); if (SingleTone.IsMouseOccupied) { bulletTowerEntity.Get <Unplaced>(); } ref Shooter ShooterComponent = ref bulletTowerEntity.Get <Shooter>();
private void ChangeToActionState() { SpawnImmunity = -1f; if (Type != CharacterType.Player) { return; } var player = Entity.Get <Player>(); player.HeadFacing = HeadFacing.Center; //don't need to send this to client, they will assume it resets }
public static void CreateDropResourcesEvent(EcsEntity deliverEntity, EcsWorld world) { var deliverComponent = deliverEntity.Get <ResourceDeliverComponent>(); var resources = deliverComponent.Resources; var position = deliverEntity.Get <MovementComponent>().CurrentPosition; foreach (var resource in resources) { resource.Position = position + randomFactor * Random.value; } world.NewEntityWith <ResourceDropEvent>(out var resourceDropEvent); resourceDropEvent.Resources = resources; }
public void Run() { foreach (int i in _takenFoods) { EcsEntity playerEntity = _takenFoods.Get2[i].PlayerEntity; var player = playerEntity.Get <PlayerComponent>(); var moveComponent = playerEntity.Get <MoveComponent>(); player.Scores += _takenFoods.Get1[i].Scores; moveComponent.Speed -= _takenFoods.Get1[i].SpeedPenalty; _ecsWorld.NewEntityWith(out UpdateScoreTableEvent _); } }
public override void EntityInit(EcsEntity ecsEntity, EcsWorld world, bool OnScene) { var points = new Vector3[lengthOfLineRenderer]; points[0] = ecsEntity.Get <LineConnection>().PositionA; points[1] = ecsEntity.Get <LineConnection>().PositionB; _root.SetPositions(points); ecsEntity.Set <LineRendererRoot>().LineRenderer = this._root; if (OnScene) { Destroy(this); } }
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); } } }
public void MovePlayerMap(ref EcsEntity entity, Character character, string mapName, Position newPosition) { character.IsActive = false; character.Map.RemoveEntity(ref entity, CharacterRemovalReason.OutOfSight); character.ResetState(); character.Position = newPosition; if (!mapIdLookup.TryGetValue(mapName, out var mapId)) { ServerLogger.LogWarning($"Map {mapName} does not exist! Could not move player."); return; } var map = Maps[mapId]; if (newPosition == Position.Zero) { map.FindPositionInRange(map.MapBounds, out var p); character.Position = newPosition; } map.AddEntity(ref entity); var player = entity.Get <Player>(); player.Connection.LastKeepAlive = Time.ElapsedTime; //reset tick time so they get 2 mins to load the map CommandBuilder.SendChangeMap(character, player); }
private bool validateEntity(EcsEntity entity) { if (!entity.Has <PositionComponent>()) { Debug.LogWarning("designation " + entity.Get <DesignationComponent>().type.NAME + " has no PositionComponent"); return(false); } DesignationComponent designation = entity.Get <DesignationComponent>(); if (designation.type.SPRITE_NAME == null) { Debug.LogWarning("designation " + entity.Get <DesignationComponent>().type.NAME + " has null spriteName"); return(false); } return(true); }
// Start is called before the first frame update // Update is called once per frame protected override void CreateEntity() { EcsEntity cityEnity = SingleTone.mainworld.NewEntity(); cityEnity.Get <Client.City>(); ref Health healthComponent = ref cityEnity.Get <Health>();
private void UpdateKeyboardInput() { var result = new float2(0, 0); var inputExist = false; if (Input.GetKey(KeyCode.A)) { result.x -= 1; inputExist = true; } if (Input.GetKey(KeyCode.D)) { result.x += 1; inputExist = true; } if (Input.GetKey(KeyCode.W)) { result.y += 1; inputExist = true; } if (Input.GetKey(KeyCode.S)) { result.y -= 1; inputExist = true; } if (inputExist) { result = math.normalize(result); } _moveEventEntity.Get <MoveEventComponent>().Value = result; }
public void AddEntity(ref EcsEntity entity, CharacterType type) { #if DEBUG //sanity check var character = entity.Get <Character>(); var chunkX = character.Position.X / 8; var chunkY = character.Position.Y / 8; if (X != chunkX || Y != chunkY) { throw new Exception("Sanity check failed: Entity added to incorrect chunk?"); } #endif switch (type) { case CharacterType.Player: Players.Add(ref entity); break; case CharacterType.Monster: Monsters.Add(ref entity); break; default: throw new Exception("Unhandled character type: " + type); } }
public ActionConditionStatusEnum addPreAction(Action action) { Debug.Log("adding pre action"); task.Get <TaskComponents.TaskActionsComponent>().addFirstPreAction(action); action.task = task; return(ActionConditionStatusEnum.NEW); }
void IInputCommand.Execute(EcsEntity entity) { var c1 = entity.Get <GameObjectComponent>(); if (vertical > 0) { goalPosition = new Vector2(c1.Transform.position.x, c1.Transform.position.y + 1); } if (vertical < 0) { goalPosition = new Vector2(c1.Transform.position.x, c1.Transform.position.y - 1); } if (horizontal > 0) { goalPosition = new Vector2(c1.Transform.position.x + 1, c1.Transform.position.y); } if (horizontal < 0) { goalPosition = new Vector2(c1.Transform.position.x - 1, c1.Transform.position.y); } var c = entity.Set <ActionMoveComponent>(); c.GoalPosition = goalPosition.ToInt2(); }
void IEcsRunSystem.Run() { if (!_moveFilter.IsEmpty()) { List <GameObject> squaresToMove = _moveFilter.Get1(0).SquaresToMove; List <Vector3> dstPos = _moveFilter.Get1(0).DstPos; Direction moveDirection = _moveFilter.Get1(0).Direction; Vector2Int moveDirectionInt = Const.DirToVecI(moveDirection); Vector3 moveDirectionF = Const.DirToVecF(moveDirection); foreach (GameObject o in _moveFilter.Get1(0).SquaresToMove) { float d = Const.MoveSpeed * Time.deltaTime; if (d > 9) { d = 9; } o.transform.position += moveDirectionF * d; } for (int i = 0; i < _moveFilter.Get1(0).SquaresToMove.Count; i++) { if (Vector3.Distance(squaresToMove[i].transform.position, dstPos[i]) < 10) { squaresToMove[i].transform.position = dstPos[i]; if (_globalData.GameField[_moveFilter.Get1(0).DstPosInts[i].x, _moveFilter.Get1(0).DstPosInts[i].y].ChangeDirection != Direction.None) { squaresToMove[i].GetComponent <SquareScript>().SetDirection(_globalData.GameField[_moveFilter.Get1(0).DstPosInts[i].x, _moveFilter.Get1(0).DstPosInts[i].y].ChangeDirection); } GameObject o = _globalData.GameField[_moveFilter.Get1(0).SrcPosInts[i].x, _moveFilter.Get1(0).SrcPosInts[i].y].Obj; _globalData.GameField[_moveFilter.Get1(0).SrcPosInts[i].x, _moveFilter.Get1(0).SrcPosInts[i].y].Obj = null; _globalData.GameField[_moveFilter.Get1(0).DstPosInts[i].x, _moveFilter.Get1(0).DstPosInts[i].y].Obj = o; _moveFilter.Get1(0).SquaresToMove.RemoveAt(i); _moveFilter.Get1(0).DstPos.RemoveAt(i); _moveFilter.Get1(0).SrcPosInts.RemoveAt(i); _moveFilter.Get1(0).DstPosInts.RemoveAt(i); i--; } } if (_moveFilter.Get1(0).SquaresToMove.Count == 0) { _moveFilter.GetEntity(0).Destroy(); EcsEntity ent1 = _world.NewEntity(); ent1.Get <CheckFinishComponent>(); } } }
// unlinks unit from task and notifies unit that task is finished private void detachPerformer(EcsEntity task, TaskFinishedComponent component) { if (task.Has <TaskPerformerComponent>()) { task.Get <TaskPerformerComponent>().performer.Replace(component); task.Del <TaskPerformerComponent>(); } }
public static Vector3Int pos(this EcsEntity entity) { if (entity.hasPos()) { return(entity.Get <PositionComponent>().position); } throw new ArgumentException("entity has no PositionComponent!"); }
private void _InitEntity() { _entity = World.NewEntity(); _entity.Get <SceneComponent>().Scene = this; // sends create event World.NewEntity().Get <SceneCreatedEvent>().Scene = this; }
private void _Show() { if (content != null) { content.SetActive(true); } if (_entity.Has <IsSceneInactiveComponent>()) { _entity.Del <IsSceneInactiveComponent>(); } _entity.Get <IsSceneActiveComponent>(); // sends event scene has been activated World.NewEntity().Get <SceneActivatedEvent>().Scene = this; }
public override Vector3Int?getPosition() { if (!entity.Has <PositionComponent>()) { Debug.LogWarning("Getting position of entity " + entity + " without PositionComponent"); return(null); } return(entity.Get <PositionComponent>().position); }
public static void RLSetMaxHealth(this EcsEntity entity, int value) { var c = entity.Get <NPCDataSheetComponent>(); if (c != null) { c.Stats.MaxHealthPoint = value; } }
public void OnRecalculateStats(EcsEntity entity) { var shieldComponent = entity.Get <DefenceComponent>(); if (shieldComponent != null) { shieldComponent.BonusValue += Values[Level]; } }
public virtual void OnSpawn(EcsEntity entity) { entity.Set <UnityView>(); UnityView view = entity.Get <UnityView>(); view.GameObject = this.gameObject; view.id = id; view.Transform = transform; }
public void OnRecalculateStats(EcsEntity entity) { var damageComponent = entity.Get <DamageComponent>(); if (damageComponent != null) { damageComponent.BonusValue += Values[Level]; } }
private void OnTriggerEnter(Collider other) { if (Entity.IsNull()) { Debug.LogError("Entity is null on coin"); return; } Entity.Get <CollisionEvent>().Type = CollisionType.Obstacle; }
// if task was completed, designation is no longer needed private void detachDesignation(EcsEntity task, TaskFinishedComponent component) { if (component.status == TaskStatusEnum.COMPLETE && task.Has <TaskDesignationComponent>()) { // TODO handle workbenches task.Get <TaskDesignationComponent>().designation.Replace(component); task.Del <TaskDesignationComponent>(); } }
private void UpdateMouseInput() { var offset = new Vector2(Screen.width / 2f, Screen.height / 2f); var mousePoint = ((Vector2)Input.mousePosition - offset).normalized; var angle = -Vector2.SignedAngle(Vector2.up, mousePoint); angle = angle < 0 ? 360 + angle : angle; _rotateEventEntity.Get <RotateEventComponent>().Value = angle; }