Unity Visual Studio C#版本同步 [英] Unity Visual Studio C# version synchronization

查看:377
本文介绍了Unity Visual Studio C#版本同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在适当的时候开始在Unity游戏中使用委托和事件来更新标签,而不是每帧都更新标签,尽管大多数情况下都不会发生变化.

I just started to use delegates and events in my Unity game to update labels when appropriate, instead of updating the labels every frame, although most of the time no changes occur.

为确保这一点,请确保一个静态事件调用

To make sure, that a static event call of

public static event OnSomething onSomething;

我使用的实际上是听众

if (onSomething!= null) {
    onSomething();
}

这只是一个方便的问题,但是Visual Studio 14(2015)说,这可以简化为

It's just a convenience problem, but Visual Studio 14 (2015) says, that this can be simplified to

onSomething?.Invoke();

我也更喜欢它,因为我熟悉nullable并想使用它们,但是如果我确实将代码更改为建议,Unity会说

which I also like more, because I'm familiar with nullables and would like to use them, but if I do change the code to the suggestion, Unity says

error CS1644: Feature `null propagating operator' cannot be used, because it is not part of the C# 4.0 language specification.

那么有没有办法使Unity项目使用C#v4.0,或者我可以告诉Visual Studio该项目使用较旧的C#版本,所以它停止了这些建议?

So is there a way to make a Unity project use v4.0 of C#, or can I tell Visual Studio, that the project uses an older version of C#, so it stops these suggestions?

一点澄清:我不需要使用任何特定的C#版本.只要没有主要理由不使用最新版本,我都想使用最新版本来使用这些超酷新功能".

Little clarification: I don't neccessarily want to use any specific C# version. I want to use the newest version possible to use these "cool new features", as long as there is no major reason not to use the newest version.

推荐答案

我不必使用任何特定的C#版本.我想要 使用最新版本,以使用这些很棒的新功能",例如 只要没有主要理由不使用最新版本即可.

I don't neccessarily want to use any specific C# version. I want to use the newest version possible to use these "cool new features", as long as there is no major reason not to use the newest version.

Unity正式 支持 .NET 3 以上的任何功能.虽然,他们目前正在对此进行研究.他们想先支持 .NET 4 ,然后再支持其他.NET版本.

Unity does not officially support anything above .NET 3. Although, they are currently working on this. They want to support .NET 4 first then other .NET version.

您可以在Unity中使用最新的C#吗?

Can you use newest C# in Unity?

是的!

butbucket 上有一个专用于此的项目,名为"Unity C#5.0和6.0集成" .您可以在此处获得它.它可以让您完全做到这一点,并且使用它的必要说明已发布在该网站上.

There is a project dedicated to this on butbucket called "Unity C# 5.0 and 6.0 Integration". You can get it here. It lets you do exactly this and the instructions required to use this is posted on that site.

这可以在iOS,Android,Windows和MacOS上使用,但是我不会仅仅因为它不受官方支持而使用它来发布我的游戏.

This works on iOS, Android, Windows and MacOS but I wouldn't use this to release my game simply because it's not officially supported.

至于尝试使用

onSomething?.Invoke();

我建议您完全不要在Unity中使用它.如果养成习惯,就会遇到很多问题.

I suggest you don't use that in your Unity at-all. You will run into many problems if you form a habit of using that.

这样做的原因是因为Unity使用此处是一个示例,而

The reason for this is because Unity uses custom equality operator for Components and GameObjects. It won't work if you try to do this on a Component or GameObject. You will simply create so many problems for your self. Here is an example of one and here is another reason to stay away from Null propagation when working in Unity.

编辑:

Unity 2017现在,然后在运行该游戏之前将其发布.

Unity 2017 now supports 4.6 which will allow this feature to work but I will still suggest you test and experiment a lot with this to make sure there is no big problem such as this during run-time before releasing your game with it.

这篇关于Unity Visual Studio C#版本同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