Skip to content

Commit

Permalink
Added flag to async/login registration. Added Kii config from editor
Browse files Browse the repository at this point in the history
  • Loading branch information
germanviscuso committed Mar 12, 2014
1 parent cb5a59e commit 8ca0d0e
Show file tree
Hide file tree
Showing 19 changed files with 455 additions and 69 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Temp/
Obj/
UnityGenerated/
Library/
Assets/AssetStoreTools*
Assets/Plugins/KiiConfig.txt*

# ===================================== #
# Visual Studio / MonoDevelop generated #
Expand Down
119 changes: 119 additions & 0 deletions Assets/Editor/ConfigManager.cs
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;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 128 additions & 0 deletions Assets/Editor/SetupUI.cs
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;
}

}
8 changes: 8 additions & 0 deletions Assets/Editor/SetupUI.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Plugins/JsonOrg.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed Assets/Plugins/KiiAnalyticsSDK.dll
Binary file not shown.
7 changes: 0 additions & 7 deletions Assets/Plugins/KiiAnalyticsSDK.dll.meta

This file was deleted.

Loading

0 comments on commit 8ca0d0e

Please sign in to comment.