c# - 执行引擎异常 : Attempting to JIT compile method 'System.Collections.Generic.Dictionary'

标签 c# ios unity-game-engine jit aot

在我的 unity3d 游戏中,我有以下字典:

 public Dictionary<string, List<UpgradeData>> upgradeList;

其中 UpgradeData 是一个非常简单的类:

public class UpgradeData
{
   public bool lockStatus;
   public bool purchased;

}

我读到here您不能使用值类型作为字典键,但据我所知,sting 不是值类型。因此,问题一定来自于使用 List 作为字典值。知道如何解决这个问题。该代码可在 Windows 平台和 MacOS 上运行。我正在尝试使用二进制格式化程序序列化该字典。我在序列化其他类时遇到了类似的问题,但我设法通过添加来解决这个问题:

 if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            System.Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
        }

我需要做什么来序列化字典?

编辑:忘记包含与字典一起使用的整个类

[Serializable]
    public class CharacterUpgradeList
    {

        private UpgradeData[] _upgrade_Data;
        private List<UpgradeData>[] upgData;

        public Dictionary<string, List<UpgradeData>> upgradeList;
        public CharacterUpgradeList()
        {
            upgData = new List<UpgradeData>[4];
            for (int i = 0; i < upgData.Length; i++)
            {
                upgData[i] = new List<UpgradeData> { 
                        new UpgradeData(),
                        new UpgradeData(),
                        new UpgradeData(),
                        new UpgradeData(),
                        new UpgradeData(),
                        new UpgradeData()
                   };
            }

            upgradeList = new Dictionary<string, List<UpgradeData>>
        {
            {"Man",upgData[0]},
            {"Woman",upgData[1]},
            {"Boy",upgData[2]},
            {"Girl",upgData[3]}

        };
        }
    }

然后我在此类中从上述类创建一个对象:

[Serializable]
class GameData
{
    public int _coinAmount, _upgradeLevel;
    public Level_Data[] _level_Data;
    public CharacterUpgradeList _charUpgradeList;
    public SerialVector2 serialVector;

    public GameData()
    {
        _charUpgradeList = new CharacterUpgradeList(); 
    }

}

我正在尝试序列化 GameData。

最佳答案

BinaryFormatter 依赖于 JIT 编译,iOS 不支持 JIT 编译。问题不在于您的数据结构,而在于平台功能限制。

您将必须使用支持完整 AOT 编译的不同序列化库。我很幸运 JsonFx 。有人推荐protobuf-net .

关于c# - 执行引擎异常 : Attempting to JIT compile method 'System.Collections.Generic.Dictionary' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28991107/

相关文章:

c# - 有没有办法在 .NET 中获取 flash 控件中的所有变量?

ios - 无法从 nib 实例化 UIView。 "warning: could not load any Objective-C class information"

c# - 为什么会出现错误“协程无法启动,因为游戏对象 'SaveInOtFade Canvas' 处于非事件状态”?

c# - 从具有相同代码的列表中选择

c# - 使用 WIA、C# 和 Win 7 进行相机捕捉

iOS 11,Unity3d随机启动崩溃

c# - 将枪放置在固定位置

c# - iOS-Unity桥接——奇怪的句子

c# - 为什么C#null在VB6中被翻译成Empty,而不是Nothing

ios - 具有透明度的 Popover ViewController?