151 lines
3.8 KiB
C#
151 lines
3.8 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEditor;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
public class PlayerPreferences : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
private const string PREFS_SHOWDIVI = "showDivi";
|
|||
|
|
private const string PREFS_REMEMBER_USERNAME = "rememberUsername";
|
|||
|
|
private const string PREFS_REMEMBER_PASSWORD = "rememberPassword";
|
|||
|
|
private const string PREFS_LOGINMUSIC = "LoginMusic";
|
|||
|
|
private const string PREFS_AUDIOVOLUME = "audioVolume";
|
|||
|
|
|
|||
|
|
private const string PREFS_USERNAME = "username";
|
|||
|
|
private const string PREFS_PASSWORD = "password";
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
// Start is called before the first frame update
|
|||
|
|
void Start()
|
|||
|
|
{
|
|||
|
|
InitDefaultPrefs();
|
|||
|
|
ReadPrefs();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
*
|
|||
|
|
* List of preferences:
|
|||
|
|
*
|
|||
|
|
* rememberUsername 1 on, 0 off - remembers username on login screen
|
|||
|
|
* showDivi 1 on, 0 off - shows or hides divi (if streaming may want to hide this)
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
|
|||
|
|
private static void InitDefaultPrefs()
|
|||
|
|
{
|
|||
|
|
// if showDivi is not set (i.e. not changed by player default to on)
|
|||
|
|
if (!PlayerPrefs.HasKey(PREFS_SHOWDIVI)) PlayerPrefs.SetInt("showDivi", 1);
|
|||
|
|
|
|||
|
|
// if remember details not set default to on
|
|||
|
|
if (!PlayerPrefs.HasKey(PREFS_REMEMBER_USERNAME)) PlayerPrefs.SetInt(PREFS_REMEMBER_USERNAME, 1);
|
|||
|
|
if (!PlayerPrefs.HasKey(PREFS_REMEMBER_PASSWORD)) PlayerPrefs.SetInt(PREFS_REMEMBER_PASSWORD, 1);
|
|||
|
|
|
|||
|
|
if (!PlayerPrefs.HasKey(PREFS_LOGINMUSIC)) PlayerPrefs.SetInt(PREFS_LOGINMUSIC, 0);
|
|||
|
|
|
|||
|
|
if (!PlayerPrefs.HasKey(PREFS_AUDIOVOLUME)) PlayerPrefs.SetFloat(PREFS_AUDIOVOLUME, 1.0f);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static void ReadPrefs()
|
|||
|
|
{
|
|||
|
|
if (PlayerPrefs.GetString(PREFS_USERNAME) != "")
|
|||
|
|
{
|
|||
|
|
string username = PlayerPrefs.GetString(PREFS_USERNAME);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void ResetPrefs()
|
|||
|
|
{
|
|||
|
|
PlayerPrefs.SetInt(PREFS_SHOWDIVI, 1);
|
|||
|
|
PlayerPrefs.SetInt(PREFS_REMEMBER_USERNAME, 1);
|
|||
|
|
PlayerPrefs.SetInt(PREFS_REMEMBER_PASSWORD, 1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void SetShowDivi(int remember)
|
|||
|
|
{
|
|||
|
|
PlayerPrefs.SetInt(PREFS_SHOWDIVI, remember);
|
|||
|
|
}
|
|||
|
|
public static int GetShowDivi()
|
|||
|
|
{
|
|||
|
|
int result;
|
|||
|
|
result = PlayerPrefs.GetInt(PREFS_SHOWDIVI);
|
|||
|
|
if (result == 1)
|
|||
|
|
{
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
// else in the event its not saved, default to 0
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// remember Login Details. 1 = remember, 0 = don't remember
|
|||
|
|
public static void WriteRememberLoginDetails(int remember)
|
|||
|
|
{
|
|||
|
|
PlayerPrefs.SetInt(PREFS_REMEMBER_USERNAME, remember);
|
|||
|
|
PlayerPrefs.SetInt(PREFS_REMEMBER_PASSWORD, remember);
|
|||
|
|
}
|
|||
|
|
public static int GetRememberUsername()
|
|||
|
|
{
|
|||
|
|
int result;
|
|||
|
|
result = PlayerPrefs.GetInt(PREFS_REMEMBER_USERNAME);
|
|||
|
|
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static int GetRememberPassword()
|
|||
|
|
{
|
|||
|
|
int result;
|
|||
|
|
result = PlayerPrefs.GetInt(PREFS_REMEMBER_PASSWORD);
|
|||
|
|
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void WriteUsername(string username)
|
|||
|
|
{
|
|||
|
|
PlayerPrefs.SetString(PREFS_USERNAME, username);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void WritePassword(string password)
|
|||
|
|
{
|
|||
|
|
PlayerPrefs.SetString(PREFS_PASSWORD, password);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public static string GetUsername()
|
|||
|
|
{
|
|||
|
|
string username;
|
|||
|
|
|
|||
|
|
if (PlayerPrefs.GetString(PREFS_USERNAME) != "")
|
|||
|
|
{
|
|||
|
|
username = PlayerPrefs.GetString(PREFS_USERNAME);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
username = "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return username;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static string GetPassword()
|
|||
|
|
{
|
|||
|
|
string password;
|
|||
|
|
|
|||
|
|
if(PlayerPrefs.GetString(PREFS_PASSWORD) != "")
|
|||
|
|
{
|
|||
|
|
password = PlayerPrefs.GetString(PREFS_PASSWORD);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
password = "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return password;
|
|||
|
|
}
|
|||
|
|
}
|