一、VSCode
VSCode生成exe
在vs中断点调试
如果没效果需要安装如下与unity相连接的插件
注释
1、代码注释
注释和取消都是都是同一个命令:选中代码,然后按住Ctrl+Shift+/
2、方法或类注释
///
导航
将变量注释展示到解释面板
1、直接显示
[Tooltip("显示注释")]//鼠标移到变量上后可以看到汉字
public class Test : MonoBehaviour
{
[Tooltip("显示注释")]
public string Tooltip;
}
2、悬停显示
[Header("显示注释")]//直接在面板上显示汉字
public class Test : MonoBehaviour
{
[Header("显示注释")]
public string Header;
}
二、C#语言
序列化与反序列化
1、安装vs和unity对于json的依赖
虽然在VS里面可以正确引用命名空间 Newtonsoft.Json,但是Unity报错:
the type or namespace name ‘newtonsoft’ could not be found (are you missing a using directive or an assembly reference?)
看来是Unity找不到程序集,这是因为Json.NET官方没有直接支持Unity。解决办法:GitHub上有大佬开发了正确在Unity配置Json.NET的工具。只需要下载一个Unity包然后导入到Unity中就行了,地址: Newtonsoft.Json-for-Unity 。
2、反序列化
{"landmark": [{"x":100, "y":200, "z": 300}, {...} ] }
Dictionary<string, List<Dictionary<string, double>>> map
= new Dictionary<string, List<Dictionary<string, double>>>();
map = JsonConvert.DeserializeObject<Dictionary<string, List<Dictionary<string, double>>>>(psObj.data);
foreach (KeyValuePair<string, List<Dictionary<string, double>>> pair in map)
{
List <Dictionary<string, double>> listOfDictionaries = pair.Value;
// 遍历列表中的每个字典
foreach (Dictionary<string, double> dictionary in listOfDictionaries)
{
// 遍历字典中的每个键值对
foreach (KeyValuePair<string, double> kvp in dictionary)
{
if (kvp.Key == "x" || kvp.Key == "y" || kvp.Key == "z") {
line.Append(kvp.Value * 100);
line.Append(",");
}
//Debug.Log($"Key: {kvp.Key}, Value: {kvp.Value}");
}
}
break;
}