private void OnDisable() { this.Clear(); IDictionaryEnumerator enumerator = this.mCameras.GetEnumerator(); try { while (enumerator.MoveNext()) { DictionaryEntry current = (DictionaryEntry)enumerator.Current; DestroyImmediate(((Camera)current.Value).gameObject); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } this.mCameras.Clear(); if (instance == this) { instance = null; } }
private void OnEnable() { instance = this; this.mStreamingWater = PlayerPrefs.GetInt("Streaming Water", 0) == 1; if (this.automaticQuality) { this.quality = GetQuality(); } }
private static void CalculateObliqueMatrix(ref Matrix4x4 projection, Vector4 clipPlane) { Vector4 b = projection.inverse * new Vector4(TasharenWater.SignExt(clipPlane.x), TasharenWater.SignExt(clipPlane.y), 1f, 1f); Vector4 vector = clipPlane * (2f / Vector4.Dot(clipPlane, b)); projection[2] = vector.x - projection[3]; projection[6] = vector.y - projection[7]; projection[10] = vector.z - projection[11]; projection[14] = vector.w - projection[15]; }
public static void SetQuality(TasharenWater.Quality q) { TasharenWater[] array = UnityEngine.Object.FindObjectsOfType(typeof(TasharenWater)) as TasharenWater[]; if (array.Length > 0) { TasharenWater[] array2 = array; for (int i = 0; i < array2.Length; i++) { TasharenWater tasharenWater = array2[i]; tasharenWater.quality = q; } } else { PlayerPrefs.SetInt("Water", (int)q); } }
private void OnWillRenderObject() { if (TasharenWater.mIsRendering) { return; } if (!base.enabled || !this.mRen || !this.mRen.enabled) { this.Clear(); return; } Material sharedMaterial = this.mRen.sharedMaterial; if (!sharedMaterial) { return; } Camera current = Camera.current; if (!current) { return; } bool supportsImageEffects = SystemInfo.supportsImageEffects; if (supportsImageEffects) { current.depthTextureMode |= DepthTextureMode.Depth; } else { this.quality = TasharenWater.Quality.Fastest; } if (!this.useRefraction) { sharedMaterial.shader.maximumLOD = ((!supportsImageEffects) ? 100 : 200); this.Clear(); return; } LayerMask reflectionMask = this.reflectionMask; int reflectionTextureSize = this.reflectionTextureSize; if (reflectionMask == 0 || reflectionTextureSize < 512) { sharedMaterial.shader.maximumLOD = 300; this.Clear(); } else { sharedMaterial.shader.maximumLOD = 400; TasharenWater.mIsRendering = true; Camera reflectionCamera = this.GetReflectionCamera(current, sharedMaterial, reflectionTextureSize); Vector3 position = this.mTrans.position; Vector3 up = this.mTrans.up; this.CopyCamera(current, reflectionCamera); float w = -Vector3.Dot(up, position); Vector4 plane = new Vector4(up.x, up.y, up.z, w); Matrix4x4 zero = Matrix4x4.zero; TasharenWater.CalculateReflectionMatrix(ref zero, plane); Vector3 position2 = current.transform.position; Vector3 position3 = zero.MultiplyPoint(position2); reflectionCamera.worldToCameraMatrix = current.worldToCameraMatrix * zero; Vector4 clipPlane = this.CameraSpacePlane(reflectionCamera, position, up, 1f); Matrix4x4 projectionMatrix = current.projectionMatrix; TasharenWater.CalculateObliqueMatrix(ref projectionMatrix, clipPlane); reflectionCamera.projectionMatrix = projectionMatrix; reflectionCamera.cullingMask = (-17 & reflectionMask.value); reflectionCamera.targetTexture = this.mTex; GL.SetRevertBackfacing(true); reflectionCamera.transform.position = position3; Vector3 eulerAngles = current.transform.eulerAngles; reflectionCamera.transform.eulerAngles = new Vector3(0f, eulerAngles.y, eulerAngles.z); reflectionCamera.Render(); reflectionCamera.transform.position = position2; GL.SetRevertBackfacing(false); TasharenWater.mIsRendering = false; } }
private void Awake() { this.mTrans = base.transform; this.mRen = base.renderer; this.quality = TasharenWater.GetQuality(); }