diff --git a/Assets/QuickSheet/Editor/Util/SingletonScriptableObject.cs b/Assets/QuickSheet/Editor/Util/SingletonScriptableObject.cs
new file mode 100644
index 0000000..551425c
--- /dev/null
+++ b/Assets/QuickSheet/Editor/Util/SingletonScriptableObject.cs
@@ -0,0 +1,30 @@
+using System.Linq;
+using UnityEngine;
+
+namespace UnityQuickSheet
+{
+ ///
+ /// Abstract class for making reload-proof singletons out of ScriptableObjects
+ /// Returns the asset created on editor, null if there is none
+ /// Based on https://www.youtube.com/watch?v=VBA1QCoEAX4
+ ///
+ /// See Also:
+ /// blog page: http://baraujo.net/unity3d-making-singletons-from-scriptableobjects-automatically/
+ /// gist page: https://gist.github.com/baraujo/07bb162a1f916595cad1a2d1fee5e72d
+ ///
+ /// Type of the singleton
+
+ public abstract class SingletonScriptableObject : ScriptableObject where T : ScriptableObject
+ {
+ static T _instance = null;
+ public static T Instance
+ {
+ get
+ {
+ if (!_instance)
+ _instance = Resources.FindObjectsOfTypeAll().FirstOrDefault();
+ return _instance;
+ }
+ }
+ }
+}
diff --git a/Assets/QuickSheet/ExcelPlugin/Editor/Excel Settings.asset b/Assets/QuickSheet/ExcelPlugin/Editor/Excel Settings.asset
new file mode 100644
index 0000000..2fb8150
Binary files /dev/null and b/Assets/QuickSheet/ExcelPlugin/Editor/Excel Settings.asset differ
diff --git a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettings.asset.meta b/Assets/QuickSheet/ExcelPlugin/Editor/Excel Settings.asset.meta
similarity index 64%
rename from Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettings.asset.meta
rename to Assets/QuickSheet/ExcelPlugin/Editor/Excel Settings.asset.meta
index 2890bf4..dff3cd0 100644
--- a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettings.asset.meta
+++ b/Assets/QuickSheet/ExcelPlugin/Editor/Excel Settings.asset.meta
@@ -1,6 +1,6 @@
fileFormatVersion: 2
-guid: e24afd6f5c8e036499742994493be560
-timeCreated: 1444701701
+guid: f37cda8add312d644bf1272f72d0ad61
+timeCreated: 1500383140
licenseType: Pro
NativeFormatImporter:
userData:
diff --git a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelMachine.cs b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelMachine.cs
index d493bfe..f13cd93 100644
--- a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelMachine.cs
+++ b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelMachine.cs
@@ -32,15 +32,15 @@ public int CurrentSheetIndex
[SerializeField]
protected int currentSelectedSheet = 0;
- // excel and google plugin have its own template files,
- // so we need to set the different path when the asset file is created.
- private readonly string excelTemplatePath = "QuickSheet/ExcelPlugin/Templates";
///
/// Note: Called when the asset file is created.
///
+
private void Awake() {
- TemplatePath = excelTemplatePath;
+ // excel and google plugin have its own template files,
+ // so we need to set the different path when the asset file is created.
+ TemplatePath = ExcelSettings.Instance.TemplatePath;
}
///
diff --git a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettings.asset b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettings.asset
deleted file mode 100644
index c3d5d30..0000000
--- a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettings.asset
+++ /dev/null
@@ -1,15 +0,0 @@
-%YAML 1.1
-%TAG !u! tag:unity3d.com,2011:
---- !u!114 &11400000
-MonoBehaviour:
- m_ObjectHideFlags: 0
- m_PrefabParentObject: {fileID: 0}
- m_PrefabInternal: {fileID: 0}
- m_GameObject: {fileID: 0}
- m_Enabled: 1
- m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: a7f75662a54ccdd4fac555acce15d166, type: 3}
- m_Name: ExcelSettings
- m_EditorClassIdentifier:
- RuntimePath:
- EditorPath:
diff --git a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettings.cs b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettings.cs
index f9c4912..6b427bd 100644
--- a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettings.cs
+++ b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettings.cs
@@ -15,13 +15,13 @@ namespace UnityQuickSheet
///
/// A class manages excel setting.
///
- public class ExcelSettings : ScriptableObject
+ [CreateAssetMenu(menuName = "QuickSheet/Setting/Excel Setting")]
+ public class ExcelSettings : SingletonScriptableObject
{
- // A path of default setting file is located.
- public static string AssetPath = "Assets/QuickSheet/ExcelPlugin/Editor/";
-
- // A filename of setting .asset file.
- public static readonly string AssetFileName = "ExcelSettings.asset";
+ ///
+ /// A default path where .txt template files are.
+ ///
+ public string TemplatePath = "QuickSheet/ExcelPlugin/Templates";
///
/// A path where generated ScriptableObject derived class and its data class script files are to be put.
@@ -33,20 +33,6 @@ public class ExcelSettings : ScriptableObject
///
public string EditorPath = string.Empty;
- ///
- /// A singleton instance.
- ///
- private static ExcelSettings s_Instance = null;
-
- ///
- /// Create new account setting asset file if there is already one then select it.
- ///
- [MenuItem("Assets/Create/QuickSheet/Setting/Excel Setting")]
- public static void CreateExcelSetting()
- {
- ExcelSettings.Create();
- }
-
///
/// Select currently exist account setting asset file.
///
@@ -56,88 +42,8 @@ public static void Edit()
Selection.activeObject = Instance;
if (Selection.activeObject == null)
{
- Debug.LogError(@"No ExcelSetting.asset file is found. Create setting file first. See the menu at 'Assets/Create/QuickSheet/Setting/Excel Setting'.");
+ Debug.LogError(@"No ExcelSetting.asset file is found. Create setting file first. See the menu at 'Create/QuickSheet/Setting/Excel Setting'.");
}
}
-
- ///
- /// Checks ExcelSetting.asset file exist at the specified path(AssetPath+AssetFileName).
- ///
- public bool CheckPath()
- {
- string file = AssetDatabase.GetAssetPath(Selection.activeObject);
- string assetFile = AssetPath + ExcelSettings.AssetFileName;
-
- return (file == assetFile) ? true : false;
- }
-
- ///
- /// A property for a singleton instance.
- ///
- public static ExcelSettings Instance
- {
- get
- {
- if (s_Instance == null)
- {
- string path = ExcelSettings.AssetPath + ExcelSettings.AssetFileName;
- s_Instance = AssetDatabase.LoadAssetAtPath(path, typeof(ExcelSettings)) as ExcelSettings;
- if (s_Instance == null)
- {
- string title = string.Format(@"No {0} is found!", AssetFileName);
- string message = string.Format(@"No {0} is found at '{1}'. \n Press 'Create' button to create a default one.", AssetFileName, AssetPath);
- bool ok = EditorUtility.DisplayDialog(
- title,
- message,
- "Create",
- "Cancel"
- );
-
- // create excel setting .asset file if it does not exist under the asset path.
- if (ok)
- s_Instance = ExcelSettings.Create();
- }
- }
- return s_Instance;
- }
- }
-
- ///
- /// Create .asset file for excel setting.
- ///
- public static ExcelSettings Create()
- {
- string filePath = CustomAssetUtility.GetUniqueAssetPathNameOrFallback(AssetFileName);
- s_Instance = (ExcelSettings)AssetDatabase.LoadAssetAtPath(filePath, typeof(ExcelSettings));
-
- if (s_Instance == null)
- {
- s_Instance = CreateInstance();
-
- string path = CustomAssetUtility.GetUniqueAssetPathNameOrFallback(AssetFileName);
- AssetDatabase.CreateAsset(s_Instance, path);
-
- ExcelSettings.AssetPath = Path.GetDirectoryName(path);
- ExcelSettings.AssetPath += "/";
-
- // saves file path of the created asset.
- EditorUtility.SetDirty(s_Instance);
- AssetDatabase.SaveAssets();
-
- EditorUtility.DisplayDialog(
- "Validate Settings",
- "Default excel settings file has been created for accessing excel spreadsheet. Set valid runtime editor paths before proceeding.",
- "OK"
- );
- }
- else
- {
- Debug.LogWarning("Already exist at " + filePath);
- }
-
- Selection.activeObject = s_Instance;
-
- return s_Instance;
- }
}
}
diff --git a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettingsEditor.cs b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettingsEditor.cs
index 69c1eb0..eeeec26 100644
--- a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettingsEditor.cs
+++ b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelSettingsEditor.cs
@@ -17,11 +17,9 @@ namespace UnityQuickSheet
[CustomEditor(typeof(ExcelSettings))]
public class ExcelSettingsEditor : Editor
{
- ExcelSettings setting;
-
public void OnEnable()
{
- setting = target as ExcelSettings;
+
}
public override void OnInspectorGUI()
@@ -32,48 +30,27 @@ public override void OnInspectorGUI()
EditorGUILayout.Separator();
- // paths for runtime and editor folder which will contain generated script files.
GUILayout.BeginHorizontal();
- GUILayout.Label("Setting FilePath: ", GUILayout.Width(110));
- // prevent to modify by manual
- GUILayout.TextField(ExcelSettings.AssetPath, 120);
- GUILayout.EndHorizontal();
-
- GUILayout.BeginHorizontal();
- GUILayout.Label("Setting FileName: ", GUILayout.Width(110));
- // read-only
- GUILayout.TextField(ExcelSettings.AssetFileName, 120);
+ GUILayout.Label("Template Path: ", GUILayout.Width(100));
+ ExcelSettings.Instance.TemplatePath = GUILayout.TextField(ExcelSettings.Instance.TemplatePath);
GUILayout.EndHorizontal();
EditorGUILayout.Separator();
- if (setting.CheckPath())
- {
- GUILayout.BeginHorizontal();
- GUILayout.Label("Runtime Path: ", GUILayout.Width(100));
- setting.RuntimePath = GUILayout.TextField(setting.RuntimePath);
- GUILayout.EndHorizontal();
+ GUILayout.BeginHorizontal();
+ GUILayout.Label("Runtime Path: ", GUILayout.Width(100));
+ ExcelSettings.Instance.RuntimePath = GUILayout.TextField(ExcelSettings.Instance.RuntimePath);
+ GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUILayout.Label("Editor Path: ", GUILayout.Width(100));
- setting.EditorPath = GUILayout.TextField(setting.EditorPath);
- GUILayout.EndHorizontal();
- }
- else
- {
- GUILayout.BeginHorizontal();
- GUILayout.Toggle(true, "", "CN EntryError", GUILayout.Width(20));
- GUILayout.BeginVertical();
- GUILayout.Label("", GUILayout.Height(12));
- GUILayout.Label("Correct the path of the ExcelSetting.asset file.", GUILayout.Height(20));
- GUILayout.EndVertical();
- GUILayout.EndHorizontal();
- }
+ GUILayout.BeginHorizontal();
+ GUILayout.Label("Editor Path: ", GUILayout.Width(100));
+ ExcelSettings.Instance.EditorPath = GUILayout.TextField(ExcelSettings.Instance.EditorPath);
+ GUILayout.EndHorizontal();
if (GUI.changed)
{
- EditorUtility.SetDirty(setting);
+ EditorUtility.SetDirty(ExcelSettings.Instance);
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/Impl/Serializer.cs b/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/Impl/Serializer.cs
index 1c41fab..e1b8191 100644
--- a/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/Impl/Serializer.cs
+++ b/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/Impl/Serializer.cs
@@ -20,12 +20,12 @@ public ListEntry Serialize(T e) {
public ListEntry Serialize(T e, ListEntry record) {
foreach (var p in typeof (T).GetProperties()) {
- if (p.CanRead) {
- record.Elements.Add(new ListEntry.Custom {
- LocalName = p.Name.ToLowerInvariant(), // for some reason this HAS to be lowercase or it throws
- Value = ToNullOrString(p.GetValue(e, null)),
- });
- }
+ if (p.CanRead) {
+ record.Elements.Add(new ListEntry.Custom {
+ LocalName = p.Name.ToLowerInvariant(), // for some reason this HAS to be lowercase or it throws
+ Value = ToNullOrString(p.GetValue(e, null)),
+ });
+ }
}
return record;
}
@@ -41,14 +41,14 @@ public object ConvertFrom(object value, Type t) {
var nc = new NullableConverter(t);
return nc.ConvertFrom(value);
}
-
- //HACK: modified to return enum.
- if (t.IsEnum)
- {
- return Enum.Parse(t, value.ToString(), true);
- }
- else
- return Convert.ChangeType(value, t);
+
+ //HACK: modified to return enum.
+ if (t.IsEnum)
+ {
+ return Enum.Parse(t, value.ToString(), true);
+ }
+ else
+ return Convert.ChangeType(value, t);
}
public T Deserialize(ListEntry e) {
@@ -58,10 +58,10 @@ public T Deserialize(ListEntry e) {
var property = t.GetProperty(c.LocalName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
if (property == null)
continue;
- if (property.CanWrite) {
-
- try
- {
+ if (property.CanWrite) {
+
+ try
+ {
if (property.PropertyType.IsArray)
{
const char DELIMETER = ','; // '\n'
@@ -123,12 +123,12 @@ public T Deserialize(ListEntry e) {
property.SetValue(r, value, null);
}
- }
- catch(Exception exc)
- {
- Debug.LogError ("GDataDB Serialization Exception: " + exc.Message + " ListEntry LocalName: " + c.LocalName);
- }
- }
+ }
+ catch(Exception exc)
+ {
+ Debug.LogError ("GDataDB Serialization Exception: " + exc.Message + " ListEntry LocalName: " + c.LocalName);
+ }
+ }
}
return r;
}
diff --git a/Assets/QuickSheet/GDataPlugin/Editor/Google Data Settings.asset b/Assets/QuickSheet/GDataPlugin/Editor/Google Data Settings.asset
new file mode 100644
index 0000000..877fc6b
Binary files /dev/null and b/Assets/QuickSheet/GDataPlugin/Editor/Google Data Settings.asset differ
diff --git a/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettings.asset.meta b/Assets/QuickSheet/GDataPlugin/Editor/Google Data Settings.asset.meta
similarity index 64%
rename from Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettings.asset.meta
rename to Assets/QuickSheet/GDataPlugin/Editor/Google Data Settings.asset.meta
index d4a1fdb..1453277 100644
--- a/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettings.asset.meta
+++ b/Assets/QuickSheet/GDataPlugin/Editor/Google Data Settings.asset.meta
@@ -1,6 +1,6 @@
fileFormatVersion: 2
-guid: fe5b4ba143358444c932c44eedc4a76f
-timeCreated: 1443165040
+guid: de069546a9e7f3340afcaabb8a149e47
+timeCreated: 1500383124
licenseType: Pro
NativeFormatImporter:
userData:
diff --git a/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettings.asset b/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettings.asset
deleted file mode 100644
index 2121cd6..0000000
--- a/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettings.asset
+++ /dev/null
@@ -1,27 +0,0 @@
-%YAML 1.1
-%TAG !u! tag:unity3d.com,2011:
---- !u!114 &11400000
-MonoBehaviour:
- m_ObjectHideFlags: 0
- m_PrefabParentObject: {fileID: 0}
- m_PrefabInternal: {fileID: 0}
- m_GameObject: {fileID: 0}
- m_Enabled: 1
- m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: dbcda13c00cae4f4087d84a149a1c70b, type: 3}
- m_Name: GoogleDataSettings
- m_EditorClassIdentifier:
- RuntimePath:
- EditorPath:
- OAuth2Data:
- client_id:
- auth_uri: https://accounts.google.com/o/oauth2/auth
- token_uri: https://accounts.google.com/o/oauth2/token
- auth_provider_x509_cert_url: https://www.googleapis.com/oauth2/v1/certs
- client_secret:
- redirect_uris:
- - urn:ietf:wg:oauth:2.0:oob
- - http://localhost
- _AccessCode:
- _RefreshToken:
- _AccessToken:
diff --git a/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettings.cs b/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettings.cs
index 0e90264..2946362 100644
--- a/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettings.cs
+++ b/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettings.cs
@@ -16,12 +16,9 @@ namespace UnityQuickSheet
///
/// A class manages google account setting.
///
- public class GoogleDataSettings : ScriptableObject
+ [CreateAssetMenu(menuName = "QuickSheet/Setting/GoogleData Setting")]
+ public class GoogleDataSettings : SingletonScriptableObject
{
- public static string AssetPath = "Assets/QuickSheet/GDataPlugin/Editor/";
-
- public static readonly string AssetFileName = "GoogleDataSettings.asset";
-
// A flag which indicates use local installed oauth2 json file for authentication or not.
static public bool useOAuth2JsonFile = false;
@@ -36,6 +33,11 @@ public string JsonFilePath
}
private string jsonFilePath = string.Empty;
+ ///
+ /// A default path where .txt template files are.
+ ///
+ public string TemplatePath = "QuickSheet/GDataPlugin/Templates";
+
///
/// A path where generated ScriptableObject derived class and its data class script files are to be put.
///
@@ -67,20 +69,6 @@ public struct OAuth2JsonData
public string _AccessToken = "";
- ///
- /// A singleton instance.
- ///
- private static GoogleDataSettings s_Instance;
-
- ///
- /// Create new account setting asset file if there is already one then select it.
- ///
- [MenuItem("Assets/Create/QuickSheet/Setting/GoogleData Setting")]
- public static void CreateGoogleDataSetting()
- {
- GoogleDataSettings.Create();
- }
-
///
/// Select currently exist account setting asset file.
///
@@ -93,84 +81,5 @@ public static void Edit()
Debug.LogError("No GoogleDataSettings.asset file is found. Create setting file first.");
}
}
-
- ///
- /// Checks GoogleDataSetting.asset file exist at the specified path(AssetPath+AssetFileName).
- ///
- public bool CheckPath()
- {
- string file = AssetDatabase.GetAssetPath(Selection.activeObject);
- string assetFile = AssetPath + GoogleDataSettings.AssetFileName;
-
- return (file == assetFile) ? true : false;
- }
-
- ///
- /// A property for a singleton instance.
- ///
- public static GoogleDataSettings Instance
- {
- get
- {
- if (s_Instance == null)
- {
- string path = GoogleDataSettings.AssetPath + GoogleDataSettings.AssetFileName;
- s_Instance = (GoogleDataSettings)AssetDatabase.LoadAssetAtPath(path, typeof(GoogleDataSettings));
- if (s_Instance == null)
- {
- string title = string.Format(@"No {0} is found!", AssetFileName);
- string message = string.Format(@"No {0} is found at '{1}'. \n Press 'Create' button to create a default one.", AssetFileName, AssetPath);
- bool ok = EditorUtility.DisplayDialog(
- title,
- message,
- "Create",
- "Cancel"
- );
-
- if (ok)
- s_Instance = GoogleDataSettings.Create();
- }
- }
- return s_Instance;
- }
- }
-
- ///
- /// Create .asset file for google spreadsheet setting if it does not exist.
- ///
- public static GoogleDataSettings Create()
- {
- string filePath = CustomAssetUtility.GetUniqueAssetPathNameOrFallback(AssetFileName);
- s_Instance = (GoogleDataSettings)AssetDatabase.LoadAssetAtPath(filePath, typeof(GoogleDataSettings));
-
- if (s_Instance == null)
- {
- s_Instance = CreateInstance();
-
- string path = CustomAssetUtility.GetUniqueAssetPathNameOrFallback(AssetFileName);
- AssetDatabase.CreateAsset(s_Instance, path);
-
- GoogleDataSettings.AssetPath = Path.GetDirectoryName(path);
- GoogleDataSettings.AssetPath += "/";
-
- // saves file path of the created asset.
- EditorUtility.SetDirty(s_Instance);
- AssetDatabase.SaveAssets();
-
- EditorUtility.DisplayDialog(
- "Validate Settings",
- "Default google data settings file has been created for accessing Google project page. You should validate these before proceeding.",
- "OK"
- );
- }
- else
- {
- Debug.LogWarning("Already exist at " + filePath);
- }
-
- Selection.activeObject = s_Instance;
-
- return s_Instance;
- }
}
}
\ No newline at end of file
diff --git a/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettingsEditor.cs b/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettingsEditor.cs
index 26a5242..75e6723 100644
--- a/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettingsEditor.cs
+++ b/Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettingsEditor.cs
@@ -1,7 +1,7 @@
///////////////////////////////////////////////////////////////////////////////
///
/// GoogleDataSettingsEditor.cs
-///
+///
/// (c)2013 Kim, Hyoun Woo
///
///////////////////////////////////////////////////////////////////////////////
@@ -44,12 +44,8 @@ public static void Instate()
[CustomEditor(typeof(GoogleDataSettings))]
public class GoogleDataSettingsEditor : Editor
{
- GoogleDataSettings setting;
-
public void OnEnable()
{
- setting = target as GoogleDataSettings;
-
// resolve TlsException error
UnsafeSecurityPolicy.Instate();
}
@@ -63,166 +59,143 @@ public override void OnInspectorGUI()
EditorGUILayout.Separator();
- // path and asset file name which contains a google account and password.
- GUILayout.BeginHorizontal();
- GUILayout.Label("Setting FilePath: ", GUILayout.Width(110));
- // prevent to modify by manual
- GUILayout.TextField(GoogleDataSettings.AssetPath, 120);
- GUILayout.EndHorizontal();
-
- GUILayout.BeginHorizontal();
- GUILayout.Label("Setting FileName: ", GUILayout.Width(110));
- // read-only
- GUILayout.TextField(GoogleDataSettings.AssetFileName, 120);
- GUILayout.EndHorizontal();
+ GUIStyle helpBoxStyle = GUI.skin.GetStyle("HelpBox");
+ helpBoxStyle.richText = true;
+ const string infoMsg = "Copying 'client_id' and 'client_secret' from Google Developer Console and pasting that into the textfields without specifying json file is also working, if you don't want to install oauth2 json file on the local disk.";
+ GUIHelper.HelpBox(infoMsg, MessageType.Info);
- EditorGUILayout.Separator();
+ const int LabelWidth = 90;
- if (setting.CheckPath())
+ using (new GUILayout.HorizontalScope())
{
- EditorGUILayout.Separator();
-
- GUIStyle helpBoxStyle = GUI.skin.GetStyle("HelpBox");
- helpBoxStyle.richText = true;
- const string infoMsg = "Copying 'client_id' and 'client_secret' from Google Developer Console and pasting that into the textfields without specifying json file is also working, if you don't want to install oauth2 json file on the local disk.";
- GUIHelper.HelpBox(infoMsg, MessageType.Info);
-
- const int LabelWidth = 90;
+ GoogleDataSettings.useOAuth2JsonFile = GUILayout.Toggle(GoogleDataSettings.useOAuth2JsonFile, " I have OAuth2 JSON file");
- using (new GUILayout.HorizontalScope())
+ // reset client_id and client_secret and empty its textfields.
+ if (GUILayout.Button("Reset", GUILayout.Width(60)))
{
- GoogleDataSettings.useOAuth2JsonFile = GUILayout.Toggle(GoogleDataSettings.useOAuth2JsonFile, " I have OAuth2 JSON file");
+ GoogleDataSettings.Instance.OAuth2Data.client_id = string.Empty;
+ GoogleDataSettings.Instance.OAuth2Data.client_secret = string.Empty;
+ GoogleDataSettings.Instance._AccessCode = string.Empty;
- // reset client_id and client_secret and empty its textfields.
- if (GUILayout.Button("Reset", GUILayout.Width(60)))
- {
- setting.OAuth2Data.client_id = string.Empty;
- setting.OAuth2Data.client_secret = string.Empty;
- GoogleDataSettings.Instance._AccessCode = string.Empty;
-
- // retrieves from google developer center.
- GoogleDataSettings.Instance._RefreshToken = string.Empty;
- GoogleDataSettings.Instance._AccessToken = string.Empty;
- }
+ // retrieves from google developer center.
+ GoogleDataSettings.Instance._RefreshToken = string.Empty;
+ GoogleDataSettings.Instance._AccessToken = string.Empty;
}
- if (GoogleDataSettings.useOAuth2JsonFile)
- {
- GUILayout.BeginHorizontal(); // Begin json file setting
- GUILayout.Label("JSON File:", GUILayout.Width(LabelWidth));
+ }
+ if (GoogleDataSettings.useOAuth2JsonFile)
+ {
+ GUILayout.BeginHorizontal(); // Begin json file setting
+ GUILayout.Label("JSON File:", GUILayout.Width(LabelWidth));
- string path = "";
- if (string.IsNullOrEmpty(setting.JsonFilePath))
- path = Application.dataPath;
- else
- path = setting.JsonFilePath;
+ string path = "";
+ if (string.IsNullOrEmpty(GoogleDataSettings.Instance.JsonFilePath))
+ path = Application.dataPath;
+ else
+ path = GoogleDataSettings.Instance.JsonFilePath;
- setting.JsonFilePath = GUILayout.TextField(path, GUILayout.Width(250));
- if (GUILayout.Button("...", GUILayout.Width(20)))
+ GoogleDataSettings.Instance.JsonFilePath = GUILayout.TextField(path, GUILayout.Width(250));
+ if (GUILayout.Button("...", GUILayout.Width(20)))
+ {
+ string folder = Path.GetDirectoryName(path);
+ path = EditorUtility.OpenFilePanel("Open JSON file", folder, "json");
+ if (path.Length != 0)
{
- string folder = Path.GetDirectoryName(path);
- path = EditorUtility.OpenFilePanel("Open JSON file", folder, "json");
- if (path.Length != 0)
+ StringBuilder builder = new StringBuilder();
+ using (StreamReader sr = new StreamReader(path))
{
- StringBuilder builder = new StringBuilder();
- using (StreamReader sr = new StreamReader(path))
+ string s = "";
+ while (s != null)
{
- string s = "";
- while (s != null)
- {
- s = sr.ReadLine();
- builder.Append(s);
- }
+ s = sr.ReadLine();
+ builder.Append(s);
}
+ }
- string jsonData = builder.ToString();
+ string jsonData = builder.ToString();
- //HACK: reported a json file which has no "installed" property
- //var oauthData = JObject.Parse(jsonData).SelectToken("installed").ToString();
- //GoogleDataSettings.Instance.OAuth2Data = JsonConvert.DeserializeObject(oauthData);
+ //HACK: reported a json file which has no "installed" property
+ //var oauthData = JObject.Parse(jsonData).SelectToken("installed").ToString();
+ //GoogleDataSettings.Instance.OAuth2Data = JsonConvert.DeserializeObject(oauthData);
- //HACK: assume the parsed json string contains only one property value: JObject.Parse(jsonData).Count == 1
- JObject jo = JObject.Parse(jsonData);
- var propertyValues = jo.PropertyValues();
- foreach (JToken token in propertyValues)
- {
- string val = token.ToString();
- GoogleDataSettings.Instance.OAuth2Data = JsonConvert.DeserializeObject(val);
- }
+ //HACK: assume the parsed json string contains only one property value: JObject.Parse(jsonData).Count == 1
+ JObject jo = JObject.Parse(jsonData);
+ var propertyValues = jo.PropertyValues();
+ foreach (JToken token in propertyValues)
+ {
+ string val = token.ToString();
+ GoogleDataSettings.Instance.OAuth2Data = JsonConvert.DeserializeObject(val);
+ }
- setting.JsonFilePath = path;
+ GoogleDataSettings.Instance.JsonFilePath = path;
- // force to save the setting.
- EditorUtility.SetDirty(setting);
- AssetDatabase.SaveAssets();
- }
+ // force to save the setting.
+ EditorUtility.SetDirty(GoogleDataSettings.Instance);
+ AssetDatabase.SaveAssets();
}
- GUILayout.EndHorizontal(); // End json file setting.
}
+ GUILayout.EndHorizontal(); // End json file setting.
+ }
+
+ EditorGUILayout.Separator();
- EditorGUILayout.Separator();
+ if (GoogleDataSettings.Instance.OAuth2Data.client_id == null)
+ GoogleDataSettings.Instance.OAuth2Data.client_id = string.Empty;
+ if (GoogleDataSettings.Instance.OAuth2Data.client_secret == null)
+ GoogleDataSettings.Instance.OAuth2Data.client_secret = string.Empty;
- if (setting.OAuth2Data.client_id == null)
- setting.OAuth2Data.client_id = string.Empty;
- if (setting.OAuth2Data.client_secret == null)
- setting.OAuth2Data.client_secret = string.Empty;
+ // client_id for OAuth2
+ GUILayout.BeginHorizontal();
+ GUILayout.Label("Client ID: ", GUILayout.Width(LabelWidth));
+ GoogleDataSettings.Instance.OAuth2Data.client_id = GUILayout.TextField(GoogleDataSettings.Instance.OAuth2Data.client_id);
+ GUILayout.EndHorizontal();
- // client_id for OAuth2
- GUILayout.BeginHorizontal();
- GUILayout.Label("Client ID: ", GUILayout.Width(LabelWidth));
- setting.OAuth2Data.client_id = EditorGUILayout.TextField(setting.OAuth2Data.client_id);
- GUILayout.EndHorizontal();
+ // client_secret for OAuth2
+ GUILayout.BeginHorizontal();
+ GUILayout.Label("Client Secret: ", GUILayout.Width(LabelWidth));
+ GoogleDataSettings.Instance.OAuth2Data.client_secret = GUILayout.TextField(GoogleDataSettings.Instance.OAuth2Data.client_secret);
+ GUILayout.EndHorizontal();
- // client_secret for OAuth2
- GUILayout.BeginHorizontal();
- GUILayout.Label("Client Secret: ", GUILayout.Width(LabelWidth));
- setting.OAuth2Data.client_secret = EditorGUILayout.TextField(setting.OAuth2Data.client_secret);
- GUILayout.EndHorizontal();
+ EditorGUILayout.Separator();
- EditorGUILayout.Separator();
+ if (GUILayout.Button("Start Authentication"))
+ {
+ GDataDB.Impl.GDataDBRequestFactory.InitAuthenticate();
+ }
- if (GUILayout.Button("Start Authentication"))
+ GoogleDataSettings.Instance._AccessCode = EditorGUILayout.TextField("AccessCode", GoogleDataSettings.Instance._AccessCode);
+ if (GUILayout.Button("Finish Authentication"))
+ {
+ try
{
- GDataDB.Impl.GDataDBRequestFactory.InitAuthenticate();
+ GDataDB.Impl.GDataDBRequestFactory.FinishAuthenticate();
}
-
- GoogleDataSettings.Instance._AccessCode = EditorGUILayout.TextField("AccessCode", GoogleDataSettings.Instance._AccessCode);
- if (GUILayout.Button("Finish Authentication"))
+ catch (Exception e)
{
- try
- {
- GDataDB.Impl.GDataDBRequestFactory.FinishAuthenticate();
- }
- catch (Exception e)
- {
- EditorUtility.DisplayDialog("Error", e.Message, "OK");
- }
+ EditorUtility.DisplayDialog("Error", e.Message, "OK");
}
- EditorGUILayout.Separator();
+ }
+ EditorGUILayout.Separator();
- GUILayout.BeginHorizontal();
- GUILayout.Label("Runtime Path: ", GUILayout.Width(LabelWidth));
- setting.RuntimePath = EditorGUILayout.TextField(setting.RuntimePath);
- GUILayout.EndHorizontal();
+ GUILayout.BeginHorizontal();
+ GUILayout.Label("Template Path: ", GUILayout.Width(LabelWidth));
+ GoogleDataSettings.Instance.TemplatePath = GUILayout.TextField(GoogleDataSettings.Instance.TemplatePath);
+ GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUILayout.Label("Editor Path: ", GUILayout.Width(LabelWidth));
- setting.EditorPath = EditorGUILayout.TextField(setting.EditorPath);
- GUILayout.EndHorizontal();
- }
- else
- {
- GUILayout.BeginHorizontal();
- GUILayout.Toggle(true, "", "CN EntryError", GUILayout.Width(20));
- GUILayout.BeginVertical();
- GUILayout.Label("", GUILayout.Height(12));
- GUILayout.Label("Correct the path of the GoogleDataSetting.asset file.", GUILayout.Height(20));
- GUILayout.EndVertical();
- GUILayout.EndHorizontal();
- }
+ EditorGUILayout.Separator();
+
+ GUILayout.BeginHorizontal();
+ GUILayout.Label("Runtime Path: ", GUILayout.Width(LabelWidth));
+ GoogleDataSettings.Instance.RuntimePath = GUILayout.TextField(GoogleDataSettings.Instance.RuntimePath);
+ GUILayout.EndHorizontal();
+
+ GUILayout.BeginHorizontal();
+ GUILayout.Label("Editor Path: ", GUILayout.Width(LabelWidth));
+ GoogleDataSettings.Instance.EditorPath = GUILayout.TextField(GoogleDataSettings.Instance.EditorPath);
+ GUILayout.EndHorizontal();
if (GUI.changed)
{
- EditorUtility.SetDirty(setting);
+ EditorUtility.SetDirty(GoogleDataSettings.Instance);
}
}
}
diff --git a/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachine.cs b/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachine.cs
index 20a64b0..6077c62 100644
--- a/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachine.cs
+++ b/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachine.cs
@@ -23,17 +23,17 @@ internal class GoogleMachine : BaseMachine
[SerializeField]
public static string assetFileName = "GoogleMachine.asset";
- // excel and google plugin have its own template files,
- // so we need to set the different path when the asset file is created.
- private readonly string gDataTemplatePath = "QuickSheet/GDataPlugin/Templates";
public string AccessCode = "";
///
/// Note: Called when the asset file is created.
///
- private void Awake() {
- TemplatePath = gDataTemplatePath;
+ private void Awake()
+ {
+ // excel and google plugin have its own template files,
+ // so we need to set the different path when the asset file is created.
+ TemplatePath = GoogleDataSettings.Instance.TemplatePath;
}
///