-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <Foundation/Foundation.h> | ||
|
||
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; | ||
|
||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "CandyCoded.AppSettings.iOS", | ||
"references": [], | ||
"includePlatforms": [ | ||
"Editor", | ||
"iOS" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
<https://docs.unity3d.com/Packages/[email protected]/manual/index.html> | ||
|
||
#### 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. | ||
<https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/UserDefaults/Preferences/Preferences.html> | ||
|
||
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")); | ||
|
||
} | ||
|
||
} | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.