//-------------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2019 Tasharen Entertainment Inc
//-------------------------------------------------
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
///
/// Unity doesn't keep the values of static variables after scripts change get recompiled. One way around this
/// is to store the references in EditorPrefs -- retrieve them at start, and save them whenever something changes.
///
public class NGUISettings
{
[DoNotObfuscateNGUI] public enum ColorMode
{
Orange,
Green,
Blue,
}
#region Generic Get and Set methods
///
/// Save the specified boolean value in settings.
///
static public void SetBool (string name, bool val) { EditorPrefs.SetBool(name, val); }
///
/// Save the specified integer value in settings.
///
static public void SetInt (string name, int val) { EditorPrefs.SetInt(name, val); }
///
/// Save the specified float value in settings.
///
static public void SetFloat (string name, float val) { EditorPrefs.SetFloat(name, val); }
///
/// Save the specified string value in settings.
///
static public void SetString (string name, string val) { EditorPrefs.SetString(name, val); }
///
/// Save the specified color value in settings.
///
static public void SetColor (string name, Color c) { SetString(name, c.r + " " + c.g + " " + c.b + " " + c.a); }
///
/// Save the specified enum value to settings.
///
static public void SetEnum (string name, System.Enum val) { SetString(name, val.ToString()); }
///
/// Save the specified object in settings.
///
static public void Set (string name, Object obj)
{
if (obj == null)
{
EditorPrefs.DeleteKey(name);
}
else
{
if (obj != null)
{
string path = AssetDatabase.GetAssetPath(obj);
if (!string.IsNullOrEmpty(path))
{
EditorPrefs.SetString(name, path);
}
else
{
EditorPrefs.SetString(name, obj.GetInstanceID().ToString());
}
}
else EditorPrefs.DeleteKey(name);
}
}
///
/// Get the previously saved boolean value.
///
static public bool GetBool (string name, bool defaultValue) { return EditorPrefs.GetBool(name, defaultValue); }
///
/// Get the previously saved integer value.
///
static public int GetInt (string name, int defaultValue) { return EditorPrefs.GetInt(name, defaultValue); }
///
/// Get the previously saved float value.
///
static public float GetFloat (string name, float defaultValue) { return EditorPrefs.GetFloat(name, defaultValue); }
///
/// Get the previously saved string value.
///
static public string GetString (string name, string defaultValue) { return EditorPrefs.GetString(name, defaultValue); }
///
/// Get a previously saved color value.
///
static public Color GetColor (string name, Color c)
{
string strVal = GetString(name, c.r + " " + c.g + " " + c.b + " " + c.a);
string[] parts = strVal.Split(' ');
if (parts.Length == 4)
{
float.TryParse(parts[0], out c.r);
float.TryParse(parts[1], out c.g);
float.TryParse(parts[2], out c.b);
float.TryParse(parts[3], out c.a);
}
return c;
}
///
/// Get a previously saved enum from settings.
///
static public T GetEnum (string name, T defaultValue)
{
string val = GetString(name, defaultValue.ToString());
string[] names = System.Enum.GetNames(typeof(T));
System.Array values = System.Enum.GetValues(typeof(T));
for (int i = 0; i < names.Length; ++i)
{
if (names[i] == val)
return (T)values.GetValue(i);
}
return defaultValue;
}
///
/// Get a previously saved object from settings.
///
static public T Get (string name, T defaultValue) where T : Object
{
string path = EditorPrefs.GetString(name);
if (string.IsNullOrEmpty(path)) return null;
T retVal = NGUIEditorTools.LoadAsset(path);
if (retVal == null)
{
int id;
if (int.TryParse(path, out id))
return EditorUtility.InstanceIDToObject(id) as T;
}
return retVal;
}
#endregion
#region Convenience accessor properties
static public bool showTransformHandles
{
get { return GetBool("NGUI Transform Handles", false); }
set { SetBool("NGUI Transform Handles", value); }
}
static public bool minimalisticLook
{
get { return GetBool("NGUI Minimalistic", false); }
set { SetBool("NGUI Minimalistic", value); }
}
static public bool unifiedTransform
{
get { return GetBool("NGUI Unified", false); }
set { SetBool("NGUI Unified", value); }
}
static public Color color
{
get { return GetColor("NGUI Color", Color.white); }
set { SetColor("NGUI Color", value); }
}
static public Color foregroundColor
{
get { return GetColor("NGUI FG Color", Color.white); }
set { SetColor("NGUI FG Color", value); }
}
static public Color backgroundColor
{
get { return GetColor("NGUI BG Color", Color.black); }
set { SetColor("NGUI BG Color", value); }
}
static public ColorMode colorMode
{
get { return GetEnum("NGUI Color Mode", ColorMode.Blue); }
set { SetEnum("NGUI Color Mode", value); }
}
static public Object ambigiousFont
{
get
{
var f0 = Get("NGUI Font", null);
if (f0 != null) return f0;
var f1 = Get("NGUI Font", null);
if (f1 != null) return f1;
return Get("NGUI Font", null);
}
set { Set("NGUI Font", value); }
}
static public INGUIAtlas atlas
{
get
{
var atl = Get("NGUI Atlas", null);
if (atl != null) return atl;
return Get("NGUI Atlas", null);
}
set
{
Set("NGUI Atlas", value as Object);
}
}
static public UISpriteData GetSprite (string spriteName)
{
var atlas = NGUISettings.atlas;
return atlas != null ? atlas.GetSprite(spriteName) : null;
}
static public Texture texture
{
get { return Get("NGUI Texture", null); }
set { Set("NGUI Texture", value); }
}
static public Sprite sprite2D
{
get { return Get("NGUI Sprite2D", null); }
set { Set("NGUI Sprite2D", value); }
}
static public string selectedSprite
{
get { return GetString("NGUI Sprite", null); }
set { SetString("NGUI Sprite", value); }
}
static public UIWidget.Pivot pivot
{
get { return GetEnum("NGUI Pivot", UIWidget.Pivot.Center); }
set { SetEnum("NGUI Pivot", value); }
}
static public int layer
{
get
{
int layer = GetInt("NGUI Layer", -1);
if (layer == -1) layer = LayerMask.NameToLayer("UI");
if (layer == -1) layer = LayerMask.NameToLayer("2D UI");
return (layer == -1) ? 9 : layer;
}
set
{
SetInt("NGUI Layer", value);
}
}
static public TextAsset fontData
{
get { return Get("NGUI Font Data", null); }
set { Set("NGUI Font Data", value); }
}
static public Texture2D fontTexture
{
get { return Get("NGUI Font Texture", null); }
set { Set("NGUI Font Texture", value); }
}
static public int fontSize
{
get { return GetInt("NGUI Font Size", 16); }
set { SetInt("NGUI Font Size", value); }
}
static public int FMSize
{
get { return GetInt("NGUI FM Size", 16); }
set { SetInt("NGUI FM Size", value); }
}
static public bool fontKerning
{
get { return GetBool("NGUI Font Kerning", true); }
set { SetBool("NGUI Font Kerning", value); }
}
static public FontStyle fontStyle
{
get { return GetEnum("NGUI Font Style", FontStyle.Normal); }
set { SetEnum("NGUI Font Style", value); }
}
static public Font dynamicFont
{
get { return Get("NGUI Dynamic Font", null); }
set { Set("NGUI Dynamic Font", value); }
}
static public Font FMFont
{
get { return Get("NGUI FM Font", null); }
set { Set("NGUI FM Font", value); }
}
static public Object BMFont
{
get { return Get