Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.36 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SubwayMidWayController : MonoBehaviour
  5. {
  6.  
  7.     public Water myWater;
  8.     public Light directionalLight;
  9.     public Light[] LightsArr;
  10.     public GameObject[] decalArr;
  11.     private AudioSource waterAudioSource;
  12.     private bool showGUI;
  13.  
  14.     private float myDecalCount = 0.0f;
  15.     public float _myLightIntensity;
  16.     public float _myDirtIntensity;
  17.     public bool _spawnWater;
  18.     private int compareCount;
  19.  
  20.  
  21.     private Vector3 targetScale;
  22.     private Vector3 targetPosition;
  23.     private Vector3 initialPosition;
  24.     private Vector3 initialScale;
  25.  
  26.  
  27.  
  28.     void Awake()
  29.     {
  30.         waterAudioSource = myWater.GetComponent<AudioSource>();
  31.     }
  32.     // Use this for initialization
  33.     void Start()
  34.     {
  35.         int myDecalCountInt = decalArr.Length;
  36.         myDecalCount = (float)myDecalCountInt;
  37.         compareCount = 0;
  38.         _spawnWater = false;
  39.  
  40.  
  41.         //water
  42.         initialPosition = myWater.transform.position;
  43.         initialScale = myWater.transform.localScale;
  44.         targetScale = new Vector3(8.0f, 1.0f, 8.0f);
  45.         targetPosition = new Vector3(myWater.transform.position.x, myWater.transform.position.y, myWater.transform.position.z - 8);
  46.     }
  47.  
  48.  
  49.  
  50.     #region TriggerEnter/Exit
  51.     //User enters Zone 2
  52.     void OnTriggerEnter(Collider other)
  53.     {
  54.         if (other.gameObject.tag == "Player")
  55.         {
  56.             Debug.Log("Enter Zone 2 & activating GUI");
  57.             showGUI = true;
  58.  
  59.         }
  60.  
  61.     }
  62.  
  63.     //User leaves Zone 2
  64.     void OnTriggerExit(Collider other)
  65.     {
  66.         if (other.gameObject.tag == "Player")
  67.         {
  68.             Debug.Log("Exit Zone 2 & deactivating GUI");
  69.             showGUI = false;
  70.         }
  71.  
  72.     }
  73.  
  74.     #endregion
  75.  
  76.  
  77.     private Rect windowSize = new Rect(15, 15, 500, 400);
  78.     void OnGUI()
  79.     {
  80.         if (showGUI)
  81.         {
  82.             windowSize = GUI.Window(0, windowSize, MyWindow, "Control");
  83.         }
  84.     }
  85.  
  86.  
  87.     private void MyWindow(int id)
  88.     {
  89.         //Light Intensity
  90.         GUILayout.Space(5);
  91.         GUILayout.BeginHorizontal();
  92.         GUILayout.Label("Light Intensity", GUILayout.Width(100));
  93.         _myLightIntensity = GUI.HorizontalSlider(new Rect(10, 50, 450, 20), this.directionalLight.intensity * 10, 0.0f, 10.00f);
  94.         if (GUI.changed == true)
  95.         {
  96.             UpdateIntensity();
  97.         }
  98.         GUILayout.EndHorizontal();
  99.  
  100.         //Dirt Intensity
  101.         GUILayout.Space(25);
  102.         GUILayout.BeginHorizontal();
  103.         GUILayout.Label("Dirt Intensity", GUILayout.Width(100));
  104.         _myDirtIntensity = GUI.HorizontalSlider(new Rect(10, 100, 450, 20), _myDirtIntensity, 0.0f, myDecalCount - 1);
  105.         if (GUI.changed == true)
  106.         {
  107.             UpdateDirt();
  108.         }
  109.         GUILayout.EndHorizontal();
  110.  
  111.         //Control for spawning water in toilet
  112.         GUILayout.Space(50);
  113.         GUILayout.BeginHorizontal();
  114.         GUILayout.Label("Spawn water in toilet", GUILayout.Width(150));
  115.  
  116.         _spawnWater = GUI.Toggle(new Rect(10, 170, 100, 20), _spawnWater, "ON/OFF");
  117.  
  118.         if (GUI.changed == true)
  119.         {
  120.             SpawnWater();
  121.         }
  122.         GUILayout.EndHorizontal();
  123.  
  124.     }
  125.  
  126.  
  127.  
  128.     private void UpdateIntensity()
  129.     {
  130.         /*      foreach(Light lightElement in LightsArr)
  131.                 {
  132.                         lightElement.light.intensity = _myLightIntensity;
  133.                 }*/
  134.         GameObject.Find("First Person Controller").GetComponent<Networking>().adjustLight_Corridor(_myLightIntensity);
  135.         directionalLight.intensity = _myLightIntensity / 10;
  136.     }
  137.  
  138.     private void UpdateDirt()
  139.     {
  140.         GameObject.Find("First Person Controller").GetComponent<Networking>().adjustDirt_Corridor(_myDirtIntensity);
  141.  
  142.         if (_myDirtIntensity == 0)
  143.         {
  144.             decalArr[0].SetActive(false);
  145.         }
  146.         if (_myDirtIntensity > compareCount)
  147.         {
  148.             Debug.Log("IF: compareCount " + compareCount + " _myDirtIntensity " + (int)_myDirtIntensity);
  149.             for (int i = compareCount; i < (int)_myDirtIntensity; i++)
  150.             {
  151.                 decalArr[i].SetActive(true);
  152.             }
  153.         }
  154.         else if (_myDirtIntensity < compareCount)
  155.         {
  156.             Debug.Log("ELSE: compareCount " + compareCount + " _myDirtIntensity " + (int)_myDirtIntensity);
  157.             for (int i = compareCount; i > (int)_myDirtIntensity; i--)
  158.             {
  159.                 decalArr[i].SetActive(false);
  160.             }
  161.         }
  162.  
  163.         compareCount = (int)_myDirtIntensity;
  164.     }
  165.  
  166.  
  167.     private void SpawnWater()
  168.     {
  169.         if (_spawnWater == true) { waterAudioSource.Play(); }
  170.         else { waterAudioSource.Stop(); }
  171.     }
  172.  
  173.  
  174.  
  175.     void FixedUpdate()
  176.     {
  177.  
  178.         if (_spawnWater == true)
  179.         {
  180.             myWater.transform.localScale = Vector3.Lerp(myWater.transform.localScale, targetScale, 0.1f * Time.smoothDeltaTime);
  181.             myWater.transform.position = Vector3.Lerp(myWater.transform.position, targetPosition, 0.1f * Time.smoothDeltaTime);
  182.         }
  183.         else
  184.         {
  185.             myWater.transform.localScale = Vector3.Lerp(myWater.transform.localScale, initialScale, 0.1f * Time.smoothDeltaTime);
  186.             myWater.transform.position = Vector3.Lerp(myWater.transform.position, initialPosition, 0.1f * Time.smoothDeltaTime);
  187.         }
  188.  
  189.     }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement