全站通知:

模组调试

阅读

    

2023-11-30更新

    

最新编辑:Lu_23333

阅读:

  

更新日期:2023-11-30

  

最新编辑:Lu_23333

来自城市:天际线WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索
页面贡献者 :
xl123071
Lu_23333
一叶杳舟
施工中:欢迎协助编辑本页,请参考帮助:编辑帮助帮助:编辑规范。请从以下方面协助编辑:
  • 需要翻译

此页面的内容是有关如何调试你的模组的教程。

DebugOutputPanel

在游戏内,可以按F7打开调试输出面板。

ModTools

The recommended way for debugging is by using the Unity's debug logging API.

using UnityEngine;

Debug.Log(...);

The downside is that you can not see these logs in the game unless you use ModTools. It's really recommended to subscribe to ModTools (requires restart after install). It offers way more than just having a better console so it's really a must have if you're going to make (advanced) mods.

Output log

If you don't want to use ModTools you can locate the logged messages in the output log. <%STEAM%>\steamapps\common\Cities_Skylines\Cities_Data\output_log.txt

Alternative Logging Method

An alternative for logging would be to directly add messages to the DebugOutputPanel. When using this method please prefix your messages with your plugin name.

using ColossalFramework.Plugins;

DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "<message>");

Debugging with a debugger such as Visual Studio 2017 or VS Code

This is for Windows:

  • For Visual Studio 2017 in the installer, (or Tools->Get Tools and features), under Workloads, Mobile & Gaming, check the "Game development with Unity"
  • For VS Code add C# and Mono Debug from the extensions in the marketplace
  • Build mono.dll from source https://github.com/thardie/mono/tree/unity-5.6
    • Alternate prebuilt www.orcas.net/cities_skylines/mono.dll
  • Rename your original mono.dll (in C:\Program Files (x86)\Steam\steamapps\common\Cities_Skylines\Cities_Data\Mono)
  • Put the downloaded mono.dll in that directory
  • Check your cities still works.
  • Edit your system environment variables (Right click This PC/My computer->Properties->Advanced System Settings->Environment Variables->User Variables->New...
  • Add Variable named "MONO_DEBUGGER_AGENT", value "transport=dt_socket,address=127.0.0.1:56000,defer=y"
  • Click OK, OK, OK.
  • Make sure steam is NOT running.
  • Launch cities any way you want.
  • Open debugger (VS 2017 with your mod's code loaded, Debug->Attach Unity Debugger->Input IP->127.0.0.1:56000) (For VS Code, see launch.json below)

VS Code launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Mono",
            "request": "attach",
            "type": "mono",
            "address": "localhost",
            "port": 56000
        }
    ]
}

To disable debugging, rename or remove the environment variable. You'll need to restart Steam for it to take effect.

See also

说明

本文内容长期有效,适用任何游戏版本。

本页内容最初译自官方Wiki:Debugging Mods,经双方编辑后内容可能与来源不同。