Esempio n. 1
0
        private void _spawnCoins(IEntity entity)
        {
            var viewComponent  = entity.GetComponent <ViewComponent>();
            var go             = viewComponent.View.gameObject;
            var targetPosition = (Vector2)go.transform.position;
            var spawnCounts    = UnityEngine.Random.Range(2, 5);

            for (var i = 0; i < spawnCounts; i++)
            {
                var offsetPosition = Vector2.Scale(UnityEngine.Random.onUnitSphere, Vector2.one);
                var coinEntity     = _pool.CreateEntity();
                var coinComponent  = new CoinComponent()
                {
                    startPosition    = offsetPosition + targetPosition,
                    lifeTime         = 6,
                    elapsedTime      = 0,
                    elapsedBlinkTime = 0,
                    blinkTime        = .5f,
                    score            = 50
                };

                coinEntity.AddComponent(coinComponent);
                coinEntity.AddComponent(new ViewComponent());
            }
        }
    public void RegisterSelfAsStopped(CoinComponent coin)
    {
        if (!experimentStarted)
        {
            return;
        }

        Assert.IsTrue(MovingCoins.Contains(coin));
        MovingCoins.Remove(coin);

        // If no move coins are registered as moving, finish up this round
        if (MovingCoins.Count == 0)
        {
            OnExperimentFinished();
        }
    }
Esempio n. 3
0
    void OnTriggerEnter2D(Collider2D other)
    {
        GameObject obj = other.gameObject;

        if (obj.CompareTag("Coins"))
        {
            CoinComponent coinComponent = obj.GetComponent <CoinComponent>();
            int           coins         = coinComponent.Coins;
            coins = (int)((float)coins * wcm.GetMult());
            pcc.AddCoins(coins);
            // Play coin pickup sounds.
            coinComponent.PlaySound();

            Destroy(obj);

            GameObject pickup = (GameObject)Instantiate(Resources.Load("CoinPickup"));
            pickup.transform.position = new Vector3(transform.position.x + .75f, transform.position.y, transform.position.z);
            pickup.GetComponent <CoinPickupComponent>().SetCoins(coins);
        }
    }
    void Update()
    {
        if (startExperiment)
        {
            startExperiment = false;

            // Check if the previous experiment has finished
            if (!IsExperimentFinished())
            {
                Debug.LogWarning("Previous experiment has not yet finished");
                return;
            }

            CleanUpExperimentSpace();

            timeStarted       = DateTime.Now.Ticks;
            experimentStarted = true;

            Vector3 GridCenterOffset = new Vector3(1, 0, 1) * TestGridScale * TestGridSize * 0.5f;
            for (int index = 0; index < TestGridSize * TestGridSize; index++)
            {
                // Create a new coin
                CoinComponent coin = GameObject.Instantiate(CoinPrefab);

                // Set the manager in the coin so it can let the manager know when the coin has settled into a final position
                coin.ExperimentManager = this;

                // Determine the coins position
                int     row              = index % TestGridSize;
                int     column           = index / TestGridSize;
                Vector3 HorizontalOffset = TestGridScale * new Vector3(row, 0, column);
                float   VerticalOffset   = Mathf.Lerp(HeightMin, HeightMax, UnityEngine.Random.value);

                // Set the coin position and rotation
                coin.transform.rotation = Quaternion.Euler(UnityEngine.Random.value * 360, UnityEngine.Random.value * 360, UnityEngine.Random.value * 360);
                coin.transform.position = Ground.transform.position     // The position of the ground
                                          + Vector3.up * VerticalOffset // The random height
                                          + HorizontalOffset            // The horiztal position within the grid
                                          - GridCenterOffset;           // A grid offset to recenter the grid over the center of the ground

                // Make sure the coin has physics capabilities
                Rigidbody rb = coin.GetComponent <Rigidbody>();
                if (rb == null)
                {
                    rb = coin.gameObject.AddComponent <Rigidbody>();
                }

                // Set random velocity
                Vector3 v = UnityEngine.Random.onUnitSphere * MaximumHorizontalVelocity * UnityEngine.Random.value;
                v.y         = 0;
                rb.velocity = v;

                // Set the container for the coin, so it's nice and tiny
                coin.transform.SetParent(CoinContainer);

                // Register the new coin with the manager so it knows when the experiment is finished
                RegisterNewCoin(coin);
            }
        }

        // Check if timed out
        if (experimentStarted && (DateTime.Now.Ticks - timeStarted) >= Timeout * TimeSpan.TicksPerSecond)
        {
            // Take out coins that haven't yet settled
            foreach (CoinComponent coin in MovingCoins)
            {
                Coins.Remove(coin);
            }

            OnExperimentFinished();
        }
    }
 void RegisterNewCoin(CoinComponent coin)
 {
     Assert.IsFalse(Coins.Contains(coin));
     Coins.Add(coin);
     MovingCoins.Add(coin);
 }