Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- public class Weather_Manager : MonoBehaviour {
- // Properties
- public AudioSource audioSource;
- public AudioSource audioSourceB;
- public GameObject windSource;
- public float step = 0.33f;
- public int sampleDataLength = 512;
- public float scaleFactor = 1;
- public Material skyBox;
- public Material glowMat;
- public Material crepuscularMat;
- public Material[] treeMats;
- public float clipLoudness;
- public float clip2Loudness;
- public float oldClipLoudness;
- public float clipLoudnessB;
- private float[] clipSampleData;
- private float[] clip2SampleData;
- private float currentUpdateTime;
- public float enviroReflectivity;
- private static readonly int Contrast = Shader.PropertyToID("_Contrast");
- private static readonly int Exposure = Shader.PropertyToID("_Exposure");
- public void Awake () {
- audioSourceB = windSource.GetComponent<AudioSource>();
- clipSampleData = new float[sampleDataLength];
- clip2SampleData = new float[sampleDataLength];
- crepuscularMat.GetFloat(Contrast);
- }
- public void Update () {
- if(!PauseManager.isPaused && !Inventory_Screen_Manager.inventoryOn){
- currentUpdateTime += Time.deltaTime;
- if (currentUpdateTime >= step){
- currentUpdateTime = 0f;
- }
- else {
- currentUpdateTime += 0.1f;
- }
- audioSource.clip.GetData(clipSampleData, audioSource.timeSamples);
- audioSourceB.clip.GetData(clip2SampleData, audioSourceB.timeSamples);
- oldClipLoudness = clipLoudness;
- clipLoudness = 0f;
- clip2Loudness = 0f;
- foreach (var sample in clipSampleData){
- if (Math.Abs(sample) > 0.1f){
- clipLoudness += Math.Abs(sample);
- }
- }
- foreach (var sample2 in clip2SampleData){
- if (Math.Abs(sample2) > 0.1f){
- clip2Loudness += Math.Abs(sample2);
- }
- }
- clipLoudness /= sampleDataLength;
- clip2Loudness /= sampleDataLength;
- clipLoudness *= scaleFactor;
- clip2Loudness *= 10f;
- clipLoudness += 0.55f;
- //spin mats, set the wave influence to fake wind changes
- foreach (var material in treeMats)
- {
- material.SetFloat("_influence", clip2Loudness);
- }
- enviroReflectivity = clipLoudness;
- RenderSettings.reflectionIntensity =
- ExtensionMethods.Math.Remap(enviroReflectivity, 0.55f,1.1f,0.3f, 0.65f);
- skyBox.SetFloat(Exposure,
- ExtensionMethods.Math.Remap(enviroReflectivity, 0.55f,0.8f,
- 0.55f, 0.85f));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement