示例#1
0
    protected override string Trigger(ShipController instance)
    {
        // Kill nearby enemies
        IEnemy enemy = null;

        killRadius *= killRadius;
        foreach (IDestructable candidate in IGameManager.Instance.AllDestructables())
        {
            if ((candidate is IEnemy) && (IGameManager.DistanceSquared(transform.position, candidate.transform.position) < killRadius))
            {
                enemy = (IEnemy)candidate;
                if (enemy.Score > 0)
                {
                    GameObject clone = GlobalGameObject.Get <PoolingManager>().GetInstance(scoreLabel.gameObject, enemy.transform.position, Quaternion.identity);
                    ShipController.Instance.IncrementScore(clone.GetComponent <ScoreLabel>(), enemy.Score);
                }
                enemy.Destroy(this);
            }
        }

        // Explode
        if (explodeParticle != null)
        {
            Instantiate(explodeParticle.gameObject, transform.position, Quaternion.identity);
        }
        return("Explosive Bomb");
    }
 public void Fire(Transform gun)
 {
     // Calculate the other 2 angles
     fireAngle    = gun.rotation.eulerAngles;
     fireAngle.z += Random.Range(-spreadAngle, spreadAngle);
     GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.gameObject, gun.position, Quaternion.Euler(fireAngle));
 }
示例#3
0
    public override void Destroy(MonoBehaviour controller)
    {
        // Check if we have smaller asteroids
        if ((controller is BulletController) && (smallerAsteroids.spawnAsteroid != null) && (smallerAsteroids.spawnPositions != null))
        {
            // Start cloning small asteroids
            GameObject clone = null;
            Vector2    velocity;
            for (int index = 0; index < smallerAsteroids.spawnPositions.Length; ++index)
            {
                if (smallerAsteroids.spawnPositions[index] != null)
                {
                    // Clone the asteroid
                    clone = GlobalGameObject.Get <PoolingManager>().GetInstance(smallerAsteroids.spawnAsteroid.gameObject, smallerAsteroids.spawnPositions[index].position, Quaternion.Euler(0, 0, Random.Range(0f, 360f)));

                    // Calculate asteroids trajectory
                    velocity.x = smallerAsteroids.spawnPositions[index].position.x - transform.position.x;
                    velocity.y = smallerAsteroids.spawnPositions[index].position.y - transform.position.y;
                    velocity.Normalize();
                    velocity *= Random.Range(smallerAsteroids.speedRange.x, smallerAsteroids.speedRange.y);
                    clone.rigidbody2D.velocity = velocity;
                }
            }
        }
        base.Destroy(controller);
    }
    protected override void OnTriggerEnter2D(Collider2D info)
    {
        if (info.CompareTag("Enemy") == true)
        {
            // Kill the enemy
            IEnemy enemy = info.gameObject.GetComponent <IEnemy>();
            if (enemy.Score > 0)
            {
                GameObject clone = GlobalGameObject.Get <PoolingManager>().GetInstance(scoreLabel.gameObject, enemy.transform.position, Quaternion.identity);
                ShipController.Instance.IncrementScore(clone.GetComponent <ScoreLabel>(), enemy.Score);
            }
            enemy.Hit(this);
            Destroy(enemy);

            // Calculate the other 6 angles
            float   diffAngle  = 360f / numBullets;
            Vector3 spawnAngle = transform.rotation.eulerAngles;
            for (int index = 0; index < numBullets; ++index)
            {
                GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.gameObject, transform.position, Quaternion.Euler(spawnAngle));
                spawnAngle.z += diffAngle;
                while (spawnAngle.z < 0)
                {
                    spawnAngle.z += 360;
                }
            }
        }
    }
