-
Notifications
You must be signed in to change notification settings - Fork 254
/
FacebookBuild.cs
122 lines (107 loc) · 5.85 KB
/
FacebookBuild.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Facebook.
*
* As with any software that integrates with the Facebook platform, your use of
* this software is subject to the Facebook Developer Principles and Policies
* [http://developers.facebook.com/policy/]. This copyright 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.
*/
namespace Facebook.Unity.Editor
{
using System.Globalization;
using System.IO;
using UnityEditor;
using UnityEngine;
internal class FacebookBuild
{
private const string FacebookPath = "Assets/FacebookSDK/";
private const string SDKPath = "Assets/FacebookSDK/SDK/";
private const string ExamplesPath = "Assets/FacebookSDK/Examples/";
private const string PluginsPath = "Assets/FacebookSDK/Plugins/";
private const string StreamingAssetsPath = "Assets/StreamingAssets/";
private const string ExternalDependencyManagerPath = "Assets/ExternalDependencyManager/";
private const string EditorPath = "Assets/Editor/";
public enum Target
{
DEBUG,
RELEASE
}
private static string PackageName
{
get
{
return string.Format(
CultureInfo.InvariantCulture,
"facebook-unity-sdk-{0}.unitypackage",
FacebookSdkVersion.Build);
}
}
private static string OutputPath
{
get
{
DirectoryInfo projectRoot = Directory.GetParent(Directory.GetCurrentDirectory());
var outputDirectory = new DirectoryInfo(Path.Combine(projectRoot.FullName, "out"));
// Create the directory if it doesn't exist
outputDirectory.Create();
return Path.Combine(outputDirectory.FullName, FacebookBuild.PackageName);
}
}
// Exporting the *.unityPackage for Asset store
public static string ExportPackage()
{
Debug.Log("Exporting Facebook Unity Package...");
string path = OutputPath;
try
{
if (!File.Exists(Path.Combine(Application.dataPath, "Temp")))
{
AssetDatabase.CreateFolder("Assets", "Temp");
}
AssetDatabase.MoveAsset(SDKPath + "Resources/FacebookSettings.asset", "Assets/Temp/FacebookSettings.asset");
AssetDatabase.DeleteAsset(PluginsPath + "Android/AndroidManifest.xml");
AssetDatabase.DeleteAsset(PluginsPath + "Android/AndroidManifest.xml.meta");
string[] facebookFiles = (string[])Directory.GetFiles(FacebookPath, "*.*", SearchOption.TopDirectoryOnly);
string[] sdkFiles = (string[])Directory.GetFiles(SDKPath, "*.*", SearchOption.AllDirectories);
string[] exampleFiles = (string[])Directory.GetFiles(ExamplesPath, "*.*", SearchOption.AllDirectories);
string[] pluginsFiles = (string[])Directory.GetFiles(PluginsPath, "*.*", SearchOption.AllDirectories);
string[] streamingAssetsFiles = (string[])Directory.GetFiles(StreamingAssetsPath, "*.*", SearchOption.AllDirectories);
string[] externalDependencyManagerFiles = (string[])Directory.GetFiles(ExternalDependencyManagerPath, "*.*", SearchOption.AllDirectories);
string[] editorFiles = (string[])Directory.GetFiles(EditorPath, "*.*", SearchOption.AllDirectories);
string[] files = new string[facebookFiles.Length + sdkFiles.Length + exampleFiles.Length + pluginsFiles.Length + streamingAssetsFiles.Length + externalDependencyManagerFiles.Length + editorFiles.Length];
facebookFiles.CopyTo(files, 0);
sdkFiles.CopyTo(files, facebookFiles.Length);
exampleFiles.CopyTo(files, sdkFiles.Length + facebookFiles.Length);
pluginsFiles.CopyTo(files, sdkFiles.Length + facebookFiles.Length + exampleFiles.Length);
streamingAssetsFiles.CopyTo(files, sdkFiles.Length + facebookFiles.Length + exampleFiles.Length + pluginsFiles.Length);
externalDependencyManagerFiles.CopyTo(files, sdkFiles.Length + facebookFiles.Length + exampleFiles.Length + pluginsFiles.Length + streamingAssetsFiles.Length);
editorFiles.CopyTo(files, sdkFiles.Length + facebookFiles.Length + exampleFiles.Length + pluginsFiles.Length + streamingAssetsFiles.Length + externalDependencyManagerFiles.Length);
AssetDatabase.ExportPackage(
files,
path,
ExportPackageOptions.IncludeDependencies | ExportPackageOptions.Recurse);
}
finally
{
// Move files back no matter what
AssetDatabase.MoveAsset("Assets/Temp/FacebookSettings.asset", SDKPath + "Resources/FacebookSettings.asset");
AssetDatabase.DeleteAsset("Assets/Temp");
// regenerate the manifest
ManifestMod.GenerateManifest();
}
Debug.Log("Finished exporting!");
return path;
}
}
}