Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
neogeek committed Mar 29, 2021
0 parents commit 59598fc
Show file tree
Hide file tree
Showing 19 changed files with 436 additions and 0 deletions.
18 changes: 18 additions & 0 deletions CandyCoded.AppSettings.asmdef
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
}
7 changes: 7 additions & 0 deletions CandyCoded.AppSettings.asmdef.meta

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

21 changes: 21 additions & 0 deletions LICENSE
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.
7 changes: 7 additions & 0 deletions LICENSE.meta

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

8 changes: 8 additions & 0 deletions Plugins.meta

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

8 changes: 8 additions & 0 deletions Plugins/iOS.meta

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

28 changes: 28 additions & 0 deletions Plugins/iOS/AppSettings.cs
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);

}

}
11 changes: 11 additions & 0 deletions Plugins/iOS/AppSettings.cs.meta

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

68 changes: 68 additions & 0 deletions Plugins/iOS/AppSettings.mm
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;

}

}
37 changes: 37 additions & 0 deletions Plugins/iOS/AppSettings.mm.meta

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

16 changes: 16 additions & 0 deletions Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef
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
}
7 changes: 7 additions & 0 deletions Plugins/iOS/CandyCoded.AppSettings.iOS.asmdef.meta

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

76 changes: 76 additions & 0 deletions README.md
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"));

}

}
```
7 changes: 7 additions & 0 deletions README.md.meta

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

8 changes: 8 additions & 0 deletions Scripts.meta

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

Loading

0 comments on commit 59598fc

Please sign in to comment.