diff --git a/.travis.yml b/.travis.yml index af000e4..91adaaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: csharp +mono: alpha dist: trusty sudo: required env: global: - - iOS_SDK="v1.0.0" + - iOS_SDK="v1.0.1" - android_SDK="" branches: only: diff --git a/Assets/Zapic/Editor/iOSBuildSettings.cs b/Assets/Zapic/Editor/iOSBuildSettings.cs index 5a85cc6..ed46e9f 100644 --- a/Assets/Zapic/Editor/iOSBuildSettings.cs +++ b/Assets/Zapic/Editor/iOSBuildSettings.cs @@ -3,85 +3,197 @@ using UnityEditor.Callbacks; using System.Collections; using System.Text.RegularExpressions; +using System.Reflection; #if UNITY_IOS using UnityEditor.iOS.Xcode; +using UnityEditor.iOS.Xcode.Extensions; #endif using System.IO; -public class iOSBuildSettings +namespace Zapic { - [PostProcessBuild] - public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject) + public class iOSBuildSettings { + [PostProcessBuild] + public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject) + { #if UNITY_IOS - ConfigureXcodeSettings(buildTarget, pathToBuiltProject); - ConfigureXcodePlist(buildTarget, pathToBuiltProject); + ConfigureXcodeSettings(buildTarget, pathToBuiltProject); + ConfigureXcodePlist(buildTarget, pathToBuiltProject); #endif - } + } #if UNITY_IOS - private static void ConfigureXcodeSettings(BuildTarget buildTarget, string pathToBuiltProject) - { - if (buildTarget == BuildTarget.iOS) + private static void ConfigureXcodeSettings(BuildTarget buildTarget, string pathToBuiltProject) { + if (buildTarget != BuildTarget.iOS) + return; + Debug.Log("Running Zapic Xcode Scripts"); - string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; + string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);// pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; + //Find and load the xcode project var proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); - string targetGuid = proj.TargetGuidByName("Unity-iPhone"); + //Find the unity target + string targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); + //Force swift to be included Debug.Log("Zapic: Including Swift Libraries"); proj.SetBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES"); + //Include the frameworks directory in search path to find Zapic.framework Debug.Log("Zapic: Setting search path"); proj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks"); - //Find the existing framework id + //Find the id for Zapic.framework fild var frameworkId = proj.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/Zapic.framework"); - //Try lowercase - if(string.IsNullOrEmpty(frameworkId)){ - frameworkId = proj.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/zapic.framework"); - } - if (string.IsNullOrEmpty(frameworkId)) { Debug.LogError("Zapic: Unable to find iOS framework"); } + //Get or Add a copy files build phase Debug.Log("Zapic:Adding embedded frameworks"); - string embedPhase = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10"); + + string embedPhase = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Zapic Framework", "", "10"); proj.AddFileToBuildSection(targetGuid, embedPhase, frameworkId); - // Apply settings - File.WriteAllText(projPath, proj.WriteToString()); + const string ScriptName = "Strip Fat Library"; + + var scriptId = proj.ShellScriptByName(targetGuid, ScriptName); + + if (string.IsNullOrEmpty(scriptId)) + proj.AppendShellScriptBuildPhase(targetGuid, ScriptName, "/bin/sh", StripArchScript()); + + + //Gets the entire project as a string + string contents = proj.WriteToString(); + + //Enable CodeSignOnCopy for the framework + contents = Regex.Replace(contents, + "(?<=Embed Frameworks)(?:.*)(\\/\\* Zapic\\.framework \\*\\/)(?=; };)", + m => m.Value.Replace("/* Zapic.framework */", + "/* Zapic.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }")); + + //Save the project file + File.WriteAllText(projPath, contents); Debug.Log("Zapic:Done configuring xcode settings"); } + + private static void ConfigureXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) + { + if (buildTarget != BuildTarget.iOS) + return; + + Debug.Log("Zapic:Configuring plist"); + + // Samlpe of editing Info.plist + var plistPath = Path.Combine(pathToBuiltProject, "Info.plist"); + var plist = new PlistDocument(); + plist.ReadFromFile(plistPath); + + // Add string setting + plist.root.SetString("NSContactsUsageDescription", "We'll use your Contacts to find people you know on Zapic."); + plist.root.SetString("NSPhotoLibraryUsageDescription", "Zapic will only use the Photos you select."); + + // Apply editing settings to Info.plist + plist.WriteToFile(plistPath); + + Debug.Log("Zapic:Done configuring plist"); + } + + private static string StripArchScript() + { + return @" +echo ""Target architectures: $ARCHS"" + +APP_PATH=""${TARGET_BUILD_DIR}/${WRAPPER_NAME}"" + +find ""$APP_PATH"" -name '*.framework' -type d | while read -r FRAMEWORK +do +FRAMEWORK_EXECUTABLE_NAME=$(defaults read ""$FRAMEWORK/Info.plist"" CFBundleExecutable) +FRAMEWORK_EXECUTABLE_PATH=""$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"" +echo ""Executable is $FRAMEWORK_EXECUTABLE_PATH"" +echo $(lipo -info ""$FRAMEWORK_EXECUTABLE_PATH"") + +FRAMEWORK_TMP_PATH=""$FRAMEWORK_EXECUTABLE_PATH-tmp"" + +# remove simulator's archs if location is not simulator's directory +case ""${TARGET_BUILD_DIR}"" in +*""iphonesimulator"") +echo ""No need to remove archs"" +;; +*) +if $(lipo ""$FRAMEWORK_EXECUTABLE_PATH"" -verify_arch ""i386"") ; then +lipo -output ""$FRAMEWORK_TMP_PATH"" -remove ""i386"" ""$FRAMEWORK_EXECUTABLE_PATH"" +echo ""i386 architecture removed"" +rm ""$FRAMEWORK_EXECUTABLE_PATH"" +mv ""$FRAMEWORK_TMP_PATH"" ""$FRAMEWORK_EXECUTABLE_PATH"" +fi +if $(lipo ""$FRAMEWORK_EXECUTABLE_PATH"" -verify_arch ""x86_64"") ; then +lipo -output ""$FRAMEWORK_TMP_PATH"" -remove ""x86_64"" ""$FRAMEWORK_EXECUTABLE_PATH"" +echo ""x86_64 architecture removed"" +rm ""$FRAMEWORK_EXECUTABLE_PATH"" +mv ""$FRAMEWORK_TMP_PATH"" ""$FRAMEWORK_EXECUTABLE_PATH"" +fi +;; +esac + +echo ""Completed for executable $FRAMEWORK_EXECUTABLE_PATH"" +echo $(lipo -info ""$FRAMEWORK_EXECUTABLE_PATH"") + +done + "; + } + +#endif + } - private static void ConfigureXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) + internal static class PBXExtensions { - Debug.Log("Zapic:Configuring plist"); + /// + /// This is a hack to access the internal method. Replace this one unity makes it public + /// + /// + /// + /// + /// + /// + public static void AppendShellScriptBuildPhase(this PBXProject project, string targetGuid, string name, string shellPath, string shellScript) + { + Debug.Log("Zapic: Adding Shell script"); - // Samlpe of editing Info.plist - var plistPath = Path.Combine(pathToBuiltProject, "Info.plist"); - var plist = new PlistDocument(); - plist.ReadFromFile(plistPath); + MethodInfo dynMethod = project.GetType().GetMethod( + "AppendShellScriptBuildPhase", + BindingFlags.NonPublic | BindingFlags.Instance, + null, + CallingConventions.Any, + new System.Type[] { typeof(string), typeof(string), typeof(string), typeof(string) }, + null); - // Add string setting - plist.root.SetString("NSContactsUsageDescription", "We'll use your Contacts to find people you know on Zapic."); - plist.root.SetString("NSPhotoLibraryUsageDescription", "Zapic will only use the Photos you select."); + dynMethod.Invoke(project, new object[] { targetGuid, name, shellPath, shellScript }); + } - // Apply editing settings to Info.plist - plist.WriteToFile(plistPath); + public static string ShellScriptByName(this PBXProject project, string targetGuid, string name) + { + Debug.Log("Zapic: Getting Shell script"); - Debug.Log("Zapic:Done configuring plist"); - } + MethodInfo dynMethod = project.GetType().GetMethod( + "ShellScriptByName", + BindingFlags.NonPublic | BindingFlags.Instance); -#endif + var result = dynMethod.Invoke(project, new object[] { targetGuid, name }); + + return result as string; + } + } } + + diff --git a/Assets/Zapic/Examples/ExampleStartup.cs b/Assets/Zapic/Examples/ExampleStartup.cs index 90861b8..5829015 100644 --- a/Assets/Zapic/Examples/ExampleStartup.cs +++ b/Assets/Zapic/Examples/ExampleStartup.cs @@ -6,7 +6,7 @@ public class ExampleStartup : MonoBehaviour { void Start() { - Zapic.Start("v0.1"); + Zapic.Start(); } void Update() @@ -17,7 +17,9 @@ void Update() { {"SCORE",22}, {"PARAM2","abc"}, - {"PARAM3",true} + {"PARAM3",true}, + {"PARAM4","\"blab"}, + {"PAR\"AM5","\"blab"} }; Zapic.SubmitEvent(p); diff --git a/Assets/Zapic/IZapicInterface.cs b/Assets/Zapic/IZapicInterface.cs new file mode 100644 index 0000000..d33e087 --- /dev/null +++ b/Assets/Zapic/IZapicInterface.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; + +namespace ZapicSDK +{ + internal interface IZapicInterface + { + /// + /// Starts zapic. This should be called + /// as soon as possible during app startup. + /// + void Start(); + + /// + /// Shows the given zapic window + /// + /// View to show. + void Show(Views view); + + /// + /// Gets the current players unique id. + /// + /// The unique id. + string PlayerId(); + + /// + /// Submit a new in-game event to zapic. + /// + /// Collection of parameter names and associate values (numeric, string, bool) + void SubmitEvent(Dictionary param); + } +} \ No newline at end of file diff --git a/Assets/Zapic/MiniJSON.cs b/Assets/Zapic/MiniJSON.cs new file mode 100644 index 0000000..3032462 --- /dev/null +++ b/Assets/Zapic/MiniJSON.cs @@ -0,0 +1,632 @@ +/* + * Copyright (c) 2013 Calvin Rien + * + * Based on the JSON parser by Patrick van Bergen + * http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html + * + * Simplified it so that it doesn't throw exceptions + * and can be used in Unity iPhone with maximum code stripping. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace MiniJSON +{ + // Example usage: + // + // using UnityEngine; + // using System.Collections; + // using System.Collections.Generic; + // using MiniJSON; + // + // public class MiniJSONTest : MonoBehaviour { + // void Start () { + // var jsonString = "{ \"array\": [1.44,2,3], " + + // "\"object\": {\"key1\":\"value1\", \"key2\":256}, " + + // "\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " + + // "\"unicode\": \"\\u3041 Men\u00fa sesi\u00f3n\", " + + // "\"int\": 65536, " + + // "\"float\": 3.1415926, " + + // "\"bool\": true, " + + // "\"null\": null }"; + // + // var dict = Json.Deserialize(jsonString) as Dictionary; + // + // Debug.Log("deserialized: " + dict.GetType()); + // Debug.Log("dict['array'][0]: " + ((List) dict["array"])[0]); + // Debug.Log("dict['string']: " + (string) dict["string"]); + // Debug.Log("dict['float']: " + (double) dict["float"]); // floats come out as doubles + // Debug.Log("dict['int']: " + (long) dict["int"]); // ints come out as longs + // Debug.Log("dict['unicode']: " + (string) dict["unicode"]); + // + // var str = Json.Serialize(dict); + // + // Debug.Log("serialized: " + str); + // } + // } + + /// + /// This class encodes and decodes JSON strings. + /// Spec. details, see http://www.json.org/ + /// + /// JSON uses Arrays and Objects. These correspond here to the datatypes IList and IDictionary. + /// All numbers are parsed to doubles. + /// + public static class Json + { + /// + /// Parses the string json into a value + /// + /// A JSON string. + /// An List<object>, a Dictionary<string, object>, a double, an integer,a string, null, true, or false + public static object Deserialize(string json) + { + // save the string for debug information + if (json == null) + { + return null; + } + + return Parser.Parse(json); + } + + sealed class Parser : IDisposable + { + const string WORD_BREAK = "{}[],:\""; + + public static bool IsWordBreak(char c) + { + return Char.IsWhiteSpace(c) || WORD_BREAK.IndexOf(c) != -1; + } + + enum TOKEN + { + NONE, + CURLY_OPEN, + CURLY_CLOSE, + SQUARED_OPEN, + SQUARED_CLOSE, + COLON, + COMMA, + STRING, + NUMBER, + TRUE, + FALSE, + NULL + }; + + StringReader json; + + Parser(string jsonString) + { + json = new StringReader(jsonString); + } + + public static object Parse(string jsonString) + { + using (var instance = new Parser(jsonString)) + { + return instance.ParseValue(); + } + } + + public void Dispose() + { + json.Dispose(); + json = null; + } + + Dictionary ParseObject() + { + Dictionary table = new Dictionary(); + + // ditch opening brace + json.Read(); + + // { + while (true) + { + switch (NextToken) + { + case TOKEN.NONE: + return null; + case TOKEN.COMMA: + continue; + case TOKEN.CURLY_CLOSE: + return table; + default: + // name + string name = ParseString(); + if (name == null) + { + return null; + } + + // : + if (NextToken != TOKEN.COLON) + { + return null; + } + // ditch the colon + json.Read(); + + // value + table[name] = ParseValue(); + break; + } + } + } + + List ParseArray() + { + List array = new List(); + + // ditch opening bracket + json.Read(); + + // [ + var parsing = true; + while (parsing) + { + TOKEN nextToken = NextToken; + + switch (nextToken) + { + case TOKEN.NONE: + return null; + case TOKEN.COMMA: + continue; + case TOKEN.SQUARED_CLOSE: + parsing = false; + break; + default: + object value = ParseByToken(nextToken); + + array.Add(value); + break; + } + } + + return array; + } + + object ParseValue() + { + TOKEN nextToken = NextToken; + return ParseByToken(nextToken); + } + + object ParseByToken(TOKEN token) + { + switch (token) + { + case TOKEN.STRING: + return ParseString(); + case TOKEN.NUMBER: + return ParseNumber(); + case TOKEN.CURLY_OPEN: + return ParseObject(); + case TOKEN.SQUARED_OPEN: + return ParseArray(); + case TOKEN.TRUE: + return true; + case TOKEN.FALSE: + return false; + case TOKEN.NULL: + return null; + default: + return null; + } + } + + string ParseString() + { + StringBuilder s = new StringBuilder(); + char c; + + // ditch opening quote + json.Read(); + + bool parsing = true; + while (parsing) + { + + if (json.Peek() == -1) + { + parsing = false; + break; + } + + c = NextChar; + switch (c) + { + case '"': + parsing = false; + break; + case '\\': + if (json.Peek() == -1) + { + parsing = false; + break; + } + + c = NextChar; + switch (c) + { + case '"': + case '\\': + case '/': + s.Append(c); + break; + case 'b': + s.Append('\b'); + break; + case 'f': + s.Append('\f'); + break; + case 'n': + s.Append('\n'); + break; + case 'r': + s.Append('\r'); + break; + case 't': + s.Append('\t'); + break; + case 'u': + var hex = new char[4]; + + for (int i = 0; i < 4; i++) + { + hex[i] = NextChar; + } + + s.Append((char)Convert.ToInt32(new string(hex), 16)); + break; + } + break; + default: + s.Append(c); + break; + } + } + + return s.ToString(); + } + + object ParseNumber() + { + string number = NextWord; + + if (number.IndexOf('.') == -1) + { + long parsedInt; + Int64.TryParse(number, out parsedInt); + return parsedInt; + } + + double parsedDouble; + Double.TryParse(number, out parsedDouble); + return parsedDouble; + } + + void EatWhitespace() + { + while (Char.IsWhiteSpace(PeekChar)) + { + json.Read(); + + if (json.Peek() == -1) + { + break; + } + } + } + + char PeekChar + { + get + { + return Convert.ToChar(json.Peek()); + } + } + + char NextChar + { + get + { + return Convert.ToChar(json.Read()); + } + } + + string NextWord + { + get + { + StringBuilder word = new StringBuilder(); + + while (!IsWordBreak(PeekChar)) + { + word.Append(NextChar); + + if (json.Peek() == -1) + { + break; + } + } + + return word.ToString(); + } + } + + TOKEN NextToken + { + get + { + EatWhitespace(); + + if (json.Peek() == -1) + { + return TOKEN.NONE; + } + + switch (PeekChar) + { + case '{': + return TOKEN.CURLY_OPEN; + case '}': + json.Read(); + return TOKEN.CURLY_CLOSE; + case '[': + return TOKEN.SQUARED_OPEN; + case ']': + json.Read(); + return TOKEN.SQUARED_CLOSE; + case ',': + json.Read(); + return TOKEN.COMMA; + case '"': + return TOKEN.STRING; + case ':': + return TOKEN.COLON; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '-': + return TOKEN.NUMBER; + } + + switch (NextWord) + { + case "false": + return TOKEN.FALSE; + case "true": + return TOKEN.TRUE; + case "null": + return TOKEN.NULL; + } + + return TOKEN.NONE; + } + } + } + + /// + /// Converts a IDictionary / IList object or a simple type (string, int, etc.) into a JSON string + /// + /// A Dictionary<string, object> / List<object> + /// A JSON encoded string, or null if object 'json' is not serializable + public static string Serialize(object obj) + { + return Serializer.Serialize(obj); + } + + sealed class Serializer + { + StringBuilder builder; + + Serializer() + { + builder = new StringBuilder(); + } + + public static string Serialize(object obj) + { + var instance = new Serializer(); + + instance.SerializeValue(obj); + + return instance.builder.ToString(); + } + + void SerializeValue(object value) + { + IList asList; + IDictionary asDict; + string asStr; + + if (value == null) + { + builder.Append("null"); + } + else if ((asStr = value as string) != null) + { + SerializeString(asStr); + } + else if (value is bool) + { + builder.Append((bool)value ? "true" : "false"); + } + else if ((asList = value as IList) != null) + { + SerializeArray(asList); + } + else if ((asDict = value as IDictionary) != null) + { + SerializeObject(asDict); + } + else if (value is char) + { + SerializeString(new string((char)value, 1)); + } + else + { + SerializeOther(value); + } + } + + void SerializeObject(IDictionary obj) + { + bool first = true; + + builder.Append('{'); + + foreach (object e in obj.Keys) + { + if (!first) + { + builder.Append(','); + } + + SerializeString(e.ToString()); + builder.Append(':'); + + SerializeValue(obj[e]); + + first = false; + } + + builder.Append('}'); + } + + void SerializeArray(IList anArray) + { + builder.Append('['); + + bool first = true; + + foreach (object obj in anArray) + { + if (!first) + { + builder.Append(','); + } + + SerializeValue(obj); + + first = false; + } + + builder.Append(']'); + } + + void SerializeString(string str) + { + builder.Append('\"'); + + char[] charArray = str.ToCharArray(); + foreach (var c in charArray) + { + switch (c) + { + case '"': + builder.Append("\\\""); + break; + case '\\': + builder.Append("\\\\"); + break; + case '\b': + builder.Append("\\b"); + break; + case '\f': + builder.Append("\\f"); + break; + case '\n': + builder.Append("\\n"); + break; + case '\r': + builder.Append("\\r"); + break; + case '\t': + builder.Append("\\t"); + break; + default: + int codepoint = Convert.ToInt32(c); + if ((codepoint >= 32) && (codepoint <= 126)) + { + builder.Append(c); + } + else + { + builder.Append("\\u"); + builder.Append(codepoint.ToString("x4")); + } + break; + } + } + + builder.Append('\"'); + } + + void SerializeOther(object value) + { + // NOTE: decimals lose precision during serialization. + // They always have, I'm just letting you know. + // Previously floats and doubles lost precision too. + if (value is float) + { + builder.Append(((float)value).ToString("R")); + } + else if (value is int + || value is uint + || value is long + || value is sbyte + || value is byte + || value is short + || value is ushort + || value is ulong) + { + builder.Append(value); + } + else if (value is double + || value is decimal) + { + builder.Append(Convert.ToDouble(value).ToString("R")); + } + else + { + SerializeString(value.ToString()); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Zapic/MiniJSON.cs.meta b/Assets/Zapic/MiniJSON.cs.meta new file mode 100644 index 0000000..97cdf3b --- /dev/null +++ b/Assets/Zapic/MiniJSON.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 64195a9a2c80c4442bca8d3d1107db20 +timeCreated: 1517524241 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Zapic/Zapic.cs b/Assets/Zapic/Zapic.cs index 3f76b29..e37d1f5 100644 --- a/Assets/Zapic/Zapic.cs +++ b/Assets/Zapic/Zapic.cs @@ -25,10 +25,9 @@ static Zapic() /// Starts zapic. This should be called /// as soon as possible during app startup. /// - /// App version id. - public static void Start(string version) + public static void Start() { - _interface.Start(version); + _interface.Start(); } /// @@ -44,7 +43,7 @@ public static void Show(Views view) /// Gets the current players unique id. /// /// The unique id. - public static Guid? PlayerId() + public static string PlayerId() { return _interface.PlayerId(); } diff --git a/Assets/Zapic/ZapicEditorInterface.cs b/Assets/Zapic/ZapicEditorInterface.cs new file mode 100644 index 0000000..6e6f4d7 --- /dev/null +++ b/Assets/Zapic/ZapicEditorInterface.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace ZapicSDK +{ + internal sealed class ZapicEditorInterface : IZapicInterface + { + public void Start() + { + Debug.LogFormat("Zapic:Start"); + } + + public void Show(Views view) + { + Debug.LogFormat("Zapic:Show {0}", view); + } + + public void SubmitEvent(Dictionary param) + { + var json = MiniJSON.Json.Serialize(param); + Debug.LogFormat("Zapic: SubmitEvent: {0}", json); + } + + public string PlayerId() + { + Debug.LogFormat("Zapic:GetPlayerId"); + return "0000000-0000-0000-0000-000000000000"; + } + } +} \ No newline at end of file diff --git a/Assets/Zapic/ZapicInterface.cs b/Assets/Zapic/ZapicInterface.cs deleted file mode 100644 index dc60885..0000000 --- a/Assets/Zapic/ZapicInterface.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using UnityEngine; - -namespace ZapicSDK -{ - internal interface IZapicInterface - { - /// - /// Starts zapic. This should be called - /// as soon as possible during app startup. - /// - /// App version id. - void Start(string version); - - /// - /// Shows the given zapic window - /// - /// View to show. - void Show(Views view); - - /// - /// Gets the current players unique id. - /// - /// The unique id. - Guid? PlayerId(); - - /// - /// Submit a new in-game event to zapic. - /// - /// Collection of parameter names and associate values (numeric, string, bool) - void SubmitEvent(Dictionary param); - } - - internal sealed class ZapicEditorInterface : IZapicInterface - { - public void Start(string version) - { - LogZapicCall("Start"); - } - - public void Show(Views view) - { - LogZapicCall("Show"); - } - - public void SubmitEvent(Dictionary param) - { - LogZapicCall("SubmitEvent"); - } - - public Guid? PlayerId() - { - LogZapicCall("GetPlayerId"); - return Guid.Empty; - } - - private static void LogZapicCall(string method) - { - Debug.LogFormat("Zapic: Called {0}", method); - } - - } - - internal sealed class ZapiciOSInterface : IZapicInterface - { - #region DLLImports - - [DllImport("__Internal")] - private static extern void z_start(string version); - - [DllImport("__Internal")] - private static extern void z_show(string viewName); - - [DllImport("__Internal")] - private static extern void z_submitEventWithParams(string eventJson); - - [DllImport("__Internal")] - private static extern string z_playerId(); - - #endregion - - /// - /// Starts zapic. This should be called - /// as soon as possible during app startup. - /// - /// App version id. - public void Start(string version) - { - z_start(version); - } - - /// - /// Shows the given zapic window - /// - /// View to show. - public void Show(Views view) - { - z_show(view.ToString().ToLower()); - } - - /// - /// Gets the current players unique id. - /// - /// The unique id. - public Guid? PlayerId() - { - var val = z_playerId(); - - if (val == null) - return null; - - var id = new Guid(val); - - return id; - } - - /// - /// Submit a new in-game event to zapic. - /// - /// Collection of parameter names and associate values (numeric, string, bool) - public void SubmitEvent(Dictionary param) - { - var json = JsonUtility.ToJson(param); - - z_submitEventWithParams(json); - } - } -} \ No newline at end of file diff --git a/Assets/Zapic/ZapiciOSInterface.cs b/Assets/Zapic/ZapiciOSInterface.cs new file mode 100644 index 0000000..b7c19d2 --- /dev/null +++ b/Assets/Zapic/ZapiciOSInterface.cs @@ -0,0 +1,63 @@ +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace ZapicSDK +{ + internal sealed class ZapiciOSInterface : IZapicInterface + { + #region DLLImports + + [DllImport("__Internal")] + private static extern void z_start(); + + [DllImport("__Internal")] + private static extern void z_show(string viewName); + + [DllImport("__Internal")] + private static extern void z_submitEventWithParams(string eventJson); + + [DllImport("__Internal")] + private static extern string z_playerId(); + + #endregion + + /// + /// Starts zapic. This should be called + /// as soon as possible during app startup. + /// + /// App version id. + public void Start() + { + z_start(); + } + + /// + /// Shows the given zapic window + /// + /// View to show. + public void Show(Views view) + { + z_show(view.ToString().ToLower()); + } + + /// + /// Gets the current players unique id. + /// + /// The unique id. + public string PlayerId() + { + return z_playerId(); + } + + /// + /// Submit a new in-game event to zapic. + /// + /// Collection of parameter names and associate values (numeric, string, bool) + public void SubmitEvent(Dictionary param) + { + var json = MiniJSON.Json.Serialize(param); + + z_submitEventWithParams(json); + } + } +} \ No newline at end of file diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index ec658ca..96a9143 100644 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ diff --git a/UnityPackageManager/manifest.json b/UnityPackageManager/manifest.json new file mode 100644 index 0000000..526aca6 --- /dev/null +++ b/UnityPackageManager/manifest.json @@ -0,0 +1,4 @@ +{ + "dependencies": { + } +}