UnityReferenceHelper.cs 991 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. namespace Pathfinding {
  3. [ExecuteInEditMode]
  4. /// <summary>
  5. /// Helper class to keep track of references to GameObjects.
  6. /// Does nothing more than to hold a GUID value.
  7. /// </summary>
  8. [HelpURL("http://arongranberg.com/astar/docs/class_pathfinding_1_1_unity_reference_helper.php")]
  9. public class UnityReferenceHelper : MonoBehaviour {
  10. [HideInInspector]
  11. [SerializeField]
  12. private string guid;
  13. public string GetGUID () {
  14. return guid;
  15. }
  16. public void Awake () {
  17. Reset();
  18. }
  19. public void Reset () {
  20. if (string.IsNullOrEmpty(guid)) {
  21. guid = Pathfinding.Util.Guid.NewGuid().ToString();
  22. Debug.Log("Created new GUID - "+guid);
  23. } else {
  24. foreach (UnityReferenceHelper urh in FindObjectsOfType(typeof(UnityReferenceHelper)) as UnityReferenceHelper[]) {
  25. if (urh != this && guid == urh.guid) {
  26. guid = Pathfinding.Util.Guid.NewGuid().ToString();
  27. Debug.Log("Created new GUID - "+guid);
  28. return;
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }