Advertisement
Guest User

Untitled

a guest
Apr 12th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. /*
  2. *
  3. * Adventure Creator
  4. * by Chris Burton, 2013-2015
  5. *
  6. * "ActionTemplate.cs"
  7. *
  8. * This is a blank action template.
  9. *
  10. */
  11.  
  12. using UnityEngine;
  13. using System.Collections;
  14.  
  15. #if UNITY_EDITOR
  16. using UnityEditor;
  17. #endif
  18.  
  19. namespace AC
  20. {
  21. //this allows AC the functionality to toggle "apply root motion" on the Animator of a NPC,
  22. //why? we need it on for anims where the guy walks around, but off when the guy follows a path
  23. [System.Serializable]
  24. public class RSL_AC_ActionToggleApplyRootMotion : Action
  25. {
  26.  
  27. // Declare variables here
  28. public GameObject objectToAffect;
  29. public bool newRootMotionState;
  30.  
  31. public RSL_AC_ActionToggleApplyRootMotion ()
  32. {
  33. this.isDisplayed = true;
  34. category = ActionCategory.Custom;
  35. title = "Character: Toggle Root Motion";
  36. description = "This is a blank Action template.";
  37. }
  38.  
  39.  
  40. override public float Run ()
  41. {
  42. /*
  43. * This function is called when the action is performed.
  44. *
  45. * The float to return is the time that the game
  46. * should wait before moving on to the next action.
  47. * Return 0f to make the action instantenous.
  48. *
  49. * For actions that take longer than one frame,
  50. * you can return "defaultPauseTime" to make the game
  51. * re-run this function a short time later. You can
  52. * use the isRunning boolean to check if the action is
  53. * being run for the first time, eg:
  54. */
  55.  
  56. if (objectToAffect && objectToAffect.GetComponent<Animator>())
  57. {
  58. objectToAffect.GetComponent<Animator>().applyRootMotion = newRootMotionState;
  59. }
  60. return 0f;
  61. }
  62.  
  63.  
  64. #if UNITY_EDITOR
  65.  
  66. override public void ShowGUI ()
  67. {
  68. // Action-specific Inspector GUI code here
  69. objectToAffect = (GameObject) EditorGUILayout.ObjectField ("GameObject to affect:", objectToAffect, typeof (GameObject), true);
  70. newRootMotionState = EditorGUILayout.Toggle ("New root motion state:", newRootMotionState);
  71.  
  72. AfterRunningOption ();
  73. }
  74.  
  75.  
  76. public override string SetLabel ()
  77. {
  78. // Return a string used to describe the specific action's job.
  79. // Return a string used to describe the specific action's job.
  80. if (objectToAffect)
  81. {
  82. return (" (" + objectToAffect.name + " - " + newRootMotionState.ToString () + ")");
  83. }
  84. return "";
  85. }
  86.  
  87.  
  88.  
  89. #endif
  90.  
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement