示例#1
0
        public List <Tile> SearchTile(Tile tile, int depth = 10)
        {
            if (tile == this)
            {
                return new List <Tile>()
                       {
                           this
                       }
            }
            ;
            if (depth == 0)
            {
                return(null);
            }
            List <Tile> rez = null;
            List <Tile> tmp = null;

            if (left != null && left.passable)
            {
                rez = left.SearchTile(tile, depth - 1);
            }
            if (right != null && right.passable)
            {
                tmp = right.SearchTile(tile, depth - 1);
                if (tmp != null && (rez == null || tmp.Count < rez.Count))
                {
                    rez = tmp;
                }
            }
            if (up != null && up.passable)
            {
                tmp = up.SearchTile(tile, depth - 1);
                if (tmp != null && (rez == null || tmp.Count < rez.Count))
                {
                    rez = tmp;
                }
            }
            if (down != null && down.passable)
            {
                tmp = down.SearchTile(tile, depth - 1);
                if (tmp != null && (rez == null || tmp.Count < rez.Count))
                {
                    rez = tmp;
                }
            }
            if (rez != null)
            {
                rez.Add(this);
            }
            return(rez);
        }

        #region Spawn
        void SpawnRoutine()
        {
            if (UnityEngine.Random.Range(0, 100) <= 15 && spawned_count < GlobalDataHolder.max_units_per_spawn)
            {
                Enemy prototype = GlobalDataHolder.FindEnemy(enemy_to_spawn);
                if (prototype == null)
                {
                    return;
                }
                FieldUnit spawned = prototype.Spawn(random_no_unit_road);
                if (spawned != null)
                {
                    GlobalEventSystem.EnemySpawned(spawned);
                    spawned.OnDeath += SpawnedUnitDied;
                    ++spawned_count;
                }
            }
        }

        int spawned_count = 0;
        void SpawnedUnitDied(FieldUnit unit)
        {
            --spawned_count;
        }