DynamicBoneDemo1.cs 1.3 KB

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