void IEcsInitSystem.Initialize() { var playerBehaviour = GameObject.FindObjectOfType <PlayerBehaviour>(); Assert.IsNotNull(playerBehaviour, "Player not found. Object must contains PlayerBehavior component"); EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <TransformComponent>(out TransformComponent transformComponent) .AddComponent <PlayerTagComponent>(); transformComponent.transform = playerBehaviour.transform; }
void CreateContainerEntity() { var prefab = GetContainerPrefab(); var go = GameObject.Instantiate(prefab); go.name = prefab.name; EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <BarrierAreaContainerTagComponent>() .AddComponent <TransformComponent>(out TransformComponent transform); transform.transform = go.transform; }
void IEcsInitSystem.Initialize() { var spawnerInstance = GameObject.FindObjectOfType <BeatshipSpawnerBehaviour>(); Assert.IsNotNull(spawnerInstance, "Beatship spawner game object not found. It must contain BeatshipSpawnerBehaviour script"); EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <BeatshipSpawnerTagComponent>() .AddComponent <TransformComponent>(out TransformComponent transform) .AddComponent <BeatshipFreeFlyRadiusComponent>(out BeatshipFreeFlyRadiusComponent freeFlyRadius); transform.transform = spawnerInstance.transform; freeFlyRadius.freeFlyRadius = spawnerInstance.freeFlyRadius; }
void ClearBarrierAreaMap() { var map = _mapFilter.Components1[0].map; foreach (var row in map) { foreach (var barrierAreaEntity in row) { EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <BarrierAreaDestroyEvent>(out BarrierAreaDestroyEvent destroyEvent); destroyEvent.barrierAreaEntity = barrierAreaEntity; } } }
void SpawnBarrierArea(GameObject barrierAreaPrefab, Vector3 position, Transform parent, LinkedList <EcsEntity> row, BarrierAreaSpawnEvent.InsertPosition insertPosition) { EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <BarrierAreaSpawnEvent>(out BarrierAreaSpawnEvent spawnEvent); spawnEvent.position = position; spawnEvent.barrierAreaPrefab = barrierAreaPrefab; spawnEvent.parent = parent; spawnEvent.row = row; spawnEvent.insertPositionInRow = insertPosition; }
void ProcessCollisionEnter() { foreach (var collision in _beatshipFilter.Components2[0].collisionsOnEnter) { Vector3 collisionNormal = collision.collision.contacts[0].normal; Vector3 velocityOnCollision = _beatshipFilter.Components3[0].lastVelocity; float collisionAngle = Vector3.Angle(velocityOnCollision, -collisionNormal); var barrierBehaviour = collision.collision.gameObject.GetComponent <BarrierBehaviour>(); if (barrierBehaviour != null) { float maxCollisionAngle = _beatshipFilter.Components4[0].maxCollisionAngle; if (collisionAngle < maxCollisionAngle) { if (barrierBehaviour.isDestroyable) { EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <DelayDestroyObjectEvent>( out DelayDestroyObjectEvent destroyObjectEvent); destroyObjectEvent.gameObject = collision.collision.gameObject; } EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <BeatshipAddDamageEvent>(out BeatshipAddDamageEvent damageEvent); float damageCoefficient = 1.0f - collisionAngle / maxCollisionAngle; float damage = barrierBehaviour.damage; damageEvent.damage = damage * damageCoefficient; } } } _beatshipFilter.Components2[0].collisionsOnEnter.Clear(); }
void IEcsRunSystem.Run() { var map = _barrierAreaMapFilter.Components1[0].map; List <LinkedList <EcsEntity> > rowsToDelete = new List <LinkedList <EcsEntity> >(); foreach (var row in map) { // Find barrier areas out view radius var barrierAreasToDelete = row.Where(barrierAreaEntity => { TransformComponent barrierAreaTransformComponent = _world.GetComponent <TransformComponent>(barrierAreaEntity); SizeComponent barrierAreaSizeComponent = _world.GetComponent <SizeComponent>(barrierAreaEntity); float viewDiameter = _beatshipFilter.Components3[0].viewRadius * 2; Bounds barrierAreaBounds = new Bounds(barrierAreaTransformComponent.transform.position, barrierAreaSizeComponent.size); Bounds viewAreaBounds = new Bounds(_beatshipFilter.Components2[0].transform.position, new Vector3(viewDiameter, viewDiameter, viewDiameter)); return(!IsRectangleOverlapRectangle(barrierAreaBounds, viewAreaBounds)); }); // Destroy barrier areas out view radius foreach (var barrierAreaEntity in barrierAreasToDelete) { EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <BarrierAreaDestroyEvent>(out BarrierAreaDestroyEvent destroyEvent); destroyEvent.barrierAreaEntity = barrierAreaEntity; } } }
EcsEntity CreateBarrierAreaEntity(GameObject barrierAreaInstance, GameObject barrierAreaPrefab) { EntityBuilder.Instance(_world) .CreateEntity(out EcsEntity entity) .AddComponent <BarrierListComponent>(out BarrierListComponent barrierList) .AddComponent <TransformComponent>(out TransformComponent transform) .AddComponent <PrefabComponent>(out PrefabComponent prefab) .AddComponent <SizeComponent>(out SizeComponent size) .AddComponent <BarrierAreaTagComponent>(); barrierList.barriers = new List <BarrierBehaviour>(); transform.transform = barrierAreaInstance.transform; var collider = barrierAreaInstance.GetComponent <Collider>(); Assert.IsNotNull(collider, "BarrierArea collider not found"); size.size = collider.bounds.size; prefab.prefab = barrierAreaPrefab; return(entity); }
void CreateBeatshipEntity(GameObject beatshipInstance) { EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <BeatshipMaxCollisionAngleComponent>(out BeatshipMaxCollisionAngleComponent maxCollisionAngle) .AddComponent <BeatshipAltitudeComponent>(out BeatshipAltitudeComponent altitude) .AddComponent <BeatshipRotationComponent>(out BeatshipRotationComponent rotation) .AddComponent <BeatshipModelTransform>(out BeatshipModelTransform modelTransform) .AddComponent <BeatshipHealthComponent>(out BeatshipHealthComponent health) .AddComponent <BeatshipViewComponent>(out BeatshipViewComponent view) .AddComponent <CollisionComponent>(out CollisionComponent collision) .AddComponent <TransformComponent>(out TransformComponent transform) .AddComponent <RigidbodyComponent>(out RigidbodyComponent rigidbody) .AddComponent <PidComponent>(out PidComponent pid) .AddComponent <BeatshipLastVelocityComponent>() .AddComponent <BeatshipTagComponent>() .AddComponent <AntiGravityComponent>() .AddComponent <PidValueComponent>() .AddComponent <SpeedComponent>(); maxCollisionAngle.maxCollisionAngle = 40.0f; transform.transform = beatshipInstance.transform; rigidbody.rigidbody = beatshipInstance.GetComponent <Rigidbody>(); Assert.IsNotNull(rigidbody.rigidbody, "Beatship rigidbody not found"); var collisionBehaviour = beatshipInstance.GetComponent <CollisionBehaviour>(); collision.collider = collisionBehaviour.collider; collision.collisionsOnEnter = collisionBehaviour.collisionsOnEnter; collision.collisionsOnExit = collisionBehaviour.collisionsOnExit; collision.collisionsOnStay = collisionBehaviour.collisionsOnStay; health.health = 100.0f; pid.kp = 10.0f; pid.ki = 0.0f; pid.kd = 1.0f; altitude.defaultAltitude = 4.0f; altitude.minAltitude = 2.0f; altitude.maxAltitude = 7.0f; PitchRotationBehaviour pitchRotationBehaviour = beatshipInstance.GetComponentInChildren <PitchRotationBehaviour>(); Assert.IsNotNull(pitchRotationBehaviour, "Pitch rotation container not found. Beatship model must contained in game object which contains PitchRotationBehaviour script"); RollRotationBehaviour rollRotationBehaviour = beatshipInstance.GetComponentInChildren <RollRotationBehaviour>(); Assert.IsNotNull(pitchRotationBehaviour, "Roll rotation container not found. Beatship model must contained in game object which contains RollRotationBehaviour script"); modelTransform.pitchTransform = pitchRotationBehaviour.transform; modelTransform.rollTransform = rollRotationBehaviour.transform; BeatshipBehaviour beatshipBehaviour = beatshipInstance.GetComponent <BeatshipBehaviour>(); Assert.IsNotNull(beatshipBehaviour, "Beatship behaviour script on beatship prefab not found"); view.viewOpacityCurve = beatshipBehaviour.viewOpacityCurve; view.viewRadius = beatshipBehaviour.viewRadius; rotation.pitchCurve = beatshipBehaviour.pitchCurve; rotation.rollLimit = beatshipBehaviour.rollLimit; rotation.pitchLimit = beatshipBehaviour.pitchLimit; rotation.rollRotationSpeed = beatshipBehaviour.rollRotationSpeed; rotation.pitchRotationSpeed = beatshipBehaviour.pitchRotationSpeed; }
void ChangeLevelToGame() { EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <BarrierAreaMapResetEvent>(); }
void IEcsInitSystem.Initialize() { EntityBuilder.Instance(_world) .CreateEntity() .AddComponent <AxisComponent>(); }