コード例 #1
0
        void SpawnRows()
        {
            Transform beatshipTransform  = _beatshipFilter.Components2[0].transform;
            float     beatshipViewRadius = _beatshipFilter.Components3[0].viewRadius;

            Vector3 beatshipPosition = beatshipTransform.position;
            float   viewRadius       = beatshipViewRadius;

            Bounds farBarrierAreaBounds = new Bounds(beatshipPosition, Vector3.zero);
            bool   needSpawn            = true;

            var map = _barrierAreaMapFilter.Components1[0].map;

            if (map.Count > 0)
            {
                var firstRow = map.First.Value;
                if (firstRow.Count > 0)
                {
                    EcsEntity barrierAreaEntity = firstRow.First.Value;

                    TransformComponent barrierAreaTransformComponent =
                        _world.GetComponent <TransformComponent>(barrierAreaEntity);
                    SizeComponent barrierAreaSizeComponent = _world.GetComponent <SizeComponent>(barrierAreaEntity);

                    Bounds barrierAreaBounds = new Bounds(barrierAreaTransformComponent.transform.position,
                                                          barrierAreaSizeComponent.size);

                    if (barrierAreaBounds.max.z > farBarrierAreaBounds.max.z)
                    {
                        farBarrierAreaBounds = barrierAreaBounds;
                    }

                    // If at least one area is farther than view radius then not need spawn new area
                    if (barrierAreaBounds.max.z >= beatshipPosition.z + viewRadius)
                    {
                        needSpawn = false;
                    }
                }
            }

            // Generate spawn event
            if (needSpawn)
            {
                GameObject barrierAreaPrefab = GetBarrierAreaPrefab();

                SetPatternBarrierPrefabs(barrierAreaPrefab);

                BoxCollider barrierAreaCollider = barrierAreaPrefab.GetComponent <BoxCollider>();
                Assert.IsNotNull(barrierAreaCollider, "BarrierArea collider not found");

                Vector3 position = new Vector3(beatshipPosition.x, 0, farBarrierAreaBounds.max.z + barrierAreaCollider.size.z / 2);

                Transform parent = _barrierAreaContainerFilter.Components2[0].transform;

                // Create barrier area
                SpawnBarrierArea(barrierAreaPrefab, position, parent, null,
                                 BarrierAreaSpawnEvent.InsertPosition.Last);
            }
        }
コード例 #2
0
        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;
                }
            }
        }
コード例 #3
0
        void SpawnOnLeftSide(Transform beatshipTransform, float beatshipViewRadius)
        {
            var map = _barrierAreaMapFilter.Components1[0].map;

            // map.First is left barrier area
            foreach (var row in map)
            {
                EcsEntity leftEntity = row.First.Value;

                TransformComponent leftBarrierAreaTransformComponent = _world.GetComponent <TransformComponent>(leftEntity);
                SizeComponent      leftBarrierAreaSizeComponent      = _world.GetComponent <SizeComponent>(leftEntity);

                Bounds leftBarrierAreaBounds = new Bounds(leftBarrierAreaTransformComponent.transform.position, leftBarrierAreaSizeComponent.size);

                float leftBorderX = beatshipTransform.position.x -
                                    beatshipViewRadius;

                // If the leftmost area is to the right of the left border
                if (leftBarrierAreaBounds.min.x > leftBorderX)
                {
                    Vector3 position = new Vector3(leftBarrierAreaBounds.min.x - leftBarrierAreaBounds.size.x / 2,
                                                   leftBarrierAreaTransformComponent.transform.position.y,
                                                   leftBarrierAreaTransformComponent.transform.position.z);

                    PrefabComponent prefabComponent = _world.GetComponent <PrefabComponent>(leftEntity);

                    Transform parent = _barrierAreaContainerFilter.Components2[0].transform;

                    SetPatternBarrierPrefabs(prefabComponent.prefab);

                    // Create barrier area
                    SpawnBarrierArea(prefabComponent.prefab, position, parent, row,
                                     BarrierAreaSpawnEvent.InsertPosition.First);
                }
            }
        }