Loupe

[Unity] Notez mon application !

Ca y est, votre jeu est sur les différents store, vous en êtes fier et rien ne vous ferais plus plaisir que vos utilisateurs vous gratifies d’une bonne note et d’un commentaire pertinent. Voici une méthode simple pour essayer d’y parvenir : notifier l’utilisateur toutes les X fois au lancement de l’application.

  1. Créez une scène. Celle-ci ne sera jouée qu’une seule fois au lancement du jeu.
  2. Créez un objet vide et ajoutez le à la scène.
  3. Créez un nouveau script : StartupRatingManager.cs

       1: using System;
       2: using System.Collections.Generic;
       3: using System.Linq;
       4: using System.Text;
       5: using UnityEngine;
       6:  
       7: namespace Assets.Scripts.Managers
       8: {
       9:     public class StartupRatingManager : MonoBehaviour
      10:     {
      11:         public void Awake()
      12:         {
      13:             var ratingCount = PlayerPrefs.GetInt("RatingCount", 0);
      14:             if (ratingCount < 0)
      15:             {
      16:                 Application.LoadLevel("MainScene");
      17:                 return;
      18:             }
      19:  
      20:             ratingCount++;
      21:  
      22:             if (ratingCount >= 5)
      23:             {
      24:                 PlayerPrefs.SetInt("RatingNeeded", 1);
      25:                 PlayerPrefs.SetInt("RatingCount", 0);
      26:                 PlayerPrefs.Save();
      27:                 Application.LoadLevel("MainScene");
      28:                 return;
      29:             }
      30:  
      31:             PlayerPrefs.SetInt("RatingNeeded", 0);
      32:             PlayerPrefs.SetInt("RatingCount", ratingCount);
      33:             PlayerPrefs.Save();
      34:  
      35:             Application.LoadLevel("MainScene");
      36:         }
      37:     }
      38: }

    Ce script va donc affecter un PlayerPref qui sera utilisé par la scène principale pour savoir si elle doit notifier l’utilisateur afin de lui proposer de noter l’application, de laisser un commentaire, …

  4. Ajoutez ce script à l'objet crée précédemment.
  5. Basculez sur votre scène principale (dans notre exemple : MainScene)
  6. Créez un objet vide et ajoutez le à la scène.
  7. Créez un nouveau script : RatingManager.cs

       1: using System;
       2:  
       3: namespace Assets.Scripts.Managers
       4: {
       5:     public class RatingPopup
       6:     {
       7:         public Action OnRating;
       8:         public Action OnSendMail { get; set; }
       9:         public Action OnRemindMeLater { get; set; }
      10:  
      11:         public void Show()
      12:         {
      13:             // TODO : Display popup
      14:         }
      15:  
      16:         public void Close()
      17:         {
      18:             // TODO : Close popup
      19:         }
      20:     }
      21:  
      22:     public class RatingManager : MonoBehaviour
      23:     {
      24:         private RatingPopup _popup;
      25:  
      26:         public void Awake()
      27:         {
      28:             if (PlayerPrefs.GetInt("RatingNeeded", 0) == 1)
      29:             {
      30:                 // Create popup and set callbacks
      31:                 _popup = new RatingPopup();
      32:                 _popup.OnRating = RatingCallback;
      33:                 _popup.OnSendMail = SendMailCallback;
      34:                 _popup.OnRemindMeLater = RemindMeLaterCallback;
      35:  
      36:                 PlayerPrefs.SetInt("RatingNeeded", 0);
      37:                 PlayerPrefs.Save();
      38:             }
      39:         }
      40:  
      41:         /// <summary>
      42:         /// User want to rate
      43:         /// </summary>
      44:         public void RatingCallback()
      45:         {
      46:             _popup.Close();
      47:  
      48:             // Never ask again
      49:             PlayerPrefs.SetInt("RatingCount", -1);
      50:             PlayerPrefs.Save();
      51:  
      52: #if UNITY_WP8
      53:             // TODO : Rating for WP8
      54:  
      55: #elif UNITY_ANDROID
      56:             // TODO : Rating for Android
      57:  
      58: #elif UNITY_IOS
      59:             // TODO : Rating for iOS
      60:  
      61: #else
      62:  
      63: #endif
      64:         }
      65:  
      66:         /// <summary>
      67:         /// User want to send an email
      68:         /// </summary>
      69:         public void SendMailCallback()
      70:         {
      71:             _popup.Close();
      72:  
      73:             // Never ask again
      74:             PlayerPrefs.SetInt("RatingCount", -1);
      75:             PlayerPrefs.Save();
      76:  
      77:             Application.OpenURL("mailto:apps@xxxxxxxxxx.com");
      78:         }
      79:  
      80:         /// <summary>
      81:         /// User don't want to rate us now, ask him later
      82:         /// </summary>
      83:         public void RemindMeLaterCallback()
      84:         {
      85:             _popup.Close();
      86:  
      87:             PlayerPrefs.SetInt("RatingCount", 0);
      88:             PlayerPrefs.Save();
      89:         }
      90:     }
      91: }


    Ce script va créer une fenêtre avec 3 actions possible :
    - Noter l’application (plus aucune notification ne lui sera demandé)
    - Envoyer un email (plus aucune notification ne lui sera demandé)
    - Me le redemander plus tard (une nouvelle notification lui sera proposé après X lancements)

    Vous devez avoir votre propre gestion des popups !

  8. Ajoutez ce script à l'objet crée précédemment.

C’est terminé ! Prêt pour les 5 étoiles ?

Ces billets pourraient aussi vous intéresser

Vous nous direz ?!

Commentaires

comments powered by Disqus