把现有Unity3d游戏向Windows Phone 8.1移植(类库兼容)

来源:互联网 发布:企业开淘宝店怎样记账 编辑:程序博客网 时间:2024/04/29 05:01

关系图表: 


  • .NET CLR 是完整的微软的 .NET Framework Runtime;
  • .NET For Store Apps 是用于 Windows 8.1 Apps 及 Windows Phone 8.1 Apps 的.NET的子集;
  • Mono 是官方的Mono Runtime;
  • Unity's Mono 是Mono自己定制的用于嵌入自己引擎的Mono;
  • Windows Runtime 是微软新一代的 Native Runtime;


矛盾根源

.NET for Store Apps 是 .NET CLR 的儿子,但是却自宫的厉害。而野生的Mono只延续了.NET CLR 2.0的香火。在Windows Phone上,虽然没有新儿子长得高,但却更壮实。

反而野生的Mono能够在IOS,Android上都能立足,微软自家的新儿子把ADO.NET这种利器都给阉了。

更甚之,自己的新儿子也快要被自己掐死了,取而代之的是Windows Runtime。


具体体现

  • Mono 的类存在,.NET for Store Apps 中不存在,Windows Runtime中也不存在;
  • Mono 的类存在,.NET for Store Apps 中不存在,Windows Runtime中存在,需要改写接口(因为全都是异步);
  • Mono 的类存在,.NET for Store Apps 中也存在,但具体的接口方法不存在,需要写扩展方法或自己实现(如WinRTLegacy)。
  • Mono 的类存在,Unity's的Mono中不存在,需要自己实现。

不兼容接口列表

  • System.Collections.ArrayList
  • System.Collections.Hashtable
  • System.Collections.Queue
  • System.Collections.SortedList
  • System.Collections.Stack
  • System.Collections.Specialized.HybridDictionary
  • System.Collections.Specialized.ListDictionary
  • System.Collections.Specialized.NameValueCollection
  • System.Collections.Specialized.OrderedDictionary
  • System.Collections.Specialized.StringCollection
  • System.IO.Directory  => Windows.Storage
  • System.IO.File  => Windows.Storage
  • System.IO.FileStream  => Windows.Storage
  • System.Xml.XmlDocument
  • System.Xml.XmlTextReader
  • System.Xml.XmlTextWriter
  • System.Net.TCPClient  ==>Windows.Networking.Sockets  或者 第三方的 Photon
  • Sysmte.Cryptography  ==>Windows.Security.Cryptography 或 UnityEngine.Windows for MD5 and SHA1
  • NGUI
  • Toolkit2D

WinRTLegacy实现了一些可兼容的接口:

  • Extention methods Close() for most System.IO classes (alternatively you can use Dispose(), which is available on both Mono and .NET for Windows Store Apps)
  • WinRTLegacy.TypeExtensions has methods GetConstructor(), GetMethod(), GetProperty() for System.Type
  • WinRTLegacy.IO.StreamReader class, that is compatible with Mono System.IO.StreamReader
  • WinRTLegacy.IO.StreamWriter class, that is compatible with Mono System.IO.StreamWriter
  • WinRTLegacy.Xml.XmlReader class, that is compatible with Mono System.Xml.XmlReader
  • WinRTLegacy.Xml.XmlWriter class, that is compatible with Mono System.Xml.XmlWriter
  • WindowsRuntimeStreamExtensions 把 WinRT stream 转换成 .NET stream

解决方法

要解决几者之间的冲突,可以用条件编译来区分不同平台使用的代码:

#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR     using LegacySystem.IO; #else     using System.IO; #endif  



0 0
原创粉丝点击