using UnityEngine;
using System.Collections;
public class RateThisApp : MonoBehaviour
{
/* This script will include a rate this app dialog in your game. This is a good starting point
* for making your own. I used GameObject.Find("GameController").SendMessage("PlayClickSound");
* to make the button have a click sound. Just replace what's neccessary for your own game.
* Feel free to do whatever you want with this script, no credit is neccessary.
*/
public store whichStore;
public static store whichStoreStatic;
public GUISkin gui;
private bool showDialog = false;
private bool optOut = false;
private bool previousToggle = false;
public enum store
{
GooglePlay,
Amazon,
Other
}
void Start()
{
PlayerPrefs.SetInt("timesLaunched", PlayerPrefs.GetInt("timesLaunched", 0) + 1);
if (PlayerPrefs.GetInt("timesLaunched") >= 3)
{
showDialog = true;
}
whichStoreStatic = whichStore;
}
void OnGUI()
{
GUI.skin = gui;
if (PlayerPrefs.GetString("OptedOut", "False").ToLower() == "False".ToLower())
{
if (showDialog)
{
Time.timeScale = 0;
gui.window.fontSize = (int)(Screen.height * .05f);
GUI.Window(02, new Rect(.1f * Screen.width, .35f * Screen.height, .8f * Screen.width, .335f * Screen.height),
RateWindow, "Love it? Hate it?\nLet us know why.");
}
}
gui.label.fontSize = (int)(Screen.height * .05f);
}
void RateWindow(int windowID)
{
if (GUI.Button(new Rect(.02f * Screen.width, .126f * Screen.height, .37f * Screen.width, .13f * Screen.height), "Rate"))
{
GameObject.Find("GameController").SendMessage("PlayClickSound");
PlayerPrefs.SetString("OptedOut", optOut.ToString());
showDialog = false;
if (Debug.isDebugBuild)
{
// Don't forget to replace PACKAGE_ID and AMAZON_ASIN in both sections
Application.OpenURL("https://play.google.com/store/apps/details?id=PACKAGE_ID");
Application.OpenURL("http://www.amazon.com/gp/mas/dl/android?asin=AMAZON_ASIN");
}
else
{
switch (whichStore)
{
case store.GooglePlay:
Application.OpenURL("market://details?id=PACKAGE_ID");
break;
case store.Amazon:
Application.OpenURL("amzn://apps/android?asin=AMAZON_ASIN");
break;
case store.Other:
break;
default:
break;
}
}
Time.timeScale = 1;
}
if (GUI.Button(new Rect(.41f * Screen.width, .126f * Screen.height, .37f * Screen.width, .13f * Screen.height), "Later"))
{
GameObject.Find("GameController").SendMessage("PlayClickSound");
showDialog = false;
PlayerPrefs.SetString("OptedOut", optOut.ToString());
Time.timeScale = 1;
}
gui.toggle.fontSize = (int)(Screen.height * .03f);
// gui.toggle.padding will dictate the size of the box. I have the border set to 7 for all four values.
gui.toggle.padding.left = (int)(Screen.height * .045f);
gui.toggle.padding.top = (int)(Screen.height * .045f) + 4;
optOut = GUI.Toggle(new Rect(.02f * Screen.width, .273f * Screen.height, .05f * Screen.height, .05f * Screen.height), optOut, "");
oldAnchor = gui.label.alignment;
gui.label.alignment = TextAnchor.UpperLeft;
gui.label.fontSize = (int)(Screen.height * .0303f);
GUI.Label(new Rect(.115f * Screen.width, .279f * Screen.height, .6f * Screen.width, .1f * Screen.height), "Don't show this again");
gui.label.alignment = oldAnchor;
gui.label.fontSize = (int)(Screen.height * .05f);
}
void Update()
{
if (optOut != previousToggle)
{
GameObject.Find("GameController").SendMessage("PlayClickSound");
previousToggle = optOut;
}
}
}
Rate This App
I made a simple Rate This App script for Unity. It's quite simple, and is a great starting point if you're looking to make your own. Just replace what's necessary for your own application. If you use it, or a modified version of it, no credit is necessary or anything, the following code is CC0.
Subscribe to:
Posts (Atom)
No comments:
Post a Comment