Example #1
0
    private void OnMouseDown()
    {
        Vector3 xy = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        xy.z = 0;
        PopupScript.Create(xy, Random.Range(10, 100) * Random.Range(3, 10), PopupPrefab);
    }
    IEnumerator SpawnPopup()
    {
        ThemeManager tm = ThemeManager.instance;

        yield return(new WaitForSeconds(1f));

        //Sets a local popup variable to an instanced varient of the popup.
        tmpPopup = Instantiate(Popup, gameObject.transform);

        //set up a popup script local variable to modify the properties of the popup.
        PopupScript popUpScript = tmpPopup.GetComponent <PopupScript>();

        popUpScript.title.text       = notification.notificationTitle;
        popUpScript.description.text = notification.notificationText;
        popUpScript.icon.sprite      = notification.notificationSprite;

        //Sets the colour.
        tmpPopup.GetComponent <Image>().color = tm.toolTipColour;
        tmpPopup.transform.GetChild(0).GetComponent <Image>().color = tm.toolTipColour;

        //popup dissappears after 5 seconds.
        yield return(new WaitForSeconds(5f));

        Destroy(tmpPopup);
    }
Example #3
0
    public static PopupScript Create(Vector3 xy, int value, GameObject PopupPrefab)
    {
        GameObject  instance = Instantiate(PopupPrefab, xy, Quaternion.identity) as GameObject;
        PopupScript ps       = instance.GetComponent <PopupScript>();

        ps.SetValue(value);
        return(ps);
    }
Example #4
0
 // Use this for initialization
 void Start()
 {
     done = true;
     S    = this;
     r    = GetComponent <SpriteRenderer>();
     Clicked();
     i = 0;
     GameManagementScript.S.gameState = 2;
 }
Example #5
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "Player")
     {
         var instance = Instantiate(BloodAnimation, transform.position, Quaternion.identity) as GameObject;
         int R        = Random.Range(10, 100) * Random.Range(3, 10);
         TowerAttackScript.WasAHit(R);
         PopupScript.Create(transform.position, R, PopupPrefab);
     }
 }
Example #6
0
    // Static method to create a popup and show it
    public static void SetPopup(string message, float delay = defaultDelay, Action callback = null)
    {
        // Create popup and attach it to UI
        GameObject popupGO     = Instantiate(Resources.Load("Prefabs/GUIpopup") as GameObject);
        GameObject PopupCanvas = GameObject.Find("PopupContainer");

        popupGO.transform.SetParent(PopupCanvas.transform);

        // Configure popup
        PopupScript pScript = popupGO.GetComponent <PopupScript>();

        pScript.ConfigurePopup(message, delay, callback);
    }
    // Prompt the user to purchase a virtual item with the Facebook Pay Dialog
    // See: https://developers.facebook.com/docs/payments/reference/paydialog
    public static void BuyCoins(CoinPackage cPackage)
    {
        // Format payment URL
        string paymentURL = string.Format(PaymentObjectURL, PaymentObjects[cPackage]);

        // https://developers.facebook.com/docs/unity/reference/current/FB.Canvas.Pay
        FB.Canvas.Pay(paymentURL,
                      "purchaseitem",
                      1,
                      null, null, null, null, null,
                      (IPayResult result) =>
        {
            Debug.Log("PayCallback");
            if (result.Error != null)
            {
                Debug.LogError(result.Error);
                return;
            }
            Debug.Log(result.RawResult);

            object payIdObj;
            if (result.ResultDictionary.TryGetValue("payment_id", out payIdObj))
            {
                string payID = payIdObj.ToString();
                Debug.Log("Payment complete");
                Debug.Log("Payment id:" + payID);

                // Verify payment before awarding item
                if (VerifyPayment(payID))
                {
                    GameStateManager.CoinBalance += (int)cPackage;
                    GameStateManager.CallUIRedraw();
                    PopupScript.SetPopup("Purchase Complete", 2f);
                }
            }
            else
            {
                Debug.Log("Payment error");
            }
        });
    }
    private void OnBombBuy(BombPackage bPackage)
    {
        int price = BombPackageCost[bPackage];

        if (price <= GameStateManager.CoinBalance)
        {
            // execute transaction
            GameStateManager.CoinBalance -= price;
            GameStateManager.NumBombs    += (int)bPackage;

            // update UI
            GameStateManager.CallUIRedraw();
            PopupScript.SetPopup("Purchase Complete", 1f);

            // log App Event for spending credits
            FBAppEvents.SpentCoins(price, bPackage.ToString());
        }
        else
        {
            PopupScript.SetPopup("Not enough coins", 1f);
        }
    }
