MineBotAI.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. namespace Pathfinding.Examples {
  3. /// <summary>
  4. /// AI controller specifically made for the spider robot.
  5. /// 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.
  6. /// </summary>
  7. [RequireComponent(typeof(Seeker))]
  8. [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.")]
  9. [HelpURL("http://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_mine_bot_a_i.php")]
  10. public class MineBotAI : AIPath {
  11. /// <summary>
  12. /// Animation component.
  13. /// Should hold animations "awake" and "forward"
  14. /// </summary>
  15. public Animation anim;
  16. /// <summary>Minimum velocity for moving</summary>
  17. public float sleepVelocity = 0.4F;
  18. /// <summary>Speed relative to velocity with which to play animations</summary>
  19. public float animationSpeed = 0.2F;
  20. /// <summary>
  21. /// Effect which will be instantiated when end of path is reached.
  22. /// See: OnTargetReached
  23. /// </summary>
  24. public GameObject endOfPathEffect;
  25. #if UNITY_EDITOR
  26. protected override int OnUpgradeSerializedData (int version, bool unityThread) {
  27. if (unityThread) {
  28. var components = gameObject.GetComponents<Component>();
  29. int index = System.Array.IndexOf(components, this);
  30. foreach (System.Type newType in new [] { typeof(AIPath), typeof(MineBotAnimation) }) {
  31. var newComp = gameObject.AddComponent(newType);
  32. foreach (var field in newComp.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public)) {
  33. var oldField = this.GetType().GetField(field.Name);
  34. try {
  35. if (oldField != null) field.SetValue(newComp, oldField.GetValue(this));
  36. } catch (System.Exception e) {
  37. Debug.LogError("Failed to upgrade some fields.\n" + e);
  38. }
  39. }
  40. for (int i = components.Length - 1; i > index; i--) UnityEditorInternal.ComponentUtility.MoveComponentUp(newComp);
  41. }
  42. GameObject.DestroyImmediate(this);
  43. return 0;
  44. } else {
  45. return base.OnUpgradeSerializedData(version, unityThread);
  46. }
  47. }
  48. #endif
  49. }
  50. }