private void OnPreRender(Camera theCamera) { if (theCamera == _camera) { _clouds.SetCamera(_camera); _clouds.RenderClouds(); _fullScreenQuad.material.SetFloat("_DrawCoverage", 0.0f); _fullScreenQuad.material.SetFloat("_DrawCursor", 0.0f); _fullScreenQuad.material.SetTexture("_MainTex", _clouds.currentFrame); _clouds.cloudsSharedProperties.ApplyToMaterial(_fullScreenQuad.material); } }
void Update() { if (EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying == false) { // Unity's ordering of Enable/Disable & various isPlaying flags makes // reliably setting up/tearing down/saving etc. very convoluted when // user switches between Play/Edit. So for now just close window... // ...there *must* be a better way. Close(); return; } RefreshRenderTexture(); float fps = 1.0f / 30.0f; if (_cameraMovement.x != 0.0f || _cameraMovement.y != 0.0f || _cameraMovement.z != 0.0f || _mouseDelta.x != 0.0f || _mouseDelta.y != 0.0f) { SetNeedsUpdate(); } if (_lastFrameTime <= Time.realtimeSinceStartup - fps) { float timeDelta = Time.realtimeSinceStartup - _lastFrameTime; if (_continuousUpdate || _cloudsCatchupFrames > 0) { _clouds.UpdateAnimatedProperties(); if (_mode == 0) { float speed = 100.0f; _cloudsCamera.transform.position += _cameraMovement.x * _cloudsCamera.transform.right * timeDelta * speed; _cloudsCamera.transform.position += _cameraMovement.y * _cloudsCamera.transform.up * timeDelta * speed; _cloudsCamera.transform.position += _cameraMovement.z * _cloudsCamera.transform.forward * timeDelta * speed; _cloudsCamera.transform.Rotate(_cloudsCamera.transform.right, _mouseDelta.y, Space.World); _cloudsCamera.transform.Rotate(Vector3.up, _mouseDelta.x, Space.World); } else if (_mode != 0) { if (_mouseDown) { Vector2 brushPoint = WindowToCoverage(_lastMousePosition); bool drawCoverage = _mode == 1; bool drawType = _mode == 2; float coverageOpacity = drawCoverage ? _editorState.cursorOpacity : 0.0f; float typeOpacity = drawType ? _editorState.cursorOpacity : 0.0f; float dir = _shiftDown ? -1.0f : 1.0f; dir = _editorState.cursorBlendValues ? dir : 1.0f; _painter.Render(brushPoint, _editorState.cursorRadius, coverageOpacity * dir, typeOpacity * dir, drawCoverage, drawType, _editorState.cursorBlendValues, _coverage, _editorState.brushTexture); _editorState.MarkTempCoverageDirty(); } else if (_controlDown) { float xDelta = _lastMousePosition.x - _mousePositionAtControlDown.x; float radiusDelta = xDelta / 200.0f; float radiusRange = 0.0f; if (xDelta > 0.0f) { radiusRange = (EditorState.MaxCursorRadius - _cursorOriginalRadius) * Mathf.Min(1.0f, radiusDelta); } else { radiusRange = _cursorOriginalRadius * Mathf.Max(-1.0f, radiusDelta); } _editorState.cursorRadius = _cursorOriginalRadius + radiusRange; _guiBrushSize.value = (int)_editorState.cursorRadius * 2; } } _mouseDelta = Vector2.zero; _cloudsCatchupFrames--; if (_clouds) { _clouds.SetCamera(_cloudsCamera); _clouds.RenderClouds(); UpdateFullScreenQuadMaterial(); } _fullScreenQuad.enabled = true; _fullScreenQuad.material.SetTexture("_MainTex", _clouds.currentFrame); _cloudsCamera.Render(); _fullScreenQuad.enabled = false; Repaint(); } _lastFrameTime = Time.realtimeSinceStartup; } }