mirror of
https://github.com/Kizuren/ShantiManti.git
synced 2025-12-21 13:06:04 +01:00
Manually Upgraded Astarpath to new API
This commit is contained in:
parent
f0f1f48619
commit
ecdb3826c1
8 changed files with 15 additions and 10 deletions
|
|
@ -425,7 +425,7 @@ namespace Pathfinding {
|
|||
// If gravity is used depends on a lot of things.
|
||||
// For example when a non-kinematic rigidbody is used then the rigidbody will apply the gravity itself
|
||||
// Note that the gravity can contain NaN's, which is why the comparison uses !(a==b) instead of just a!=b.
|
||||
usingGravity = !(gravity == Vector3.zero) && (!updatePosition || ((rigid == null || rigid.isKinematic) && (rigid2D == null || rigid2D.isKinematic)));
|
||||
usingGravity = !(gravity == Vector3.zero) && (!updatePosition || ((rigid == null || rigid.isKinematic) && (rigid2D == null || rigid2D.bodyType == RigidbodyType2D.Kinematic)));
|
||||
if (rigid == null && rigid2D == null && canMove) {
|
||||
Vector3 nextPosition;
|
||||
Quaternion nextRotation;
|
||||
|
|
|
|||
|
|
@ -677,7 +677,7 @@ public class AstarPath : VersionedMonoBehaviour {
|
|||
/// </summary>
|
||||
public static void FindAstarPath () {
|
||||
if (Application.isPlaying) return;
|
||||
if (active == null) active = GameObject.FindObjectOfType<AstarPath>();
|
||||
if (active == null) active = GameObject.FindFirstObjectByType<AstarPath>();
|
||||
if (active != null && (active.data.graphs == null || active.data.graphs.Length == 0)) active.data.DeserializeGraphs();
|
||||
}
|
||||
|
||||
|
|
@ -1222,7 +1222,7 @@ public class AstarPath : VersionedMonoBehaviour {
|
|||
// Very important to set this. Ensures the singleton pattern holds
|
||||
active = this;
|
||||
|
||||
if (FindObjectsOfType(typeof(AstarPath)).Length > 1) {
|
||||
if (FindObjectsByType<AstarPath>(FindObjectsSortMode.None).Length > 1) {
|
||||
Debug.LogError("You should NOT have more than one AstarPath component in the scene at any time.\n" +
|
||||
"This can cause serious errors since the AstarPath component builds around a singleton pattern.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace Pathfinding {
|
|||
}
|
||||
|
||||
public static void FindAllModifiers () {
|
||||
var allModifiers = FindObjectsOfType(typeof(GraphModifier)) as GraphModifier[];
|
||||
var allModifiers = FindObjectsByType<GraphModifier>(FindObjectsSortMode.None);
|
||||
|
||||
for (int i = 0; i < allModifiers.Length; i++) {
|
||||
if (allModifiers[i].enabled) allModifiers[i].OnEnable();
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ namespace Pathfinding.Serialization {
|
|||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(guid)) {
|
||||
UnityReferenceHelper[] helpers = UnityEngine.Object.FindObjectsOfType(typeof(UnityReferenceHelper)) as UnityReferenceHelper[];
|
||||
UnityReferenceHelper[] helpers = UnityEngine.Object.FindObjectsByType<UnityReferenceHelper>(FindObjectsSortMode.None);
|
||||
|
||||
for (int i = 0; i < helpers.Length; i++) {
|
||||
if (helpers[i].GetGUID() == guid) {
|
||||
|
|
|
|||
|
|
@ -341,9 +341,9 @@ namespace Pathfinding.Serialization {
|
|||
}
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
foreach (var helper in UnityEngine.Object.FindObjectsOfType<UnityReferenceHelper>(true))
|
||||
foreach (var helper in UnityEngine.Object.FindObjectsByType<UnityReferenceHelper>(FindObjectsSortMode.None))
|
||||
#else
|
||||
foreach (var helper in UnityEngine.Object.FindObjectsOfType<UnityReferenceHelper>())
|
||||
foreach (var helper in UnityEngine.Object.FindObjectsByType<UnityReferenceHelper>(FindObjectsSortMode.None))
|
||||
#endif
|
||||
{
|
||||
if (helper.GetGUID() == guid) {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,12 @@ namespace Pathfinding {
|
|||
cam = Camera.main;
|
||||
// Slightly inefficient way of finding all AIs, but this is just an example script, so it doesn't matter much.
|
||||
// FindObjectsOfType does not support interfaces unfortunately.
|
||||
ais = FindObjectsOfType<MonoBehaviour>().OfType<IAstarAI>().ToArray();
|
||||
// Changed FindObjectsOfType to FindObjectsByType
|
||||
// Use the new FindObjectsByType method to find all MonoBehaviours
|
||||
// Then filter them by the IAstarAI interface
|
||||
ais = FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None)
|
||||
.OfType<IAstarAI>()
|
||||
.ToArray();
|
||||
useGUILayout = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ namespace Pathfinding {
|
|||
}
|
||||
|
||||
public static void FindAllGraphSurfaces () {
|
||||
var srf = GameObject.FindObjectsOfType(typeof(RelevantGraphSurface)) as RelevantGraphSurface[];
|
||||
var srf = FindObjectsByType<RelevantGraphSurface>(FindObjectsSortMode.None);
|
||||
|
||||
for (int i = 0; i < srf.Length; i++) {
|
||||
srf[i].OnDisable();
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Pathfinding {
|
|||
} 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 FindObjectsOfType(typeof(UnityReferenceHelper)) as UnityReferenceHelper[]) {
|
||||
foreach (UnityReferenceHelper urh in FindObjectsByType<UnityReferenceHelper>(FindObjectsSortMode.None)) {
|
||||
if (urh != this && guid == urh.guid) {
|
||||
guid = Pathfinding.Util.Guid.NewGuid().ToString();
|
||||
Debug.Log("Created new GUID - " + guid, this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue