コード例 #1
0
        private bool IsContains(objToSpawn ots, List <Vector3Int> positions, List <Vector3Int> tPointsList, Vector3Int tempPos)
        {
            bool value = false;
            List <Vector3Int> temppointsList = new List <Vector3Int>();

            for (int u = 0; u < tPointsList.Count; u++)
            {
                temppointsList.Add(tempPos + tPointsList[u]);
            }
            if (spawnedTilesPositions.Count != 0)
            {
                for (int i = 0; i < temppointsList.Count; i++)
                {
                    if (spawnedTilesPositions.Contains(temppointsList[i]))
                    {
                        return(false);
                    }
                }
            }

            for (int h = 0; h < temppointsList.Count; h++)
            {
                if (positions.Contains(temppointsList[h]))
                {
                    value = true;
                }
                else
                {
                    return(false);
                }
            }
            return(value);
        }
コード例 #2
0
        /// <summary>
        /// Starts Spawn with options;
        /// </summary>
        /// <param name="o">Object To Spawn Struct</param>
        /// <returns></returns>
        private IEnumerator objSpawnerRepeat(objToSpawn o)
        {
            if (o.enableSpawner)
            {
                switch (o.RepeateOptions) // switch between repeat options;
                {
                case repeatOptions.noRepeate:
                    StartCoroutine(objSpawner(o.enableRandomSpawn, o.randomTimeToSpawn, o.timeToSpawn, o.amountOfObjectsToSpawn, o.spawnerRadius, o.layerToAvoid, o.objectToSpawn, o.forceMode, o.force, o.addForce, o));     // simply starts main spawn without repeat;
                    yield return(0);

                    break;

                case repeatOptions.repeatAfterMainSpawnTime:
                    StartCoroutine(objSpawner(o.enableRandomSpawn, o.randomTimeToSpawn, o.timeToSpawn, o.amountOfObjectsToSpawn, o.spawnerRadius, o.layerToAvoid, o.objectToSpawn, o.forceMode, o.force, o.addForce, o));    // starts main spawn
                    if (o.randomRepeat)
                    {
                        yield return(new WaitForSecondsRealtime(UnityEngine.Random.Range(o.randomRepeatTimer.x, o.randomRepeatTimer.y)));
                    }
                    else
                    {
                        yield return(new WaitForSecondsRealtime(o.repeatTimer));
                    }
                    for (int i = 0; i < o.timesToRepeat; i++)
                    {
                        if (o.randomRepeat)
                        {
                            yield return(new WaitForSecondsRealtime(UnityEngine.Random.Range(o.randomRepeatTimer.x, o.randomRepeatTimer.y)));    // waiting for random delay;
                        }
                        else
                        {
                            yield return(new WaitForSecondsRealtime(o.repeatTimer));                                                                                                                    // waiting for delay;
                        }
                        StartCoroutine(objSpawner(o.randomRepeat, Vector2.zero, 0, o.amountOfObjectsToRespawn, o.spawnerRadius, o.layerToAvoid, o.objectToSpawn, o.forceMode, o.force, o.addForce, o)); // starts main repeated spawn
                    }
                    break;

                case repeatOptions.repeateImmediately:
                    for (int i = 0; i < o.timesToRepeat; i++)
                    {
                        if (o.randomRepeat)
                        {
                            yield return(new WaitForSecondsRealtime(UnityEngine.Random.Range(o.randomRepeatTimer.x, o.randomRepeatTimer.y)));   // waiting for random delay;
                        }
                        else
                        {
                            yield return(new WaitForSecondsRealtime(o.repeatTimer));                                                                                                                                       // waiting for delay;
                        }
                        StartCoroutine(objSpawner(o.randomRepeat, o.randomRepeatTimer, o.repeatTimer, o.amountOfObjectsToRespawn, o.spawnerRadius, o.layerToAvoid, o.objectToSpawn, o.forceMode, o.force, o.addForce, o)); // starts main repeated spawn
                    }
                    break;

                default:
                    print("Bad things Happend (( with object spawner.");
                    break;
                }
            }
        }
コード例 #3
0
        public void LoadParameters()
        {
            walTile                       = MapProperties.wallTile;
            groundTile                    = MapProperties.groundTile;
            burnedGroundTile              = MapProperties.burnedGroundTile;
            generationType                = MapProperties.worldGenerationType;
            wallsHealth                   = MapProperties.wallsHealth;
            _newGenProperties.wallChance  = MapProperties.wallChance;
            _newGenProperties.filled      = MapProperties.filled;
            _newGenProperties.empty       = MapProperties.empty;
            _newGenProperties.repeatCount = MapProperties.repeatCount;
            _newGenProperties.tileMapSize = MapProperties.tileMapSize;
            Enemies                       = MapProperties.Enemies;
            enemyAmount                   = MapProperties.enemyAmount;
            _oldGenProperties.TileAmount  = MapProperties.tileAmount;
            TileSize                      = 1;
            _oldGenProperties.chanceUp    = MapProperties.chanceUp;
            _oldGenProperties.chanceRight = MapProperties.chanceRight;
            _oldGenProperties.chanceDown  = MapProperties.chanceDown;
            _oldGenProperties.ExtraWallsX = MapProperties.ExtraWallsX;
            _oldGenProperties.ExtraWallsY = MapProperties.ExtraWallsY;

            ObjectsSpawner = MapProperties.spawner;
            if (ObjectsSpawner.Count != 0)
            {
                for (int i = 0; i < MapProperties.spawner.Count; i++)
                {
                    if (ObjectsSpawner[i].enableSpawner)
                    {
                        objToSpawn spawner = ObjectsSpawner[i];
                        if (!string.IsNullOrEmpty(spawner._tileMapName))
                        {
                            spawner._Map = GameObject.Find(spawner._tileMapName).GetComponent <Tilemap>();
                            if (spawner._Map)
                            {
                                ObjectsSpawner[i] = spawner;
                            }
                        }
                    }
                }
            }
            advanceSurfacesSettings = new List <advancedSurface>();
            advanceSurfacesSettings = MapProperties.extraSurface;
            for (int k = 0; k < advanceSurfacesSettings.Count; k++)
            {
                if (advanceSurfacesSettings[k].enableSurface)
                {
                    advancedSurface s = new advancedSurface();
                    s = advanceSurfacesSettings[k];
                    if (!s._Map)
                    {
                        s._Map = GameObject.Find(s._tileMapName).GetComponent <Tilemap>();
                        advanceSurfacesSettings[k] = s;
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Universal Object spawner.
        /// </summary>
        /// <param name="r">enable random spawn.</param>
        /// <param name="v">random time to spawn.</param>
        /// <param name="t">time to spawn.</param>
        /// <param name="a">amount of objects to spawn.</param>
        /// <param name="sr">spawner radius.</param>
        /// <param name="l">layer to avoid.</param>
        /// <param name="g">gameobject to spawn.</param>
        private IEnumerator objSpawner(bool r, Vector2 v, float t, int a, float sr, LayerMask l, GameObject g, ForceMode2D forceMode, float force, bool addForce, objToSpawn ots)
        {
            if (r)
            {
                yield return(new WaitForSecondsRealtime(UnityEngine.Random.Range(v.x, v.y)));// waiting for random delay;
            }
            else
            {
                yield return(new WaitForSecondsRealtime(t));// waiting for delay;
            }

            List <Vector3Int> tempPositions = new List <Vector3Int>();

            if (ots.targetSurfaceIndex < surfacesData.Count)
            {
                tempPositions = surfacesData[ots.targetSurfaceIndex]._positions;
            }
            if (tempPositions.Count > 0)
            {
                for (int i = 0; i < a; i++) // loop for amount of objects to spawn;
                {
                    switch (ots._spawnObject)
                    {
                    case SpawnObject.prefab:
                        Vector3 tempPoint;
                        for (int u = 0; u < tempPositions.Count; u++)
                        {
                            int _randomIndex1 = Random.Range(0, tempPositions.Count - 1);
                            tempPoint = surfacesData[ots.targetSurfaceIndex]._tileMap.CellToWorld(tempPositions[_randomIndex1]) + grid.cellSize / 2;
                            if (tempPositions.Contains(tempPositions[_randomIndex1]))
                            {
                                GameObject obj = Instantiate(g, tempPoint, Quaternion.identity); // instantiate Object to Spawn;
                                obj.transform.parent = spawnedObjects.transform;
                                if (ots.addForce)                                                // if add force is true;
                                {
                                    // Vector2 yourChoosedDirection = new Vector2(...,...); - insert your own vector here and in AddForce;
                                    obj.GetComponent <Rigidbody2D>().AddForce(new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f)) * force, forceMode);    // Add some force in random direction;
                                }
                                break;
                            }
                        }
                        break;

                    case SpawnObject.tile:
                        if (ots.tileSize != Vector2Int.zero)
                        {
                            List <Vector3Int> _p = NeighboursList(ots.tileSize.x, ots.tileSize.y);
                            for (int z = 0; z < tempPositions.Count; z++)
                            {
                                int        _randomIndex = Random.Range(0, tempPositions.Count - 1);
                                Vector3Int tempPos      = tempPositions[_randomIndex];
                                if (IsContains(ots, tempPositions, _p, tempPos))
                                {
                                    if (!spawnedTilesPositions.Contains(tempPos))
                                    {
                                        ots._Map.SetTile(tempPos, ots.tileToSpawn);
                                        spawnedTilesPositions.Add(tempPos);
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            int        _randomIndex = Random.Range(0, tempPositions.Count - 1);
                            Vector3Int tempPos      = tempPositions[_randomIndex];
                            ots._Map.SetTile(tempPos, ots.tileToSpawn);
                            spawnedTilesPositions.Add(tempPos);
                        }

                        break;

                    default:
                        break;
                    }
                }
            }
        }