Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5.  
  6. public class PathingHandler : MonoBehaviour
  7. {
  8.     private DataMap<bool> _obstacleMap;
  9.  
  10.     private PathFinder _pathFinder;
  11.  
  12.     private Dictionary<int, GameObject> _pathRequests;
  13.  
  14.     private Thread _workerThread;
  15.  
  16.     private int _id;
  17.  
  18.     [SerializeField]
  19.     private bool _createRandom;
  20.  
  21.     [SerializeField]
  22.     private bool _addObstacle;
  23.  
  24.     private void Start()
  25.     {
  26.         // init map
  27.         _obstacleMap = new DataMap<bool>(255, 255);
  28.  
  29.         // init finder
  30.         _pathFinder = new PathFinder();
  31.         _pathFinder.UpdateObstacleMap(_obstacleMap.Data);
  32.  
  33.         // start the thread
  34.         _workerThread = new Thread(new ThreadStart(_pathFinder.Start));
  35.         _workerThread.Start();
  36.  
  37.         _pathRequests = new Dictionary<int, GameObject>();
  38.         RequestPath(gameObject, new Index2D(0, 0), new Index2D(10, 10));
  39.     }
  40.  
  41.     private void OnApplicationQuit()
  42.     {
  43.         _workerThread.Abort();
  44.     }
  45.  
  46.     public void RequestPath(GameObject requestee, Index2D from, Index2D to)
  47.     {
  48.         PathRequest request = new PathRequest(_id++, from, to);
  49.         _pathFinder.AddPathRequest(request);
  50.  
  51.         _pathRequests.Add(request.Id, requestee);
  52.     }
  53.  
  54.     public void Update()
  55.     {
  56.         // check for paths
  57.         PathResult[] results = _pathFinder.GetResults();
  58.  
  59.         for (int i = 0; i < results.Length; i++)
  60.         {
  61.         // TODO: give path to object that requested it.
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement