- Home /
Add EULA to Unity Project for Android/iOS
So like I said in the title, I'm at the stage where I need to add a EULA to the mobile app I'm developing. I can't find anywhere where to create one in a Unity project, or if it has to be custom made and if so, how to even do that.
I thought at first to just add a new scene with the EULA text and buttons that either close or go further into the app, but I don't know how to make that appear only on the very first time the app is ever opened on a device.
If there is a resource/feature in Unity that already exists to do this I would greatly appreciate it if could be pointed out to me. For reference, I am using Unity 2017.3.0f3.
Answer by bonzo_ · May 17, 2018 at 07:24 PM
So for the sake of my own needs, I have created a solution that I am (at the moment) satisfied with. For documentation I'm posting it as an answer here and will outline what I did in C# and Unity.
In Unity I created a panel that contains everything involved the EULA GUI. This panel will be turned off .SetActive(false)
once the 'Accept' button is pressed.
From here I created a script 'EULAScript.cs' that is attached to the canvas of the scene.
private int ViewEULA;
void Start () {
EULAStatus();
}
public GameObject EULABox;
private void EULAStatus()
{
if (PlayerPrefs.GetInt("ViewEULA") == 1)
{
Debug.Log("EULA has been accepted");
EULABox.SetActive(false);
}
else if (PlayerPrefs.GetInt("ViewEULA") == 0)
{
Debug.Log("Int set to 0");
EULABox.SetActive(true);
}
else
{
Debug.Log("Really I should just have it just end in an else but you get the idea");
}
}
public void AcceptEULA()//Accept button
{
PlayerPrefs.SetInt("ViewEULA", 1);
EULAStatus();
Debug.Log("Accepted");
}
public void DeclineEULA()//Decline button
{
Application.Quit();
}
This differs from my commend above, as I moved the if/else logic out of the OnGUI()
and into a private class that is then called only when one of the buttons is pressed. I used integers rather than a bool for this because I was having a little trouble handling a PlayerPrefs.SetInt("ViewEULA", true);
so I just used a 1 and 0 instead. The EULAStatus()' runs in the start, which when attached to the canvas, runs each time the app loads up. So for my application, selecting decline would have the app close. I moved the
Application.Quit();` into the Decline button, because having it run when the PlayerPrefs
is set to 0, the app gets stuck in a loop of constantly quitting the moment it loads in. Take it as my style coupled with my inexperience as to why/how I'm doing it this way. I'd still love if a more experienced person (that's setting the bar real low tbh) could come by for myself and future developers and give a better answer to this.
Answer by Hoorza · May 17, 2018 at 07:45 AM
There is no future like this in Unity although it would be very nice. I am also interested in that topic for the future projects but so far I have only seen 3rd party companies that make them for you. And it is not the cheapest. I think finding very generic is a bad idea as it will only full you into thinking that you are covered and doing a good thing, but if something goes wrong you will find out that your T&Cs or EULA are flawed and do not serve the purpose. We are not lawyers so it is difficult to know what is required. Also, GDPR is coming into force on the 25 of May 2018 and that may make things easier as it will be a hot topic so people might make some tutorials. I will post more if I find something. Here is a 3rd party website that does this service:
TermsFeed.com this paid one,
EulaTemplate.com and this one seems to be free, not tested.
-
If you use them please share your experience here for others to read.
I think you might be misunderstanding my question. I don't need text for the EULA, we are beyond completely covered trust me.
What I'm looking for is code for properly handling the accept/decline buttons for the EULA. When the app is loaded in for the very first time on a device, the EULA appears, and every time after that very first time opened (assu$$anonymous$$g the user select 'Accept') the EULA never appears unless uninstalled and reinstalled.
I did find a solution, but I am not too happy with it.
public GameObject EULABox;
public int ViewEULA;
void OnGUI(){
if(PlayerPrefs.GetInt("ViewEULA") == 1){
EULABox.SetActive(false);
Debug.Log("EULA has been accepted");
}
else if (PlayerPrefs.GetInt("ViewEULA") == 1){
Application.Quit();
Debug.Log("EULA has been declined");
}
}
public void AcceptEULA(){
//THIS IS THE ACCEPT BUTTON
PlayerPrefs.SetInt("ViewEULA", 1);
}
public void Decline(){
//THIS IS THE DECLINE BUTTON
PlayerPrefs.SetInt("ViewEULA", 0);
}
$$anonymous$$y issue with this is that this will always be running, and I see the debug logs like "EULA has been declined" in the console building up to the thousands in just a couple of seconds.
Ohh my bad. Now I understand ( I hope*:p ). Well if you don't want it to be called constantly do not use OnGUI() function. This is from Unity manual:"OnGUI is called for rendering and handling GUI events."*. So it will be called every frame. Place the same code in the Start function and it will be called once every time the player starts the game until he accepts the EULA. -
You can use Scroll Rect (ScrollRect) UI element to put all of the text inside with two buttons below: "RE$$anonymous$$IND $$anonymous$$E LATER" and "ACCEPT".
Hope I understood you now :)
Answer by KVinS · Jun 19, 2018 at 09:14 PM
Well ... This is almost the solution... At first, I thought I could use:
System.Globalization.RegionInfo.CurrentRegion
But it turned out that he always displays the "US". Then I found this plugin: https://assetstore.unity.com/packages/tools/integration/precise-locale-65836 There libraries for native platforms are used.
PreciseLocale.GetRegion()
It is necessary to compare the received region with:
"BE", "EL", "LT", "PT", "BG", "ES", "LU", "RO", "CZ", "FR", "HU", "SI", "DK", "HR", "MT", "SK", "DE", "IT", "NL", "FI", "EE", "CY", "AT", "SE", "IE", "LV", "PL", "UK", "CH", "NO", "IS", "LI"
Then it remains only to copy the text from the Google's example: https://developers.google.com/admob/android/eu-consent and write the code for "npa".
AdRequest request = new AdRequest.Builder() .AddExtra("npa", "1") .Build();
(Sending a value of "1" will serve non-personalized ads)
Your answer
Follow this Question
Related Questions
Create Keystore 5 Answers
Unity Free and Mobile Platforms 1 Answer
Mixing free with free + basic android license 0 Answers
unable to run keytool 2 Answers