示例#5
0
    void Update()
    {
        // Check if the ship is in detection range, and we're ready to fire the weapon
        if ((isShipWithinRange == true) && (smallerAsteroids.spawnAsteroid != null) && (smallerAsteroids.spawnPositions != null) && ((Time.time - lastFired) > smallerAsteroids.gapBetweenAsteroids))
        {
            // Start cloning small asteroids
            for (index = 0; index < smallerAsteroids.spawnPositions.Length; ++index)
            {
                if (smallerAsteroids.spawnPositions[index] != null)
                {
                    // Clone the asteroid
                    clone = GlobalGameObject.Get <PoolingManager>().GetInstance(smallerAsteroids.spawnAsteroid.gameObject, smallerAsteroids.spawnPositions[index].position, Quaternion.Euler(0, 0, Random.Range(0f, 360f)));

                    // Calculate asteroids trajectory
                    velocity.x = smallerAsteroids.spawnPositions[index].position.x - transform.position.x;
                    velocity.y = smallerAsteroids.spawnPositions[index].position.y - transform.position.y;
                    velocity.Normalize();
                    velocity *= smallerAsteroids.speed;
                    clone.rigidbody2D.velocity = velocity;
                }
            }

            // Emit the guns
            for (index = 0; index < smallerAsteroids.gunParticles.Length; ++index)
            {
                if (smallerAsteroids.gunParticles[index] != null)
                {
                    smallerAsteroids.gunParticles[index].Emit(50);
                }
            }

            // Update time
            lastFired = Time.time;
        }
    }
示例#6
0
    public override void Destroy(MonoBehaviour controller)
    {
        if (explodeParticle != null)
        {
            if ((controller is BulletController) || (controller is IPowerUp))
            {
                if ((powerUps != null) && (powerUps.NumberOfEntries > 0))
                {
                    GameObject powerUp = powerUps.RandomElement;
                    if (powerUp != null)
                    {
                        GlobalGameObject.Get <PoolingManager>().GetInstance(powerUp.gameObject, transform.position, Quaternion.identity);
                    }
                }
                CloneDetonator();
            }
            else if (controller is ShipController)
            {
                CloneDetonator();
            }
        }

        // Deactivate the gameobject, effectively returning this asset back to the pooling manager
        gameObject.SetActive(false);
        allHomingBullets.Clear();
    }
示例#7
0
 public void Setup()
 {
     _controller             = GlobalGameObject.AddComponent <MockShopController>();
     _controller.Credentials = new ShopCredentials();
     _editor      = Editor.CreateEditor(_controller) as ShopControllerBaseEditor;
     _editor.View = Substitute.For <IShopControllerBaseEditorView>();
 }
示例#8
0
    public IEnemy GenerateEnemy()
    {
        // Grab a pooled enemy
        GameObject clone = GlobalGameObject.Get <PoolingManager>().GetInstance(prefabGameObject);

        // Return the enemy script
        IEnemy returnEnemy = clone.GetComponent <IEnemy>();

        returnEnemy.Life = life;

        // Position the enemy
        Transform cloneTransform = clone.transform;

        cloneTransform.position = position;
        cloneTransform.rotation = rotation;

        // Check if this enemy is supposed to have a rigidbody
        if ((hasRigidBody == true) && (returnEnemy.physicsBody != null))
        {
            // If so, update its rigidbody
            returnEnemy.physicsBody.velocity        = velocity;
            returnEnemy.physicsBody.angularVelocity = angularVelocity;
        }

        // Check if this enemy is supposed to have a renderer
        if ((hasRenderer == true) && (returnEnemy.mainRenderer != null))
        {
            // If so, update it's renderer
            returnEnemy.mainRenderer.color = color;
        }

        return(returnEnemy);
    }
示例#9
0
    // Use this for initialization
    IEnumerator GenerateSprites()
    {
        allSprites.Clear();
        if (backgroundPrefabObject == null)
        {
            backgroundPrefabObject = backgroundPrefab.gameObject;
        }

        // Setup variables
        GameObject       clone = null;
        BackgroundSprite clonedScript = null;
        int     numPrefab = 0, iteration = 0;
        Vector3 position = transform.position;

        // Generate background sprites
        for (; iteration < numIterations; ++iteration)
        {
            for (numPrefab = 0; numPrefab < numPrefabsPerIteration; ++numPrefab)
            {
                // Randomize z-axis
                position.z = Random.Range(zRange.x, zRange.y);

                // Clone the sprite
                clone = GlobalGameObject.Get <PoolingManager>().GetInstance(
                    backgroundPrefabObject, position, Quaternion.identity);
                clonedScript = clone.GetComponent <BackgroundSprite>();
                clonedScript.MaxDistanceFromShip = maxRange;
                clonedScript.Alpha = ZToAlpha(position.z);
                allSprites.Add(clonedScript);
            }
            yield return(new WaitForSeconds(gapPerIteration));
        }
    }
