summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/MinimumUnityVersionWarning.cs
blob: 966d3015b4079054f0597e3e600f8860e2702980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma warning disable IDE0051

using System.Collections;
using UnityEngine;
using Pathfinding.Util;

namespace Pathfinding.Examples {
	[ExecuteInEditMode]
	[HelpURL("https://arongranberg.com/astar/documentation/stable/minimumunityversionwarning.html")]
	public class MinimumUnityVersionWarning : MonoBehaviour {
#if !MODULE_ENTITIES || !UNITY_2022_2_OR_NEWER
		bool requiresUnity2022_2;
		bool requiresEntities;


		void Awake () {
			requiresEntities = UnityCompatibility.FindAnyObjectByType<Pathfinding.FollowerEntity>() != null || UnityCompatibility.FindAnyObjectByType<Pathfinding.Examples.LightweightRVO>() != null;
			// Box colliders from scenes created in Unity 2022+ are not compatible with older versions of Unity. They will end with the wrong size.
			// The minimum version of the entitites package also requires Unity 2022
			requiresUnity2022_2 = UnityCompatibility.FindAnyObjectByType<BoxCollider>() != null || requiresEntities;
		}

		IEnumerator Start () {
			// Catch dynamically spawned prefabs
			yield return null;
			Awake();
		}
#endif

		void OnGUI () {
#if !UNITY_2022_2_OR_NEWER
			if (requiresUnity2022_2) {
				var rect = new Rect(Screen.width/2 - 325, Screen.height/2 - 30, 650, 60);
				GUILayout.BeginArea(rect, "", "box");
				GUILayout.Label("<b>Unity version too low</b>\nThis example scene can unfortunately not be played in your version of Unity, due to compatibility issues.\nYou must upgrade to Unity 2022.2 or later.");
				GUILayout.EndArea();
				return;
			}
#endif

#if !MODULE_ENTITIES
			if (requiresEntities) {
				var rect = new Rect(Screen.width/2 - 325, Screen.height/2 - 30, 650, 80);
				GUILayout.BeginArea(rect, "", "box");
#if UNITY_EDITOR
				GUILayout.Label("<b>Just one more step</b>\nThis example scene requires version 1.0 or higher of the <b>Entities</b> package to be installed.");
				if (GUILayout.Button("Install")) {
					UnityEditor.PackageManager.Client.Add("com.unity.entities");
				}
#else
				GUILayout.Label("<b>Just one more step</b>\nThis example scene requires version 1.0 or higher of the <b>Entities</b> package to be installed\nYou can install it from the Unity Package Manager");
#endif
				GUILayout.EndArea();
				return;
			}
#endif
		}
	}
}