InteractionDemo.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using UnityEngine;
  2. using System.Collections;
  3. using RootMotion.FinalIK;
  4. namespace RootMotion.Demos {
  5. /// <summary>
  6. /// Simple demo controller for the InteractionSystem.
  7. /// </summary>
  8. public class InteractionDemo : MonoBehaviour {
  9. public InteractionSystem interactionSystem; // Reference to the InteractionSystem of the character
  10. public bool interrupt; // Can we interrupt an interaction of an effector?
  11. // The interaction objects
  12. public InteractionObject ball, benchMain, benchHands, button, cigarette, door;
  13. private bool isSitting;
  14. // GUI for calling the interactions
  15. void OnGUI() {
  16. interrupt = GUILayout.Toggle(interrupt, "Interrupt");
  17. // While seated
  18. if (isSitting) {
  19. if (!interactionSystem.inInteraction && GUILayout.Button("Stand Up")) {
  20. interactionSystem.ResumeAll();
  21. isSitting = false;
  22. }
  23. return;
  24. }
  25. // While standing
  26. if (GUILayout.Button("Pick Up Ball")) {
  27. interactionSystem.StartInteraction(FullBodyBipedEffector.RightHand, ball, interrupt);
  28. }
  29. if (GUILayout.Button("Button Left Hand")) {
  30. interactionSystem.StartInteraction(FullBodyBipedEffector.LeftHand, button, interrupt);
  31. }
  32. if (GUILayout.Button("Button Right Hand")) {
  33. interactionSystem.StartInteraction(FullBodyBipedEffector.RightHand, button, interrupt);
  34. }
  35. if (GUILayout.Button("Put Out Cigarette")) {
  36. interactionSystem.StartInteraction(FullBodyBipedEffector.RightFoot, cigarette, interrupt);
  37. }
  38. if (GUILayout.Button("Open Door")) {
  39. interactionSystem.StartInteraction(FullBodyBipedEffector.LeftHand, door, interrupt);
  40. }
  41. // This is a multiple-effector interaction
  42. if (!interactionSystem.inInteraction && GUILayout.Button("Sit Down")) {
  43. interactionSystem.StartInteraction(FullBodyBipedEffector.Body, benchMain, interrupt);
  44. interactionSystem.StartInteraction(FullBodyBipedEffector.LeftThigh, benchMain, interrupt);
  45. interactionSystem.StartInteraction(FullBodyBipedEffector.RightThigh, benchMain, interrupt);
  46. interactionSystem.StartInteraction(FullBodyBipedEffector.LeftFoot, benchMain, interrupt);
  47. interactionSystem.StartInteraction(FullBodyBipedEffector.LeftHand, benchHands, interrupt);
  48. interactionSystem.StartInteraction(FullBodyBipedEffector.RightHand, benchHands, interrupt);
  49. isSitting = true;
  50. }
  51. }
  52. }
  53. }