这是我的细胞绘画方法。
DataGridView grid = (DataGridView)sender;
if ( e.RowIndex == -1 || e.ColumnIndex == -1 )
{ return; }
if ( ( grid.Rows [ e.RowIndex ].Cells [ e.ColumnIndex ].Value == null ) )
return;
Brush gridBrush = new SolidBrush(GridList[0].GridColor),backColorBrush = new SolidBrush(e.CellStyle.BackColor);
Pen gridLinePen = new Pen(gridBrush);
// Erase the cell.
e.Graphics.FillRectangle ( backColorBrush, e.CellBounds );
// Draw the grid lines (only the right and bottom lines;
// DataGridView takes care of the others).
e.Graphics.DrawLine ( gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, …Run Code Online (Sandbox Code Playgroud) 我目前正在使用 Unity 的代码进行教程学习,在本节中存在额外的挑战,但不会帮助您解决它。它说我必须防止玩家向生成狗发送垃圾邮件空格键。我是 C# 新手,我开始在网上查找,但我看到了一些关于 CoRoutines 的内容,但我仍然不知道那是什么,有没有一种简单的方法可以做到这一点,在网上搜索我发现了类似的东西,但我无法使其工作。我也尝试制作一些像 canSpawn 这样的条件,但我不知道如何很好地实现它,Unity 给了我一个错误,我不能在 bool 和按键事件之间使用 &&
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControllerX : MonoBehaviour
{
public GameObject dogPrefab;
public float time = 2.0f;
public float timer = Time.time;
// Update is called once per frame
void Update()
{
timer -= Time.deltaTime;
if (timer > time)
{
// On spacebar press, send dog
if (Input.GetKeyDown(KeyCode.Space))
{
spawnDog();
}
timer = time;
}
void spawnDog()
{
Instantiate(dogPrefab, transform.position, dogPrefab.transform.rotation);
}
}
Run Code Online (Sandbox Code Playgroud) 我经常用if ( gameobject == null ),但听说游戏里这个很贵。
我检查了if ( gameobject == null )和if ( boolvalue == false ),但没有注意到任何差异。
您能解释一下为什么这项检查费用昂贵吗?先感谢您。