summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/Editor/LegacyEditorHelper.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-23 10:08:29 +0800
committerchai <215380520@qq.com>2024-05-23 10:08:29 +0800
commit8722a9920c1f6119bf6e769cba270e63097f8e25 (patch)
tree2eaf9865de7fb1404546de4a4296553d8f68cc3b /Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/Editor/LegacyEditorHelper.cs
parent3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff)
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/Editor/LegacyEditorHelper.cs')
-rw-r--r--Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/Editor/LegacyEditorHelper.cs29
1 files changed, 29 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/Editor/LegacyEditorHelper.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/Editor/LegacyEditorHelper.cs
new file mode 100644
index 0000000..45d2dab
--- /dev/null
+++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/Editor/LegacyEditorHelper.cs
@@ -0,0 +1,29 @@
+using UnityEngine;
+using UnityEditor;
+using System.Linq;
+
+namespace Pathfinding.Legacy {
+ public static class LegacyEditorHelper {
+ public static void UpgradeDialog (Object[] targets, System.Type upgradeType) {
+ EditorGUILayout.BeginVertical(EditorStyles.helpBox);
+ var gui = EditorGUIUtility.IconContent("console.warnicon");
+ gui.text = "You are using the compatibility version of this component. It is recommended that you upgrade to the newer version. This may change the component's behavior.";
+ EditorGUILayout.LabelField(GUIContent.none, gui, EditorStyles.wordWrappedMiniLabel);
+ if (GUILayout.Button("Upgrade")) {
+ Undo.RecordObjects(targets.Select(s => (s as Component).gameObject).ToArray(), "Upgrade from Legacy Component");
+ foreach (var tg in targets) {
+ var comp = tg as Component;
+ var components = comp.gameObject.GetComponents<Component>();
+ int index = System.Array.IndexOf(components, comp);
+ var newRVO = Undo.AddComponent(comp.gameObject, upgradeType);
+ foreach (var field in newRVO.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public)) {
+ field.SetValue(newRVO, field.GetValue(comp));
+ }
+ Undo.DestroyObjectImmediate(comp);
+ for (int i = components.Length - 1; i > index; i--) UnityEditorInternal.ComponentUtility.MoveComponentUp(newRVO);
+ }
+ }
+ EditorGUILayout.EndVertical();
+ }
+ }
+}