Esempio n. 1
0
    // Use this for initialization
    public void Initialize()
    {
        // prepare which object has been purchased
        PurchasedPowerUps.Clear();

        for (int i = 0; i < SpawnedModel.Length; i++)
        {
            PowerupSpawnModel spawnedModel = SpawnedModel [i];
            Debug.Log(spawnedModel.DatabaseName + " need purchased:" + spawnedModel.NeedPurchased);

            // check purchase
            if (spawnedModel.NeedPurchased)
            {
                Debug.Log(spawnedModel.DatabaseName + " check purchased:" + GameSaveManager.Instance.CheckPurchase(spawnedModel.DatabaseName));

                if (GameSaveManager.Instance.CheckPurchase(spawnedModel.DatabaseName))
                {
                    PurchasedPowerUps.Add(spawnedModel);
                }
            }
            else
            {
                PurchasedPowerUps.Add(spawnedModel);
            }
        }

        SetPercentageRange();
    }
Esempio n. 2
0
    public virtual Entity Spawn()
    {
        int randomNum = Random.Range(0, _TotalRange);

        PowerupSpawnModel model = GetDesiredRange(PurchasedPowerUps.ToArray(), randomNum);

        if (model != null)
        {
            string poolName = model.PoolName;

            if (poolName != null && poolName != "")
            {
                GameObjectPool gameObjectPool = PoolManager.Instance.GetPool(poolName);

                if (gameObjectPool != null)
                {
                    GameObject spawnedEntity = gameObjectPool.Get();

                    if (spawnedEntity != null)
                    {
                        Entity e = spawnedEntity.GetComponent <Entity> ();

                        if (e != null)
                        {
                            // get random position
                            int randomPosIndex = Random.Range(0, Positions.Length - 1);

                            Vector3 randomPosition = Positions [randomPosIndex].position;
                            Vector3 endPosition    = new Vector3(
                                randomPosition.x + Random.Range(MinOffset.x, MaxOffset.x),
                                randomPosition.y + Random.Range(MinOffset.y, MaxOffset.y),
                                randomPosition.z + Random.Range(MinOffset.z, MaxOffset.z));
                            e.transform.position = randomPosition;
                            e.gameObject.SetActive(true);

                            OnEntitySpawned(e);

                            e.Init();

                            SpawnCount++;
                            return(e);
                        }
                    }
                }
            }
        }
        return(null);
    }
Esempio n. 3
0
    // Load PowerupSpawnModel using its probability range
    protected PowerupSpawnModel GetDesiredRange(PowerupSpawnModel[] targetArray, int value)
    {
        int i = 0;

        while (i < PurchasedPowerUps.Count)
        {
            PowerupSpawnModel currentModel = PurchasedPowerUps [i];
            if (currentModel.IsInRange(value))
            {
                return(currentModel);
            }
            else
            {
                i++;
            }
        }

        return(null);
    }
Esempio n. 4
0
    private void SetPercentageRange()
    {
        //reset
        _TotalRange = 0;

        // set the percentage range
        int startRange = 0;
        int endRange   = 0;

        for (int i = 0; i < PurchasedPowerUps.Count; i++)
        {
            PowerupSpawnModel currentModel = PurchasedPowerUps [i];

            _TotalRange += currentModel.Probability;

            startRange = endRange + (i > 0?1:0);
            endRange   = startRange + currentModel.Probability - 1;

            currentModel.SetPercentageRange(startRange, endRange);
        }
    }