Skip to content

Commit 1da57ee

Browse files
JordiFBfacebook-github-bot
authored andcommitted
Fixed issue with Windows devices and build targets
Summary: Added a checker when the user launch the app in editor mode. This check will check the build target platform and set an internal variable with this information. This internal variable is used to launch Windows SDK only if is running on windows devices and build target is windows. Reviewed By: SergioGuerreroFB Differential Revision: D37859022 fbshipit-source-id: 4b549cbc44e0f5e6dc499fc96efb5c360317137b
1 parent e503505 commit 1da57ee

File tree

4 files changed

+85
-7
lines changed

4 files changed

+85
-7
lines changed

Facebook.Unity.Editor/Facebook.Unity.Editor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<Compile Include="iOS\PBX\Serializer.cs" />
6969
<Compile Include="iOS\PBX\Utils.cs" />
7070
<Compile Include="FacebookImporter.cs" />
71+
<Compile Include="FacebookPlayModeChanged.cs" />
7172
</ItemGroup>
7273
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
7374
<ItemGroup>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
5+
* copy, modify, and distribute this software in source code or binary form for use
6+
* in connection with the web services and APIs provided by Facebook.
7+
*
8+
* As with any software that integrates with the Facebook platform, your use of
9+
* this software is subject to the Facebook Developer Principles and Policies
10+
* [http://developers.facebook.com/policy/]. This copyright notice shall be
11+
* included in all copies or substantial portions of the software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
*/
20+
21+
namespace Facebook.Unity.Editor
22+
{
23+
using Facebook.Unity.Settings;
24+
using UnityEditor;
25+
using System;
26+
27+
[InitializeOnLoadAttribute]
28+
public static class PlayModeStateChanged
29+
{
30+
static PlayModeStateChanged()
31+
{
32+
EditorApplication.playModeStateChanged += OnPlayModeStateChange;
33+
}
34+
35+
private static void OnPlayModeStateChange(PlayModeStateChange state)
36+
{
37+
if (state == PlayModeStateChange.EnteredPlayMode)
38+
{
39+
FacebookSettings.EditorBuildTarget = (FacebookSettings.BuildTarget) Enum.Parse(typeof(FacebookSettings.BuildTarget), EditorUserBuildSettings.activeBuildTarget.ToString(), true); ;
40+
}
41+
}
42+
}
43+
}

Facebook.Unity.Settings/FacebookSettings.cs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,41 @@
1818
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1919
*/
2020

21-
using System;
22-
2321
namespace Facebook.Unity.Settings
2422
{
2523
using System.Collections.Generic;
26-
using System.IO;
2724
using UnityEngine;
2825

2926
/// <summary>
3027
/// Facebook settings.
3128
/// </summary>
3229
public class FacebookSettings : ScriptableObject
3330
{
31+
32+
3433
public const string FacebookSettingsAssetName = "FacebookSettings";
3534
public const string FacebookSettingsPath = "FacebookSDK/SDK/Resources";
3635
public const string FacebookSettingsAssetExtension = ".asset";
3736

37+
public enum BuildTarget {
38+
StandaloneOSX,
39+
StandaloneWindows,
40+
iOS,
41+
Android,
42+
StandaloneWindows64,
43+
WebGL,
44+
WSAPlayer,
45+
StandaloneLinux64,
46+
PS4,
47+
XboxOne,
48+
tvOS,
49+
Switch,
50+
Stadia,
51+
CloudRendering,
52+
PS5,
53+
none,
54+
}
55+
3856
private static List<OnChangeCallback> onChangeCallbacks = new List<OnChangeCallback>();
3957
private static FacebookSettings instance;
4058

@@ -72,6 +90,25 @@ public class FacebookSettings : ScriptableObject
7290

7391
public delegate void OnChangeCallback();
7492

93+
private BuildTarget editorBuildTargetName = BuildTarget.none;
94+
95+
/// <summary>
96+
/// Gets or sets the current editor build target
97+
/// </summary>
98+
/// <value>Build target name</value>
99+
public static BuildTarget EditorBuildTarget
100+
{
101+
get
102+
{
103+
return Instance.editorBuildTargetName;
104+
}
105+
106+
set
107+
{
108+
Instance.editorBuildTargetName = value;
109+
}
110+
}
111+
75112
/// <summary>
76113
/// Gets or sets the index of the selected app.
77114
/// </summary>

Facebook.Unity/FB.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,23 +250,20 @@ public static void Init(
250250

251251
if (Constants.IsEditor)
252252
{
253-
if (Application.platform == RuntimePlatform.WindowsEditor)
253+
if (Application.platform == RuntimePlatform.WindowsEditor && (FacebookSettings.EditorBuildTarget == FacebookSettings.BuildTarget.StandaloneWindows || FacebookSettings.EditorBuildTarget == FacebookSettings.BuildTarget.StandaloneWindows64))
254254
{
255-
FacebookLogger.Warn("You are running Facebook Windows SDK on a Windows device.");
256255
FB.OnDLLLoadedDelegate = delegate
257256
{
258257
((WindowsFacebook)FB.facebook).Init(appId, FB.ClientToken, onHideUnity, onInitComplete);
259258
};
260259
ComponentFactory.GetComponent<WindowsFacebookLoader>();
261-
262260
}
263261
else
264262
{
265263
FB.OnDLLLoadedDelegate = delegate
266264
{
267265
((EditorFacebook)FB.facebook).Init(onInitComplete);
268266
};
269-
270267
ComponentFactory.GetComponent<EditorFacebookLoader>();
271268
ComponentFactory.GetComponent<CodelessCrawler>();
272269
ComponentFactory.GetComponent<CodelessUIInteractEvent>();

0 commit comments

Comments
 (0)