Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        public void ExportCubemap(kode80Clouds clouds, FullScreenQuad fullScreenQuad, Camera targetCamera)
        {
            _clouds         = clouds;
            _fullScreenQuad = fullScreenQuad;

            kode80Clouds.SubPixelSize oldSubPixelSize = _clouds.subPixelSize;
            int oldDownsample = _clouds.downsample;

            _clouds.subPixelSize = kode80Clouds.SubPixelSize.Sub1x1;
            _clouds.downsample   = 1;
            _clouds.UpdateSharedFromPublicProperties();

            GameObject cmGO = GameObject.Instantiate(targetCamera.gameObject);

            cmGO.name             = "CubeMapCam";
            cmGO.hideFlags        = HideFlags.HideAndDontSave;
            _camera               = cmGO.GetComponent <Camera>();
            _camera.targetTexture = null;

            _fullScreenQuad.enabled = true;

            Cubemap cm = new Cubemap(2048, TextureFormat.RGB24, false);

            Camera.onPreRender += OnPreRender;
            _camera.RenderToCubemap(cm);

            Camera.onPreRender     -= OnPreRender;
            _fullScreenQuad.enabled = false;
            UnityEngine.Object.DestroyImmediate(cmGO);

            SaveCubeMap(cm, "Assets/kode80Clouds.cubemap");
            //SaveCubeMapFaces(cm, "Assets/kode80Clouds");


            _clouds.subPixelSize = oldSubPixelSize;
            _clouds.downsample   = oldDownsample;
            _clouds.UpdateSharedFromPublicProperties();

            _camera         = null;
            _clouds         = null;
            _fullScreenQuad = null;
        }
Ejemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        player      = GameObject.Find("Player");
        clouds      = GameObject.Find("Clouds").GetComponent <kode80.Clouds.kode80Clouds>();
        skybox      = RenderSettings.skybox;
        rotationRef = new GameObject("Skybox Rotation Reference").transform;
        rotationRef.SetParent(transform);

        // Find current julian Date
        System.DateTime nowGMT = System.DateTime.Now.ToUniversalTime();
        julianDate = (long)(367 * nowGMT.Year - 7 * (nowGMT.Year + (nowGMT.Month + 9) / 12) / 4 + 275 * nowGMT.Month / 9 + nowGMT.Day + 1721013.5
                            + nowGMT.ToUniversalTime().Hour / 24 - 0.5 * Mathf.Sign(100 * nowGMT.Year + nowGMT.Month - 190002.5F) + 0.5);
        gmtTimeOfDay = nowGMT.Hour + nowGMT.Minute / 60D + nowGMT.Second / 3600D; // Time of day in hours


        playerLat  = 90;                                           // Initial position of skybox, or, the point on the skydome directly above one's head at the north pole
        playerLong = 0;
        StarInstancer.CreateFromFile("big_dipper.txt");            // Make stars from file
        clouds.coverageOffsetPerFrame = new Vector2(0.01F, 0.07F); // Arbitrary values
        Update();

        Instantiate(Resources.Load <GameObject>("Sun")).transform.SetParent(transform); // Sun must be instantiated before moon
        Instantiate(Resources.Load <GameObject>("Moon")).transform.SetParent(transform);

        // Rotate islands around
        // Or not, because apparently terrain is static

        /*
         * Vector3 northProj = Vector3.ProjectOnPlane(SkyboxController.North, Vector3.up).normalized;
         * float rotation = Vector3.Angle(Vector3.forward, northProj);
         * Transform islands = GameObject.Find("Islands").transform;
         * for (int i = 0; i < islands.childCount; ++i) {
         *  Transform island = islands.GetChild(i);
         *  island.RotateAround(Vector3.zero, Vector3.up, rotation);   // Islands should be initially oriented as if z-axis were North
         * }
         */
    }
Ejemplo n.º 5
0
 void Start()
 {
     CreateMaterialsIfNeeded();
     clouds = GameObject.FindObjectOfType <kode80Clouds>();
 }