Git Product home page Git Product logo

pathfindingproject's Introduction

PathFindingProject

This is my diploma work

About

  • Project uses multithreading.
  • Non-linear grid! You can reduce tiles count without loose accuracy.
  • Simple usage.
  • Work with tiles with different passability.
  • Bulk pathfinding. Many start positions, one finish.

Wiki

Installing with Unity Package Manager

(Requires Unity version 2018.3.0b7 or above)

To install this project as a Git dependency using the Unity Package Manager, add the following line to your project's manifest.json:

"com.dasik.pathfinding": "https://github.com/Dasik/PathFindingProject.git"

You will need to have Git installed and available in your system's PATH.

Installing without Unity Package Manager

Or you can just copy the folder 'Runtime' in your asset scripts folder.

How to use

//scan area
CurrentMap.ScanArea(ScanArea.LeftBottomPoint, ScanArea.RightTopPoint,
  callback:() =>
    {
      //remove some area
      CurrentMap.RemoveArea(RemoveArea.LeftBottomPoint, RemoveArea.RightTopPoint);
    });
    
public class PathManager : MonoBehaviour
{
	public PathFinding PathFinder;
	private BulkPathTask<AgentScript> bulkPathFinderTask;
	private SinglePathTask singlePathFinderTask;
  public AgentScript agent;
	public bool useBulkPathFinding = true;

	public void Update()
	{
// pathfinding can work with bulk operations.    
		if (useBulkPathFinding)
		{
			if (bulkPathFinderTask != null && bulkPathFinderTask.Status == PathTaskStatus.Completed)
			{
				foreach (var path in bulkPathFinderTask.Path)
				{
        //key is some class that can take a path 
					path.Key.ApplyPath(path.Value);
				}
        bulkPathFinderTask.Dispose();
				bulkPathFinderTask = null;
			}
		}
		else
		{
			if (singlePathFinderTask==null)
				return;
			
      if (singlePathFinderTask.Status == PathTaskStatus.Completed)
      {
        agent.ApplyPath(singlePathFinderTask.Path);
        singlePathFinderTask.Dispose();
        singlePathFinderTask = null;
      }	
		}
	}

	public void SetPath(Vector2 targetPoint, double accuracy = 1d)
	{
		if (bulkPathFinderTask != null)
		{
			bulkPathFinderTask.Dispose();
			bulkPathFinderTask = null;
		}

		if (singlePathFinderTask != null)
		{
      singlePathFinderTask.Dispose();
			singlePathFinderTask = null;
		}

		foreach (var item in ObjectGenerator.Instance.Agents)
		{
      //stop moving!
			item.ApplyPath(new List<Cell>());
		}


		if (useBulkPathFinding)
		{
  // generate dictionary (object,position)
			var objectsStartPosition = ObjectGenerator.Instance.Agents.ToDictionary(agent => agent, agent => agent.Position);
  //finding path
			bulkPathFinderTask = PathFinder.GetPathesAsync(objectsStartPosition, targetPoint);
		}
		else
		{
				singlePathFinderTask = PathFinder.GetPathAsync(agent.Position, targetPoint, accuracy);
		}
	}
}

pathfindingproject's People

Contributors

dasik avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

bmjoy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.