Compacted json format (was Color[] now is Color32[]).

Commented out code that opens json file when saved.
pull/413/head
Sean Mann 2018-02-18 23:28:41 -05:00
parent b5f8f17203
commit 8d4a2fe698
1 changed files with 23 additions and 6 deletions

View File

@ -82,7 +82,7 @@ namespace UnityEngine.UI.Extensions.ColorPicker
try try
{ {
var jsonColors = JsonUtility.FromJson<JsonColor>(jsonData); var jsonColors = JsonUtility.FromJson<JsonColor>(jsonData);
presets.AddRange(jsonColors.colors); presets.AddRange(jsonColors.GetColors());
} }
catch (System.Exception e) catch (System.Exception e)
{ {
@ -105,9 +105,8 @@ namespace UnityEngine.UI.Extensions.ColorPicker
return; return;
} }
var jsonColor = new JsonColor() { var jsonColor = new JsonColor();
colors = presets.ToArray() jsonColor.SetColors(presets.ToArray());
};
string jsonData = JsonUtility.ToJson(jsonColor); string jsonData = JsonUtility.ToJson(jsonColor);
@ -122,7 +121,7 @@ namespace UnityEngine.UI.Extensions.ColorPicker
break; break;
case SaveType.JsonFile: case SaveType.JsonFile:
System.IO.File.WriteAllText(JsonFilePath, jsonData); System.IO.File.WriteAllText(JsonFilePath, jsonData);
Application.OpenURL(JsonFilePath); //Application.OpenURL(JsonFilePath);
break; break;
default: default:
throw new System.NotImplementedException(saveType.ToString()); throw new System.NotImplementedException(saveType.ToString());
@ -131,7 +130,25 @@ namespace UnityEngine.UI.Extensions.ColorPicker
protected class JsonColor protected class JsonColor
{ {
public Color[] colors; public Color32[] colors;
public void SetColors(Color[] colorsIn)
{
this.colors = new Color32[colorsIn.Length];
for (int i = 0; i < colorsIn.Length; i++)
{
this.colors[i] = colorsIn[i];
}
}
public Color[] GetColors()
{
Color[] colorsOut = new Color[colors.Length];
for (int i = 0; i < colors.Length; i++)
{
colorsOut[i] = colors[i];
}
return colorsOut;
}
} }
public virtual void CreatePreset(Color color, bool loading) public virtual void CreatePreset(Color color, bool loading)