NewPath.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. #if UNITY_EDITOR
  5. using UnityEditor;
  6. #endif
  7. public class NewPath : MonoBehaviour {
  8. private List<Vector3> points = new List<Vector3>();
  9. public int pointLenght = 0;
  10. public Vector3 mousePos;
  11. public string pathName;
  12. public bool errors;
  13. public bool exit;
  14. public GameObject par;
  15. [HideInInspector]
  16. [SerializeField]
  17. public PathType PathType = PathType.PeoplePath;
  18. public List<Vector3> PointsGet()
  19. {
  20. return points;
  21. }
  22. public void PointSet(int index, Vector3 pos)
  23. {
  24. points.Add(pos);
  25. if(par == null)
  26. {
  27. par = new GameObject();
  28. par.name = "New path points";
  29. par.transform.parent = gameObject.transform;
  30. }
  31. var prefab = GameObject.Find("Population System").GetComponent<PopulationSystemManager>().pointPrefab;
  32. var obj = Instantiate(prefab, pos, Quaternion.identity) as GameObject;
  33. obj.name = "p" + index;
  34. obj.transform.parent = par.transform;
  35. }
  36. #if UNITY_EDITOR
  37. public void OnDrawGizmos()
  38. {
  39. Selection.activeGameObject = gameObject;
  40. ActiveEditorTracker.sharedTracker.isLocked = true;
  41. Gizmos.color = Color.green;
  42. if(pointLenght > 0 && !exit)
  43. {
  44. Gizmos.DrawLine(points[pointLenght - 1], mousePos);
  45. }
  46. if(pointLenght > 1)
  47. {
  48. for(int i = 0; i < pointLenght - 1; i++)
  49. Gizmos.DrawLine(points[i], points[i + 1]);
  50. }
  51. }
  52. #endif
  53. }