Skip to content

Instantly share code, notes, and snippets.

@grimmdev
Created February 23, 2016 08:30
Show Gist options
  • Save grimmdev/b052d2dcd2a806808e46 to your computer and use it in GitHub Desktop.
Save grimmdev/b052d2dcd2a806808e46 to your computer and use it in GitHub Desktop.
Preferences Utility for Unity 3D and uLiveWallpaper
// Sean Loper
// 2016
// PreferenceUtility.cs
using UnityEngine;
using System.Globalization;
using LostPolygon.uLiveWallpaper;
public class PreferenceUtility
{
// I had already implemented this way before they even thought of making their own implementation.
public static bool Exists(string key)
{
return !string.IsNullOrEmpty(LiveWallpaper.Preferences.GetString (key));
}
public static bool getBool(string key, string fallback)
{
return System.Convert.ToBoolean (LiveWallpaper.Preferences.GetString (key, fallback));
}
public static int getInt(string key, string fallback)
{
return System.Convert.ToInt32 (LiveWallpaper.Preferences.GetString (key, fallback));
}
public static string getString(string key, string fallback)
{
return LiveWallpaper.Preferences.GetString (key, fallback);
}
public static Color getHexColor(string key, string fallback)
{
string c = LiveWallpaper.Preferences.GetString (key, fallback);
byte r = byte.Parse(c.Substring(1,3), NumberStyles.HexNumber);
byte g = byte.Parse(c.Substring(3,2), NumberStyles.HexNumber);
byte b = byte.Parse(c.Substring(5,2), NumberStyles.HexNumber);
return new Color32(r,g,b, 255);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment