private void DrawHouse(PFCanvas canvas) { var scale = 0.5f; canvas.Save(); canvas.SetCurrentTransform( Matrix4x4.Translate(new Vector2(0, Screen.height - 160)) * Matrix4x4.Scale(new Vector2(scale, scale)) ); canvas.SetLineWidth(10.0f * scale); canvas.SetStrokeStyle(Color.black); canvas.SetFillStyle(Color.black); canvas.SetLineJoin(PFLineJoin.Round); // Draw walls. canvas.StrokeRect(new Rect(75.0f, 140.0f, 150.0f, 110.0f)); // Draw door. canvas.FillRect(new Rect(130.0f, 190.0f, 40.0f, 60.0f)); // Draw roof. var path = new PFPath(); path.MoveTo(new Vector2(50.0f, 140.0f)); path.LineTo(new Vector2(150.0f, 60.0f)); path.LineTo(new Vector2(250.0f, 140.0f)); path.ClosePath(); canvas.StrokePath(path); canvas.Restore(); }
void Update() { if (ranTests) { return; } // Just some smoke tests to make sure we don't segfault. var gState = GetComponent <GlobalStateScript>(); if (!gState.IsPathfinderEnabled()) { return; } var path = new PFPath(); // We should be able to clone paths. path.Clone(); var canvas = new PFCanvas(gState.GetFontContext(), new Vector2(10, 10)); // We should be able to pass empty strings. canvas.FillText("", new Vector2(0, 0)); ranTests = true; print("Successfully ran smoke tests."); }
public void FillPath(PFPath path) { EnsureHandleIsValid(); var pathHandleToConsume = path.PrepareToConsume(); PF.PFCanvasFillPath(handle, pathHandleToConsume); }
public override void Exit() { // 혹시나 못쓴 cost는 싹 써버리기 owner.actionPointsRemain = Mathf.Max(owner.actionPointsRemain - _cost, 0); EventMgr.Instance.onUnitRunExit.Invoke(new UnitStateEvent(owner)); _path = null; }
private void drawCircles(PFCanvas canvas, Vector2 center) { for (int index = 0; index < CIRCLE_COUNT; index++) { var radius = (index + 1) * CIRCLE_SPACING * SCALE; var path = new PFPath(); path.Ellipse(center, new Vector2(radius, radius), 0, 0, Mathf.PI * 2.0f); canvas.StrokePath(path); } }
public PFPath(PFPath targetToClone = null) { if (targetToClone != null) { handle = PF.PFPathClone(targetToClone.handle); } else { handle = PF.PFPathCreate(); } }
// Command를 할수 있는지 없는지만 검사합니다. // 생성자대용으로 사용합니다. public static bool CreateCommand(Unit unit, PFPath path, out MoveCommand moveCommand) { if (unit.actionPointsRemain >= unit.GetActionSlot(ActionType.Move).cost *path.Length) { moveCommand = new MoveCommand(path); return(true); } else { moveCommand = null; return(false); } }
private void OnClickCubeCanGo(Cube cubeClicked) { // for wait state this.cubeClicked = cubeClicked; // chage state to wait state of unitRunExit, pathUpdateEnd Event ChangeStateToWaitState(); // unit move PFPath pathToDest = unit.GetCube.paths.Find((p) => p.destination == cubeClicked); MoveCommand moveCommand; if (MoveCommand.CreateCommand(unit, pathToDest, out moveCommand)) { unit.EnqueueCommand(moveCommand); // update paths in the destination cube (cubeClicked as Cube).UpdatePaths( unit.actionPoints / unit.GetActionSlot(ActionType.Move).cost, cube => (cube as Cube).GetUnit() != null && (cube as Cube).GetUnit() != unit); } }
// AI Simulation에서만 사용할 함수입니다. public static void ForceCreateCommand(PFPath path, out MoveCommand moveCommand) { moveCommand = new MoveCommand(path); }
private MoveCommand(PFPath path) { _path = path; }
public int CalcMoveAPCost(PFPath path) => (path.path.Count - 1) * owner.GetActionSlot(ActionType.Move).cost;
/// <summary> /// maxDistance로 갈수 있는 큐브들을 BFS로 찾아 OnServe콜백함수의 PFPath인자로 돌려줍니다. /// </summary> /// <param name="maxDistance">BFS로 찾을 최대 거리</param> /// <param name="OnServe">함수가 끝나면 호출할 함수를 전달하세요. 함수의 인자로 Path가 전달됩니다.</param> /// <param name="cubeIgnore">Path에 포함시키지 않을 Predicate</param> /// <returns></returns> private IEnumerator BFSPathfinding( INavable start, List <INavable> navables, int maxDistance, Action <List <PFPath> > OnServe, Func <INavable, bool> cubeIgnore) { OnSearchBegin(); // 나중에 cost가 정해진 노드들만 path로 만들기 위함 List <PFNode> table = new List <PFNode>(); // BFS: Initialization Queue <PFNode> queue = new Queue <PFNode>(); PFNode startNode = new PFNode(start, null, 0); queue.Enqueue(startNode); table.Add(startNode); // BFS: Traversal int maxLoop = 40; int currLoop = 0; while (queue.Count > 0) { PFNode currNode = queue.Dequeue(); if (currNode.cost >= maxDistance) { continue; } List <INavable> neighborCubes = currNode.cube.Neighbors; foreach (var neighborCube in neighborCubes) { if (cubeIgnore(neighborCube)) { continue; } if (table.Any(node => node.cube == neighborCube)) { continue; // 이미 다른 Path에 있음 } PFNode newNode = new PFNode(neighborCube, currNode, currNode.cost + 1); queue.Enqueue(newNode); table.Add(newNode); } currLoop++; if (currLoop >= maxLoop) { currLoop = 0; yield return(null); } } // Path Construction List <PFPath> paths = new List <PFPath>(); currLoop = 0; foreach (var destination in table) { PFPath path = new PFPath(start, destination); path.Add(destination); PFNode currNode = destination; while (currNode.prevNode != null) { path.Add(currNode.prevNode); currNode = currNode.prevNode; } path.Reverse(); paths.Add(path); currLoop++; if (currLoop >= maxLoop) { currLoop = 0; yield return(null); } } // return by Calling Callback Function OnServe(paths); OnSearchEnd(); }
public Unit_Move_(Unit owner, PFPath path, int apCost) : base(owner) { _path = path; _cost = apCost; _cubesToGo = new Queue <Cube>(path.path.Cast <Cube>()); }