我正在开发用 C# 转换并插入到 Unity 项目中的 Haxe 代码。
转换工作正常,当我在 Unity 中单独导入生成的类时,我能够使用它。
为了让它工作,我必须将整个生成的 src
文件夹引入 Unity,包括 Type.cs
文件。
但是,当我导入“后处理堆栈”(一个基本的 Unity 扩展)时,由于名称冲突而出现错误。 Type
类也是一个基本的 C# 类,它由后处理脚本使用。
haxe-Type
优先并中断编译:
Assets/PostProcessing/Runtime/PostProcessingBehaviour.cs(406,30): error CS1502: The best overloaded method match for `System.Collections.Generic.Dictionary<Type,System.Collections.Generic.KeyValuePair<UnityEngine.Rendering.CameraEvent,UnityEngine.Rendering.CommandBuffer>>.Add(Type, System.Collections.Generic.KeyValuePair<UnityEngine.Rendering.CameraEvent,UnityEngine.Rendering.CommandBuffer>)' has some invalid arguments
Assets/PostProcessing/Runtime/PostProcessingBehaviour.cs(406,34): error CS1503: Argument `#1' cannot convert `System.Type' expression to type `Type'
我不知道是否可以通过尝试使用 C#/Unity/Mono 搜索路径来解决这个问题。
我想知道将所有 haxe 顶级类(可选)包装到 haxe
命名空间或特殊的 haxe-default
命名空间是否更合适,或者例如,将它们作为前缀添加到 class HType
中。
这种基本类型的名称冲突可能会出现在许多其他上下文中,而不仅仅是在 Unity 中。
最佳答案
我在 C# 的 Haxe 文档中找到了解决方案: https://github.com/HaxeFoundation/HaxeManual/wiki/Haxe-C%23
-D no-root generate package-less haxe types in the haxe.root namespace to avoid conflicts with other types in the root namespace
这样,所有全局级别的类都将在命名空间 haxe.root
下生成。
关于namespaces - 如何避免 haxe Type 类和 C# Type 类之间的冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45631475/