From 8722a9920c1f6119bf6e769cba270e63097f8e25 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 23 May 2024 10:08:29 +0800 Subject: + astar project --- .../Utilities/UnityReferenceHelper.cs | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Utilities/UnityReferenceHelper.cs (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Utilities/UnityReferenceHelper.cs') diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Utilities/UnityReferenceHelper.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Utilities/UnityReferenceHelper.cs new file mode 100644 index 0000000..e4d895c --- /dev/null +++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Utilities/UnityReferenceHelper.cs @@ -0,0 +1,39 @@ +using Pathfinding.Util; +using UnityEngine; + +namespace Pathfinding { + [ExecuteInEditMode] + /// + /// Helper class to keep track of references to GameObjects. + /// Does nothing more than to hold a GUID value. + /// + [HelpURL("https://arongranberg.com/astar/documentation/stable/unityreferencehelper.html")] + public class UnityReferenceHelper : MonoBehaviour { + [HideInInspector] + [SerializeField] + private string guid; + + public string GetGUID() => guid; + + public void Awake () { + Reset(); + } + + public void Reset () { + if (string.IsNullOrEmpty(guid)) { + guid = Pathfinding.Util.Guid.NewGuid().ToString(); + Debug.Log("Created new GUID - " + guid, this); + } else if (gameObject.scene.name != null) { + // Create a new GUID if there are duplicates in the scene. + // Don't do this if this is a prefab (scene.name == null) + foreach (UnityReferenceHelper urh in UnityCompatibility.FindObjectsByTypeUnsorted()) { + if (urh != this && guid == urh.guid) { + guid = Pathfinding.Util.Guid.NewGuid().ToString(); + Debug.Log("Created new GUID - " + guid, this); + return; + } + } + } + } + } +} -- cgit v1.1-26-g67d0