-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added flag to async/login registration. Added Kii config from editor
- Loading branch information
1 parent
cb5a59e
commit 8ca0d0e
Showing
19 changed files
with
455 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
public class ConfigManager { | ||
|
||
private static ConfigManager sInstance = null; | ||
|
||
bool mDirty = false; | ||
string mFile; | ||
Dictionary<string, string> mDict = new Dictionary<string, string>(); | ||
|
||
public const string CFG_FILE_PATH = "Assets/Plugins/KiiConfig.txt"; | ||
public const string CFG_APP_ID = "cfg.AppId"; | ||
public const string CFG_APP_KEY = "cfg.AppKey"; | ||
public const string CFG_APP_SITE = "cfg.AppSite"; | ||
|
||
public static ConfigManager Instance { | ||
get { | ||
if (sInstance == null) { | ||
sInstance = new ConfigManager(); | ||
} | ||
return sInstance; | ||
} | ||
} | ||
|
||
private ConfigManager() { | ||
string ds = Path.DirectorySeparatorChar.ToString(); | ||
mFile = CFG_FILE_PATH.Replace("/", ds); | ||
|
||
if (File.Exists(mFile)) { | ||
StreamReader rd = new StreamReader(mFile); | ||
while (!rd.EndOfStream) { | ||
string line = rd.ReadLine(); | ||
if (line == null || line.Trim().Length == 0) { | ||
break; | ||
} | ||
line = line.Trim(); | ||
string[] p = line.Split(new char[] { '=' }, 2); | ||
if (p.Length >= 2) { | ||
mDict[p[0].Trim()] = p[1].Trim(); | ||
} | ||
} | ||
rd.Close(); | ||
} | ||
|
||
} | ||
|
||
public string Get(string key, string defaultValue) { | ||
if (mDict.ContainsKey(key)) { | ||
return mDict[key]; | ||
} else { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
public string Get(string key) { | ||
return Get(key, ""); | ||
} | ||
|
||
public bool GetBool(string key, bool defaultValue) { | ||
return Get(key, defaultValue ? "true" : "false").Equals("true"); | ||
} | ||
|
||
public bool GetBool(string key) { | ||
return Get(key, "false").Equals("true"); | ||
} | ||
|
||
public string GetAppId () | ||
{ | ||
return Get(CFG_APP_ID); | ||
} | ||
|
||
public string GetAppKey () | ||
{ | ||
return Get(CFG_APP_KEY); | ||
} | ||
|
||
public string GetAppSite () | ||
{ | ||
return Get(CFG_APP_SITE); | ||
} | ||
|
||
public void Set(string key, string val) { | ||
mDict[key] = val; | ||
mDirty = true; | ||
} | ||
|
||
public void Set(string key, bool val) { | ||
Set(key, val ? "true" : "false"); | ||
} | ||
|
||
public void SetAppId(string val) | ||
{ | ||
Set (CFG_APP_ID, val); | ||
} | ||
|
||
public void SetAppKey(string val) | ||
{ | ||
Set (CFG_APP_KEY, val); | ||
} | ||
|
||
public void SetAppSite(string val) | ||
{ | ||
Set (CFG_APP_SITE, val); | ||
} | ||
|
||
public void Save() { | ||
if (!mDirty) { | ||
return; | ||
} | ||
StreamWriter wr = new StreamWriter(mFile, false); | ||
foreach (string key in mDict.Keys) { | ||
wr.WriteLine(key + "=" + mDict[key]); | ||
} | ||
wr.Close(); | ||
mDirty = false; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Assets/Scripts/Backend/KiiInit.cs.meta → Assets/Editor/ConfigManager.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
using System.Collections; | ||
using System.IO; | ||
|
||
public class SetupUI : EditorWindow { | ||
private string mAppId = ""; | ||
private string mAppKey = ""; | ||
private string mAppSite = ""; | ||
string[] options = new string[] {"United States", "Japan", "China"}; | ||
int index = 0; | ||
|
||
[MenuItem("Kii Game Cloud/Setup...", false, 1)] | ||
public static void MenuItemSetup() { | ||
EditorWindow.GetWindow(typeof(SetupUI)); | ||
} | ||
|
||
void OnEnable() { | ||
mAppId = ConfigManager.Instance.GetAppId(); | ||
mAppKey = ConfigManager.Instance.GetAppKey(); | ||
mAppSite = ConfigManager.Instance.GetAppSite(); | ||
index = SiteToIndex (mAppSite); | ||
} | ||
|
||
void Save() { | ||
ConfigManager.Instance.SetAppId(mAppId); | ||
ConfigManager.Instance.SetAppKey(mAppKey); | ||
mAppSite = IndexToSite (index); | ||
ConfigManager.Instance.SetAppSite(mAppSite); | ||
ConfigManager.Instance.Save(); | ||
} | ||
|
||
void OnGUI() { | ||
// Title | ||
GUILayout.BeginArea(new Rect(20, 20, position.width - 40, position.height - 40)); | ||
GUILayout.Label("Kii Game Cloud Setup", EditorStyles.boldLabel); | ||
GUILayout.Label("Setup your app parameters here to connect your game with Kii Game Cloud\nThese parameters can be obtained by creating an app at developer.kii.com"); | ||
GUILayout.Space(10); | ||
|
||
// App ID field | ||
GUILayout.Label("App Id", EditorStyles.boldLabel); | ||
//GUILayout.Label("App Id description"); | ||
mAppId = EditorGUILayout.TextField("Enter your App Id", mAppId); | ||
GUILayout.Space(10); | ||
|
||
// App Key field | ||
GUILayout.Label("App Key", EditorStyles.boldLabel); | ||
//GUILayout.Label("App Key description"); | ||
mAppKey = EditorGUILayout.TextField("Enter your App Key", mAppKey); | ||
GUILayout.Space(10); | ||
|
||
// Site combo | ||
GUILayout.Label("Site", EditorStyles.boldLabel); | ||
GUILayout.Label("Location of the game backend for this app"); | ||
index = EditorGUILayout.Popup(index, options); | ||
GUILayout.Space(10); | ||
|
||
// Setup button | ||
if (GUILayout.Button("Save")) { | ||
DoSetup(); | ||
} | ||
GUILayout.EndArea(); | ||
} | ||
|
||
void DoSetup() { | ||
|
||
Save(); | ||
|
||
if (!IsValidAppId(mAppId)) { | ||
Alert("Malformed App Id"); | ||
return; | ||
} | ||
if (!IsValidAppKey(mAppKey)) { | ||
Alert("Malformed App Key"); | ||
return; | ||
} | ||
|
||
ConfigManager.Instance.Save(); | ||
AssetDatabase.Refresh(); | ||
Alert("Success", "Setup Complete"); | ||
Close(); | ||
} | ||
|
||
bool IsValidAppId (string mAppId) | ||
{ | ||
return mAppId.Length == 8; | ||
} | ||
|
||
bool IsValidAppKey (string mAppKey) | ||
{ | ||
return mAppKey.Length == 32; | ||
} | ||
|
||
private void Alert(string s) { | ||
Alert("Error", s); | ||
} | ||
|
||
private void Alert(string title, string s) { | ||
EditorUtility.DisplayDialog(title, s, "Ok"); | ||
} | ||
|
||
private string IndexToSite (int index) | ||
{ | ||
switch (index) | ||
{ | ||
case 0: | ||
return "US"; | ||
case 1: | ||
return "JP"; | ||
case 2: | ||
return "CN"; | ||
default: | ||
return "US"; | ||
} | ||
} | ||
|
||
private int SiteToIndex (string site) | ||
{ | ||
if(site.Equals("US")) | ||
return 0; | ||
if(site.Equals("JP")) | ||
return 1; | ||
if(site.Equals("CN")) | ||
return 2; | ||
return 0; | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.