diff options
author | chai <215380520@qq.com> | 2024-05-23 10:08:29 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-05-23 10:08:29 +0800 |
commit | 8722a9920c1f6119bf6e769cba270e63097f8e25 (patch) | |
tree | 2eaf9865de7fb1404546de4a4296553d8f68cc3b /Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/MineBotAI.cs | |
parent | 3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff) |
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/MineBotAI.cs')
-rw-r--r-- | Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/MineBotAI.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/MineBotAI.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/MineBotAI.cs new file mode 100644 index 0000000..100b23e --- /dev/null +++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/MineBotAI.cs @@ -0,0 +1,54 @@ +using UnityEngine; + +namespace Pathfinding.Examples { + /// <summary> + /// AI controller specifically made for the spider robot. + /// Deprecated: This script has been replaced by Pathfinding.Examples.MineBotAnimation. Any uses of this script in the Unity editor will be automatically replaced by one AIPath component and one MineBotAnimation component. + /// </summary> + [RequireComponent(typeof(Seeker))] + [System.Obsolete("This script has been replaced by Pathfinding.Examples.MineBotAnimation. Any uses of this script in the Unity editor will be automatically replaced by one AIPath component and one MineBotAnimation component.")] + [HelpURL("https://arongranberg.com/astar/documentation/stable/minebotai.html")] + public class MineBotAI : AIPath { + /// <summary> + /// Animation component. + /// Should hold animations "awake" and "forward" + /// </summary> + public Animation anim; + + /// <summary>Minimum velocity for moving</summary> + public float sleepVelocity = 0.4F; + + /// <summary>Speed relative to velocity with which to play animations</summary> + public float animationSpeed = 0.2F; + + /// <summary> + /// Effect which will be instantiated when end of path is reached. + /// See: OnTargetReached + /// </summary> + public GameObject endOfPathEffect; + +#if UNITY_EDITOR + protected override void OnUpgradeSerializedData (ref Serialization.Migrations migrations, bool unityThread) { + if (unityThread) { + var components = gameObject.GetComponents<Component>(); + int index = System.Array.IndexOf(components, this); + foreach (System.Type newType in new [] { typeof(AIPath), typeof(MineBotAnimation) }) { + var newComp = gameObject.AddComponent(newType); + foreach (var field in newComp.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public)) { + var oldField = this.GetType().GetField(field.Name); + try { + if (oldField != null) field.SetValue(newComp, oldField.GetValue(this)); + } catch (System.Exception e) { + Debug.LogError("Failed to upgrade some fields.\n" + e); + } + } + for (int i = components.Length - 1; i > index; i--) UnityEditorInternal.ComponentUtility.MoveComponentUp(newComp); + } + GameObject.DestroyImmediate(this); + } else { + base.OnUpgradeSerializedData(ref migrations, unityThread); + } + } +#endif + } +} |