示例#10
0
        public void Setup()
        {
            _shopController             = GlobalGameObject.AddComponent <MockShopController>();
            _shopController.Credentials = new ShopCredentials(Utils.TestShopDomain, Utils.TestAccessToken);

            _shop = Substitute.For <IShop>();
            _shopController.Shop = _shop;
        }
        public void AddingAComponentCreatesGlobalObject()
        {
            Assert.IsNull(GlobalGameObject.Name);
            GlobalGameObject.AddComponent <LoaderComponent>();
            var gameObject = GameObject.Find(GlobalGameObject.Name);

            Assert.IsNotNull(gameObject);
        }
示例#12
0
        public void Setup()
        {
            _controller             = GlobalGameObject.AddComponent <SingleProductShopController>();
            _controller.Credentials = new ShopCredentials("", "");

            _editor      = Editor.CreateEditor(_controller) as SingleProductShopControllerEditor;
            _editor.View = Substitute.For <ISingleProductShopControllerEditorView>();
        }
示例#13
0
    protected override string Trigger(ShipController instance)
    {
        // Setup variables
        int        index      = 0;
        GameObject clone      = null;
        float      diffAngle  = 360f / maxNumBullets;
        Vector3    spawnAngle = transform.rotation.eulerAngles;

        BulletControllerHoming[] allGeneratedBullets = new BulletControllerHoming[maxNumBullets];
        int numEnemiesTargeted = 0;

        // Generate all bullets
        for (index = 0; index < maxNumBullets; ++index)
        {
            // Clone bullet
            clone = GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.gameObject, transform.position, Quaternion.Euler(spawnAngle));
            allGeneratedBullets[index] = clone.GetComponent <BulletControllerHoming>();

            // Update angle
            spawnAngle.z += diffAngle;
            while (spawnAngle.z < 0)
            {
                spawnAngle.z += 360;
            }
        }

        // Search for enemies in range
        foreach (IDestructable candidate in IGameManager.Instance.AllDestructables())
        {
            if (candidate is IEnemy)
            {
                // Target this enemy
                allGeneratedBullets[numEnemiesTargeted].Target = (IEnemy)candidate;
                ++numEnemiesTargeted;

                // Make sure the number of targeted enemies doesn't exceed the number of bullets
                if (numEnemiesTargeted >= maxNumBullets)
                {
                    // If so, stop searching for enemies
                    break;
                }
            }
        }

        // Check if we have any bullets left that hasn't targeted an enemy
        if ((numEnemiesTargeted > 0) && (numEnemiesTargeted < maxNumBullets))
        {
            // Change the other bullet's target to the same enemies found earlier
            for (index = numEnemiesTargeted; index < maxNumBullets; ++index)
            {
                allGeneratedBullets[index].Target = allGeneratedBullets[(index % numEnemiesTargeted)].Target;
            }
        }

        return("Homing Bomb");
    }
 public void Awake()
 {
     if (Instance == null)
     {
         DontDestroyOnLoad(gameObject);
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
 }
 protected override void OnTriggerEnter2D(Collider2D info)
 {
     if (info.CompareTag("Enemy") == true)
     {
         IEnemy enemy = info.gameObject.GetComponent <IEnemy>();
         if (enemy.Score > 0)
         {
             GameObject clone = GlobalGameObject.Get <PoolingManager>().GetInstance(scoreLabel.gameObject, enemy.transform.position, Quaternion.identity);
             ShipController.Instance.IncrementScore(clone.GetComponent <ScoreLabel>(), enemy.Score);
         }
         enemy.Hit(this);
     }
 }
示例#16
0
    IGridCell GetCellFromPool(IGridCell originalCell)
    {
        // Clone this cell
        int        identifier   = originalCell.TypeIdentifier;
        string     originalName = originalCell.OriginalName;
        GameObject clonedCell   = GlobalGameObject.Get <PoolingManager>().GetInstance(originalCell.CellObject);
        IGridCell  returnCell   = clonedCell.GetComponent <IGridCell>();

        // Update the cell's information
        returnCell.Manager        = this;
        returnCell.TypeIdentifier = identifier;
        returnCell.OriginalName   = originalName;
        return(returnCell);
    }
示例#17
0
    void Awake()
    {
        if (globalGameObjectInstance != null)
        {
            Destroy(gameObject);
        }
        else
        {
            globalGameObjectInstance = this;
        }

        sceneLoader             = GetComponentInChildren <SceneLoader>();
        transitionalUIDisplayer = GetComponentInChildren <TransitionalUIDisplayer>();
    }
示例#18
0
    /// <summary>
    /// Called when the first scene is loaded.
    /// </summary>
    public void FirstSceneAwake(GlobalGameObject globalGameObject)
    {
        // Cache the transform everything will be pooled to
        poolingParent = transform;

        // Preload everything
        GameObject clone = null;

        for (int index = 0; index < objectsToPreload.Length; ++index)
        {
            clone = GetInstance(objectsToPreload[index]);
            clone.SetActive(false);
        }
    }
示例#19
0
    protected override string Trigger(ShipController instance)
    {
        // Calculate the other 6 angles
        float   diffAngle  = 360f / numBullets;
        Vector3 spawnAngle = transform.rotation.eulerAngles;

        for (int index = 0; index < numBullets; ++index)
        {
            GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.gameObject, transform.position, Quaternion.Euler(spawnAngle));
            spawnAngle.z += diffAngle;
            while (spawnAngle.z < 0)
            {
                spawnAngle.z += 360;
            }
        }
        return("Scatter Bomb");
    }
