From 59598fc7fd407f5cf096f7d0eeef563bc86616c7 Mon Sep 17 00:00:00 2001 From: Scott Doxey Date: Mon, 29 Mar 2021 02:31:47 -0400 Subject: [PATCH] Initial commit. --- CandyCoded.AppSettings.asmdef | 18 +++++ CandyCoded.AppSettings.asmdef.meta | 7 ++ LICENSE | 21 +++++ LICENSE.meta | 7 ++ Plugins.meta | 8 ++ Plugins/iOS.meta | 8 ++ Plugins/iOS/AppSettings.cs | 28 +++++++ Plugins/iOS/AppSettings.cs.meta | 11 +++ Plugins/iOS/AppSettings.mm | 68 +++++++++++++++++ Plugins/iOS/AppSettings.mm.meta | 37 +++++++++ Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef | 16 ++++ .../CandyCoded.AppSettings.iOS.asmdef.meta | 7 ++ README.md | 76 +++++++++++++++++++ README.md.meta | 7 ++ Scripts.meta | 8 ++ Scripts/AppSettings.cs | 66 ++++++++++++++++ Scripts/AppSettings.cs.meta | 11 +++ package.json | 25 ++++++ package.json.meta | 7 ++ 19 files changed, 436 insertions(+) create mode 100644 CandyCoded.AppSettings.asmdef create mode 100644 CandyCoded.AppSettings.asmdef.meta create mode 100644 LICENSE create mode 100644 LICENSE.meta create mode 100644 Plugins.meta create mode 100644 Plugins/iOS.meta create mode 100644 Plugins/iOS/AppSettings.cs create mode 100644 Plugins/iOS/AppSettings.cs.meta create mode 100644 Plugins/iOS/AppSettings.mm create mode 100644 Plugins/iOS/AppSettings.mm.meta create mode 100644 Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef create mode 100644 Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef.meta create mode 100644 README.md create mode 100644 README.md.meta create mode 100644 Scripts.meta create mode 100644 Scripts/AppSettings.cs create mode 100644 Scripts/AppSettings.cs.meta create mode 100644 package.json create mode 100644 package.json.meta diff --git a/CandyCoded.AppSettings.asmdef b/CandyCoded.AppSettings.asmdef new file mode 100644 index 0000000..395009a --- /dev/null +++ b/CandyCoded.AppSettings.asmdef @@ -0,0 +1,18 @@ +{ + "name": "CandyCoded.AppSettings", + "references": [ + "CandyCoded.AppSettings.iOS" + ], + "includePlatforms": [ + "Editor", + "iOS" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} diff --git a/CandyCoded.AppSettings.asmdef.meta b/CandyCoded.AppSettings.asmdef.meta new file mode 100644 index 0000000..7bb7fc9 --- /dev/null +++ b/CandyCoded.AppSettings.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: b78bcedc04435490b8a495f12e15c9b7 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9fb0f11 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2021 Scott Doxey + +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. diff --git a/LICENSE.meta b/LICENSE.meta new file mode 100644 index 0000000..4e4957f --- /dev/null +++ b/LICENSE.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: aaa9045d726d643419c1e28442a45479 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins.meta b/Plugins.meta new file mode 100644 index 0000000..44653ad --- /dev/null +++ b/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e071a4510be994df3bb54e3c53b1a14d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS.meta b/Plugins/iOS.meta new file mode 100644 index 0000000..ec2ae14 --- /dev/null +++ b/Plugins/iOS.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5c1810977256c4687a0c254a195d5afb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/AppSettings.cs b/Plugins/iOS/AppSettings.cs new file mode 100644 index 0000000..c166f6f --- /dev/null +++ b/Plugins/iOS/AppSettings.cs @@ -0,0 +1,28 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +using System.Runtime.InteropServices; + +namespace CandyCoded.AppSettings.iOS +{ + + public static class AppSettings + { + + [DllImport("__Internal")] + public static extern bool GetBoolean(string key); + + [DllImport("__Internal")] + public static extern double GetDouble(string key); + + [DllImport("__Internal")] + public static extern float GetFloat(string key); + + [DllImport("__Internal")] + public static extern int GetInteger(string key); + + [DllImport("__Internal")] + public static extern string GetString(string key); + + } + +} diff --git a/Plugins/iOS/AppSettings.cs.meta b/Plugins/iOS/AppSettings.cs.meta new file mode 100644 index 0000000..e5d0721 --- /dev/null +++ b/Plugins/iOS/AppSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f1a555faa35924105a981a429d8b2666 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/AppSettings.mm b/Plugins/iOS/AppSettings.mm new file mode 100644 index 0000000..8767b17 --- /dev/null +++ b/Plugins/iOS/AppSettings.mm @@ -0,0 +1,68 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +#import + +extern "C" +{ + + const bool GetBoolean(const char* key) { + + NSString* keyString = [NSString stringWithUTF8String: key]; + + const bool value = [[NSUserDefaults standardUserDefaults] boolForKey: keyString]; + + return value; + + } + + const double GetDouble(const char* key) { + + NSString* keyString = [NSString stringWithUTF8String: key]; + + const double value = [[NSUserDefaults standardUserDefaults] doubleForKey: keyString]; + + return value; + + } + + const float GetFloat(const char* key) { + + NSString* keyString = [NSString stringWithUTF8String: key]; + + const float value = [[NSUserDefaults standardUserDefaults] floatForKey: keyString]; + + return value; + + } + + const int GetInteger(const char* key) { + + NSString* keyString = [NSString stringWithUTF8String: key]; + + const int value = (int)[[NSUserDefaults standardUserDefaults] integerForKey: keyString]; + + return value; + + } + + const char* GetString(const char* key) { + + NSString* keyString = [NSString stringWithUTF8String: key]; + + NSString* nsValue = [[NSUserDefaults standardUserDefaults] stringForKey: keyString]; + + if (nsValue) { + + char* value = (char*)malloc(nsValue.length + 1); + + strcpy(value, [nsValue UTF8String]); + + return value; + + } + + return NULL; + + } + +} diff --git a/Plugins/iOS/AppSettings.mm.meta b/Plugins/iOS/AppSettings.mm.meta new file mode 100644 index 0000000..4edc536 --- /dev/null +++ b/Plugins/iOS/AppSettings.mm.meta @@ -0,0 +1,37 @@ +fileFormatVersion: 2 +guid: f67cd6e9391ec4e068acac6c54087165 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + iPhone: iOS + second: + enabled: 1 + settings: {} + - first: + tvOS: tvOS + second: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef b/Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef new file mode 100644 index 0000000..a985cea --- /dev/null +++ b/Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef @@ -0,0 +1,16 @@ +{ + "name": "CandyCoded.AppSettings.iOS", + "references": [], + "includePlatforms": [ + "Editor", + "iOS" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} diff --git a/Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef.meta b/Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef.meta new file mode 100644 index 0000000..ade9944 --- /dev/null +++ b/Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e8d7d418e464d48bc8f4182fc6aeb1ed +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md new file mode 100644 index 0000000..af99fec --- /dev/null +++ b/README.md @@ -0,0 +1,76 @@ +# App Settings + +> ⚙️ Get app specific settings from the OS. + +[![npm](https://img.shields.io/npm/v/xyz.candycoded.appsettings)](https://www.npmjs.com/package/xyz.candycoded.appsettings) + +### Unity Package Manager + + + +#### Git + +```json +{ + "dependencies": { + "xyz.candycoded.appsettings": "https://github.com/CandyCoded/appsettings.git#v1.0.0", + ... + } +} +``` + +#### Scoped UPM Registry + +```json +{ + "dependencies": { + "xyz.candycoded.appsettings": "1.0.0", + ... + }, + "scopedRegistries": [ + { + "name": "candycoded", + "url": "https://registry.npmjs.com", + "scopes": ["xyz.candycoded"] + } + ] +} +``` + +## Usage + +### Create `Settings.bundle` in iOS project + +> Note: This will have to be done on each new build so safe the `.bundle` file somewhere outside the `Builds/` folder. + + + +1. Right-click on the project in the project navigator +1. Click **New File...** +1. Search for **Resources / Settings Bundle** +1. Click **Next** +1. Rename the file if necessary +1. Click **Create** +1. Click on the newly created **Settings.bundle/Root.plist** file in the project navigator +1. Make necessary changes + +### Reference the values from your app + +> Note: The key used is the field **Identifier** in the **Settings.bundle/Root.plist** file. + +```csharp +using CandyCoded.AppSettings; +using UnityEngine; + +public class TestAppSettings : MonoBehaviour +{ + + private void Start() + { + + Debug.Log(AppSettings.GetFloat("version")); + + } + +} +``` diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..c374cd2 --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: df8a9820503b846508051d5610653e5a +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts.meta b/Scripts.meta new file mode 100644 index 0000000..dd479c3 --- /dev/null +++ b/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6bd36c7b6c4e14608b0738f11fbb82f0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/AppSettings.cs b/Scripts/AppSettings.cs new file mode 100644 index 0000000..7d78ffc --- /dev/null +++ b/Scripts/AppSettings.cs @@ -0,0 +1,66 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace CandyCoded.AppSettings +{ + + public static class AppSettings + { + + public static bool GetBoolean(string key) + { + +#if UNITY_IOS && !UNITY_EDITOR + return iOS.AppSettings.GetBoolean(key); +#endif + + return false; + + } + + public static double GetDouble(string key) + { + +#if UNITY_IOS && !UNITY_EDITOR + return iOS.AppSettings.GetDouble(key); +#endif + + return 0; + + } + + public static float GetFloat(string key) + { + +#if UNITY_IOS && !UNITY_EDITOR + return iOS.AppSettings.GetFloat(key); +#endif + + return 0; + + } + + public static int GetInteger(string key) + { + +#if UNITY_IOS && !UNITY_EDITOR + return iOS.AppSettings.GetInteger(key); +#endif + + return 0; + + } + + public static string GetString(string key) + { + +#if UNITY_IOS && !UNITY_EDITOR + return iOS.AppSettings.GetString(key); +#endif + + return ""; + + } + + } + +} diff --git a/Scripts/AppSettings.cs.meta b/Scripts/AppSettings.cs.meta new file mode 100644 index 0000000..91aa518 --- /dev/null +++ b/Scripts/AppSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 946a8daa3646d4397bfd0b77c92fcedd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..a5df725 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "xyz.candycoded.appsettings", + "displayName": "App Settings", + "version": "1.0.0", + "unity": "2019.2", + "unityRelease": "0f1", + "description": "Get app specific settings from the OS.", + "license": "MIT", + "dependencies": { + }, + "keywords": [ + "ios", + "settings" + ], + "author": { + "name": "Scott Doxey", + "email": "hello@scottdoxey.com", + "homepage": "http://scottdoxey.com/" + }, + "homepage": "https://github.com/CandyCoded/AppSettings", + "repository": { + "type": "git", + "url": "git@github.com:CandyCoded/AppSettings.git" + } +} diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..4740f10 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 23b4baf3297b244c5a6ce4563125ec7c +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: