DynamicBoneDemo1.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using UnityEngine;
  2. using System.Collections;
  3. public class DynamicBoneDemo1 : MonoBehaviour
  4. {
  5. public GameObject m_Player;
  6. float m_weight = 1;
  7. float m_sleepTime;
  8. void Update()
  9. {
  10. m_Player.transform.Rotate(new Vector3(0, Input.GetAxis("Horizontal") * Time.deltaTime * 200, 0));
  11. m_Player.transform.Translate(transform.forward * Input.GetAxis("Vertical") * Time.deltaTime * 4);
  12. }
  13. void OnGUI()
  14. {
  15. float x = 50;
  16. float y = 50;
  17. float w1 = 100;
  18. float w2 = 200;
  19. float h = 24;
  20. GUI.Label(new Rect(x, y, w2, h), "Press arrow key to move");
  21. Animation a = m_Player.GetComponentInChildren<Animation>();
  22. y += h;
  23. a.enabled = GUI.Toggle(new Rect(x, y, w2, h), a.enabled, "Play Animation");
  24. y += h * 2;
  25. DynamicBone[] dbs = m_Player.GetComponents<DynamicBone>();
  26. GUI.Label(new Rect(x, y, w2, h), "Choose dynamic bone:");
  27. y += h;
  28. dbs[0].enabled = dbs[1].enabled = GUI.Toggle(new Rect(x, y, w1, h), dbs[0].enabled, "Breasts");
  29. y += h;
  30. dbs[2].enabled = GUI.Toggle(new Rect(x, y, w1, h), dbs[2].enabled, "Tail");
  31. y += h;
  32. GUI.Label(new Rect(x, y, w2, h), "Weight");
  33. m_weight = GUI.HorizontalSlider(new Rect(x + 50, y, w1, h), m_weight, 0, 1);
  34. foreach (var db in dbs)
  35. db.SetWeight(m_weight);
  36. /*
  37. y += h * 2;
  38. GUI.Label(new Rect(x, y, w2, h), "Sleep");
  39. m_sleepTime = GUI.HorizontalSlider(new Rect(x + 50, y, w1, h), m_sleepTime, 0, 1);
  40. if (m_sleepTime > 0)
  41. System.Threading.Thread.Sleep((int)(m_sleepTime * 100));
  42. y += h;
  43. GUI.Label(new Rect(x, y, w2, h), "Time Scale");
  44. Time.timeScale = GUI.HorizontalSlider(new Rect(x + 80, y, w1, h), Time.timeScale, 0, 2);
  45. */
  46. }
  47. }