示例#20
0
    public void AddHomingBullet(BulletControllerHoming bullet)
    {
        if (bullet != null)
        {
            allHomingBullets.Add(bullet);
            if (bullet.reticle != null)
            {
                // Grab a reticle from the pool manager
                homingReticle = GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.reticle);

                // Position the reticle
                Transform reticleTransform = homingReticle.transform;
                reticleTransform.position = transform.position;
                reticleTransform.rotation = Quaternion.identity;
                reticleTransform.parent   = transform;
            }
        }
    }
示例#21
0
    // Update is called once per frame
    void Update()
    {
        if (ShipController.Instance.ShipState == ShipController.State.Playing)
        {
            // Check if we can still spawn objects
            if ((NumDestructables < maxNumObjects) && ((Time.time - mLastSpawned) > CurrentState.waitBeforeSpawning))
            {
                // Check if the ship exceeded the current threshold
                if ((mSpawnStateIndex < (mCurrentSpawnStates.Count - 1)) && (ShipController.Instance.Score >= mCumulativeScoreThreshold))
                {
                    ++mSpawnStateIndex;
                    mCumulativeScoreThreshold += CurrentState.scoreThreshold;
                }

                // Get the center of where we want to spawn the object
                mCameraCenterPosition   = Camera.main.transform.position;
                mCameraCenterPosition.z = ShipController.Instance.transform.position.z;

                GameObject cloneObject = null;
                for (mIndex = 0; mIndex < CurrentState.numberOfObjectsToSpawnAtOnce; ++mIndex)
                {
                    // Randomize spawn location
                    mSpawnPosition    = mCameraCenterPosition;
                    mRandomOffset     = Random.insideUnitCircle.normalized;
                    mSpawnPosition.x += (mRandomOffset.x * distanceFromCamera);
                    mSpawnPosition.y += (mRandomOffset.y * distanceFromCamera);

                    // Spawn the object there
                    mClone = CurrentState.RandomObject;
                    if (mClone != null)
                    {
                        cloneObject = GlobalGameObject.Get <PoolingManager>().GetInstance(mClone.gameObject, mSpawnPosition, Quaternion.Euler(0, 0, Random.Range(0f, 360f)));
                        AddDestructable(cloneObject.GetComponent <IDestructable>());
                    }
                }

                // Update the last spawn time
                mLastSpawned = Time.time;
            }

            // Destroy far away objects
            DestroyFarAwayDestructables();
        }
    }
