Godot C# 扩展方法持续更新

前言

为了简化Godot 的编写,我会将我的扩展方法写在这里面。

更新日期(2023年10月15日)

Nuget 包安装


扩展方法

csharp 复制代码
 public static class GD_Extension
 {
     /// <summary>
     /// 假数据生成,详情请看Bogus官方文档
     /// </summary>
     public static Faker Faker = new Faker();

     /// <summary>
     /// 获取子节点,需要保证子节点命名完全一致
     /// </summary>
     /// <typeparam name="T1"></typeparam>
     /// <typeparam name="T2"></typeparam>
     /// <param name="root">node跟节点</param>
     /// <param name="childNode">子节点属性,需要保证和场景命名完全一致</param>
     /// <param name="nameExpression">获取子节点命名字符串</param>
     /// <exception cref="Exception"></exception>
     public static void GetChildNode<T1,T2>(this T1 root,ref T2  childNode, 
         [CallerArgumentExpression(nameof(childNode))] string nameExpression = null)
         where T1: Node where T2: Node
     {
         childNode = root.GetNode<T2>(nameExpression);
         if(childNode == null)
         {
             var str = $"{nameExpression} node is null!";
             GD.Print(str);
             throw new Exception(str);
         }
     }
     /// <summary>
     /// Godot 序列号输出
     /// </summary>
     /// <param name="obj"></param>
     /// <param name="formatting"></param>
     public static void GD_Print(object obj,Formatting formatting = Formatting.Indented)
     {
         GD.Print(JsonConvert.SerializeObject(obj,formatting));

     }

 }
相关推荐
阿蒙Amon9 天前
《C#图解教程 第5版》深度推荐
开发语言·c#
暖馒9 天前
C#委托与事件的区别
开发语言·c#
JosieBook9 天前
【C#】C#异步编程:异步延时 vs 阻塞延时深度对比
c#·多线程·异步·阻塞
甄天9 天前
WPF中MVVM和MVVMLight模式
c#·wpf·visual studio
冰茶_9 天前
ASP.NET Core API文档与测试实战指南
后端·学习·http·ui·c#·asp.net
_oP_i9 天前
实现 “WebView2 获取word选中内容
开发语言·c#·word
Kookoos10 天前
ABP vNext + Azure Application Insights:APM 监控与性能诊断最佳实践
后端·c#·.net·abp vnext
专注VB编程开发20年10 天前
asp.net core Razor动态语言编程代替asp.net .aspx更高级吗?
开发语言·后端·c#·asp.net·.net
安木夕10 天前
C#.Net筑基-优雅LINQ的查询艺术
c#·.net
10 天前
Lua复习之何为闭包
开发语言·unity·游戏引擎·lua·交互