Example #1
0
        // ReSharper disable once UnusedMember.Local
        private void Start()
        {
            if (listenerPrefab == null)
            {
                return;
            }
            var variable = WorldVariableTracker.GetWorldVariable(name);

            if (variable == null)
            {
                return;
            }

            var curVal = variable.CurrentIntValue;

            listenerPrefab.UpdateValue(curVal, curVal);
        }
        private void FillPool()
        {
            // fill weighted pool
            for (var item = 0; item < poolItems.Count; item++)
            {
                var poolItem = poolItems[item];

                var includeItem = true;

                switch (poolItem.activeMode)
                {
                case LevelSettings.ActiveItemMode.Always:
                    break;

                case LevelSettings.ActiveItemMode.Never:
                    continue;

                case LevelSettings.ActiveItemMode.IfWorldVariableInRange:
                    if (poolItem.activeItemCriteria.statMods.Count == 0)
                    {
                        includeItem = false;
                    }

                    // ReSharper disable once ForCanBeConvertedToForeach
                    for (var i = 0; i < poolItem.activeItemCriteria.statMods.Count; i++)
                    {
                        var stat = poolItem.activeItemCriteria.statMods[i];
                        if (!WorldVariableTracker.VariableExistsInScene(stat._statName))
                        {
                            Debug.LogError(
                                string.Format(
                                    "Prefab Pool '{0}' could not find World Variable '{1}', which is used in its Active Item Criteria.",
                                    transform.name,
                                    stat._statName));
                            includeItem = false;
                            break;
                        }

                        var variable = WorldVariableTracker.GetWorldVariable(stat._statName);
                        if (variable == null)
                        {
                            includeItem = false;
                            break;
                        }
                        var varVal = stat._varTypeToUse == WorldVariableTracker.VariableType._integer
                                ? variable.CurrentIntValue
                                : variable.CurrentFloatValue;

                        var min = stat._varTypeToUse == WorldVariableTracker.VariableType._integer
                                ? stat._modValueIntMin
                                : stat._modValueFloatMin;
                        var max = stat._varTypeToUse == WorldVariableTracker.VariableType._integer
                                ? stat._modValueIntMax
                                : stat._modValueFloatMax;

                        if (min > max)
                        {
                            LevelSettings.LogIfNew(
                                "The Min cannot be greater than the Max for Active Item Limit in Prefab Pool '" +
                                transform.name + "'. Skipping item '" + poolItem.prefabToSpawn.name + "'.");
                            includeItem = false;
                            break;
                        }

                        if (!(varVal < min) && !(varVal > max))
                        {
                            continue;
                        }
                        includeItem = false;
                        break;
                    }

                    break;

                case LevelSettings.ActiveItemMode.IfWorldVariableOutsideRange:
                    if (poolItem.activeItemCriteria.statMods.Count == 0)
                    {
                        includeItem = false;
                    }

                    // ReSharper disable once ForCanBeConvertedToForeach
                    for (var i = 0; i < poolItem.activeItemCriteria.statMods.Count; i++)
                    {
                        var stat     = poolItem.activeItemCriteria.statMods[i];
                        var variable = WorldVariableTracker.GetWorldVariable(stat._statName);
                        if (variable == null)
                        {
                            includeItem = false;
                            break;
                        }
                        var varVal = stat._varTypeToUse == WorldVariableTracker.VariableType._integer
                                ? variable.CurrentIntValue
                                : variable.CurrentFloatValue;

                        var min = stat._varTypeToUse == WorldVariableTracker.VariableType._integer
                                ? stat._modValueIntMin
                                : stat._modValueFloatMin;
                        var max = stat._varTypeToUse == WorldVariableTracker.VariableType._integer
                                ? stat._modValueIntMax
                                : stat._modValueFloatMax;

                        if (min > max)
                        {
                            LevelSettings.LogIfNew(
                                "The Min cannot be greater than the Max for Active Item Limit in Prefab Pool '" +
                                transform.name + "'. Skipping item '" + poolItem.prefabToSpawn.name + "'.");
                            includeItem = false;
                            break;
                        }

                        if (!(varVal >= min) || !(varVal <= max))
                        {
                            continue;
                        }
                        includeItem = false;
                        break;
                    }

                    break;
                }

                if (!includeItem)
                {
                    continue;
                }

                for (var i = 0; i < poolItem.thisWeight.Value; i++)
                {
                    _poolItemIndexes.Add(item);
                }
            }

            if (_poolItemIndexes.Count == 0)
            {
                LevelSettings.LogIfNew("The Prefab Pool '" + name +
                                       "' has no active Prefab Pool items. Please add some or delete the Prefab pool before continuing. Disabling Core GameKit.");
                LevelSettings.IsGameOver = true;
                return;
            }

            _isValid = true;
        }