public static GameObject CreateRenderCube(GridPos pos, Vector3 scale, Color color, GameObject parent) { newVertices = CreateVertices(scale); newTriangles = CreateTriangles(); var obj = new GameObject("MeshObject"); obj.AddComponent<MeshRenderer>(); obj.AddComponent<MeshFilter>(); obj.AddComponent<BoxCollider>(); obj.transform.position = new Vector3(pos.x, pos.y, pos.z); obj.GetComponent<BoxCollider>().size = new Vector3(scale.x * 2, scale.y * 2, scale.z * 2); var m = new Mesh(); obj.GetComponent<MeshFilter>().mesh = m; m.vertices = newVertices; m.triangles = newTriangles; //m.uv = UVDATA obj.GetComponent<MeshRenderer>().material = BaseMaterial; //obj.GetComponent<MeshRenderer>().material.color = color; // VISIBILITY obj.GetComponent<MeshRenderer>().enabled = false; obj.transform.parent = parent.transform; return obj; }
public Node SetNode(GridPos iPos, bool? iWalkable = null) { if (iWalkable.HasValue) { if (iWalkable.Value == true) { Node retVal = null; if (m_nodes.TryGetValue(iPos, out retVal)) { return retVal; } Node newNode = new Node(iPos.x, iPos.y, iWalkable); m_nodes.Add(iPos, newNode); return newNode; } else { removeNode(iPos); } } else { Node newNode = new Node(iPos.x, iPos.y, true); m_nodes.Add(iPos, newNode); return newNode; } return null; }
void CreateWorldLayers() { int colorCounter = 0; GridPos pos = GridUtils.WorldToGrid(transform.position, gridMinSize); GridPos vpos; GridPos gpos; for (int z = -1; z <= 1; z++) { for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { gpos = new GridPos(pos.x + x, pos.y + y, pos.z + z); vpos = new GridPos(pos.x + x * gridMinSize * 9, pos.y + y * gridMinSize * 9, pos.z + z * gridMinSize * 9); //L3Dict.Add(gpos.ToKeyString(), createRenderCube(vpos, new Vector3(45f, 0.1f, 45f), baseColors[colorCounter % 2 + 4])); vpos = new GridPos(pos.x + x * gridMinSize * 3, pos.y + y * gridMinSize * 3, pos.z + z * gridMinSize * 3); //L2Dict.Add(gpos.ToKeyString(), createRenderCube(vpos, new Vector3(15f, 1.5f, 15f), baseColors[colorCounter % 2 + 2])); vpos = new GridPos(pos.x + x * gridMinSize, pos.y + y * gridMinSize, pos.z + z * gridMinSize); //L1Dict.Add(gpos.ToKeyString(), createRenderCube(vpos, new Vector3(5f, 3f, 5f), baseColors[colorCounter++ % 2])); } } } }
public GridPos Delta(GridPos newPos) { GridPos g = new GridPos( -(x - newPos.x), -(y - newPos.y), -(z - newPos.z)); return g; }
public void CreateCubeLayers(Vector3 targetPosition) { GridUtils.BaseMaterial = BaseMaterial; int colorCounter = 0; GridPos pos = GridUtils.WorldToGrid(targetPosition, GridMinSize); GridPos vpos; GridPos gpos; float cubesize; worldObject = new GameObject("WorldRenderObject"); worldObject.transform.position = targetPosition; GameObject locObj; for (int z = -1; z <= 1; z++) { for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { //Debug.Log(String.Format("{0} {1} {2}", gpos.x, gpos.y, gpos.z)); pos = GridUtils.WorldToGrid(targetPosition, GridMinSize * 9); gpos = new GridPos(pos.x + x, pos.y + y, pos.z + z); vpos = new GridPos(gpos.x * GridMinSize * 9, gpos.y * GridMinSize * 9, gpos.z * GridMinSize * 9); cubesize = GridMinSize * 9 / 2f ; //L3Dict.Add(gpos.ToKeyString(), GridUtils.CreateRenderCube(vpos, new Vector3(45f, 0.1f, 45f), GridUtils.BaseColors[colorCounter % 2 + 4], worldObject)); L3Dict.Add(gpos.ToKeyString(), GridUtils.CreateRenderCube(vpos, new Vector3(cubesize, cubesize, cubesize), GridUtils.BaseColors[colorCounter % 2 + 4], worldObject)); locObj = Instantiate(LocatorCube, vpos.ToVector3(), Quaternion.identity) as GameObject; locObj.transform.parent = worldObject.transform; pos = GridUtils.WorldToGrid(targetPosition, GridMinSize * 3); gpos = new GridPos(pos.x + x, pos.y + y, pos.z + z); vpos = new GridPos(gpos.x * GridMinSize * 3, gpos.y * GridMinSize * 3, gpos.z * GridMinSize * 3); cubesize = GridMinSize * 3 / 2f; //L2Dict.Add(gpos.ToKeyString(), GridUtils.CreateRenderCube(vpos, new Vector3(15f, 1f, 15f), GridUtils.BaseColors[colorCounter % 2 + 2], worldObject)); L2Dict.Add(gpos.ToKeyString(), GridUtils.CreateRenderCube(vpos, new Vector3(cubesize, cubesize, cubesize), GridUtils.BaseColors[colorCounter % 2 + 2], worldObject)); locObj = Instantiate(LocatorCube, vpos.ToVector3(), Quaternion.identity) as GameObject; locObj.transform.parent = worldObject.transform; pos = GridUtils.WorldToGrid(targetPosition, GridMinSize); gpos = new GridPos(pos.x + x, pos.y + y, pos.z + z); vpos = new GridPos(gpos.x * GridMinSize, gpos.y * GridMinSize, gpos.z * GridMinSize); cubesize = GridMinSize / 2f; //L1Dict.Add(gpos.ToKeyString(), GridUtils.CreateRenderCube(vpos, new Vector3(5f, 2f, 5f), GridUtils.BaseColors[colorCounter++ % 2], worldObject)); L1Dict.Add(gpos.ToKeyString(), GridUtils.CreateRenderCube(vpos, new Vector3(cubesize, cubesize, cubesize), GridUtils.BaseColors[colorCounter++ % 2], worldObject)); locObj = Instantiate(LocatorCube, vpos.ToVector3(), Quaternion.identity) as GameObject; locObj.transform.parent = worldObject.transform; } } } EnabledTracking = true; }
public JumpPointParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, bool iAllowEndNodeUnWalkable = true, bool iCrossCorner = true, bool iCrossAdjacentPoint = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN) : this(iGrid, iAllowEndNodeUnWalkable, iCrossCorner, iCrossAdjacentPoint, iMode) { m_startNode = m_searchGrid.GetNodeAt(iStartPos.x, iStartPos.y); m_endNode = m_searchGrid.GetNodeAt(iEndPos.x, iEndPos.y); if (m_startNode == null) m_startNode = new Node(iStartPos.x, iStartPos.y, true); if (m_endNode == null) m_endNode = new Node(iEndPos.x, iEndPos.y, true); }
public bool Equals(GridPos pos) { if ((x == pos.x) && (y == pos.y) && (z == pos.z)) { return true; } else { return false; } }
private GameObject CreateWorldCube(GridPos pos, Vector3 scale, Color color) { //newVertices = createVertices(scale); //newTriangles = createTriangles(); var obj = new GameObject("MeshObject"); obj.AddComponent<MeshRenderer>(); obj.AddComponent<MeshFilter>(); obj.transform.position = new Vector3(pos.x, pos.y, pos.z); var m = new Mesh(); obj.GetComponent<MeshFilter>().mesh = m; //m.vertices = newVertices; //m.triangles = newTriangles; //m.uv = UVDATA //obj.GetComponent<MeshRenderer>().material = baseMaterial; obj.GetComponent<MeshRenderer>().material.color = color; return obj; }
public static void WriteLevelToConsole() { IEnumerable<GridPos> roomPositions = HighLevelRoom.HighLevelLocDict.Keys; int minX = roomPositions.Min(g => g.X); int maxX = roomPositions.Max(g => g.X); int minY = roomPositions.Min(g => g.Y); int maxY = roomPositions.Max(g => g.Y); Console.WriteLine("({0}, {1}) to ({2}, {3})", minX, minY, maxX, maxY); Console.WriteLine(); for (GridPos g = new GridPos(minX, maxY); g.Y >= minY; g.Y--) { for (g.X = minX; g.X <= maxX; g.X++) { if (HighLevelRoom.HighLevelLocDict.ContainsKey(g)) Console.Write(HighLevelRoom.HighLevelLocDict[g].Type); else Console.Write(" "); } Console.WriteLine(string.Empty); } }
void UpdateGridCubes(ref GridPos prevGridPosL, ref GridPos newGridPosL, int gridSize, Dictionary<String, GameObject> LDict, int level) { newGridPosL = GridUtils.WorldToGrid(playerObject.transform.position, gridSize); if (!prevGridPosL.Equals(newGridPosL)) { GridPos deltaPos = prevGridPosL.Delta(newGridPosL); GridPos vPosL; string vPosKeyL; GameObject gObj; Vector3 newVector3; GridPos newGridPos; if (deltaPos.x != 0) { for (var i = -1; i <= 1; i++) { for (var j = -1; j <= 1; j++) { vPosL = new GridPos(prevGridPosL.x - deltaPos.x, prevGridPosL.y + i, prevGridPosL.z + j); vPosKeyL = vPosL.ToKeyString(); if (LDict.ContainsKey(vPosKeyL)) { gObj = LDict[vPosKeyL]; LDict.Remove(vPosKeyL); newGridPos = new GridPos(newGridPosL.x + deltaPos.x, prevGridPosL.y + i, prevGridPosL.z + j); newVector3 = new Vector3(newGridPos.x * gridSize, newGridPos.y * gridSize, newGridPos.z * gridSize); gObj.transform.position = newVector3; LDict.Add(newGridPos.ToKeyString(), gObj); StartCoroutine(TransitionRenderCube(gObj, level, newGridPos)); } else { Debug.Log("KEY NOT FOUND :" + vPosKeyL); } } } } if (deltaPos.z != 0) { for (var i = -1 + deltaPos.x; i <= 1 + deltaPos.x; i++) { for (var j = -1; j <= 1; j++) { vPosL = new GridPos(prevGridPosL.x + i, prevGridPosL.y + j, prevGridPosL.z - deltaPos.z); vPosKeyL = vPosL.ToKeyString(); if (LDict.ContainsKey(vPosKeyL)) { gObj = LDict[vPosKeyL]; LDict.Remove(vPosKeyL); newGridPos = new GridPos(prevGridPosL.x + i, prevGridPosL.y + j, newGridPosL.z + deltaPos.z); newVector3 = new Vector3(newGridPos.x * gridSize, newGridPos.y * gridSize, newGridPos.z * gridSize); gObj.transform.position = newVector3; LDict.Add(newGridPos.ToKeyString(), gObj); StartCoroutine(TransitionRenderCube(gObj, level, newGridPos)); } else { Debug.Log("KEY NOT FOUND :" + vPosKeyL); } } } } if (deltaPos.y != 0) { for (var i = -1 + deltaPos.x; i <= 1 + deltaPos.x; i++) { for (var j = -1 + deltaPos.z; j <= 1 + deltaPos.z; j++) { vPosL = new GridPos(prevGridPosL.x + i, prevGridPosL.y - deltaPos.y, prevGridPosL.z + j); vPosKeyL = vPosL.ToKeyString(); if (LDict.ContainsKey(vPosKeyL)) { gObj = LDict[vPosKeyL]; LDict.Remove(vPosKeyL); newGridPos = new GridPos(prevGridPosL.x + i, newGridPosL.y + deltaPos.y, prevGridPosL.z + j); newVector3 = new Vector3(newGridPos.x * gridSize, newGridPos.y * gridSize, newGridPos.z * gridSize); gObj.transform.position = newVector3; LDict.Add(newGridPos.ToKeyString(), gObj); StartCoroutine(TransitionRenderCube(gObj, level, newGridPos)); } else { Debug.Log("KEY NOT FOUND :" + vPosKeyL); } } } } prevGridPosL = newGridPosL; } }
public override bool SetWalkableAt(int iX, int iY, bool iWalkable) { if (!IsInside(iX,iY)) return false; GridPos pos = new GridPos(iX, iY); m_nodePool.SetNode(pos, iWalkable); return true; }
public static FlatHexPoint getPoint(GridPos _position) { return(new FlatHexPoint(_position.x, _position.y)); }
public bool GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 pos_local, out Vector3 pos_matrix, out GridPos gp_matrix) { pos_world = Vector3.zero; pos_local = Vector3.zero; pos_matrix = Vector3.zero; gp_matrix = GridPos.Zero; Ray ray = DragProcessor.Camera.ScreenPointToRay(DragProcessor.CurrentMousePosition_Screen); Physics.Raycast(ray, out RaycastHit hit, 1000f, LayerManager.Instance.LayerMask_DragAreas); if (hit.collider) { if (hit.collider == BoxCollider) { pos_world = hit.point; //todo!!!!! return(true); } else { return(false); } } return(false); }
public IEnumerator Load() { DebugLog("+Load()"); var pyriteQuery = new PyriteQuery(this, SetName, ModelVersion, PyriteServer); yield return StartCoroutine(pyriteQuery.LoadAll()); DebugLog("CubeQuery complete."); var pyriteLevel = pyriteQuery.DetailLevels[DetailLevel]; var allOctCubes = pyriteQuery.DetailLevels[DetailLevel].Octree.AllItems(); foreach (var octCube in allOctCubes) { var pCube = CreateCubeFromCubeBounds(octCube); var x = pCube.X; var y = pCube.Y; var z = pCube.Z; var cubePos = pyriteLevel.GetWorldCoordinatesForCube(pCube); if (UseCameraDetection) { // Move cube to the orientation we want also move it up since the model is around -600 var g = (GameObject) //Instantiate(PlaceHolderCube, new Vector3(-cubePos.x, cubePos.z + 600, -cubePos.y), //Instantiate(PlaceHolderCube, new Vector3(-cubePos.x, cubePos.z, -cubePos.y), Instantiate(PlaceHolderCube, new Vector3(cubePos.x, cubePos.y, cubePos.z), Quaternion.identity); //var loc = Instantiate(LocatorCube, new Vector3(cubePos.x, cubePos.y, cubePos.z), Quaternion.identity) as GameObject; var loc = Instantiate(LocatorCube, cubePos, Quaternion.identity) as GameObject; loc.transform.parent = gameObject.transform; g.transform.parent = gameObject.transform; //g.GetComponent<MeshRenderer>().material.color = _colorList[_colorSelector%_colorList.Length]; g.GetComponent<IsRendered>().SetCubePosition(x, y, z, DetailLevel, pyriteQuery, this); g.transform.localScale = new Vector3( pyriteLevel.WorldCubeScale.x, pyriteLevel.WorldCubeScale.z, pyriteLevel.WorldCubeScale.y); _colorSelector++; } else { var loadRequest = new LoadCubeRequest(x, y, z, DetailLevel, pyriteQuery, null); EnqueueLoadCubeRequest(loadRequest); } } if (CameraRig != null) { //DebugLog("Moving camera"); // Hardcoding some values for now //var min = new Vector3(pyriteLevel.ModelBoundsMin.x, pyriteLevel.ModelBoundsMin.y, // pyriteLevel.ModelBoundsMin.z); //var max = new Vector3(pyriteLevel.ModelBoundsMax.x, pyriteLevel.ModelBoundsMax.y, // pyriteLevel.ModelBoundsMax.z); //min += pyriteLevel.WorldCubeScale/2; //max -= pyriteLevel.WorldCubeScale/2; //var newCameraPosition = min + (max - min)/2.0f; //newCameraPosition += new Vector3(0, 0, (max - min).z*1.4f); //CameraRig.transform.position = newCameraPosition; //CameraRig.transform.rotation = Quaternion.Euler(0, 180, 0); //DebugLog("Done moving camera"); //var delta = pyriteLevel.ModelBoundsMax - pyriteLevel.ModelBoundsMin; //var center = pyriteLevel.ModelBoundsMin + new Vector3(-delta.x / 2, delta.z /2 , -delta.y); //CameraRig.transform.position = center; //var allOctCubes = pyriteQuery.DetailLevels[DetailLevel].Octree.AllItems(); // RPL CONVERSION List<GridPos> gList = new List<GridPos>(); Dictionary<string, CubeBounds> gDict = new Dictionary<string, CubeBounds>(); foreach (var octCube in allOctCubes) { var pCube = CreateCubeFromCubeBounds(octCube); var x = pCube.X; var y = pCube.Y; var z = pCube.Z; var gPos = new GridPos(x, y, z); gList.Add(gPos); gDict.Add(gPos.ToKeyString(), octCube); } int midIndex = gList.Count / 2; var gMid = gList.OrderBy(n => n.x).ThenBy(n => n.y).ThenBy(n => n.z).ToList()[midIndex]; var cubeBound = CreateCubeFromCubeBounds(gDict[gMid.ToKeyString()]); var cubeVector3 = pyriteLevel.GetWorldCoordinatesForCube(cubeBound); CameraRig.transform.position = cubeVector3; var r = Instantiate(LocatorCube, cubeVector3, Quaternion.identity) as GameObject; r.GetComponent<MeshRenderer>().material.color = Color.green; r.transform.localScale = new Vector3(12f, 12f, 12f); //Instantiate(RenderCubes); //RenderCubes.GetComponent<RenderCubes3D>().GridMinSize = (int)(pyriteQuery.DetailLevels[DetailLevel].WorldCubeScale.x); // World Size cut to 3x3x3 Sections //RenderCubes.GetComponent<RenderCubes3D>().CreateCubeLayers(CameraRig.transform.position); } DebugLog("-Load()"); }
private static GridPos? jumpLoop(JumpPointParam iParam, int iX, int iY, int iPx, int iPy) { GridPos? retVal = null; Stack<JumpSnapshot> stack = new Stack<JumpSnapshot>(); JumpSnapshot currentSnapshot = new JumpSnapshot(); JumpSnapshot newSnapshot = null; currentSnapshot.iX = iX; currentSnapshot.iY = iY; currentSnapshot.iPx = iPx; currentSnapshot.iPy = iPy; currentSnapshot.stage = 0; stack.Push(currentSnapshot); while (stack.Count != 0) { currentSnapshot = stack.Pop(); switch (currentSnapshot.stage) { case 0: if (!iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY)) { retVal = null; continue; } else if (iParam.SearchGrid.GetNodeAt(currentSnapshot.iX, currentSnapshot.iY).Equals(iParam.EndNode)) { retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY); continue; } currentSnapshot.tDx = currentSnapshot.iX - currentSnapshot.iPx; currentSnapshot.tDy = currentSnapshot.iY - currentSnapshot.iPy; currentSnapshot.jx = null; currentSnapshot.jy = null; if (iParam.CrossCorner) { // check for forced neighbors // along the diagonal if (currentSnapshot.tDx != 0 && currentSnapshot.tDy != 0) { if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - currentSnapshot.tDx, currentSnapshot.iY + currentSnapshot.tDy) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - currentSnapshot.tDx, currentSnapshot.iY)) || (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY - currentSnapshot.tDy) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY - currentSnapshot.tDy))) { retVal= new GridPos(currentSnapshot.iX, currentSnapshot.iY); continue; } } // horizontally/vertically else { if (currentSnapshot.tDx != 0) { // moving along x if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY + 1) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + 1)) || (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY - 1) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY - 1))) { retVal= new GridPos(currentSnapshot.iX, currentSnapshot.iY); continue; } } else { if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + 1, currentSnapshot.iY + currentSnapshot.tDy) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + 1, currentSnapshot.iY)) || (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - 1, currentSnapshot.iY + currentSnapshot.tDy) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - 1, currentSnapshot.iY))) { retVal= new GridPos(currentSnapshot.iX, currentSnapshot.iY); continue; } } } // when moving diagonally, must check for vertical/horizontal jump points if (currentSnapshot.tDx != 0 && currentSnapshot.tDy != 0) { currentSnapshot.stage = 1; stack.Push(currentSnapshot); newSnapshot = new JumpSnapshot(); newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx; newSnapshot.iY = currentSnapshot.iY; newSnapshot.iPx = currentSnapshot.iX; newSnapshot.iPy = currentSnapshot.iY; newSnapshot.stage = 0; stack.Push(newSnapshot); continue; } // moving diagonally, must make sure one of the vertical/horizontal // neighbors is open to allow the path // moving diagonally, must make sure one of the vertical/horizontal // neighbors is open to allow the path if (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) || iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy)) { newSnapshot = new JumpSnapshot(); newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx; newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy; newSnapshot.iPx = currentSnapshot.iX; newSnapshot.iPy = currentSnapshot.iY; newSnapshot.stage = 0; stack.Push(newSnapshot); continue; } else if (iParam.CrossAdjacentPoint) { newSnapshot = new JumpSnapshot(); newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx; newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy; newSnapshot.iPx = currentSnapshot.iX; newSnapshot.iPy = currentSnapshot.iY; newSnapshot.stage = 0; stack.Push(newSnapshot); continue; } } else //if (!iParam.CrossCorner) { // check for forced neighbors // along the diagonal if (currentSnapshot.tDx != 0 && currentSnapshot.tDy != 0) { if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY + currentSnapshot.tDy) && iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY)) || (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY + currentSnapshot.tDy) && iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy))) { retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY); continue; } } // horizontally/vertically else { if (currentSnapshot.tDx != 0) { // moving along x if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + 1) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - currentSnapshot.tDx, currentSnapshot.iY + 1)) || (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY - 1) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - currentSnapshot.tDx, currentSnapshot.iY - 1))) { retVal= new GridPos(currentSnapshot.iX, currentSnapshot.iY); continue; } } else { if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + 1, currentSnapshot.iY) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + 1, currentSnapshot.iY - currentSnapshot.tDy)) || (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - 1, currentSnapshot.iY) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - 1, currentSnapshot.iY - currentSnapshot.tDy))) { retVal= new GridPos(currentSnapshot.iX, currentSnapshot.iY); continue; } } } // when moving diagonally, must check for vertical/horizontal jump points if (currentSnapshot.tDx != 0 && currentSnapshot.tDy != 0) { currentSnapshot.stage = 3; stack.Push(currentSnapshot); newSnapshot = new JumpSnapshot(); newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx; newSnapshot.iY = currentSnapshot.iY; newSnapshot.iPx = currentSnapshot.iX; newSnapshot.iPy = currentSnapshot.iY; newSnapshot.stage = 0; stack.Push(newSnapshot); continue; } // moving diagonally, must make sure both of the vertical/horizontal // neighbors is open to allow the path if (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) && iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy)) { newSnapshot = new JumpSnapshot(); newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx; newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy; newSnapshot.iPx = currentSnapshot.iX; newSnapshot.iPy = currentSnapshot.iY; newSnapshot.stage = 0; stack.Push(newSnapshot); continue; } } retVal = null; break; case 1: currentSnapshot.jx = retVal; currentSnapshot.stage = 2; stack.Push(currentSnapshot); newSnapshot = new JumpSnapshot(); newSnapshot.iX = currentSnapshot.iX; newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy; newSnapshot.iPx = currentSnapshot.iX; newSnapshot.iPy = currentSnapshot.iY; newSnapshot.stage = 0; stack.Push(newSnapshot); break; case 2: currentSnapshot.jy = retVal; if (currentSnapshot.jx != null || currentSnapshot.jy != null) { retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY); continue; } // moving diagonally, must make sure one of the vertical/horizontal // neighbors is open to allow the path if (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) || iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy)) { newSnapshot = new JumpSnapshot(); newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx; newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy; newSnapshot.iPx = currentSnapshot.iX; newSnapshot.iPy = currentSnapshot.iY; newSnapshot.stage = 0; stack.Push(newSnapshot); continue; } else if (iParam.CrossAdjacentPoint) { newSnapshot = new JumpSnapshot(); newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx; newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy; newSnapshot.iPx = currentSnapshot.iX; newSnapshot.iPy = currentSnapshot.iY; newSnapshot.stage = 0; stack.Push(newSnapshot); continue; } retVal = null; break; case 3: currentSnapshot.jx = retVal; currentSnapshot.stage = 4; stack.Push(currentSnapshot); newSnapshot = new JumpSnapshot(); newSnapshot.iX = currentSnapshot.iX; newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy; newSnapshot.iPx = currentSnapshot.iX; newSnapshot.iPy = currentSnapshot.iY; newSnapshot.stage = 0; stack.Push(newSnapshot); break; case 4: currentSnapshot.jy = retVal; if (currentSnapshot.jx != null || currentSnapshot.jy != null) { retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY); continue; } // moving diagonally, must make sure both of the vertical/horizontal // neighbors is open to allow the path if (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) && iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy)) { newSnapshot = new JumpSnapshot(); newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx; newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy; newSnapshot.iPx = currentSnapshot.iX; newSnapshot.iPy = currentSnapshot.iY; newSnapshot.stage = 0; stack.Push(newSnapshot); continue; } retVal = null; break; } } return retVal; }
public bool SetWalkableAt(GridPos iPos, bool iWalkable) { return(this.SetWalkableAt(iPos.x, iPos.y, iWalkable)); }
public override bool SetWalkableAt(int iX, int iY, bool iWalkable) { GridPos pos = new GridPos(iX, iY); m_nodePool.SetNode(pos, iWalkable); if (iWalkable) { if (iX < m_gridRect.minX || m_notSet) m_gridRect.minX = iX; if (iX > m_gridRect.maxX || m_notSet) m_gridRect.maxX = iX; if (iY < m_gridRect.minY || m_notSet) m_gridRect.minY = iY; if (iY > m_gridRect.maxY || m_notSet) m_gridRect.maxY = iY; m_notSet = false; } else { if (iX == m_gridRect.minX || iX == m_gridRect.maxX || iY == m_gridRect.minY || iY == m_gridRect.maxY) m_notSet = true; } return true; }
public bool Equals(GridPos p) { return(x == p.x && y == p.y); }
public override Node GetNodeAt(GridPos iPos) { return(this.m_nodePool.GetNode(iPos)); }
public void Draggable_OnMousePressed(DragAreaIndicator dragAreaIndicator, Vector3 diffFromStart, Vector3 deltaFromLastFrame) { void ResumePausedDrag() { InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix; UIInventory.RemoveItem(InventoryItem, true); Destroy(gameObject); DragManager.Instance.ResumePausedDrag(); } if (dragAreaIndicator == UIInventory.DragAreaIndicator) { if (UIInventory.RotateItemKeyDownHandler != null && UIInventory.RotateItemKeyDownHandler.Invoke()) { Rotate(); } if (diffFromStart.magnitude > Draggable_DragMinDistance) { Vector2 diffLocal = RectTransform.parent.InverseTransformVector(diffFromStart); Vector2 currentLocalPos = dragStartLocalPos + diffLocal; GridPosR diff_world = GridPos.GetGridPosByPointXY(diffLocal, UIInventory.GridSize); diff_world.orientation = InventoryItem.GridPos_Matrix.orientation; GridPosR diff_matrix = UIInventory.CoordinateTransformationHandler_FromPosToMatrixIndex(diff_world); GridPosR gp_matrix = dragStartGridPos_Matrix + diff_matrix; gp_matrix.orientation = InventoryItem.GridPos_Matrix.orientation; InventoryItem.GridPos_Matrix = gp_matrix; SetVirtualGridPos(InventoryItem.GridPos_World); RectTransform.anchoredPosition = currentLocalPos; } } else { Vector2 diffLocal = RectTransform.parent.InverseTransformVector(diffFromStart); Vector2 currentLocalPos = dragStartLocalPos + diffLocal; RectTransform.anchoredPosition = currentLocalPos; UIInventory.UIInventoryPanel.UIInventoryVirtualOccupationQuadRoot.Clear(); if (dragAreaIndicator != null) // drag to other DragAreas { if (DragManager.Instance.PausedDrag != null) { ResumePausedDrag(); } else { // only when mouse move to available grid then generate previewItem if (dragAreaIndicator is UIInventoryDragAreaIndicator uiDAI) { uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 pos_local, out Vector3 pos_matrix, out GridPos gp_matrix); GridPosR gpr = gp_matrix; gpr.orientation = InventoryItem.GridPos_Matrix.orientation; InventoryItem previewItem = new InventoryItem(InventoryItem.Clone().ItemContentInfo, uiDAI.UIInventory, gpr); uiDAI.UIInventory.AddPreviewItem(previewItem); UIInventoryItem uiInventoryItem = uiDAI.UIInventory.UIInventoryPanel.GetUIInventoryItem(previewItem.GUID); DragManager.Instance.PauseDrag(); DragManager.Instance.CurrentDrag = uiInventoryItem.Draggable; uiInventoryItem.Draggable.SetOnDrag(true, uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.BoxCollider, UIInventory.DragProcessor); } } } else // drag to non-DragArea { if (DragManager.Instance.PausedDrag != null) { ResumePausedDrag(); } } } }
public virtual void ReplanGlobal(Platform platform) { // create searchGrid data structure for the EpPathFinding BaseGrid searchGrid = new StaticGrid(platform.Map.Rows, platform.Map.Columns); List <Tuple <double, GridPos> > searchPoses = new List <Tuple <double, GridPos> > (); // possible search poses for (int i = 0; i < platform.Map.Rows; i++) { for (int j = 0; j < platform.Map.Columns; j++) { if (platform.Map.MapMatrix[i, j] < platform.OccupiedThreshold) { searchGrid.SetWalkableAt(i, j, true); } if ((platform.Map.MapMatrix[i, j] >= platform.FreeThreshold) && (platform.Map.MapMatrix[i, j] <= platform.OccupiedThreshold)) { RegionLimits limits = platform.Map.CalculateLimits(i, j, 1); List <Pose> posesl = limits.GetPosesWithinLimits(); foreach (Pose p in posesl) { if (platform.Map.MapMatrix[p.X, p.Y] < platform.FreeThreshold) { double d = Math.Sqrt(Math.Pow(p.X - platform.Pose.X, 2) + Math.Pow(p.Y - platform.Pose.Y, 2)); searchPoses.Add(new Tuple <double, GridPos>(d, new GridPos(i, j))); break; } } } } } // set unaccessable for those places where are platforms and their enviroment within 1 step radius foreach (Platform plt in platform.ObservedPlatforms) { if (plt.Equals(platform)) { continue; } RegionLimits limits = platform.Map.CalculateLimits(plt.Pose.X, plt.Pose.Y, 1); List <Pose> posesl = limits.GetPosesWithinLimits(); foreach (Pose p in posesl) { searchGrid.SetWalkableAt(p.X, p.Y, false); } } // bound the search to avoid large computation // select the first closest 50 candidates based on L2 distance int maxNumOfSearchPoses = 50; searchPoses.Sort((t1, t2) => t1.Item1.CompareTo(t2.Item1)); if (searchPoses.Count > maxNumOfSearchPoses) { searchPoses.RemoveRange(maxNumOfSearchPoses, searchPoses.Count - maxNumOfSearchPoses); } // init search GridPos startPos = new GridPos(platform.Pose.X, platform.Pose.Y); GridPos endPos = new GridPos(20, 10); JumpPointParam jpParam = new JumpPointParam(searchGrid, startPos, endPos, false, true, true); // find the best path double bestPathScore = Double.PositiveInfinity; List <GridPos> bestPath = null; foreach (Tuple <double, GridPos> p in searchPoses) { //jpParam.Reset(startPos, p); jpParam.Reset(new GridPos(platform.Pose.X, platform.Pose.Y), p.Item2); List <GridPos> resultPathList = JumpPointFinder.FindPath(jpParam); if (resultPathList.Count > 2) { double score = 0; for (int i = 1; i < resultPathList.Count; i++) { score += Math.Sqrt(Math.Pow(resultPathList[i].x - resultPathList[i - 1].x, 2) + Math.Pow(resultPathList[i].y - resultPathList[i - 1].y, 2)); } if (score < bestPathScore) { bestPathScore = score; bestPath = resultPathList; bestFronterier = new Pose(resultPathList.Last().x, resultPathList.Last().y); } } } // convert the best path to command sequence if ((bestPath != null) && (bestPath.Count > 2)) { List <Pose> bestPathConv = new List <Pose>(); bestPathConv.Add(platform.Pose); for (int i = 1; i < bestPath.Count; i++) { Pose prevPose = bestPathConv.Last(); Pose goalPose = new Pose(bestPath[i].x, bestPath[i].y); int dxl = Math.Sign(goalPose.X - prevPose.X); int dyl = Math.Sign(goalPose.Y - prevPose.Y); while (!prevPose.Equals(goalPose)) // it's a bit dangerous here { Pose newPose = new Pose(prevPose.X + dxl, prevPose.Y + dyl); prevPose = newPose; bestPathConv.Add(newPose); } } for (int i = bestPathConv.Count - 2; i > 0; i--) { int dx = bestPathConv[i + 1].X - bestPathConv[i].X; int dy = bestPathConv[i + 1].Y - bestPathConv[i].Y; double dalpha = Math.Atan2(dy, dx); Pose newPose = new Pose(bestPathConv[i].X, bestPathConv[i].Y, dalpha); commandSequence.Push(newPose); } } }
public void RefreshMechaMatrix(out List <MechaComponentBase> conflictComponents, out List <MechaComponentBase> isolatedComponents) { foreach (MechaComponentBase mcb in mechaComponents) { mcb.MechaComponentGrids.SetIsolatedIndicatorShown(false); mcb.MechaComponentGrids.TurnOffAllForbidIndicator(); } List <GridPos> coreGPs = new List <GridPos>(); List <MechaComponentBase> notConflictComponents = new List <MechaComponentBase>(); // Find conflict components List <GridPos> conflictGridPositions = new List <GridPos>(); conflictComponents = new List <MechaComponentBase>(); for (int z = 0; z < mechaComponentMatrix.GetLength(0); z++) { for (int x = 0; x < mechaComponentMatrix.GetLength(1); x++) { mechaComponentMatrix[z, x] = null; } } foreach (MechaComponentBase mcb in mechaComponents) { bool isCore = mcb.MechaComponentInfo.MechaComponentType == MechaComponentType.Core; bool hasConflict = false; foreach (GridPos gp in mcb.MechaComponentInfo.OccupiedGridPositions) { GridPos gp_matrix = gp.ConvertGridPosToMatrixIndex(); if (gp_matrix.x < 0 || gp_matrix.x >= mechaComponentMatrix.GetLength(1) || gp_matrix.z < 0 || gp_matrix.z >= mechaComponentMatrix.GetLength(0)) { hasConflict = true; conflictGridPositions.Add(gp_matrix); } else { if (mechaComponentMatrix[gp_matrix.z, gp_matrix.x] != null) { hasConflict = true; conflictGridPositions.Add(gp_matrix); } else { mechaComponentMatrix[gp_matrix.z, gp_matrix.x] = mcb; if (isCore) { coreGPs.Add(gp_matrix); } } } } if (hasConflict) { conflictComponents.Add(mcb); } else { notConflictComponents.Add(mcb); } } foreach (GridPos gp in conflictGridPositions) { AddForbidComponentIndicator(gp); } // Find isolated components List <GridPos> isolatedGridPositions = new List <GridPos>(); isolatedComponents = new List <MechaComponentBase>(); int[,] connectedMatrix = new int[ConfigManager.EDIT_AREA_SIZE * 2 + 1, ConfigManager.EDIT_AREA_SIZE * 2 + 1]; foreach (MechaComponentBase mcb in notConflictComponents) { foreach (GridPos gp in mcb.MechaComponentInfo.OccupiedGridPositions) { GridPos gp_matrix = gp.ConvertGridPosToMatrixIndex(); connectedMatrix[gp_matrix.z, gp_matrix.x] = 1; } } Queue <GridPos> connectedQueue = new Queue <GridPos>(); foreach (GridPos coreGP in coreGPs) { connectedMatrix[coreGP.z, coreGP.x] = 2; connectedQueue.Enqueue(coreGP); } void connectPos(int z, int x) { if (x < 0 || x >= mechaComponentMatrix.GetLength(1) || z < 0 || z >= mechaComponentMatrix.GetLength(0)) { return; } else { int a = connectedMatrix[z, x]; if (connectedMatrix[z, x] == 1) { connectedQueue.Enqueue(new GridPos(x, z)); connectedMatrix[z, x] = 2; } } } while (connectedQueue.Count > 0) { GridPos gp = connectedQueue.Dequeue(); connectPos(gp.z + 1, gp.x); connectPos(gp.z - 1, gp.x); connectPos(gp.z, gp.x - 1); connectPos(gp.z, gp.x + 1); } for (int z = 0; z < connectedMatrix.GetLength(0); z++) { for (int x = 0; x < connectedMatrix.GetLength(1); x++) { if (connectedMatrix[z, x] == 1) { isolatedGridPositions.Add((new GridPos(x, z))); MechaComponentBase isolatedComponent = mechaComponentMatrix[z, x]; if (!isolatedComponents.Contains(isolatedComponent)) { isolatedComponents.Add(isolatedComponent); } } } } foreach (GridPos gp in isolatedGridPositions) { AddIsolatedComponentIndicator(gp); } }
public override Node GetNodeAt(GridPos iPos) { if (!IsInside(iPos)) return null; return m_nodePool.GetNode(iPos); }
public void RefreshConflictAndIsolation(out List <InventoryItem> conflictItems, out List <InventoryItem> isolatedItems) { foreach (InventoryItem item in InventoryInfo.InventoryItems) { item.OnIsolatedHandler?.Invoke(false); item.OnResetConflictHandler?.Invoke(); } List <GridPos> coreGPs = new List <GridPos>(); List <InventoryItem> notConflictItems = new List <InventoryItem>(); // Find conflict items List <GridPos> conflictGridPositions = new List <GridPos>(); conflictItems = new List <InventoryItem>(); for (int col = 0; col < Columns; col++) { for (int row = 0; row < Rows; row++) { InventoryItemMatrix[col, row] = null; } } foreach (InventoryItem item in InventoryInfo.InventoryItems) { bool isRootItem = item.AmIRootItemInIsolationCalculationHandler != null && item.AmIRootItemInIsolationCalculationHandler.Invoke(); bool hasConflict = false; foreach (GridPos gp_matrix in item.OccupiedGridPositions_Matrix) { if (gp_matrix.x < 0 || gp_matrix.x >= Columns || gp_matrix.z < 0 || gp_matrix.z >= Rows) { hasConflict = true; conflictGridPositions.Add(gp_matrix); } else { if (InventoryItemMatrix[gp_matrix.x, gp_matrix.z] != null) { hasConflict = true; conflictGridPositions.Add(gp_matrix); } else { InventoryItemMatrix[gp_matrix.x, gp_matrix.z] = item; if (isRootItem) { coreGPs.Add(gp_matrix); } } } } if (hasConflict) { conflictItems.Add(item); } else { notConflictItems.Add(item); } } foreach (GridPos gp in conflictGridPositions) { AddForbidComponentIndicator(gp); } // Find isolated components List <GridPos> isolatedGridPositions = new List <GridPos>(); isolatedItems = new List <InventoryItem>(); int[,] connectedMatrix = new int[Columns, Rows]; foreach (InventoryItem item in notConflictItems) { foreach (GridPos gp_matrix in item.OccupiedGridPositions_Matrix) { connectedMatrix[gp_matrix.x, gp_matrix.z] = 1; } } Queue <GridPos> connectedQueue = new Queue <GridPos>(); foreach (GridPos coreGP in coreGPs) { connectedMatrix[coreGP.x, coreGP.z] = 2; connectedQueue.Enqueue(coreGP); } void connectPos(int col, int row) { if (row < 0 || row >= Rows || col < 0 || col >= Columns) { return; } else { if (connectedMatrix[col, row] == 1) { connectedQueue.Enqueue(new GridPos(col, row)); connectedMatrix[col, row] = 2; } } } while (connectedQueue.Count > 0) { GridPos gp = connectedQueue.Dequeue(); connectPos(gp.x + 1, gp.z); connectPos(gp.x - 1, gp.z); connectPos(gp.x, gp.z - 1); connectPos(gp.x, gp.z + 1); } for (int col = 0; col < Columns; col++) { for (int row = 0; row < Rows; row++) { if (connectedMatrix[col, row] == 1) { isolatedGridPositions.Add((new GridPos(col, row))); InventoryItem isolatedItem = InventoryItemMatrix[col, row]; if (!isolatedItems.Contains(isolatedItem)) { isolatedItems.Add(isolatedItem); } } } } foreach (GridPos gp in isolatedGridPositions) { AddIsolatedComponentIndicator(gp); } }
public override void Reset() { int rectCount=(m_gridRect.maxX-m_gridRect.minX) * (m_gridRect.maxY-m_gridRect.minY); if (m_nodePool.Nodes.Count > rectCount) { GridPos travPos = new GridPos(0, 0); for (int xTrav = m_gridRect.minX; xTrav <= m_gridRect.maxX; xTrav++) { travPos.x = xTrav; for (int yTrav = m_gridRect.minY; yTrav <= m_gridRect.maxY; yTrav++) { travPos.y = yTrav; Node curNode=m_nodePool.GetNode(travPos); if (curNode!=null) curNode.Reset(); } } } else { foreach (KeyValuePair<GridPos, Node> keyValue in m_nodePool.Nodes) { keyValue.Value.Reset(); } } }
private void AddIsolatedComponentIndicator(GridPos gp_matrix) { InventoryItem item = InventoryItemMatrix[gp_matrix.x, gp_matrix.z]; item?.OnIsolatedHandler?.Invoke(true); }
public override bool IsWalkableAt(GridPos iPos) { return m_nodePool.Nodes.ContainsKey(iPos); }
public void MoveEntity(blockData entity, GridPos newPos) { levelBlocks[entity.blockPos.x, entity.blockPos.y, entity.blockPos.z] = BLOCK_NULL; levelBlocks[newPos.x, newPos.y, newPos.z] = entity.blockID; entity.blockPos = newPos; }
private bool IsFarEnough(Vector2 sample) { GridPos pos = new GridPos(sample, cellSize); int xmin = Mathf.Max(pos.x - 2, 0); int ymin = Mathf.Max(pos.y - 2, 0); int xmax = Mathf.Min(pos.x + 2, grid.GetLength(0) - 1); int ymax = Mathf.Min(pos.y + 2, grid.GetLength(1) - 1); //randomly modify the radius to cluster the samples float modRad2 = radius2 * CustomMathf.RemapValue(Mathf.PerlinNoise(sample.x + Random.seed, sample.y + Random.seed), clusterRange.x, clusterRange.y); for (int y = ymin; y <= ymax; y++) { for (int x = xmin; x <= xmax; x++) { Vector2 s = grid[x, y]; if (s != Vector2.zero) { Vector2 d = s - sample; if (d.x * d.x + d.y * d.y < modRad2) return false; } } } return true; // Note: we use the zero vector to denote an unfilled cell in the grid. This means that if we were // to randomly pick (0, 0) as a sample, it would be ignored for the purposes of proximity-testing // and we might end up with another sample too close from (0, 0). This is a very minor issue. }
protected bool isInside(GridPos iPos) { return(isInside(iPos.x, iPos.y)); }
public abstract bool SetWalkableAt(GridPos iPos, bool iWalkable);
public override Node GetNodeAt(GridPos iPos) { return(GetNodeAt(iPos.x, iPos.y)); }
public bool Equals(GridPos gp) { return(gp.x == x && gp.z == z && gp.orientation == orientation); }
public override bool IsWalkableAt(GridPos iPos) { return(IsWalkableAt(iPos.x, iPos.y)); }
IEnumerator TransitionRenderCube(GameObject obj, int level, GridPos gPos) { // STORE CUBE DATA // // Check if in Cache // -- Set cache entry as MRU // -- NOT: Create new cache entry, remove LRU entry if needed // LOAD CUBE DATA // // Check if in Cache // -- Load entry, set as MRU // -- NOT: Load from Web yield return null; }
public override bool SetWalkableAt(GridPos iPos, bool iWalkable) { return(SetWalkableAt(iPos.x, iPos.y, iWalkable)); }
internal abstract void _reset(GridPos iStartPos, GridPos iEndPos, BaseGrid iSearchGrid = null);
public void _ToString() { var pos = new GridPos(5, 6); Assert.AreNotEqual(pos.ToString(), "(X=5, Y=6)"); }
public bool IsInside(GridPos iPos) { return IsInside(iPos.x, iPos.y); }
public override Node GetNodeAt(int iX, int iY) { GridPos pos = new GridPos(iX, iY); return(GetNodeAt(pos)); }
public override bool IsWalkableAt(GridPos iPos) { if (!IsInside(iPos)) return false; return m_nodePool.Nodes.ContainsKey(iPos); }
public override bool IsWalkableAt(int iX, int iY) { GridPos pos = new GridPos(iX, iY); return(IsWalkableAt(pos)); }
public override bool IsWalkableAt(int iX, int iY) { GridPos pos = new GridPos(iX, iY); return IsWalkableAt(pos); }
public override bool IsWalkableAt(GridPos iPos) { return(m_nodes.ContainsKey(iPos)); }
public override Node GetNodeAt(GridPos iPos) { return m_nodePool.GetNode(iPos); }
protected bool isInside(GridPos iPos) { return isInside(iPos.x, iPos.y); }
public override Node GetNodeAt(int iX, int iY) { GridPos pos = new GridPos(iX, iY); return GetNodeAt(pos); }
public override bool IsWalkableAt(GridPos iPos) { return IsWalkableAt(iPos.x, iPos.y); }
/// Adds the sample to the active samples queue and the grid before returning it private Vector2 AddSample(Vector2 sample) { activeSamples.Add(sample); GridPos pos = new GridPos(sample, cellSize); grid[pos.x, pos.y] = sample; return sample; }
public void Update() { if (GameStateManager.Instance.GetState() == GameState.Building) { if (DragManager.Instance.CurrentDrag == null && DragManager.Instance.Current_DragArea.Equals(DragAreaDefines.MechaEditorArea)) { // Mouse Right button drag for rotate view if (ControlManager.Instance.Building_MouseRight.Down) { onMouseDrag_Right = true; if (GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 _, out Vector3 _, out GridPos _)) { mouseDownPos_Right = pos_world; } } if (onMouseDrag_Right && ControlManager.Instance.Building_MouseRight.Pressed) { if (GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 _, out Vector3 _, out GridPos _)) { Vector3 startVec = mouseDownPos_Right - transform.position; Vector3 endVec = pos_world - transform.position; float rotateAngle = Vector3.SignedAngle(startVec, endVec, transform.up); if (Mathf.Abs(rotateAngle) > 3) { ClientBattleManager.Instance.PlayerMecha.transform.Rotate(0, rotateAngle, 0); mouseDownPos_Right = pos_world; } } else { onMouseDrag_Right = false; mouseDownPos_Right = Vector3.zero; } } if (ControlManager.Instance.Building_MouseRight.Up) { onMouseDrag_Right = false; mouseDownPos_Right = Vector3.zero; } // Mouse Left button drag for move whole mecha if (ControlManager.Instance.Building_MouseLeft.Down) { onMouseDrag_Left = true; if (GetMousePosOnThisArea(out Vector3 pos, out Vector3 _, out Vector3 _, out GridPos _)) { mouseDownPos_Left = pos; } } if (onMouseDrag_Left && ControlManager.Instance.Building_MouseLeft.Pressed) { if (GetMousePosOnThisArea(out Vector3 pos, out Vector3 _, out Vector3 _, out GridPos _)) { Vector3 delta = pos - mouseDownPos_Left; Vector3 delta_local = ClientBattleManager.Instance.PlayerMecha.transform.InverseTransformVector(delta); GridPos delta_local_GP = GridPos.GetGridPosByPointXZ(delta_local, 1); if (delta_local_GP.x != 0 || delta_local_GP.z != 0) { ClientBattleManager.Instance.PlayerMecha.MechaInfo.MechaEditorInventory.MoveAllItemTogether(delta_local_GP); mouseDownPos_Left = pos; } } else { onMouseDrag_Left = false; mouseDownPos_Left = Vector3.zero; } } if (ControlManager.Instance.Building_MouseLeft.Up) { onMouseDrag_Left = false; mouseDownPos_Left = Vector3.zero; } } } }
public void Reset(GridPos iStartPos, GridPos iEndPos, BaseGrid iSearchGrid = null) { openList.Clear(); m_startNode = null; m_endNode = null; if (iSearchGrid != null) m_searchGrid = iSearchGrid; m_searchGrid.Reset(); m_startNode = m_searchGrid.GetNodeAt(iStartPos.x, iStartPos.y); m_endNode = m_searchGrid.GetNodeAt(iEndPos.x, iEndPos.y); if (m_startNode == null) m_startNode = new Node(iStartPos.x, iStartPos.y, true); if (m_endNode == null) m_endNode = new Node(iEndPos.x, iEndPos.y, true); }
public static Point2D GetCellCenterPoint(GridPos point, int step) { return(new Point2D(point.x * step + step / 2, point.y * step + step / 2)); }
public List <Node> GetNeighbors(Node iNode, DiagonalMovement diagonalMovement) { int tX = iNode.x; int tY = iNode.y; List <Node> neighbors = new List <Node>(); bool tS0 = false, tD0 = false, tS1 = false, tD1 = false, tS2 = false, tD2 = false, tS3 = false, tD3 = false; GridPos pos = new GridPos(); if (this.IsWalkableAt(pos.Set(tX, tY - 1))) { neighbors.Add(GetNodeAt(pos)); tS0 = true; } if (this.IsWalkableAt(pos.Set(tX + 1, tY))) { neighbors.Add(GetNodeAt(pos)); tS1 = true; } if (this.IsWalkableAt(pos.Set(tX, tY + 1))) { neighbors.Add(GetNodeAt(pos)); tS2 = true; } if (this.IsWalkableAt(pos.Set(tX - 1, tY))) { neighbors.Add(GetNodeAt(pos)); tS3 = true; } switch (diagonalMovement) { case DiagonalMovement.Always: tD0 = true; tD1 = true; tD2 = true; tD3 = true; break; case DiagonalMovement.Never: break; case DiagonalMovement.IfAtLeastOneWalkable: tD0 = tS3 || tS0; tD1 = tS0 || tS1; tD2 = tS1 || tS2; tD3 = tS2 || tS3; break; case DiagonalMovement.OnlyWhenNoObstacles: tD0 = tS3 && tS0; tD1 = tS0 && tS1; tD2 = tS1 && tS2; tD3 = tS2 && tS3; break; default: break; } if (tD0 && this.IsWalkableAt(pos.Set(tX - 1, tY - 1))) { neighbors.Add(GetNodeAt(pos)); } if (tD1 && this.IsWalkableAt(pos.Set(tX + 1, tY - 1))) { neighbors.Add(GetNodeAt(pos)); } if (tD2 && this.IsWalkableAt(pos.Set(tX + 1, tY + 1))) { neighbors.Add(GetNodeAt(pos)); } if (tD3 && this.IsWalkableAt(pos.Set(tX - 1, tY + 1))) { neighbors.Add(GetNodeAt(pos)); } return(neighbors); }
private void btnSearch_Click(object sender, EventArgs e) { for (int resultTrav = 0; resultTrav < m_resultLine.Count; resultTrav++) { m_resultLine[resultTrav].Dispose(); } m_resultLine.Clear(); for (int resultTrav = 0; resultTrav < m_resultBox.Count; resultTrav++) { m_resultBox[resultTrav].Dispose(); } m_resultBox.Clear(); GridPos startPos = new GridPos(); GridPos endPos = new GridPos(); for (int widthTrav = 0; widthTrav < width; widthTrav++) { for (int heightTrav = 0; heightTrav < height; heightTrav++) { if (m_rectangles[widthTrav][heightTrav].boxType != BoxType.Wall) { searchGrid.SetWalkableAt(new GridPos(widthTrav, heightTrav), true); } else { searchGrid.SetWalkableAt(new GridPos(widthTrav, heightTrav), false); } if (m_rectangles[widthTrav][heightTrav].boxType == BoxType.Start) { startPos.x = widthTrav; startPos.y = heightTrav; } if (m_rectangles[widthTrav][heightTrav].boxType == BoxType.End) { endPos.x = widthTrav; endPos.y = heightTrav; } } } jumpParam.DiagonalMovement = (DiagonalMovement)cbbJumpType.SelectedIndex; jumpParam.UseRecursive = cbUseRecursive.Checked; jumpParam.Reset(startPos, endPos); List <GridPos> resultList = JumpPointFinder.FindPath(jumpParam); for (int resultTrav = 0; resultTrav < resultList.Count - 1; resultTrav++) { m_resultLine.Add(new GridLine(m_rectangles[resultList[resultTrav].x][resultList[resultTrav].y], m_rectangles[resultList[resultTrav + 1].x][resultList[resultTrav + 1].y])); } for (int widthTrav = 0; widthTrav < jumpParam.SearchGrid.width; widthTrav++) { for (int heightTrav = 0; heightTrav < jumpParam.SearchGrid.height; heightTrav++) { if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav) == null) { continue; } if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav).isOpened) { ResultBox resultBox = new ResultBox(widthTrav * 20, heightTrav * 20 + 50, ResultBoxType.Opened); m_resultBox.Add(resultBox); } if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav).isClosed) { ResultBox resultBox = new ResultBox(widthTrav * 20, heightTrav * 20 + 50, ResultBoxType.Closed); m_resultBox.Add(resultBox); } } } this.Invalidate(); }
public void Init(GridPos pos) { this.gridPos = pos; }
public bool IsInside(GridPos iPos) { return(IsInside(iPos.X, iPos.Y)); }
public override Node GetNodeAt(GridPos iPos) { return GetNodeAt(iPos.x, iPos.y); }
public void SetTargetPos(GridPos targetPos) { this.targetPos = targetPos; }
public override bool SetWalkableAt(GridPos iPos, bool iWalkable) { return SetWalkableAt(iPos.x, iPos.y, iWalkable); }
public SkillGrid(GridPos gridPos, SkillGridType skillGridType) { GridPos = gridPos; SkillGridType = skillGridType; }