Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Viewer : MonoBehaviour {
- public Transform sopwith;
- public Transform fokker;
- public Light keyLight;
- public Light fillLight;
- public float sensitivity;
- private Transform thisTransform;
- private Vector3 previousMousePos;
- private Vector3 deltaPos;
- private float cameraDistance;
- private float keyLightStrength;
- private float fillLightStrenth;
- private float ambientLightStrength;
- private bool overGUI;
- private Rect sliderRect;
- void Awake () {
- thisTransform = sopwith;
- fokker.gameObject.SetActiveRecursively (false);
- cameraDistance = 75.0f;
- keyLightStrength = PlayerPrefs.GetFloat ("Viewer-KeyIntensity", 1.0f);
- fillLightStrenth = PlayerPrefs.GetFloat ("Viewer-FillIntensity", 0.2f);
- ambientLightStrength = PlayerPrefs.GetFloat ("Viewer-AmbientIntensity", 0.2f);
- sliderRect = new Rect(25, Screen.height - 175, 200, 175 );
- }
- void OnDisable () {
- PlayerPrefs.SetFloat ("Viewer-KeyIntensity", keyLightStrength);
- PlayerPrefs.SetFloat ("Viewer-FillIntensity", fillLightStrenth);
- PlayerPrefs.SetFloat ("Viewer-AmbientIntensity", ambientLightStrength);
- }
- void OnGUI () {
- GUILayout.BeginArea (new Rect(25, 25, 80, 200));
- if (GUILayout.Button ("Sopwith")) {
- thisTransform = sopwith;
- // thisTransform.eulerAngles = Vector3.zero;
- sopwith.gameObject.SetActiveRecursively (true);
- fokker.gameObject.SetActiveRecursively (false);
- }
- if (GUILayout.Button ("Fokker")) {
- thisTransform = fokker;
- // thisTransform.eulerAngles = Vector3.zero;
- fokker.gameObject.SetActiveRecursively (true);
- sopwith.gameObject.SetActiveRecursively (false);
- }
- if (GUILayout.Button ("Reset")) {
- thisTransform.eulerAngles = Vector3.zero;
- }
- GUILayout.EndArea ();
- GUILayout.BeginArea (sliderRect);
- GUILayout.Label ("Key Light Intensity: " + keyLight.intensity);
- GUILayout.BeginHorizontal ();
- GUILayout.Label ("0", GUILayout.MaxWidth(10));
- keyLightStrength = GUILayout.HorizontalSlider (keyLightStrength, 0.0f, 1.0f);
- GUILayout.Label ("1", GUILayout.MaxWidth(10));
- keyLight.intensity = keyLightStrength;
- GUILayout.EndHorizontal ();
- GUILayout.Label ("Fill Light Intensity: " + fillLight.intensity);
- GUILayout.BeginHorizontal ();
- GUILayout.Label ("0", GUILayout.MaxWidth(10));
- fillLightStrenth = GUILayout.HorizontalSlider (fillLightStrenth, 0.0f, 1.0f);
- GUILayout.Label ("1", GUILayout.MaxWidth(10));
- fillLight.intensity = fillLightStrenth;
- GUILayout.EndHorizontal ();
- GUILayout.Label ("Ambient Light Intensity: " + (ambientLightStrength * 255));
- GUILayout.BeginHorizontal ();
- GUILayout.Label ("0", GUILayout.MaxWidth(10));
- ambientLightStrength = GUILayout.HorizontalSlider (ambientLightStrength, 0.0f, 1.0f);
- GUILayout.Label ("1", GUILayout.MaxWidth(10));
- RenderSettings.ambientLight = new Color (ambientLightStrength, ambientLightStrength, ambientLightStrength);
- GUILayout.EndHorizontal ();
- GUILayout.EndArea ();
- GUILayout.BeginArea (new Rect(Screen.width - 105, 25, 80, 200));
- if (GUILayout.Button ("Close View")) cameraDistance = 75;
- if (GUILayout.Button ("RR1")) cameraDistance = 150;
- if (GUILayout.Button ("RR2")) cameraDistance = 300;
- if (GUILayout.Button ("RR3")) cameraDistance = 450;
- if (GUILayout.Button ("RR4")) cameraDistance = 600;
- Vector3 newPosition = Vector3.zero;
- newPosition.z = cameraDistance;
- Camera.main.transform.position = newPosition;
- GUILayout.EndArea ();
- // if (sliderRect.Contains (Input.mousePosition)) {
- //// if (Input.GetMouseButton(0) && sliderRect.Contains (Input.mousePosition)) {
- //// overGUI = true;
- //// Debug.Log ("Over GUI");
- // } else {
- // overGUI = false;
- //// Debug.Log ("NOT Over GUI");
- // }
- if (sliderRect.Contains (Event.current.mousePosition)) {
- // if (Input.GetMouseButton(0) && sliderRect.Contains (Input.mousePosition)) {
- overGUI = true;
- // Debug.Log ("Over GUI");
- } else {
- overGUI = false;
- // Debug.Log ("NOT Over GUI");
- }
- // Debug.Log ("Rect: " + sliderRect.x + ", " + sliderRect.y + ", " + (sliderRect.x + sliderRect.width) + ", " + (sliderRect.y + sliderRect.height));
- // Debug.Log ("-----Event.current.mousePosition: " + Event.current.mousePosition);
- // Rect guiRect = GUILayoutUtility.GetLastRect();
- // if (Event.current != null && Event.current.isMouse) {
- // if (Event.current != null && Event.current.type == EventType.Repaint && Event.current.isMouse) {
- // overGUI = sliderRect.Contains(Input.mousePosition);
- // Debug.Log (overGUI);
- // }
- }
- void Update () {
- if (!overGUI) {
- // if (sliderRect.Contains (Input.mousePosition)) {
- //// if (Input.GetMouseButton(0) && sliderRect.Contains (Input.mousePosition)) {
- // Debug.Log ("Over GUI");
- // } else {
- // Debug.Log ("NOT Over GUI");
- if (Input.GetMouseButtonDown(0)) {
- previousMousePos = Input.mousePosition;
- } else {
- deltaPos = Vector3.zero;
- }
- if (Input.GetMouseButton(0)) {
- deltaPos = Input.mousePosition - previousMousePos;
- previousMousePos = Input.mousePosition;
- Vector3 newRotation = Vector3.zero;
- newRotation.x = -deltaPos.y * sensitivity;
- newRotation.y = -deltaPos.x * sensitivity;
- thisTransform.Rotate (newRotation, Space.World);
- }
- }
- // Debug.Log ("Input.mousePosition: " + Input.mousePosition);
- // Debug.Log ("Rect: " + sliderRect.x + ", " + sliderRect.y + ", " + (sliderRect.x + sliderRect.width) + ", " + (sliderRect.y + sliderRect.height));
- // if (!overGUI) {
- // if (Input.GetMouseButtonDown(0)) {
- // previousMousePos = Input.mousePosition;
- // } else {
- // deltaPos = Vector3.zero;
- // }
- //
- // if (Input.GetMouseButton(0)) {
- // deltaPos = Input.mousePosition - previousMousePos;
- // previousMousePos = Input.mousePosition;
- // Vector3 newRotation = Vector3.zero;
- // newRotation.x = -deltaPos.y * sensitivity;
- // newRotation.y = -deltaPos.x * sensitivity;
- // thisTransform.Rotate (newRotation, Space.World);
- // }
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement