Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Threading;
- public class PathingHandler : MonoBehaviour
- {
- private DataMap<bool> _obstacleMap;
- private PathFinder _pathFinder;
- private Dictionary<int, GameObject> _pathRequests;
- private Thread _workerThread;
- private int _id;
- [SerializeField]
- private bool _createRandom;
- [SerializeField]
- private bool _addObstacle;
- private void Start()
- {
- // init map
- _obstacleMap = new DataMap<bool>(255, 255);
- // init finder
- _pathFinder = new PathFinder();
- _pathFinder.UpdateObstacleMap(_obstacleMap.Data);
- // start the thread
- _workerThread = new Thread(new ThreadStart(_pathFinder.Start));
- _workerThread.Start();
- _pathRequests = new Dictionary<int, GameObject>();
- RequestPath(gameObject, new Index2D(0, 0), new Index2D(10, 10));
- }
- private void OnApplicationQuit()
- {
- _workerThread.Abort();
- }
- public void RequestPath(GameObject requestee, Index2D from, Index2D to)
- {
- PathRequest request = new PathRequest(_id++, from, to);
- _pathFinder.AddPathRequest(request);
- _pathRequests.Add(request.Id, requestee);
- }
- public void Update()
- {
- // check for paths
- PathResult[] results = _pathFinder.GetResults();
- for (int i = 0; i < results.Length; i++)
- {
- // TODO: give path to object that requested it.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement