-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github: NicholasSheehan | ||
custom: https://www.paypal.me/NicholasSheehan |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.idea* | ||
*_ReSharper.Caches* | ||
[Tt]emp/ | ||
[Tt]emp.meta | ||
[Oo]bj/ | ||
[Oo]bj.meta | ||
[Bb]uild | ||
[Ll]ibrary/ |
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,52 @@ | ||
#if UNITY_ANDROID | ||
|
||
using UnityEngine; | ||
|
||
namespace UnityNative.Sharing | ||
{ | ||
public class AndroidUnityNativeSharingAdapter : IUnityNativeSharingAdapter | ||
{ | ||
/// <summary> | ||
/// Android package name and class | ||
/// </summary> | ||
private const string AndroidClass = "com.UnityNative.Sharing.UnityNativeSharingAdapter"; | ||
|
||
/// <summary> | ||
/// Android method name to call to share a screenshot with text | ||
/// </summary> | ||
private const string ShareScreenshotWithTextMethodName = "ShareScreenshotAndText"; | ||
|
||
/// <summary> | ||
/// Android method name to call to share text | ||
/// </summary> | ||
private const string ShareTextMethodName = "ShareText"; | ||
|
||
/// <summary> | ||
/// UnityNativeSharingAdapter.java | ||
/// </summary> | ||
private readonly AndroidJavaClass sharingJavaClass; | ||
|
||
public AndroidUnityNativeSharingAdapter() | ||
{ | ||
AndroidJNI.AttachCurrentThread(); | ||
|
||
sharingJavaClass = new AndroidJavaClass(AndroidClass); | ||
} | ||
|
||
public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With") | ||
{ | ||
AndroidJNI.AttachCurrentThread(); | ||
|
||
sharingJavaClass.CallStatic(ShareScreenshotWithTextMethodName, shareText, filePath, showShareDialogBox, shareDialogBoxText); | ||
} | ||
|
||
public void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With") | ||
{ | ||
AndroidJNI.AttachCurrentThread(); | ||
|
||
sharingJavaClass.CallStatic(ShareTextMethodName, shareText, showShareDialogBox, shareDialogBoxText); | ||
} | ||
} | ||
} | ||
|
||
#endif //UNITY_ANDROID |
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,8 @@ | ||
namespace UnityNative.Sharing | ||
{ | ||
public interface IUnityNativeSharingAdapter | ||
{ | ||
void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With"); | ||
void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With"); | ||
} | ||
} |
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,25 @@ | ||
#if UNITY_IOS | ||
|
||
namespace UnityNative.Sharing | ||
{ | ||
public class IosUnityNativeSharingAdapter : IUnityNativeSharingAdapter | ||
{ | ||
[System.Runtime.InteropServices.DllImport("__Internal")] | ||
private static extern void UnityNative_Sharing_ShareTextAndScreenshot(string shareText, string filePath); | ||
|
||
[System.Runtime.InteropServices.DllImport("__Internal")] | ||
private static extern void UnityNative_Sharing_ShareText(string shareText); | ||
|
||
public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With") | ||
{ | ||
UnityNative_Sharing_ShareTextAndScreenshot(shareText, filePath); | ||
} | ||
|
||
public void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With") | ||
{ | ||
UnityNative_Sharing_ShareText(shareText); | ||
} | ||
} | ||
} | ||
|
||
#endif //UNITY_IOS |
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,13 @@ | ||
namespace UnityNative.Sharing | ||
{ | ||
public class NullUnityNativeSharingAdapter : IUnityNativeSharingAdapter | ||
{ | ||
public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With") | ||
{ | ||
} | ||
|
||
public void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With") | ||
{ | ||
} | ||
} | ||
} |
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,11 @@ | ||
# Changelog | ||
All notable changes to this package will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
|
||
## [1.0.0] - 2020-04-13 | ||
### This is the first release of *Unity-Native-Sharing*. |
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,39 @@ | ||
# Reporting Issues | ||
**The issue tracker is not a support forum.** Unless you can provide precise *technical information* regarding an issue, you *should not post in it*. If you post support questions, generic messages to the developers or vague reports without technical details, they will be closed and locked. | ||
|
||
If you believe you have a valid issue report, please post text or screenshots of the issue, along with the version / commit, any error messages and reproduction steps. | ||
|
||
# Contributing | ||
Coding style is very important when making commits, just try to follow as many of them as possible. | ||
|
||
It's impossible for everyone to follow each rule perfectly, the rules are just a guide to help consistency and maintainability | ||
|
||
### Class Structure | ||
UnityNative projects are written with the [SOLID](https://en.wikipedia.org/wiki/SOLID) principle in mind. This also allows the projects to be used with [Inversion of Control](https://en.wikipedia.org/wiki/Inversion_of_control) | ||
|
||
TL;DR **ALL** objects should be stored as their interface implementation (`IUnityNativeSharingAdapter`) and not the concrete (`AndroidUnityNativeSharingAdapter`). Public variables should be defined in the interface as properties (`int i { get; }`) | ||
|
||
### Naming Rules | ||
* Scope: Explicit e.g. `private int i;` `internal int i;` `public int i;` | ||
* Functions: `PascalCase` | ||
* Variables: `PascalCase` for `public` and `camelCase` for everything else, including `const` | ||
* Classes: `PascalCase` | ||
* Namespaces: `UnityNative.PROJECT.SCOPE` e.g. `UnityNative.Sharing.Adapters` | ||
* Variable Ordering: Alphabetical | ||
* Method Ordering: Static Methods, Constructor, Instance Methods | ||
|
||
### Indentation/Whitespace Style | ||
Do not use tabs, use 4-spaces instead. | ||
|
||
### Comments | ||
Comment all public methods | ||
|
||
### Pull Requests | ||
Make each pull request as small and clean as possible, if a change in a class isn't needed for what is being worked on, remove it from the PR. | ||
|
||
The aim is to merge squash each commit into master, this allows the commits to be atomic and makes life a lot easier if a commit needs to be reverted | ||
|
||
Include as much detail in each commit, this should include a condensed description as the PR title, and include details in the PR message, when squashed, the commit title should be the PR title with a link to the PR e.g. #101 Fixed bug in XYZ | ||
|
||
### Releases | ||
Each release will have it's own branch and GitHub release, this allows the specific releases of the project to be pulled with Unity's Package Manager |
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,16 @@ | ||
{ | ||
"name": "UnityNative.Sharing.Editor", | ||
"references": [ | ||
"UnityNative.Sharing" | ||
], | ||
"optionalUnityReferences": [], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [] | ||
} |
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,9 @@ | ||
<dependencies> | ||
<androidPackages> | ||
<androidPackage spec="com.android.support:support-v4:26.1.0"> | ||
<repositories> | ||
<repository>https://maven.google.com</repository> | ||
</repositories> | ||
</androidPackage> | ||
</androidPackages> | ||
</dependencies> |
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,62 @@ | ||
#if UNITY_IOS | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEditor.Callbacks; | ||
using UnityEditor.iOS.Xcode; | ||
using UnityEngine; | ||
|
||
namespace UnityNative.Sharing.Editor | ||
{ | ||
internal static class UnityNativeSharing_iOSPlistKeys | ||
{ | ||
/// <summary> | ||
/// Keys to add to Info.plist for iOS, this stops the app from crashing when attempting to save screenshots to the library | ||
/// </summary> | ||
private static readonly Dictionary<string, string> infoPlistStringKeys = new Dictionary<string, string> | ||
{ | ||
{"NSPhotoLibraryUsageDescription", "This App Can Save Screenshots For Sharing"}, | ||
{"NSPhotoLibraryAddUsageDescription", "This App Can Save Screenshots To Your Photo Album For Sharing"}, | ||
}; | ||
|
||
[PostProcessBuild(0)] | ||
public static void EditXcodeProject(BuildTarget target, string pathToBuiltProject) | ||
{ | ||
if (target != BuildTarget.iOS) return; | ||
|
||
Edit_Plist(pathToBuiltProject); | ||
} | ||
|
||
/// <summary> | ||
/// Edits the Info.plist file and adds in a missing key | ||
/// </summary> | ||
/// <param name="pathToBuiltProject">Path to the build project</param> | ||
private static void Edit_Plist(string pathToBuiltProject) | ||
{ | ||
Debug.Log("Starting Editing of Info.plist"); | ||
|
||
var plistPath = pathToBuiltProject + "/Info.plist"; | ||
var plist = new PlistDocument(); | ||
plist.ReadFromString(File.ReadAllText(plistPath)); | ||
|
||
// Get root | ||
PlistElementDict rootDict = plist.root; | ||
|
||
// Add string keys | ||
foreach (var entry in infoPlistStringKeys) | ||
{ | ||
// Only add the key if needed, another plugin may have already set this | ||
if (rootDict.values.ContainsKey(entry.Key)) | ||
continue; | ||
|
||
rootDict.SetString(entry.Key, entry.Value); | ||
Debug.Log($"Added \"{entry.Key} = {entry.Value}\" to Info.plist"); | ||
} | ||
|
||
// Saves the plist file | ||
File.WriteAllText(plistPath, plist.WriteToString()); | ||
Debug.Log("Saving Edited Info.plist"); | ||
} | ||
} | ||
} | ||
#endif //UNITY_IOS |
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.