【问题标题】:Dictionary and Items protected members of a KeyedCollection in Unity3d 5.3.1?Unity3d 5.3.1中KeyedCollection的字典和项目受保护成员?
【发布时间】:2016-01-27 12:22:46
【问题描述】:

我已经使用 Unity 5 一年了,一切正常,直到上周我们有了将 IDE 更新到 5.3.1 版本的想法。

现在编译器显示两个错误:

The name `Dictionary' does not exist in the current context.
The name `Items' does not exist in the current context.

两者都本地化为一个简单的 KeyedCollection

public class CommandProcessQueueCollection : KeyedCollection<int, CommandProcessQueue>
{
   public bool TryGetQueue(int id, out CommandProcessQueue queue)
   {
       if (Dictionary != null)
       {
           return Dictionary.TryGetValue(id, out queue);
       }

       foreach (var i in Items)
       {
           var k = GetKeyForItem(i);
           if (Comparer.Equals(id, k))
           {
              queue = i;
              return true;
           }
       }
       queue = default(CommandProcessQueue);

       return false;
   }

   protected override int GetKeyForItem(CommandProcessQueue queue)
   {
      return queue.Id;
   }
}

经过多次尝试,事情变得更加棘手,因为完全相同的代码已在 5 台安装了 5.3.1 的不同机器上编译。

嗯,5 个中有 2 个被证明可以编译没有任何错误

此外,msbuild 似乎编译代码也没有任何错误。

在机器之间,Mono 用于编译的 .NetFramework 可能存在差异。

你对这个奇怪的问题有什么想法吗?

PS:我正在添加 using System.Collections.ObjectModel,并且我当前在 Unity 编辑器中的 API 兼容性选项设置为 .NET 2.0。

【问题讨论】:

  • FWIW 您是否尝试过在代码中将Dictionary 明确替换为System.Collections.ObjectModel.Dictionary? (甚至以为你是using。)可能是冲突造成的灾难?

标签: c# unity3d mono


【解决方案1】:

好的,我的团队解决了。

在那些机器上没有安装 Windows 对 Editor 5.3.1f1 的支持,因此 webplayer 的标准模块正在运行,并且很少有 .NET 的 API 不可用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2016-06-12
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多