首页 技术 正文
技术 2022年11月10日
0 收藏 703 点赞 4,144 浏览 1848 个字

在平时开发游戏过程中,遇到一些编写代码很繁琐的问题. 我发现我团队中每个人都会遇到,就算打写出来分享下经验.

条件断点

利用IDE提供的工具, 右键断点的时候 输入条件, 当条件达成的时候,断点才能命中. (以前不知道这个功能总是要关闭游戏->编写代码-> 重新运行游戏 –> 查看结果 这个流程非常麻烦)

class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 100; i++)
{
if (i == 50) //利用条件断点,不写代码情况下 断点到某一个条件
{
Console.WriteLine("我断点到了");
}
}
Console.ReadKey();
}
}

运行表达式

你在想在某一个时段运行xxx代码, 可以通过以下方式. 选择某一个变量右键-> 快速监视

利用反射更好的编写测试代码

在我编写代码的时候,需要编写一些测试工具方便调试游戏,  但是在编写一些测试代码的时候,  总是为了方便,快速不小心破坏了代码的原有结构, 比如一个字段private 为了快速的访问到 就改成public.  我写了阶段简单实用的代码

public static class RefStatic
{ public static FieldInfo RefFieldVal(this object t, string name)
{
FieldInfo info = t.GetType().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic);
return info;
} public static FieldInfo RefStaticFieldVal(this object t, string name)
{
FieldInfo info = t.GetType().GetField(name, BindingFlags.Static | BindingFlags.NonPublic);
return info;
} public static FieldInfo RefSetFieldVal(this object t, string name, object val)
{
FieldInfo info = t.GetType().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic);
if (info != null)
info.SetValue(t, val); return info;
} public static FieldInfo RefSetStaticFieldVal(this object t, string name, object val)
{
FieldInfo info = t.GetType().GetField(name, BindingFlags.Static | BindingFlags.NonPublic);
if (info != null)
info.SetValue(t, val); return info;
} public static PropertyInfo RefSetPropertyVal(this object t, string name, object val)
{
PropertyInfo info = t.GetType().GetProperty(name);
if (info != null)
info.SetValue(t, val, null); return info;
} public static MethodInfo RefExecuteMethod(this object t, string name, object[] parameters)
{
MethodInfo info = t.GetType().GetMethod(name, BindingFlags.NonPublic | BindingFlags.Instance);
if (info != null)
info.Invoke(t, parameters); return info;
}
}

使用的栗子:

if (GUILayout.Button("生成全部单元格"))
{
var bag = (Panel_CommonBag)target;
GameObject[] go = (GameObject[])bag.RefFieldVal("m_CellList").GetValue(bag);
for (int i = 0; i < go.Length; i++)
{
KnapsackColumn k = go[i].GetComponent<KnapsackColumn>();
k.CreateCell();
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,493
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297