WindowAutoYaw.cs 745 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Examples/Window Auto-Yaw")]
  4. public class WindowAutoYaw : MonoBehaviour
  5. {
  6. private void OnDisable()
  7. {
  8. this.mTrans.localRotation = Quaternion.identity;
  9. }
  10. private void OnEnable()
  11. {
  12. if (this.uiCamera == null)
  13. {
  14. this.uiCamera = NGUITools.FindCameraForLayer(base.gameObject.layer);
  15. }
  16. this.mTrans = base.transform;
  17. }
  18. private void Update()
  19. {
  20. if (this.uiCamera != null)
  21. {
  22. Vector3 vector = this.uiCamera.WorldToViewportPoint(this.mTrans.position);
  23. this.mTrans.localRotation = Quaternion.Euler(0f, (vector.x * 2f - 1f) * this.yawAmount, 0f);
  24. }
  25. }
  26. public int updateOrder;
  27. public Camera uiCamera;
  28. public float yawAmount = 20f;
  29. private Transform mTrans;
  30. }