void OnDestroy() { if (instance == this) { instance = null; } }
void LateUpdate() { if (materialToUpdate == null || Time.time < mNextUpdate) { return; } mNextUpdate = Time.time + updateFrequency; if (mCam == null) { GameObject go = new GameObject("RealtimeCubemap Camera"); go.hideFlags = HideFlags.HideAndDontSave; mCamTrans = go.transform; mCam = go.AddComponent <Camera>(); mCam.enabled = false; } if (mTex == null) { int size = 32 << (int)cubemapSize; mTex = new RenderTexture(size, size, 16); mTex.isPowerOfTwo = true; mTex.isCubemap = true; mTex.hideFlags = HideFlags.HideAndDontSave; if (!string.IsNullOrEmpty(textureFieldToUpdate)) { mPrevious = materialToUpdate.GetTexture(textureFieldToUpdate); materialToUpdate.SetTexture(textureFieldToUpdate, mTex); } } // Render to texture mCamTrans.position = transform.position; mCam.cullingMask = cameraMask; mCam.nearClipPlane = cameraNearFar.x; mCam.farClipPlane = cameraNearFar.y; // Move the distant objects to the current position and render the view DistantObjects.AssumeCameraPosition(mCamTrans.position); mCam.RenderToCubemap(mTex); DistantObjects.RestoreCameraPosition(); }
void OnStart() { if (instance != null) { if (!Application.isEditor) { Debug.LogWarning("Can only have one DistantObjects script in the scene!"); Destroy(this); } return; } instance = this; mTrans = transform; mCamTrans = Camera.main.transform; mCameraOrigin = mCamTrans.position; mInitialOffset = mCameraOrigin - mTrans.position; if (Application.isPlaying) { SGUpdateManager.AddLateUpdate(10, this, CustomUpdate); } }
void OnDestroy() { if (instance == this) instance = null; }