예제 #1
0
    public void TrySpawnAll()
    {
        foreach (Spawnable spawnable in spawnables)
        {
            startTime = Time.realtimeSinceStartup;
            for (int i = 0; i < spawnable.quantity; i++)
            {
                GameObject            prefab         = spawnable.prefabs.RandomElement();
                SpawnObstacle         prefabObstacle = prefab.GetComponentInChildren <SpawnObstacle>();
                SphericalRegionCircle prefabRegion   = (prefabObstacle != null)? prefabObstacle.region : null;
                Vector3 direction;
                bool    zeroDirection, outsideSpawnRegion, blockedBySomeObstacle;
                bool IsStillOnTime() => (curTime - startTime) <= maxTimeRandomizing;

                do
                {
                    direction             = UnityEngine.Random.insideUnitSphere.normalized;
                    curTime               = Time.realtimeSinceStartup;
                    zeroDirection         = direction == Vector3.zero;
                    outsideSpawnRegion    = !spawnRegion.Contains(direction);
                    blockedBySomeObstacle = SpawnObstacle.AnyBlocksSpawn(obstacleIds, prefabRegion, direction);
                } while ((zeroDirection || outsideSpawnRegion || blockedBySomeObstacle) && IsStillOnTime());
                if (!IsStillOnTime())
                {
                    Debug.Log("Timed out spawning " + prefab + " #" + (i + 1) + "." + (outsideSpawnRegion? " Outside spawn region.":"") + (blockedBySomeObstacle ? " Blocked by some obstacle." : ""));
                    break;
                }
                Transform newObj = Instantiate(prefab).transform;
                newObj.position = direction.normalized * radius;
                newObj.up       = direction;
                newObj.parent   = parent;
            }
            Debug.Log("Time spent spawning: " + (Time.realtimeSinceStartup - startTime));
        }
    }
예제 #2
0
 public bool BlocksSpawn(List <string> possibilities, SphericalRegionCircle other, Vector3 hypotheticalUp) => MatchesIdentifiers(possibilities) && region.WouldOverlap(other, hypotheticalUp);
예제 #3
0
 public static bool AnyBlocksSpawn(List <string> possibilities, SphericalRegionCircle other, Vector3 hypotheticalUp) => instanceList.Exists(i => i.BlocksSpawn(possibilities, other, hypotheticalUp));