Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nicloay committed Nov 30, 2017
0 parents commit ebf1140
Show file tree
Hide file tree
Showing 177 changed files with 9,588 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Assets/Appirater.meta

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

38 changes: 38 additions & 0 deletions Assets/Appirater/Appirater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

namespace Appirater
{
public class Appirater
{

[DllImport("__Internal")]
private static extern void _Init(string appId, int daysUntilPrompt, int usesUntilPrompt,
int significantEventsUntilPrompt, int timeBeforeReminding, bool debug);


public static void Init(string appId, int daysUntilPrompt, int usesUntilPrompt,
int significantEventsUntilPrompt, int timeBeforeReminding, bool debug)
{
_Init(appId, daysUntilPrompt, usesUntilPrompt, significantEventsUntilPrompt, timeBeforeReminding, debug);
}

[DllImport("__Internal")]
private static extern void _DidSignificantEvent();

public static void DidSignificantEvent()
{
_DidSignificantEvent();
}

[DllImport("__Internal")]
private static extern void _AppGoesToBackground(bool idInBackground);

public void AppGoesToBackground(bool isInBackground)
{
AppGoesToBackground(isInBackground);
}
}
}
12 changes: 12 additions & 0 deletions Assets/Appirater/Appirater.cs.meta

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

9 changes: 9 additions & 0 deletions Assets/Appirater/NativeLocale.meta

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

9 changes: 9 additions & 0 deletions Assets/Appirater/NativeLocale/Editor.meta

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

80 changes: 80 additions & 0 deletions Assets/Appirater/NativeLocale/Editor/NativeLocale.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using ChillyRoom.UnityEditor.iOS.Xcode;

public class NativeLocale
{
public static void AddLocalizedStringsIOS(string projectPath, string localizedDirectoryPath)
{
DirectoryInfo dir = new DirectoryInfo(localizedDirectoryPath);
if(!dir.Exists)
return;

List<string> locales = new List<string>();
var localeDirs = dir.GetDirectories("*.lproj", SearchOption.TopDirectoryOnly);

foreach(var sub in localeDirs)
locales.Add(Path.GetFileNameWithoutExtension(sub.Name));

AddLocalizedStringsIOS(projectPath, localizedDirectoryPath, locales);
}

public static void AddLocalizedStringsIOS(string projectPath, string localizedDirectoryPath, List<string> validLocales)
{
string projPath = projectPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
PBXProject proj = new PBXProject();
proj.ReadFromFile(projPath);

foreach(var locale in validLocales)
{
// copy contents in the localization directory to project directory
string src = Path.Combine(localizedDirectoryPath, locale + ".lproj");
string dst = Path.Combine(projectPath, "Unity-iPhone/" + locale + ".lproj");
if (Directory.Exists(dst))
{
Directory.Delete(dst,true);
}
DirectoryCopy(src, dst);

string fileRelatvePath = string.Format("Unity-iPhone/{0}.lproj/AppiraterLocalizable.strings", locale);
proj.AddLocalization("InfoPlist.strings", locale, fileRelatvePath);
}

proj.WriteToFile(projPath);
}


private static void DirectoryCopy(string sourceDirName, string destDirName)
{
DirectoryInfo dir = new DirectoryInfo(sourceDirName);

if (!dir.Exists)
return;

if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}

FileInfo[] files = dir.GetFiles();

foreach (FileInfo file in files)
{
// skip unity meta files
if(file.FullName.EndsWith(".meta"))
continue;
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, false);
}

DirectoryInfo[] dirs = dir.GetDirectories();
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath);
}
}
}
12 changes: 12 additions & 0 deletions Assets/Appirater/NativeLocale/Editor/NativeLocale.cs.meta

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

51 changes: 51 additions & 0 deletions Assets/Appirater/NativeLocale/Editor/PostProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.IO;
using ChillyRoom.UnityEditor.iOS.Xcode;

public class PostProcess: MonoBehaviour
{
[PostProcessBuildAttribute(9999)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target == BuildTarget.iOS)
{
OnIOSBuild(target, path);
}
}

private static void OnIOSBuild(BuildTarget target, string path)
{
NativeLocale.AddLocalizedStringsIOS(path, Path.Combine(Application.dataPath, "Appirater/iOS"));
AddStoreKitFramework(path);
}

private const string SoreKitFramework = "StoreKit.framework";
private static void AddStoreKitFramework(string projectPath)
{

string projPath = projectPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
PBXProject proj = new PBXProject();
proj.ReadFromFile(projPath);

// if (!proj.ContainsFramework(proj.ProjectGuid(), SoreKitFramework))
// {
// proj.AddFrameworkToProject(proj.ProjectGuid(), SoreKitFramework, false);
// }


foreach (string targetName in new string[] {PBXProject.GetUnityTargetName(), PBXProject.GetUnityTestTargetName()})
{
string guid = proj.TargetGuidByName(targetName);
if (!proj.ContainsFramework(guid, SoreKitFramework))
{
proj.AddFrameworkToProject(guid, SoreKitFramework, false);
}
}



proj.WriteToFile(projPath);
}
}
12 changes: 12 additions & 0 deletions Assets/Appirater/NativeLocale/Editor/PostProcess.cs.meta

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

9 changes: 9 additions & 0 deletions Assets/Appirater/NativeLocale/Editor/Xcode.meta

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

Loading

0 comments on commit ebf1140

Please sign in to comment.