Example #9
0
    public void CreatePopup(string title, string desc, string btn_txt, Color btn_color, Color sprite_color, Color bg_color, Sprite sprite_, bool has_color = true)
    {
        Debug.Log("Creating popup with title: " + title);

        // Instantiate a popup game object (prefab) and set the properties.
        if (popup_instance == null)
        {
            popup_instance = Instantiate(popup_prefab, popup_prefab.transform.position, popup_prefab.transform.rotation);
            popup_instance.transform.SetParent(GameObject.Find("Canvas").transform);
        }

        // TODO: Set the properties for popup_instance
        PopupScript popup_ = popup_instance.GetComponent <PopupScript>();

        popup_.setTitle(title);
        popup_.setMessage(desc);
        popup_.setButton(btn_txt, btn_color);
        popup_.setImage(sprite_, sprite_color, has_color);
        popup_.setBackground(bg_color);

        // Show the popup
        popup_instance.SetActive(true);
    }
 // The Graph API for Scores allows you to publish scores from your game to Facebook
 // This allows Friend Smash! to create a friends leaderboard keeping track of the top scores achieved by the player and their friends.
 // For more information on the Scores API see: https://developers.facebook.com/docs/games/scores
 //
 // When publishing a player's scores, these scores will be visible to their friends who also play your game.
 // As a result, the player needs to grant the app an extra permission, publish_actions, in order to publish scores.
 // This means we need to ask for the extra permission, as well as handling the
 // scenario where that permission wasn't previously granted.
 //
 public static void PostScore(int score, Action callback = null)
 {
     // Check for 'publish_actions' as the Scores API requires it for submitting scores
     if (FBLogin.HavePublishActions)
     {
         var query = new Dictionary <string, string>();
         query["score"] = score.ToString();
         FB.API(
             "/me/scores",
             HttpMethod.POST,
             delegate(IGraphResult result)
         {
             Debug.Log("PostScore Result: " + result.RawResult);
             // Fetch fresh scores to update UI
             FBGraph.GetScores();
         },
             query
             );
     }
     else
     {
         // Showing context before prompting for publish actions
         // See Facebook Login Best Practices: https://developers.facebook.com/docs/facebook-login/best-practices
         PopupScript.SetPopup("Prompting for Publish Permissions for Scores API", 4f, delegate
         {
             // Prompt for `publish actions` and if granted, post score
             FBLogin.PromptForPublish(delegate
             {
                 if (FBLogin.HavePublishActions)
                 {
                     PostScore(score);
                 }
             });
         });
     }
 }
Example #11
0
    // Callback for FB.AppRequest
    private static void AppRequestCallback(IAppRequestResult result)
    {
        // Error checking
        Debug.Log("AppRequestCallback");
        if (result.Error != null)
        {
            Debug.LogError(result.Error);
            return;
        }
        Debug.Log(result.RawResult);

        // Check response for success - show user a success popup if so
        object obj;

        if (result.ResultDictionary.TryGetValue("cancelled", out obj))
        {
            Debug.Log("Request cancelled");
        }
        else if (result.ResultDictionary.TryGetValue("request", out obj))
        {
            PopupScript.SetPopup("Request Sent", 3f);
            Debug.Log("Request sent");
        }
    }
 void Awake()
 {
     ps = GetComponent <PopupScript>();
 }