Skip to content

Commit

Permalink
Merge branch 'typeColors'
Browse files Browse the repository at this point in the history
  • Loading branch information
Siccity committed Dec 27, 2018
2 parents 3ced922 + 8d445fa commit 3450b5f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Scripts/Editor/NodeEditorPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum NoodleType { Curve, Line, Angled }
/// <summary> The last key we checked. This should be the one we modify </summary>
private static string lastKey = "xNode.Settings";

private static Dictionary<string, Color> typeColors = new Dictionary<string, Color>();
private static Dictionary<Type, Color> typeColors = new Dictionary<Type, Color>();
private static Dictionary<string, Settings> settings = new Dictionary<string, Settings>();

[System.Serializable]
Expand Down Expand Up @@ -136,15 +136,16 @@ private static void TypeColorsGUI(string key, Settings settings) {
EditorGUILayout.LabelField("Types", EditorStyles.boldLabel);

//Display type colors. Save them if they are edited by the user
List<string> typeColorKeys = new List<string>(typeColors.Keys);
foreach (string typeColorKey in typeColorKeys) {
Color col = typeColors[typeColorKey];
foreach (var typeColor in typeColors) {
Type type = typeColor.Key;
string typeColorKey = NodeEditorUtilities.PrettyName(type);
Color col = typeColor.Value;
EditorGUI.BeginChangeCheck();
EditorGUILayout.BeginHorizontal();
col = EditorGUILayout.ColorField(typeColorKey, col);
EditorGUILayout.EndHorizontal();
if (EditorGUI.EndChangeCheck()) {
typeColors[typeColorKey] = col;
typeColors[type] = col;
if (settings.typeColors.ContainsKey(typeColorKey)) settings.typeColors[typeColorKey] = col;
else settings.typeColors.Add(typeColorKey, col);
SavePrefs(typeColorKey, settings);
Expand All @@ -167,7 +168,7 @@ private static Settings LoadPrefs() {
public static void ResetPrefs() {
if (EditorPrefs.HasKey(lastKey)) EditorPrefs.DeleteKey(lastKey);
if (settings.ContainsKey(lastKey)) settings.Remove(lastKey);
typeColors = new Dictionary<string, Color>();
typeColors = new Dictionary<Type, Color>();
VerifyLoaded();
NodeEditorWindow.RepaintAll();
}
Expand All @@ -186,19 +187,21 @@ private static void VerifyLoaded() {
public static Color GetTypeColor(System.Type type) {
VerifyLoaded();
if (type == null) return Color.gray;
string typeName = type.PrettyName();
if (!typeColors.ContainsKey(typeName)) {
if (settings[lastKey].typeColors.ContainsKey(typeName)) typeColors.Add(typeName, settings[lastKey].typeColors[typeName]);
Color col;
if (!typeColors.TryGetValue(type, out col)) {
string typeName = type.PrettyName();
if (settings[lastKey].typeColors.ContainsKey(typeName)) typeColors.Add(type, settings[lastKey].typeColors[typeName]);
else {
#if UNITY_5_4_OR_NEWER
UnityEngine.Random.InitState(typeName.GetHashCode());
#else
UnityEngine.Random.seed = typeName.GetHashCode();
#endif
typeColors.Add(typeName, new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value));
col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
typeColors.Add(type, col);
}
}
return typeColors[typeName];
return col;
}
}
}

0 comments on commit 3450b5f

Please sign in to comment.