示例#22
0
        /// <summary>
        /// Starts the native checkout flow.
        /// </summary>
        /// <param name="key">
        /// A Base64-encoded Android Pay public key found on the Shopify admin page.
        /// </param>
        /// <param name="shopMetadata">
        /// Some metadata associated with the current shop, such as name and payment settings.
        /// </param>
        /// <param name="success">
        /// Callback to be invoked when the checkout flow is successfully completed.
        /// </param>
        /// <param name="canceled">
        /// Callback to be invoked when the checkout flow is canceled by the user.
        /// </param>
        /// <param name="failure">
        /// Callback to be called when the checkout flow fails.
        /// </param>
        public void Checkout(
            string key,
            ShopMetadata shopMetadata,
            CheckoutSuccessCallback success,
            CheckoutCancelCallback canceled,
            CheckoutFailureCallback failure
            )
        {
            // TODO: Store callbacks and extract items we need from the cart to pass to Android Pay.
            OnSuccess  = success;
            OnCanceled = canceled;
            OnFailure  = failure;

            var checkout = CartState.CurrentCheckout;

            MerchantName = shopMetadata.Name; // TODO: Replace with Shop name
            var pricingLineItems       = GetPricingLineItemsFromCheckout(checkout);
            var pricingLineItemsString = pricingLineItems.ToJsonString();
            var currencyCodeString     = checkout.currencyCode().ToString("G");

            CountryCodeString = shopMetadata.PaymentSettings.countryCode().ToString("G");
            var requiresShipping = checkout.requiresShipping();

#if !SHOPIFY_MONO_UNIT_TEST
            object[] args =
            {
                MerchantName,
                key,
                pricingLineItemsString,
                currencyCodeString,
                CountryCodeString,
                requiresShipping
            };
            AndroidPayCheckoutSession.Call("checkoutWithAndroidPay", args);
            if (AndroidPayEventBridge == null)
            {
                AndroidPayEventBridge          = GlobalGameObject.AddComponent <AndroidPayEventReceiverBridge>();
                AndroidPayEventBridge.Receiver = this;
            }
#endif
        }
        public IEnumerator ObjectLivesWhenNewSceneIsLoadedIn()
        {
            Assert.IsNull(GlobalGameObject.Name);
            GlobalGameObject.AddComponent <LoaderComponent>();
            var gameObject = GameObject.Find(GlobalGameObject.Name);

            Assert.IsNotNull(gameObject);

            var originalScene = SceneManager.GetActiveScene();

            var loadOp = SceneManager.LoadSceneAsync("IntegrationTestBlankScene");

            loadOp.allowSceneActivation = true;
            while (!loadOp.isDone)
            {
                yield return(null);
            }

            gameObject = GameObject.Find(GlobalGameObject.Name);
            Assert.IsNotNull(gameObject);
        }
