Ejemplo n.º 1
0
 static void DisplayWindow()
 {
     window = (CubemapPreviewer)EditorWindow.GetWindow(typeof(CubemapPreviewer));
 }
Ejemplo n.º 2
0
    void OnGUI()
    {
        //Get window if null
        if (window == null)
        {
            window = (CubemapPreviewer)EditorWindow.GetWindow(typeof(CubemapPreviewer));
        }

        //Create or remove if we have a cubemap texture
        if (previewCubemap != null && cubemapObj == null)
        {
            CreateCubemap();
        }
        else if (previewCubemap == null)
        {
            RemoveCubemap();
        }

        float fieldHeight = position.height * 0.02f;

        //Check for cubemap change
        EditorGUI.BeginChangeCheck();
        previewCubemap = (Cubemap)EditorGUILayout.ObjectField(previewCubemap, typeof(Cubemap), false);

        if (EditorGUI.EndChangeCheck())
        {
            UpdateCubemapTexture();
        }

        //Mouse sensitivity
        EditorGUI.BeginChangeCheck();
        sensitivity = EditorGUILayout.Vector2Field("Sensitivity", sensitivity);
        zoomAmount  = EditorGUILayout.Slider("Zoom", zoomAmount, 60, 120);
        smoothVaule = EditorGUILayout.FloatField("Smooth", smoothVaule);
        if (EditorGUI.EndChangeCheck())
        {
            hasSelectedCubemapView = false;
        }

        //Breathing space
        GUILayout.Space(10);

        //Create Camera if we dont have one yet
        if (cam == null)
        {
            CreateViewingCamera();
        }
        else
        {
            //Update FOV
            cam.fieldOfView = zoomAmount;

            //Render our Rendertexture
            cam.Render();

            //Draw it
            GUI.DrawTexture(new Rect(0, position.height * 0.25f, position.width, position.height * 0.75f), cam.targetTexture);

            //Mouse Events for controlling Look Controller for Cubemap View
            if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
            {
                //Clicked inside cubemap view
                Rect cubemapRect = new Rect(0, position.height * 0.25f, position.width, position.height * 0.75f);

                if (cubemapRect.Contains(Event.current.mousePosition))
                {
                    hasSelectedCubemapView = true;
                }

                //Clicked outside cubemap view
                Rect propertyRect = new Rect(0, 0, position.width, position.height * 0.25f);

                if (propertyRect.Contains(Event.current.mousePosition))
                {
                    hasSelectedCubemapView = false;
                }
            }

            //Update Mouse Delta for Rotation Movement
            UpdateEditorMouse();

            //What it says on the tin (WISOTT)
            Repaint();
        }
    }