Пример #1
0
        static MapInitSystem()
        {
            PlayerPrototypes = Resources.LoadAll <PlayerObject>("SO/Players")
                               .ToDictionary(po => Regex.Match(po.name,
                                                               "^([A-Z][a-z]+)") // Первая часть до следующей большой буквы
                                             .Value.ToLower());

            Skins = Resources.LoadAll <SkinInfo>("SO/Skins")
                    .ToDictionary(po => Regex.Match(po.name,
                                                    "^([A-Z][a-z]+)") // Первая часть до следующей большой буквы
                                  .Value);

            if (PlayerPrototypes.Any(p => p.Value == null))
            {
                throw new Exception($"В {nameof(MapInitSystem)} playerPrototype был null.");
            }

            if (Skins.Any(p => p.Value == null))
            {
                throw new Exception($"В {nameof(MapInitSystem)} skin был null.");
            }

            FlameCircle = Resources.Load <FlameCircleObject>("SO/BaseObjects/FlameCircle");
            if (FlameCircle == null)
            {
                throw new Exception($"В {nameof(MapInitSystem)} flameCircle был null.");
            }
            mapIntRadius = Mathf.CeilToInt(((CircleColliderInfo)FlameCircle.colliderInfo).radius);

            RandomAsteroid = Resources.Load <RandomObject>("SO/BaseObjects/RandomAsteroid");
            if (RandomAsteroid == null)
            {
                throw new Exception($"В {nameof(MapInitSystem)} asteroid был null.");
            }

            SpaceStation = Resources.Load <BaseWithHealthObject>("SO/BaseObjects/SpaceStation");
            if (SpaceStation == null)
            {
                throw new Exception($"В {nameof(MapInitSystem)} spaceStation был null.");
            }

            RandomBonus = Resources.Load <RandomObject>("SO/Bonuses/PickableObjects/RandomSmallBonus");
            if (RandomBonus == null)
            {
                throw new Exception($"В {nameof(MapInitSystem)} bonus был null.");
            }

            UpgradeBonus = Resources.Load <UpgradeBonusObject>("SO/Bonuses/PickableObjects/SmallUpgradeBonus");
            if (UpgradeBonus == null)
            {
                throw new Exception($"В {nameof(MapInitSystem)} upgrade bonus был null.");
            }

            Boss = Resources.Load <FighterObject>("SO/BaseObjects/ScarabBoss");
            if (Boss == null)
            {
                throw new Exception($"В {nameof(MapInitSystem)} boss был null.");
            }
        }
 public bool TryGetObject(ref int randomValue, out EntityCreatorObject resultObject)
 {
     randomValue -= probability;
     if (randomValue < 0)
     {
         resultObject = currentObject;
         return(true);
     }
     else
     {
         resultObject = null;
         return(false);
     }
 }
    public override void FillEntity(GameContext context, GameEntity entity)
    {
        var probability = random.Next(maxProbability);

        EntityCreatorObject result = null;

        foreach (var probabilityObject in objects)
        {
            if (probabilityObject.TryGetObject(ref probability, out result)) break;
        }

        if (result == null)
        {
            entity.isDestroyed = true;
        }
        else
        {
            result.FillEntity(context, entity);
        }
    }