Example #1
0
        void OnEnable()
        {
            minSize     = new Vector2(350.0f, 150.0f);
            _testButton = AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/kode80/Clouds/Editor/gui/button_camera.png");


            _editorState = FindOrCreateEditorState();
            bool isWindowOpening = _editorState.EditorWindowEnabled();

            _clouds = GameObject.FindObjectOfType <kode80Clouds>();

            _fullScreenQuad = CreateFullScreenQuad();
            _cloudsCamera   = CreateCloudsCamera();
            _fullScreenQuad.targetCamera = _cloudsCamera;

            _clouds.SetCamera(_cloudsCamera);
            _clouds.onValidateDelegate += OnCloudsValidate;

            CreateGUI();

            _painter           = CreateInstance <TexturePainter>();
            _painter.hideFlags = HideFlags.HideAndDontSave;

            _coverage = _editorState.tempCoverage;
            if (isWindowOpening)
            {
                if (_clouds.cloudCoverage != null)
                {
                    _editorState.CopyCoverageAssetToTemp(_clouds.cloudCoverage as Texture2D);
                }
                else
                {
                    ClearCoverage();
                }
            }

            _originalCoverage     = _clouds.cloudCoverage;
            _clouds.cloudCoverage = _coverage;

            UpdateFullScreenQuadMaterial();

            wantsMouseMove = true;
            SetNeedsUpdate();
            _lastFrameTime = Time.realtimeSinceStartup;
            RefreshCamerasArray();
            RefreshRenderTexture();

            EditorApplication.modifierKeysChanged += OnModifierKeysChanged;
        }
        void OnDisable()
        {
            if (_testButton)
            {
                Resources.UnloadAsset(_testButton);
                _testButton = null;
            }

            _editorState.EditorWindowDisabled();
            EditorApplication.modifierKeysChanged -= OnModifierKeysChanged;
            _coverage = null;

            if (_cloudsCamera)
            {
                DestroyImmediate(_cloudsCamera.gameObject);
                _cloudsCamera = null;
            }

            if (_renderTexture)
            {
                DestroyImmediate(_renderTexture);
                _renderTexture = null;
            }

            if (_fullScreenQuad)
            {
                DestroyImmediate(_fullScreenQuad.gameObject);
                _fullScreenQuad = null;
            }

            if (_painter)
            {
                DestroyImmediate(_painter);
                _painter = null;
            }

            if (_clouds)
            {
                _clouds.onValidateDelegate -= OnCloudsValidate;
                _clouds.cloudCoverage       = _originalCoverage;
                _clouds = null;
            }
        }