【发布时间】:2015-03-30 00:33:37
【问题描述】:
我在尝试使用 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() (在资产/终极 GUI Kit/Facebook/Scripts/FB.cs:337)
我知道通常您只需将 if unity 4.6 添加到FB.cs。但是,在我从这个类开始的模板中没有这一行。那么我该如何解决呢?这是我的FB.cs 文件中RemoteFacebookLoader 类的定义:
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 的事情,并且unity 无法从IFacebook 程序集中加载这种类型。查看统一控制台的screenshot。
其实是这样写的:
Assets/Ultimate GUI Kit/Facebook/Scripts/FB.cs(212,13):错误 CS0246: 找不到类型或命名空间名称“OGActionType”。你是 缺少 using 指令或程序集引用?
这是我刚刚加载的FB.cs 文件中RemoteFacebookLoader 类的定义:
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();
}
}
【问题讨论】:
-
已解决,感谢 d12frosted