示例#24
0
    public void Fire(Transform gun)
    {
        // Shoot the main bullet
        GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.gameObject, gun.position, gun.rotation);

        // Calculate the other 2 angles
        mainAngle     = gun.rotation.eulerAngles;
        otherAngle    = mainAngle;
        otherAngle.z -= spreadAngle;
        while (otherAngle.z < 0)
        {
            otherAngle.z += 360;
        }
        GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.gameObject, gun.position, Quaternion.Euler(otherAngle));
        otherAngle    = mainAngle;
        otherAngle.z += spreadAngle;
        while (otherAngle.z > 360)
        {
            otherAngle.z -= 360;
        }
        GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.gameObject, gun.position, Quaternion.Euler(otherAngle));
    }
    void Awake()
    {
        // Check if there's an instance of this script
        if (instance == null)
        {
            // Set the instance
            instance         = this;
            cachedGameObject = gameObject;
            cachedtransform  = transform;

            // Mark the game object to not destroy itself when switching scenes
            DontDestroyOnLoad(cachedGameObject);

            // Go through all the script components, check if they implement IGlobalScript, and call FirstSceneAwake
            MonoBehaviour[] allScripts = cachedGameObject.GetComponentsInChildren <MonoBehaviour>();
            for (int index = 0; index < allScripts.Length; ++index)
            {
                if (allScripts[index] is IGlobalScript)
                {
                    ((IGlobalScript)allScripts[index]).FirstSceneAwake(this);
                }
            }
        }
        else
        {
            // Go through all the script components in instance,  check if they implement IGlobalScript, and call SubsequentSceneAwake
            MonoBehaviour[] allScripts = instance.cachedGameObject.GetComponentsInChildren <MonoBehaviour>();
            for (int index = 0; index < allScripts.Length; ++index)
            {
                if (allScripts[index] is IGlobalScript)
                {
                    ((IGlobalScript)allScripts[index]).FirstSceneAwake(instance);
                }
            }

            // Destroy this game object
            Destroy(gameObject);
        }
    }
        /// <summary>
        /// Starts the process of making a payment through Apple Pay.
        /// </summary>
        /// <remarks>
        ///  Displays a payment interface to the user based on the contents of the Cart
        /// </remarks>
        /// <param name="key">Merchant ID for Apple Pay from the Apple Developer Portal</param>
        /// <param name="shopMetadata">The shop's metadata containing name and payment settings</param>
        /// <param name="success">Delegate method that will be notified upon a successful payment</param>
        /// <param name="failure">Delegate method that will be notified upon a failure during the checkout process</param>
        /// <param name="cancelled">Delegate method that will be notified upon a cancellation during the checkout process</param>
        public void Checkout(string key, ShopMetadata shopMetadata, CheckoutSuccessCallback success, CheckoutCancelCallback cancelled, CheckoutFailureCallback failure)
        {
            OnSuccess   = success;
            OnCancelled = cancelled;
            OnFailure   = failure;
            StoreName   = shopMetadata.Name;

#if !(SHOPIFY_MONO_UNIT_TEST || SHOPIFY_TEST)
            var checkout = CartState.CurrentCheckout;

            var supportedNetworksString = SerializedPaymentNetworksFromCardBrands(shopMetadata.PaymentSettings.acceptedCardBrands());

            var summaryItems  = GetSummaryItemsFromCheckout(checkout);
            var summaryString = Json.Serialize(summaryItems);

            var currencyCodeString = checkout.currencyCode().ToString("G");
            var countryCodeString  = shopMetadata.PaymentSettings.countryCode().ToString("G");

            var requiresShipping = checkout.requiresShipping();

            if (ApplePayEventBridge == null)
            {
                ApplePayEventBridge          = GlobalGameObject.AddComponent <ApplePayEventReceiverBridge>();
                ApplePayEventBridge.Receiver = this;
            }

            if (_CreateApplePaySession(GlobalGameObject.Name, key, countryCodeString, currencyCodeString, supportedNetworksString, summaryString, null, requiresShipping))
            {
                _PresentApplePayAuthorization();
            }
            else
            {
                var error = new ShopifyError(ShopifyError.ErrorType.NativePaymentProcessingError, "Unable to create an Apple Pay payment request. Please check that your merchant ID is valid.");
                OnFailure(error);
            }
#endif
        }
示例#27
0
 public void TearDown()
 {
     GlobalGameObject.Destroy();
 }
示例#28
0
 public void Fire(Transform gun)
 {
     GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.gameObject, gun.position, gun.rotation);
 }
示例#29
0
 /// <summary>
 /// Called when any scene after the first one is loaded.
 /// </summary>
 public void SubsequentSceneAwake(GlobalGameObject globalGameObject)
 {
     // Do nothing
 }
 public void Setup()
 {
     _controller  = GlobalGameObject.AddComponent <MultiProductShopController>();
     _editor      = Editor.CreateEditor(_controller) as MultiProductShopControllerEditor;
     _editor.View = Substitute.For <IMultiProductShopControllerEditorView>();
 }