Advertisement
LittleAngel

ModelViewer

Oct 19th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Rotator : MonoBehaviour {
  5. public Transform sopwith;
  6. public Transform fokker;
  7. public Light keyLight;
  8. public float sensitivity;
  9.  
  10. private Transform thisTransform;
  11. private Vector3 previousMousePos;
  12. private Vector3 deltaPos;
  13. private float cameraDistance;
  14. private float keyLightStrength;
  15. private bool overGUI;
  16. private Rect sliderRect;
  17. // private bool changingLightStrength;
  18.  
  19.  
  20. void Awake () {
  21. thisTransform = sopwith;
  22. fokker.gameObject.SetActiveRecursively (false);
  23. cameraDistance = 75.0f;
  24. keyLightStrength = 1.0f;
  25. sliderRect = new Rect((Screen.width/2) - 100, 25, 200, 75);
  26. // changingLightStrength = false;
  27. }
  28.  
  29. void OnGUI () {
  30. GUILayout.BeginArea (new Rect(25, 25, 80, 200));
  31. // GUILayout.BeginVertical ();
  32. if (GUILayout.Button ("Sopwith")) {
  33. thisTransform = sopwith;
  34. // thisTransform.eulerAngles = Vector3.zero;
  35. sopwith.gameObject.SetActiveRecursively (true);
  36. fokker.gameObject.SetActiveRecursively (false);
  37. }
  38. if (GUILayout.Button ("Fokker")) {
  39. thisTransform = fokker;
  40. // thisTransform.eulerAngles = Vector3.zero;
  41. fokker.gameObject.SetActiveRecursively (true);
  42. sopwith.gameObject.SetActiveRecursively (false);
  43. }
  44. if (GUILayout.Button ("Reset")) {
  45. thisTransform.eulerAngles = Vector3.zero;
  46. }
  47. // GUILayout.EndVertical ();
  48. GUILayout.EndArea ();
  49.  
  50. GUILayout.BeginArea (sliderRect);
  51. GUILayout.BeginHorizontal ();
  52. GUILayout.Label ("0", GUILayout.MaxWidth(10));
  53. keyLightStrength = GUILayout.HorizontalSlider (keyLightStrength, 0.0f, 1.0f);
  54. GUILayout.Label ("1", GUILayout.MaxWidth(10));
  55. keyLight.intensity = keyLightStrength;
  56. GUILayout.EndHorizontal ();
  57. GUILayout.Label ("Key Light Intensity: " + keyLight.intensity);
  58. GUILayout.EndArea ();
  59.  
  60. GUILayout.BeginArea (new Rect(Screen.width - 105, 25, 80, 200));
  61. if (GUILayout.Button ("Close View")) cameraDistance = 75;
  62. if (GUILayout.Button ("RR1")) cameraDistance = 150;
  63. if (GUILayout.Button ("RR2")) cameraDistance = 300;
  64. if (GUILayout.Button ("RR3")) cameraDistance = 450;
  65. if (GUILayout.Button ("RR4")) cameraDistance = 600;
  66.  
  67. Vector3 newPosition = Vector3.zero;
  68. newPosition.z = cameraDistance;
  69. Camera.main.transform.position = newPosition;
  70. GUILayout.EndArea ();
  71.  
  72. if (sliderRect.Contains (Input.mousePosition)) {
  73. // if (Input.GetMouseButton(0) && sliderRect.Contains (Input.mousePosition)) {
  74. // overGUI = true;
  75. // Debug.Log ("Over GUI");
  76. } else {
  77. overGUI = false;
  78. // Debug.Log ("NOT Over GUI");
  79. }
  80.  
  81. if (sliderRect.Contains (Event.current.mousePosition)) {
  82. // if (Input.GetMouseButton(0) && sliderRect.Contains (Input.mousePosition)) {
  83. overGUI = true;
  84. // Debug.Log ("Over GUI");
  85. } else {
  86. overGUI = false;
  87. // Debug.Log ("NOT Over GUI");
  88. }
  89. Debug.Log ("-----Event.current.mousePosition: " + Event.current.mousePosition);
  90. // Rect guiRect = GUILayoutUtility.GetLastRect();
  91. // if (Event.current != null && Event.current.isMouse) {
  92. // if (Event.current != null && Event.current.type == EventType.Repaint && Event.current.isMouse) {
  93. // overGUI = sliderRect.Contains(Input.mousePosition);
  94. // Debug.Log (overGUI);
  95. // }
  96. }
  97.  
  98. void Update () {
  99. if (!overGUI) {
  100. // if (sliderRect.Contains (Input.mousePosition)) {
  101. //// if (Input.GetMouseButton(0) && sliderRect.Contains (Input.mousePosition)) {
  102. // Debug.Log ("Over GUI");
  103. // } else {
  104. // Debug.Log ("NOT Over GUI");
  105.  
  106. if (Input.GetMouseButtonDown(0)) {
  107. previousMousePos = Input.mousePosition;
  108. } else {
  109. deltaPos = Vector3.zero;
  110. }
  111.  
  112. if (Input.GetMouseButton(0)) {
  113. deltaPos = Input.mousePosition - previousMousePos;
  114. previousMousePos = Input.mousePosition;
  115. Vector3 newRotation = Vector3.zero;
  116. newRotation.x = -deltaPos.y * sensitivity;
  117. newRotation.y = -deltaPos.x * sensitivity;
  118. thisTransform.Rotate (newRotation, Space.World);
  119. }
  120. }
  121. Debug.Log ("Input.mousePosition: " + Input.mousePosition);
  122.  
  123. // if (!overGUI) {
  124. // if (Input.GetMouseButtonDown(0)) {
  125. // previousMousePos = Input.mousePosition;
  126. // } else {
  127. // deltaPos = Vector3.zero;
  128. // }
  129. //
  130. // if (Input.GetMouseButton(0)) {
  131. // deltaPos = Input.mousePosition - previousMousePos;
  132. // previousMousePos = Input.mousePosition;
  133. // Vector3 newRotation = Vector3.zero;
  134. // newRotation.x = -deltaPos.y * sensitivity;
  135. // newRotation.y = -deltaPos.x * sensitivity;
  136. // thisTransform.Rotate (newRotation, Space.World);
  137. // }
  138. // }
  139. }
  140. }
  141.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement