public void IdentifyMovableNodes(TurnCharacter ch) { CharacterGridMovement gm = ch.CharGO.GetComponent <CharacterGridMovement>(); GridMovableNode currentN = gm.CurrentNode; gm.MovableNodes.Add(currentN); foreach (GridMovableNode n in currentN.AllNeighborNodes) { if (!CheckIfNodeOccupied(n)) { if (!gm.MovableNodes.Contains(n)) { gm.MovableNodes.Add(n); } for (int i = 1; i < this.moveDistance; i++) { foreach (GridMovableNode ni in n.AllNeighborNodes) { if (!gm.MovableNodes.Contains(ni)) { gm.MovableNodes.Add(ni); } } } } } AssignNodeMatsFromCharacter(gm); }
private void StartCreateGrid() { nodeList = new List <GridMovableNode>(); gridPieceList = new List <GameObject>(); gridPieceD = 2.55f; // depth (z-scale) of a grid piece gridPieceW = 2.05f; // width (x-scale) of a grid piece // Center this on the grid to position pieces based on this position this.gameObject.transform.position = new Vector3(-(gridPieceW * gridWidth * 0.5f), 0f, -(gridPieceD * gridDepth * 0.5f)); for (int z = 0; z < gridDepth; z++) { for (int x = 0; x < gridWidth; x++) { GameObject currentGridPiece; GridMovableNode currentNode = new GridMovableNode(x, z); nodeList.Add(currentNode); gridPieceList.Add(currentGridPiece = Instantiate(gridPiecePrefab, this.transform.position + new Vector3(((0.5f * gridPieceW) + (x * gridPieceW)), 0f, (0.5f * gridPieceD) + (z * gridPieceD)), Quaternion.identity)); currentGridPiece.GetComponentInChildren <UnityMovableNodeContainer>().AssignedNode = currentNode; } } foreach (GridMovableNode n1 in nodeList) { foreach (GridMovableNode n2 in nodeList) { n1.MatchUpNeighbors(n2); } } }
private void UpdateCheckMoveCursor() { int targetX = CursorGridPosX, targetZ = CursorGridPosZ; GridMovableNode targetNode; if (inputHdlr.UpKeyDown) { targetZ++; } if (inputHdlr.DownKeyDown) { targetZ--; } if (inputHdlr.LeftKeyDown) { targetX--; } if (inputHdlr.RightKeyDown) { targetX++; } targetNode = gridMgrInstance.GetNode(targetX, targetZ); if (targetNode != null) { CursorGridPosX = targetX; CursorGridPosZ = targetZ; cursorCurrentNode = targetNode; } }
public GameObject GetOccupantOfNode(GridMovableNode queryNode) { foreach (GameObject c in ActiveCharsGO) { if (c.GetComponent <CharacterGridMovement>().CurrentNode == queryNode) { return(c); } } return(null); }
public bool CheckIfNodeOccupied(GridMovableNode queryNode) { foreach (GameObject c in ActiveCharsGO) { if (c.GetComponent <CharacterGridMovement>().CurrentNode == queryNode) { return(true); } } return(false); }
/// <summary> /// Gets the node container script of a node, allowing Unity things to be done with it. /// </summary> /// <param name="node"></param> /// <returns></returns> public UnityMovableNodeContainer GetNodeContainer(GridMovableNode node) { foreach (GameObject cont in gridPieceList) { if (cont.GetComponentInChildren <UnityMovableNodeContainer>().AssignedNode == node) { return(cont.GetComponentInChildren <UnityMovableNodeContainer>()); } } return(null); }
/// <summary> /// Gets a node at abstracted position x, z in the node list. Defaults to null. /// </summary> /// <param name="x"></param> /// <param name="z"></param> /// <returns></returns> public GridMovableNode GetNode(int x, int z) { GridMovableNode returnNode = null; // default to null foreach (GridMovableNode n in nodeList) { if (n.XValue == x && n.ZValue == z) { returnNode = n; return(returnNode); } } return(returnNode); }
public void SetCurrentNode() { this.CurrentNode = gridMgrInstance.GetNode(GridPosX, GridPosZ); }
private void UpdateSetCursorLocationOnNode() { this.cursorCurrentNode = gridMgrInstance.GetNode(CursorGridPosX, CursorGridPosZ); attackCursorInstance.transform.position = gridMgrInstance.GetNodeContainer(cursorCurrentNode).gameObject.transform.position; }