尝试使用Facebook Unity SDK时遇到错误:
无法从中安全地加载程序集 https://integrated-plugin-canvas-rsrc.fbsbx.com/rsrc/unity/lib/sdk_4.0/CanvasFacebook.dll UnityEngine.Debug:LogError(Object)FbDebug:Error(String) c__Iterator3:MoveNext()(在Assets / Ultimate GUI上 试剂盒/ Facebook的/脚本/ FB.cs:337)
我知道通常你只需要将{4.6}添加到FB.cs
。然而,在我开始使用这个类的模板中没有这一行。那我该怎么办呢?以下是RemoteFacebookLoader
文件中FB.cs
类的定义:
public abstract class RemoteFacebookLoader: MonoBehaviour {
public delegate void LoadedDllCallback(IFacebook fb);
private const string facebookNamespace = "Facebook.";
private const int maxRetryLoadCount = 3;
private static int retryLoadCount = 0;
public static IEnumerator LoadFacebookClass(string className, LoadedDllCallback callback) {
#if UNITY_EDITOR || UNITY_WEBPLAYER
var url = string.Format(IntegratedPluginCanvasLocation.DllUrl, className);
var www = new WWW(url);
FbDebug.Log("loading dll: " + url);
yield
return www;
if (www.error != null) {
FbDebug.Error(www.error);
if (retryLoadCount < maxRetryLoadCount) {
++retryLoadCount;
#else
var www = new WWW("");
yield
return www;#endif#
if UNITY_WEBPLAYER FBComponentFactory.AddComponent < CanvasFacebookLoader > ();#endif#
if UNITY_EDITOR || UNITY_WEBPLAYER
}
www.Dispose();
yield
break;
}
var assembly = Security.LoadAndVerifyAssembly(www.bytes, );
if (assembly == null) {
FbDebug.Error("Could not securely load assembly from " + url);
www.Dispose();
yield
break;
}
var facebookClass = assembly.GetType(facebookNamespace + className);
if (facebookClass == null) {
FbDebug.Error(className + " not found in assembly!");
www.Dispose();
yield
break;
}
// load the Facebook component into the gameobject
// using the "as" cast so it'll null if it fails to cast, instead of exception
var fb = typeof(FBComponentFactory)
.GetMethod("GetComponent")
.MakeGenericMethod(facebookClass)
.Invoke(null, new object[] {
IfNotExist.AddNew
}) as IFacebook;
if (fb == null) {
FbDebug.Error(className + " couldn't be created.");
www.Dispose();
yield
break;
}
callback(fb);
www.Dispose();
#endif
}
protected abstract string className {
get;
}
IEnumerator Start() {
var loader = LoadFacebookClass(className, OnDllLoaded);
while (loader.MoveNext()) {
yield
return loader.Current;
}
Destroy(this);
}
private void OnDllLoaded(IFacebook fb) {
FB.facebook = fb;
FB.OnDllLoaded();
}
}
更新
看起来我使用的是旧的Facebook SDK(v4.0)。所以我更新了FB.cs
文件,现在我又收到了其他错误。他们说OGACTIONTYPE
并且团结不能从IFacebook
汇编加载此类型。查看统一控制台的screenshot。
实际上它说:
Assets / Ultimate GUI Kit / Facebook / Scripts / FB.cs(212,13):错误CS0246: 类型或命名空间名称`OGActionType&#39;无法找到。你是 缺少using指令或程序集引用?
以下是我刚加载的RemoteFacebookLoader
文件中FB.cs
类的定义:
public abstract class RemoteFacebookLoader : MonoBehaviour
{
public delegate void LoadedDllCallback(IFacebook fb);
private const string facebookNamespace = "Facebook.";
private const int maxRetryLoadCount = 3;
private static int retryLoadCount = 0;
public static IEnumerator LoadFacebookClass(string className, LoadedDllCallback callback)
{
var url = string.Format(IntegratedPluginCanvasLocation.DllUrl, className);
var www = new WWW(url);
FbDebug.Log("loading dll: " + url);
yield return www;
if (www.error != null)
{
FbDebug.Error(www.error);
if (retryLoadCount < maxRetryLoadCount)
{
++retryLoadCount;
#if UNITY_WEBPLAYER
FBComponentFactory.AddComponent<CanvasFacebookLoader>();
#endif
}
www.Dispose();
yield break;
}
#if !UNITY_WINRT
#if UNITY_4_5 || UNITY_4_6 || UNITY_5_0
var authTokenWww = new WWW(IntegratedPluginCanvasLocation.KeyUrl);
yield return authTokenWww;
if (authTokenWww.error != null)
{
FbDebug.Error("Cannot load from " + IntegratedPluginCanvasLocation.KeyUrl + ": " + authTokenWww.error);
authTokenWww.Dispose();
yield break;
}
var assembly = Security.LoadAndVerifyAssembly(www.bytes, authTokenWww.text);
#else
var assembly = Security.LoadAndVerifyAssembly(www.bytes);
#endif
if (assembly == null)
{
FbDebug.Error("Could not securely load assembly from " + url);
www.Dispose();
yield break;
}
var facebookClass = assembly.GetType(facebookNamespace + className);
if (facebookClass == null)
{
FbDebug.Error(className + " not found in assembly!");
www.Dispose();
yield break;
}
// load the Facebook component into the gameobject
// using the "as" cast so it'll null if it fails to cast, instead of exception
var fb = typeof(FBComponentFactory)
.GetMethod("GetComponent")
.MakeGenericMethod(facebookClass)
.Invoke(null, new object[] { IfNotExist.AddNew }) as IFacebook;
if (fb == null)
{
FbDebug.Error(className + " couldn't be created.");
www.Dispose();
yield break;
}
callback(fb);
#endif
www.Dispose();
}
protected abstract string className { get; }
IEnumerator Start()
{
var loader = LoadFacebookClass(className, OnDllLoaded);
while (loader.MoveNext())
{
yield return loader.Current;
}
Destroy(this);
}
private void OnDllLoaded(IFacebook fb)
{
FB.facebook = fb;
FB.OnDllLoaded();
}
}
答案 0 :(得分:1)
您的FB.cs
似乎已过时。对于Unity 4.6,您应该使用最新版本的Facebook Unity SDk。您可以在official page上下载。
另一个可能的问题 - 您修改了此文件。除非你真的知道自己在做什么,否则你不应该这样做。
回到你的问题。
var assembly = Security.LoadAndVerifyAssembly(www.bytes,);
^
此代码已损坏。 ,
之后www.bytes
符号的作用是什么?
对于Unity 4.6,它应该在尝试加载程序集之前下载unityhash
文件。所以实际上这个调用应该是这样的:
var assembly = Security.LoadAndVerifyAssembly(www.bytes, hashValue);
在我的Unity SDK版本中,我有类似
的内容#if UNITY_4_5 || UNITY_4_6 || UNITY_5_0
var authTokenWww = new WWW(IntegratedPluginCanvasLocation.KeyUrl);
yield return authTokenWww;
if (authTokenWww.error != null)
{
Debug.LogError("Cannot load from " + IntegratedPluginCanvasLocation.KeyUrl + ": " + authTokenWww.error);
authTokenWww.Dispose();
yield break;
}
var assembly = Security.LoadAndVerifyAssembly(www.bytes, authTokenWww.text);
#else
var assembly = Security.LoadAndVerifyAssembly(www.bytes);
#endif
<强>更新强>
我们在聊天中讨论了一个问题后,我们找到了现有问题的解决方案。我正在为那些可能遇到类似情况的人更新我的问题。
所以解决OP的问题:
FB.cs
,而是整个Facebook
文件夹!)< / LI>