Exemplo n.º 1
0
 void OnDestroy()
 {
     if (instance == this)
     {
         instance = null;
     }
 }
Exemplo n.º 2
0
    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();
    }
Exemplo n.º 3
0
    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);
        }
    }
Exemplo n.º 4
0
    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);
        }
    }
Exemplo n.º 5
0
 void OnDestroy()
 {
     if (instance == this) instance = null;
 }