c# - 我可以在 Visual Studio/Code 中测试/运行 Unity C# 吗?

标签 c# visual-studio unity3d visual-studio-code

我正在开发一个 Unity 项目,想测试/尝试一些代码:即加载 CSV 文件并保存在不同的词典中。至于现在,我在 Visual Studio/Code 中编码,必须切换回 Unity 才能运行它。

有没有办法直接在 Visual Studio/Code 中测试运行代码 - 仅用于控制台输出? 这将非常适合测试,而不是一直来回切换。

谢谢

最佳答案

我的一个游戏项目,我建立了一个独立于Unity项目的VS项目,并将所有的cs文件绑定(bind)在那里。

以这种方式测试的文件根本没有使用UnityEngine,但您也可以为测试设置一个虚拟的UnityEngine。此文件夹的位置在 Unity 项目文件夹之外,以防止 Unity 接触那些测试 cs 文件和 vcproj 文件。

在 VS 项目中,我可以简单地包含 Unity-project Assets 文件夹中的任何 cs 文件。

我的目录结构:

ProjectRoot/  <== real project root folder.
    .git/    <== git tracking for unity part and testcode.
    Unity/   <==  Unity's project homedirectory.
        Assets/
            script
                ... various scripts.
        mats/
        scenes/
        .....     <==  lots of Unity project stuff
    testcode.sln
    testcode.vcproj  <== refers to cs files from testcode AND Unity.
    testcode/
        testclass.cs
        .....

为了测试,我在 VS 中打开 testcode.sln,然后在其中编译并运行它。 Unity 不需要开放。

关于c# - 我可以在 Visual Studio/Code 中测试/运行 Unity C# 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61405044/

相关文章:

c++ - 如何在 Windows 7 上查看 .dmp 文件?

c# - 如何在 Unity C# 中访问动画参数?

unity3d - Raycasting 在 Unity 2d 游戏中找到鼠标单击对象

c# - 程序迷宫移除旧碰撞器

c# - 值类型的引用相等性

c++ - 获取 Visual Studio 使用的 C++ 标准版本

c# - 在 Visual Studio 中创建基于服务的数据库

c# - 如何让 WPF 验证冒泡到父控件?

c# - .Net 程序集加载问题期间出现 BadImageFormatException

C# WPF OnPaint 方法替代?