本文整理汇总了C#中GridCell类的典型用法代码示例。如果您正苦于以下问题:C# GridCell类的具体用法?C# GridCell怎么用?C# GridCell使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GridCell类属于命名空间,在下文中一共展示了GridCell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStraightOneDirection
public Vector2 GetStraightOneDirection(Vector3 mouse_down, Vector3 mouse_up)
{
Vector2 returnVector = Vector2.zero;
GridCell mouseDownCell = GridHelper.GetGridCell(mouse_down);
GridCell mouseUpCell = GridHelper.GetGridCell(mouse_up);
Vector3 temp;
if (mouse_down.x > mouse_up.x) { temp.x = mouse_down.x; mouse_down.x = mouse_up.x; mouse_up.x = temp.x; }
if (mouse_down.z > mouse_up.z) { temp.z = mouse_down.z; mouse_down.z = mouse_up.z; mouse_up.z = temp.z; }
minGridCell = GridHelper.GetGridCell (mouse_down);
maxGridCell = GridHelper.GetGridCell (mouse_up);
if (maxGridCell.gridPosition.x - minGridCell.gridPosition.x >= maxGridCell.gridPosition.y - minGridCell.gridPosition.y) {
// horizontal
if (mouseDownCell.gridPosition.x < mouseUpCell.gridPosition.x)
returnVector = new Vector2(1,0);
else
returnVector = new Vector2(-1,0);
} else {
// vertical
if (mouseDownCell.gridPosition.y < mouseUpCell.gridPosition.y)
returnVector = new Vector2(0,1);
else
returnVector = new Vector2(0,-1);
}
//print ("direction vector = " + returnVector);
return returnVector;
}
示例2: Graph
public Graph(CatAndMouseGame game, GridCell[,] grid)
{
this.game = game;
this.grid = grid;
rows = grid.GetLength(0);
columns = grid.GetLength(1);
adjacencyList = new Node[rows * columns];
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < columns; ++j)
{
grid[i, j] = new GridCell(game, new Vector2(i * 32, j * 32));
List<Node> adjacentNodes = new List<Node>();
// Check NSEW
if (j - 1 >= 0) adjacentNodes.Add(new Node(i, j - 1));
if (j + 1 < columns) adjacentNodes.Add(new Node(i, j + 1));
if (i - 1 >= 0) adjacentNodes.Add(new Node(i - 1, j));
if (i + 1 < rows) adjacentNodes.Add(new Node(i + 1, j));
List<Node> cornerNodes = new List<Node>();
// Check all
if (i - 1 >= 0 && j - 1 >= 0) cornerNodes.Add(new Node(i - 1, j - 1));
if (i - 1 >= 0 && j + 1 < columns) cornerNodes.Add(new Node(i - 1, j + 1));
if (i + 1 < rows && j - 1 >= 0) cornerNodes.Add(new Node(i + 1, j - 1));
if (i + 1 < rows && j + 1 < columns) cornerNodes.Add(new Node(i + 1, j + 1));
adjacencyList[columns * i + j] = new Node(i, j);
allNodes.Add(adjacencyList[columns * i + j]);
adjacencyList[columns * i + j].AdjacentNodes = adjacentNodes;
adjacencyList[columns * i + j].CornerNodes = cornerNodes;
}
}
}
示例3: ExlposionApplied
void ExlposionApplied(GridCell cell, Bomb bomb, float fatality)
{
int f = (int)fatality;
Text.text = "-" + f;
transform.position = Camera.main.WorldToScreenPoint(cell.transform.position);
mAnimator.SetTrigger ("Indicate");
}
示例4: AsDynamicXml_WhenGivenValidGridCell_ShouldReturnDynamicXml
public void AsDynamicXml_WhenGivenValidGridCell_ShouldReturnDynamicXml()
{
var c = new GridCell() { Alias = "test", DataType = -88, Name = "Test", Value = "1234" };
var x = c.AsDynamicXml();
Assert.IsInstanceOfType(x, typeof(DynamicXml));
}
示例5: GetPropertyValue_WhenGivenValidGridCell_ShouldReturnPropertyValue
public void GetPropertyValue_WhenGivenValidGridCell_ShouldReturnPropertyValue()
{
var c = new GridCell() { Alias = "test", DataType = -41, Name = "Test", Value = "01/04/2013 00:00:00" };
var x = c.GetPropertyValue();
Assert.IsInstanceOfType(x, typeof(DateTime));
}
示例6: GetAffections
public Dictionary<float, List<GridCell>> GetAffections(GridCell center, int range)
{
var aff = new Dictionary<float, List<GridCell>> ();
aff.Add (1f, new List<GridCell>(new GridCell[]{center}));
if (range <= 1)
return aff;
for (int r = 1; r < range; r++) {
var p = 1f - ((float)r / range);
var clist = new List<GridCell>();
var cu = GetCell(center.Position + new Vector2(0, r));
var cur = GetCell(center.Position + new Vector2(r, r));
var cr = GetCell(center.Position + new Vector2(r, 0));
var cdr = GetCell(center.Position + new Vector2(r, -r));
var cd = GetCell(center.Position + new Vector2(0, -r));
var cld = GetCell(center.Position + new Vector2(-r, -r));
var cl = GetCell(center.Position + new Vector2(-r, 0));
var clu = GetCell(center.Position + new Vector2(-r, r));
if(cu) clist.Add(cu);
if(cur) clist.Add(cur);
if(cr) clist.Add(cr);
if(cdr) clist.Add(cdr);
if(cd) clist.Add(cd);
if(cld) clist.Add(cld);
if(cl) clist.Add(cl);
if(clu) clist.Add(clu);
aff.Add (p, clist);
}
return aff;
}
示例7: FindWordLocation
/// <summary>
/// Finds an sets a vaild location for the word to be placed
/// </summary>
/// <param name="xRange"></param>
/// <param name="yRange"></param>
/// <param name="word"></param>
/// <param name="grid"></param>
/// <returns></returns>
protected PlacedWord FindWordLocation(IEnumerable<int> xRange, IEnumerable<int> yRange, string word, WordSearch grid)
{
xRange = xRange.Shuffle();
yRange = yRange.Shuffle();
var placeFound=false;
GridCell startPos = new GridCell();
//Find a Valid location
foreach (var currentX in xRange) {
foreach (var currentY in yRange)
{
placeFound = this.TryPlaceWordLetters(word, new GridCell(currentX, currentY), grid);
if (placeFound)
{
startPos = new GridCell(currentX,currentY);
break;
}
}
if(placeFound) break;
}
//Set Word
if(placeFound)
{
for (var i = 0; i < word.Length; i++)
{
this.SetCellValue(startPos, i, grid, word[i]);
}
return new PlacedWord(word, this.GetDisplayDirection(), startPos);
}else{
return null;
}
}
示例8: ToString_WhenGivenValidGridCell_ShouldReturnValue
public void ToString_WhenGivenValidGridCell_ShouldReturnValue()
{
var c = new GridCell() { Value = "1234" };
var x = c.ToString();
Assert.AreEqual(x, c.Value);
}
示例9: UniformGridBroadphase
public UniformGridBroadphase(int width, int height, int cellSize) : this()
{
Width = width;
Height = height;
CellSize = cellSize;
CellsHigh = Height / cellSize;
CellsWide = Width / cellSize;
TotalCells = CellsHigh * CellsWide;
Offset = new Point(width / 2, height / 2);
_invCellSize = 1f / (float)cellSize;
_pairs = new OverlappingPairCache();
_cells = new GridCell[TotalCells];
for (int i = 0; i < _cells.Length; i++)
_cells[i] = new GridCell();
neighbourOffset = new int[]
{
-CellsWide - 1, // top-left
-CellsWide, // top
-CellsWide + 1, // top-right
-1, // left
0,
1, // right
CellsWide - 1, // bottom-left
CellsWide, // bottom
CellsWide + 1, // bottom-right
};
}
示例10: AgentSprite
public AgentSprite(CatAndMouseGame game, Texture2D texture, Vector2 position, UserSprite target, GridCell[,] gridCell, Graph graph)
: base(game, texture, position)
{
this.target = target;
this.gridCell = gridCell;
this.graph = graph;
}
示例11: GetNeighbours
public GridCell[] GetNeighbours()
{
GridCell[] returnList = new GridCell[8];
int index = 0;
for (int x = (int)gridCell.gridPosition.x - 1; x <= gridCell.gridPosition.x + 1; x++)
{
for (int y = (int)gridCell.gridPosition.y - 1; y <= gridCell.gridPosition.y + 1; y++)
{
if (x == gridCell.gridPosition.x && y == gridCell.gridPosition.y) { } // this cell, SKIP
else if (IsWalkable())
{
returnList[index] = GridHelper.GetGridCell(x, y);
/*
if (returnList[index] == null) // if it's null, leave index the same
index--;
index++;*/
if (returnList[index] != null) // if it's null, leave index the same
index++;
}
else
{
//Debug.Log("not adding anything here!!!");
}
}
}
return returnList;
}
示例12: GVDKarla
public GVDKarla(ObstacleGrid grid)
{
this.grid = grid;
open = new IntervalHeap<GridCellValue>();
ties = new LinkedList<GridCell>();
dist = new float[grid.NumColumns, grid.NumRows];
distNew = new float[grid.NumColumns, grid.NumRows];
parent = new GridCell[grid.NumColumns, grid.NumRows];
tie = new GridCell[grid.NumColumns, grid.NumRows];
obst = new int[grid.NumColumns, grid.NumRows];
valid = new HashSet<int>();
voro = new bool[grid.NumColumns, grid.NumRows];
for (int c = grid.NumColumns - 1; c >= 0; c--)
for (int r = grid.NumRows - 1; r >= 0; r--)
{
dist[c, r] = float.PositiveInfinity;
distNew[c, r] = float.PositiveInfinity;
parent[c, r] = GridCell.Unknown;
tie[c, r] = GridCell.Unknown;
obst[c, r] = -1;
voro[c, r] = false;
}
}
示例13: ShowDragging
/*
* Show dragging UI when trying to build an AreaBuilding
* @param mouse_down is mouse position when mouse pressed
* @param mouse_up is mouse position when mouse released
*/
public void ShowDragging(Vector3 mouse_down, Vector3 mouse_up)
{
// flip order of mouseUp and mouseDown if necessary so that lowest x and y are in mouseDown
Vector3 temp;
if (mouse_down.x > mouse_up.x) { temp.x = mouse_down.x; mouse_down.x = mouse_up.x; mouse_up.x = temp.x; }
if (mouse_down.z > mouse_up.z) { temp.z = mouse_down.z; mouse_down.z = mouse_up.z; mouse_up.z = temp.z; }
// get gridCell, size, and center for calcuation
minGridCell = GridHelper.GetGridCell (mouse_down);
maxGridCell = GridHelper.GetGridCell (mouse_up);
size = new Vector2 (maxGridCell.gridPosition.x - minGridCell.gridPosition.x + 1,
maxGridCell.gridPosition.y - minGridCell.gridPosition.y + 1);
if (size != area_building_factory.GetSize ())
{
area_building_factory.SetupPositionAndSize (minGridCell.gridPosition, size);
this.transform.position = area_building_factory.UpdateSelectionObject (minGridCell, maxGridCell, size);
DraggingUpdateLabels (minGridCell, size);
if (!this.gameObject.activeSelf)
NGUITools.SetActive (this.gameObject, true);
}
}
示例14: Update
void Update()
{
if (mMaxSecurity == -1)
mMaxSecurity = MapGrid.MaximumSecurity ();
var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
pos.z = Camera.main.transform.position.z;
var dir = new Vector3 (0, 0, 1);
var hit = Physics2D.Raycast (pos, dir, 100f, CellLayer);
if (hit) {
var cell = hit.transform.GetComponent<GridCell>();
if(cell && mHighlightedCell != cell) {
transform.position = Camera.main.WorldToScreenPoint(cell.transform.position);
var pMin = Camera.main.WorldToScreenPoint(cell.GetComponent<BoxCollider2D>().bounds.min);
var pMax = Camera.main.WorldToScreenPoint(cell.GetComponent<BoxCollider2D>().bounds.max);
var sizeW = pMax.x - pMin.x;
var sizeH = pMax.y - pMin.y;
ColorTarget.sizeDelta = new Vector2(sizeW, sizeH);
ColorTarget.GetComponent<Image>().color = Color.Lerp(LowRiskColor, HighRiskColor, (float)cell.Security / mMaxSecurity);
Population.text = FormatPopulation(cell.Population);
Security.text = cell.Security.ToString();
mHighlightedCell = cell;
}
else if(!cell) {
mHighlightedCell = null;
}
}
}
示例15: GetBombInCell
public Bomb GetBombInCell(GridCell cell) {
foreach (var bomb in GetBombs()) {
if(bomb.Target == cell && (bomb.CurrentStatus == Bomb.Status.Deployed || bomb.CurrentStatus == Bomb.Status.Ready))
return bomb;
}
return null;
}