Example #1
0
        public static void UpdateShadowInfoWithBrightestSpot(CubemapInfo cubemapInfo)
        {
            LookDevResources.m_LookDevCubeToLatlong.SetTexture("_MainTex", cubemapInfo.cubemap);
            LookDevResources.m_LookDevCubeToLatlong.SetVector("_WindowParams", new Vector4(10000f, -1000f, 2f, 0f));
            LookDevResources.m_LookDevCubeToLatlong.SetVector("_CubeToLatLongParams", new Vector4(0.0174532924f * cubemapInfo.angleOffset, 0.5f, 1f, 3f));
            LookDevResources.m_LookDevCubeToLatlong.SetPass(0);
            int num  = 250;
            int num2 = 125;

            Graphics.Blit(cubemapInfo.cubemap, LookDevResources.m_BrightestPointRT, LookDevResources.m_LookDevCubeToLatlong);
            LookDevResources.m_BrightestPointTexture.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0, false);
            LookDevResources.m_BrightestPointTexture.Apply();
            Color[] pixels = LookDevResources.m_BrightestPointTexture.GetPixels();
            float   num3   = 0f;

            for (int i = 0; i < num2; i++)
            {
                for (int j = 0; j < num; j++)
                {
                    Vector3 vector = new Vector3(pixels[i * num + j].r, pixels[i * num + j].g, pixels[i * num + j].b);
                    float   num4   = vector.x * 0.2126729f + vector.y * 0.7151522f + vector.z * 0.072175f;
                    if (num3 < num4)
                    {
                        Vector2 vector2 = LookDevEnvironmentWindow.PositionToLatLong(new Vector2((float)j / (float)(num - 1) * 2f - 1f, (float)i / (float)(num2 - 1) * 2f - 1f));
                        cubemapInfo.shadowInfo.latitude  = vector2.x;
                        cubemapInfo.shadowInfo.longitude = vector2.y - cubemapInfo.angleOffset;
                        num3 = num4;
                    }
                }
            }
        }
 public static void UpdateShadowInfoWithBrightestSpot(CubemapInfo cubemapInfo)
 {
     m_LookDevCubeToLatlong.SetTexture("_MainTex", cubemapInfo.cubemap);
     m_LookDevCubeToLatlong.SetVector("_WindowParams", new Vector4(10000f, -1000f, 2f, 0f));
     m_LookDevCubeToLatlong.SetVector("_CubeToLatLongParams", new Vector4(0.01745329f * cubemapInfo.angleOffset, 0.5f, 1f, 3f));
     m_LookDevCubeToLatlong.SetPass(0);
     int num = 250;
     int num2 = 0x7d;
     Graphics.Blit(cubemapInfo.cubemap, m_BrightestPointRT, m_LookDevCubeToLatlong);
     m_BrightestPointTexture.ReadPixels(new Rect(0f, 0f, (float) num, (float) num2), 0, 0, false);
     m_BrightestPointTexture.Apply();
     Color[] pixels = m_BrightestPointTexture.GetPixels();
     float num3 = 0f;
     for (int i = 0; i < num2; i++)
     {
         for (int j = 0; j < num; j++)
         {
             Vector3 vector = new Vector3(pixels[(i * num) + j].r, pixels[(i * num) + j].g, pixels[(i * num) + j].b);
             float num6 = ((vector.x * 0.2126729f) + (vector.y * 0.7151522f)) + (vector.z * 0.072175f);
             if (num3 < num6)
             {
                 Vector2 vector2 = LookDevEnvironmentWindow.PositionToLatLong(new Vector2(((((float) j) / ((float) (num - 1))) * 2f) - 1f, ((((float) i) / ((float) (num2 - 1))) * 2f) - 1f));
                 cubemapInfo.shadowInfo.latitude = vector2.x;
                 cubemapInfo.shadowInfo.longitude = vector2.y - cubemapInfo.angleOffset;
                 num3 = num6;
             }
         }
     }
 }
        private void DrawLatLongThumbnail(CubemapInfo infos, float angleOffset, float intensity, float alpha, Rect textureRect)
        {
            GUIStyle gUIStyle = "dockarea";

            LookDevResources.m_LookDevCubeToLatlong.SetVector("_WindowParams", new Vector4(this.m_displayRect.height, this.m_PositionInLookDev.y + 17f, (float)gUIStyle.margin.top, EditorGUIUtility.pixelsPerPoint));
            LookDevResources.m_LookDevCubeToLatlong.SetVector("_CubeToLatLongParams", new Vector4(0.0174532924f * angleOffset, alpha, intensity, 0f));
            Graphics.DrawTexture(textureRect, infos.cubemap, LookDevResources.m_LookDevCubeToLatlong, 1);
        }
        public void InsertHDRI(Cubemap cubemap, int insertionIndex)
        {
            Undo.RecordObject(this.m_LookDevView.envLibrary, "Insert HDRI");
            Undo.RecordObject(this.m_LookDevView.config, "Insert HDRI");
            Cubemap cubemap0 = null;
            Cubemap cubemap1 = null;

            if (cubemap == LookDevResources.m_DefaultHDRI)
            {
                cubemap0 = LookDevResources.m_DefaultHDRI;
                cubemap1 = LookDevResources.m_DefaultHDRI;
            }
            else
            {
                cubemap0 = this.m_HDRIList[this.m_LookDevView.config.lookDevContexts[0].currentHDRIIndex].cubemap;
                cubemap1 = this.m_HDRIList[this.m_LookDevView.config.lookDevContexts[1].currentHDRIIndex].cubemap;
            }
            int num = this.m_HDRIList.FindIndex((CubemapInfo x) => x.cubemap == cubemap);

            if (num == -1)
            {
                this.m_Dirty = true;
                CubemapInfo cubemapInfo = null;
                for (int i = 0; i < this.m_HDRIList.Count; i++)
                {
                    if (this.m_HDRIList[i].cubemapShadowInfo.cubemap == cubemap)
                    {
                        cubemapInfo = this.m_HDRIList[i].cubemapShadowInfo;
                        cubemapInfo.SetCubemapShadowInfo(cubemapInfo);
                        break;
                    }
                }
                if (cubemapInfo == null)
                {
                    cubemapInfo         = new CubemapInfo();
                    cubemapInfo.cubemap = cubemap;
                    cubemapInfo.ambientProbe.Clear();
                    cubemapInfo.alreadyComputed = false;
                    cubemapInfo.SetCubemapShadowInfo(cubemapInfo);
                }
                int count = this.m_HDRIList.Count;
                this.m_HDRIList.Insert((insertionIndex != -1) ? insertionIndex : count, cubemapInfo);
                if (cubemapInfo.cubemap != LookDevResources.m_DefaultHDRI)
                {
                    LookDevResources.UpdateShadowInfoWithBrightestSpot(cubemapInfo);
                }
            }
            if (num != insertionIndex && num != -1 && insertionIndex != -1)
            {
                CubemapInfo item = this.m_HDRIList[num];
                this.m_HDRIList.RemoveAt(num);
                this.m_HDRIList.Insert((num <= insertionIndex) ? (insertionIndex - 1) : insertionIndex, item);
            }
            this.m_LookDevView.config.lookDevContexts[0].UpdateProperty(LookDevProperty.HDRI, this.m_HDRIList.FindIndex((CubemapInfo x) => x.cubemap == cubemap0));
            this.m_LookDevView.config.lookDevContexts[1].UpdateProperty(LookDevProperty.HDRI, this.m_HDRIList.FindIndex((CubemapInfo x) => x.cubemap == cubemap1));
            this.m_LookDevView.Repaint();
        }
 private void DrawLatLongThumbnail(CubemapInfo infos, float angleOffset, float intensity, float alpha, Rect textureRect)
 {
     GUIStyle style = "dockarea";
     LookDevResources.m_LookDevCubeToLatlong.SetVector("_WindowParams", new Vector4(this.m_displayRect.height, this.m_PositionInLookDev.y + 17f, (float) style.margin.top, EditorGUIUtility.pixelsPerPoint));
     LookDevResources.m_LookDevCubeToLatlong.SetVector("_CubeToLatLongParams", new Vector4(0.01745329f * angleOffset, alpha, intensity, 0f));
     GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
     Graphics.DrawTexture(textureRect, infos.cubemap, LookDevResources.m_LookDevCubeToLatlong, 1);
     GL.sRGBWrite = false;
 }
 public void CancelSelection()
 {
     this.m_SelectedCubemap = null;
     this.m_SelectedCubemapInfo = null;
     this.m_SelectedShadowCubemapOwnerInfo = null;
     this.m_SelectedLightIconIndex = -1;
     this.m_SelectedShadowInfo = null;
     this.m_HoveringCubeMapIndex = -1;
     this.m_DragBeingPerformed = false;
 }
Example #7
0
 public void CancelSelection()
 {
     this.m_SelectedCubemap                = null;
     this.m_SelectedCubemapInfo            = null;
     this.m_SelectedShadowCubemapOwnerInfo = null;
     this.m_SelectedLightIconIndex         = -1;
     this.m_SelectedShadowInfo             = null;
     this.m_HoveringCubeMapIndex           = -1;
     this.m_DragBeingPerformed             = false;
 }
Example #8
0
        private void DrawLatLongThumbnail(CubemapInfo infos, float angleOffset, float intensity, float alpha, Rect textureRect)
        {
            // We need texture rect to clip correctly the Graphics.DrawTexture done for library GUI (otherwise it goes out the window)
            // But we can't use scissor rect here to clip the texture when outside the draw area because SetScissorRect in script only work if we are
            // in C++ code that have scissor enable, which is not the case here. We will clip in shader instead.
            // For this we will use the VPOS register and the y position of the widget to clip (see LookDevCubeToLatlong.shader).
            // To get current position y we need to take into account the tab panel + the menu panel.  Menu panel size is in m_PositionInLookDev.y
            // But tabsize panel is in DockAreas.cs: BeginOffsetArea (new Rect (r.x + 2, r.y + kTabHeight, r.width - 4, r.height - kTabHeight - 2), GUIContent.none, "TabWindowBackground");
            // This part exactly:  r.y + kTabHeight. r.y seems to always be 2 so use that for now (setup in z) and is store in ((GUIStyle)("dockarea"))overlay.margin.top
            GUIStyle overlay = "dockarea";

            LookDevResources.m_LookDevCubeToLatlong.SetVector("_WindowParams", new Vector4(m_displayRect.height, m_PositionInLookDev.y + DockArea.kTabHeight, overlay.margin.top, EditorGUIUtility.pixelsPerPoint));
            LookDevResources.m_LookDevCubeToLatlong.SetVector("_CubeToLatLongParams", new Vector4(Mathf.Deg2Rad * angleOffset, alpha, intensity, 0.0f));

            Graphics.DrawTexture(textureRect, infos.cubemap, LookDevResources.m_LookDevCubeToLatlong, 1);
        }
 public void OnBeforeSerialize()
 {
     this.m_SerialShadowMapHDRIList.Clear();
     for (int i = 0; i < this.m_HDRIList.Count; i++)
     {
         CubemapInfo shadowCubemapInfo = this.m_HDRIList[i].cubemapShadowInfo;
         this.m_HDRIList[i].serialIndexMain = this.m_HDRIList.FindIndex((CubemapInfo x) => x == shadowCubemapInfo);
         if (this.m_HDRIList[i].serialIndexMain == -1)
         {
             this.m_HDRIList[i].serialIndexShadow = this.m_SerialShadowMapHDRIList.FindIndex((CubemapInfo x) => x == shadowCubemapInfo);
             if (this.m_HDRIList[i].serialIndexShadow == -1)
             {
                 this.m_SerialShadowMapHDRIList.Add(shadowCubemapInfo);
                 this.m_HDRIList[i].serialIndexShadow = this.m_SerialShadowMapHDRIList.Count - 1;
             }
         }
     }
 }
Example #10
0
        // Find brightest spot of the cubemap
        static public void UpdateShadowInfoWithBrightestSpot(CubemapInfo cubemapInfo)
        {
            m_LookDevCubeToLatlong.SetTexture("_MainTex", cubemapInfo.cubemap);
            m_LookDevCubeToLatlong.SetVector("_WindowParams", new Vector4(10000, -1000.0f, 2, 0.0f));                                         // Neutral value to not clip
            m_LookDevCubeToLatlong.SetVector("_CubeToLatLongParams", new Vector4(Mathf.Deg2Rad * cubemapInfo.angleOffset, 0.5f, 1.0f, 3.0f)); // We use LOD 3 to take a region rather than a single pixel in the map
            m_LookDevCubeToLatlong.SetPass(0);

            int width  = (int)LookDevEnvironmentWindow.m_HDRIWidth;
            int height = (int)LookDevEnvironmentWindow.m_latLongHeight;

            // Convert cubemap to a 2D LatLong to read on CPU
            Graphics.Blit(cubemapInfo.cubemap, m_BrightestPointRT, m_LookDevCubeToLatlong);
            m_BrightestPointTexture.ReadPixels(new Rect(0, 0, width, height), 0, 0, false);
            m_BrightestPointTexture.Apply();

            // CPU read back
            // From Doc: The returned array is a flattened 2D array, where pixels are laid out left to right, bottom to top (i.e. row after row)
            Color[] color = m_BrightestPointTexture.GetPixels();

            float maxLum = 0.0f;

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    Vector3 rgb = new Vector3(color[y * width + x].r, color[y * width + x].g, color[y * width + x].b);

                    float lum = rgb.x * 0.2126729f + rgb.y * 0.7151522f + rgb.z * 0.0721750f;

                    if (maxLum < lum)
                    {
                        Vector2 vec = LookDevEnvironmentWindow.PositionToLatLong(new Vector2(((float)x / (float)(width - 1)) * 2.0f - 1.0f, ((float)y / (float)(height - 1)) * 2.0f - 1.0f));
                        cubemapInfo.shadowInfo.latitude  = vec.x;
                        cubemapInfo.shadowInfo.longitude = vec.y - cubemapInfo.angleOffset;

                        maxLum = lum;
                    }
                }
            }
        }
Example #11
0
        public void OnBeforeSerialize()
        {
            m_SerialShadowMapHDRIList.Clear();

            // We need to 'convert' all shadow cubemap to index before saving, any shadow cubemap without matching HDRI in the main list
            // will be added to the HDRI list for serialization.
            for (int i = 0; i < m_HDRIList.Count; ++i)
            {
                CubemapInfo shadowCubemapInfo = m_HDRIList[i].cubemapShadowInfo;

                // Check if we have already added it to shadow cubemap list
                m_HDRIList[i].serialIndexMain = m_HDRIList.FindIndex(x => x == shadowCubemapInfo);
                if (m_HDRIList[i].serialIndexMain == -1)
                {
                    m_HDRIList[i].serialIndexShadow = m_SerialShadowMapHDRIList.FindIndex(x => x == shadowCubemapInfo);
                    if (m_HDRIList[i].serialIndexShadow == -1)
                    {
                        m_SerialShadowMapHDRIList.Add(shadowCubemapInfo);
                        m_HDRIList[i].serialIndexShadow = m_SerialShadowMapHDRIList.Count - 1;
                    }
                }
            }
        }
Example #12
0
 public void SetCubemapShadowInfo(CubemapInfo newCubemapShadowInfo)
 {
     cubemapShadowInfo          = newCubemapShadowInfo;
     shadowInfo.shadowIntensity = newCubemapShadowInfo == this ? kDefaultShadowIntensity : 1.0f;
     shadowInfo.shadowColor     = Color.white;
 }
Example #13
0
        // If insertionIndex is -1 it mean we insert at the end of the list
        public void InsertHDRI(Cubemap cubemap, int insertionIndex)
        {
            Undo.RecordObject(m_LookDevView.envLibrary, "Insert HDRI");
            Undo.RecordObject(m_LookDevView.config, "Insert HDRI");

            // Handle cubemap index remapping for both context. Simply do it brute force in all cases.
            // Save the cubemap info before any modification to m_HDRIList.
            // Also if we are inserting m_DefaultHDRI, it mean we have an empty m_HDRIList
            Cubemap cubemap0 = null;
            Cubemap cubemap1 = null;

            if (cubemap == LookDevResources.m_DefaultHDRI)
            {
                cubemap0 = LookDevResources.m_DefaultHDRI;
                cubemap1 = LookDevResources.m_DefaultHDRI;
            }
            else
            {
                cubemap0 = m_HDRIList[m_LookDevView.config.lookDevContexts[0].currentHDRIIndex].cubemap;
                cubemap1 = m_HDRIList[m_LookDevView.config.lookDevContexts[1].currentHDRIIndex].cubemap;
            }

            // Check if the cubemap already exist
            int iIndex = m_HDRIList.FindIndex(x => x.cubemap == cubemap);

            // Create cubemap if it doesn't exist
            if (iIndex == -1)
            {
                m_Dirty = true;

                CubemapInfo newInfo = null;

                // Check if the cubemap exist but as a shadow cubemap only
                // in this case we don't recreate the CubemapInfo, but we still insert it as a new one.
                for (int i = 0; i < m_HDRIList.Count; ++i)
                {
                    if (m_HDRIList[i].cubemapShadowInfo.cubemap == cubemap)
                    {
                        newInfo = m_HDRIList[i].cubemapShadowInfo;
                        // Prevent recursion with shadow cubemap info
                        newInfo.SetCubemapShadowInfo(newInfo);
                        break;
                    }
                }

                if (newInfo == null)
                {
                    newInfo         = new CubemapInfo();
                    newInfo.cubemap = cubemap;
                    newInfo.ambientProbe.Clear();
                    newInfo.alreadyComputed = false;
                    newInfo.SetCubemapShadowInfo(newInfo); // By default we use the same cubemap for the version without sun.
                }

                int newCubemapIndex = m_HDRIList.Count;
                // Add the cubemap to the specified location or last if no location provide
                m_HDRIList.Insert(insertionIndex == -1 ? newCubemapIndex : insertionIndex, newInfo);

                // When inserting the default HDRI the first time, the lookdev env is not yet ready.
                // But as we default the latlong light position of ShadowInfo to brightest location of default HDRI this is not a problem to not call the function.
                if (newInfo.cubemap != LookDevResources.m_DefaultHDRI)
                {
                    LookDevResources.UpdateShadowInfoWithBrightestSpot(newInfo);
                }
            }

            // If we haven't inserted at end of the list, if it is not a new cubemap and if we do not insert at the same place, we need to shift current cubemap position in the list
            if (iIndex != insertionIndex && iIndex != -1 && insertionIndex != -1)
            {
                // Get cubemap info before modifying m_LookDevSetup.m_HDRIList;
                CubemapInfo infos = m_HDRIList[iIndex];

                m_HDRIList.RemoveAt(iIndex);
                // If we insert after the removed cubemap we need to increase the index
                m_HDRIList.Insert(iIndex > insertionIndex ? insertionIndex : insertionIndex - 1, infos);
            }

            m_LookDevView.config.lookDevContexts[0].UpdateProperty(LookDevProperty.HDRI, m_HDRIList.FindIndex(x => x.cubemap == cubemap0));
            m_LookDevView.config.lookDevContexts[1].UpdateProperty(LookDevProperty.HDRI, m_HDRIList.FindIndex(x => x.cubemap == cubemap1));

            m_LookDevView.Repaint();
        }
Example #14
0
 public void OnGUI(int windowID)
 {
     if (!(this.m_LookDevView == null))
     {
         List <CubemapInfo> hdriList = this.m_LookDevView.envLibrary.hdriList;
         bool flag = 146f * (float)hdriList.Count > this.m_PositionInLookDev.height;
         if (flag)
         {
             this.m_ScrollPosition = EditorGUILayout.BeginScrollView(this.m_ScrollPosition, new GUILayoutOption[0]);
         }
         else
         {
             this.m_ScrollPosition = new Vector2(0f, 0f);
         }
         if (hdriList.Count == 1)
         {
             Color color = GUI.color;
             GUI.color = Color.gray;
             Vector2 vector   = GUI.skin.label.CalcSize(LookDevEnvironmentWindow.styles.sDragAndDropHDRIText);
             Rect    position = new Rect(this.m_PositionInLookDev.width * 0.5f - vector.x * 0.5f, this.m_PositionInLookDev.height * 0.5f - vector.y * 0.5f, vector.x, vector.y);
             GUI.Label(position, LookDevEnvironmentWindow.styles.sDragAndDropHDRIText);
             GUI.color = color;
         }
         for (int i = 0; i < hdriList.Count; i++)
         {
             CubemapInfo cubemapInfo = hdriList[i];
             ShadowInfo  shadowInfo  = cubemapInfo.shadowInfo;
             int         intProperty = this.m_LookDevView.config.GetIntProperty(LookDevProperty.HDRI, LookDevEditionContext.Left);
             int         num         = this.m_LookDevView.config.GetIntProperty(LookDevProperty.HDRI, LookDevEditionContext.Right);
             if (this.m_LookDevView.config.lookDevMode == LookDevMode.Single1 || this.m_LookDevView.config.lookDevMode == LookDevMode.Single2)
             {
                 num = -1;
             }
             bool     flag2           = i == intProperty || i == num;
             Color    selectionColor  = Color.black;
             Color    selectionColor2 = Color.black;
             GUIStyle style           = EditorStyles.miniLabel;
             if (flag2)
             {
                 if (i == intProperty)
                 {
                     selectionColor  = LookDevView.m_FirstViewGizmoColor;
                     selectionColor2 = LookDevView.m_FirstViewGizmoColor;
                     style           = LookDevEnvironmentWindow.styles.sLabelStyleFirstContext;
                 }
                 else if (i == num)
                 {
                     selectionColor  = LookDevView.m_SecondViewGizmoColor;
                     selectionColor2 = LookDevView.m_SecondViewGizmoColor;
                     style           = LookDevEnvironmentWindow.styles.sLabelStyleSecondContext;
                 }
                 if (intProperty == num)
                 {
                     selectionColor  = LookDevView.m_FirstViewGizmoColor;
                     selectionColor2 = LookDevView.m_SecondViewGizmoColor;
                     style           = LookDevEnvironmentWindow.styles.sLabelStyleBothContext;
                 }
             }
             GUILayout.BeginVertical(new GUILayoutOption[]
             {
                 GUILayout.Width(250f)
             });
             int num2 = hdriList.FindIndex((CubemapInfo x) => x == this.m_SelectedCubemapInfo);
             if ((this.m_SelectedCubemap != null || this.m_DragBeingPerformed) && this.GetInsertionRect(i).Contains(Event.current.mousePosition) && ((num2 - i != 0 && num2 - i != -1) || num2 == -1))
             {
                 GUILayout.Label(GUIContent.none, LookDevEnvironmentWindow.styles.sSeparatorStyle, new GUILayoutOption[0]);
                 GUILayoutUtility.GetRect(250f, 16f);
             }
             GUILayout.Label(GUIContent.none, LookDevEnvironmentWindow.styles.sSeparatorStyle, new GUILayoutOption[0]);
             GUILayout.BeginHorizontal(new GUILayoutOption[]
             {
                 GUILayout.Width(250f),
                 GUILayout.Height(18f)
             });
             StringBuilder stringBuilder = new StringBuilder();
             stringBuilder.Append(i.ToString());
             stringBuilder.Append(" - ");
             stringBuilder.Append(cubemapInfo.cubemap.name);
             GUILayout.Label(stringBuilder.ToString(), style, new GUILayoutOption[]
             {
                 GUILayout.Height(18f),
                 GUILayout.MaxWidth(175f)
             });
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(LookDevEnvironmentWindow.styles.sEnvControlIcon, LookDevView.styles.sToolBarButton, new GUILayoutOption[0]))
             {
                 Rect last = GUILayoutUtility.topLevel.GetLast();
                 PopupWindow.Show(last, new LookDevEnvironmentWindow.EnvSettingsWindow(this.m_LookDevView, cubemapInfo));
                 GUIUtility.ExitGUI();
             }
             using (new EditorGUI.DisabledScope(cubemapInfo.cubemap == LookDevResources.m_DefaultHDRI))
             {
                 if (GUILayout.Button(LookDevEnvironmentWindow.styles.sCloseIcon, LookDevView.styles.sToolBarButton, new GUILayoutOption[0]))
                 {
                     this.m_LookDevView.envLibrary.RemoveHDRI(cubemapInfo.cubemap);
                 }
             }
             GUILayout.EndHorizontal();
             Rect lastRect = GUILayoutUtility.GetLastRect();
             if (Event.current.type == EventType.MouseDown && lastRect.Contains(Event.current.mousePosition))
             {
                 Event.current.Use();
             }
             Rect rect = GUILayoutUtility.GetRect(250f, 125f);
             rect.width = 253f;
             float   num3      = 24f;
             float   num4      = num3 * 0.5f;
             float   latitude  = shadowInfo.latitude;
             float   longitude = shadowInfo.longitude;
             Vector2 vector2   = this.LatLongToPosition(latitude, longitude + cubemapInfo.angleOffset) * 0.5f + new Vector2(0.5f, 0.5f);
             Rect    position2 = rect;
             position2.x      = position2.x + vector2.x * rect.width - num4;
             position2.y      = position2.y + (1f - vector2.y) * rect.height - num4;
             position2.width  = num3;
             position2.height = num3;
             Rect position3 = rect;
             position3.x      = position3.x + vector2.x * rect.width - num4 * 0.5f;
             position3.y      = position3.y + (1f - vector2.y) * rect.height - num4 * 0.5f;
             position3.width  = num3 * 0.5f;
             position3.height = num3 * 0.5f;
             Rect rect2;
             Rect textureRect;
             this.GetFrameAndShadowTextureRect(rect, out rect2, out textureRect);
             if (this.m_LookDevView.config.enableShadowCubemap)
             {
                 EditorGUIUtility.AddCursorRect(position3, MouseCursor.Pan);
             }
             if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))
             {
                 if (!Event.current.control && Event.current.button == 0 && this.m_SelectedCubeMapOffsetIndex == -1)
                 {
                     if (this.m_LookDevView.config.enableShadowCubemap && position3.Contains(Event.current.mousePosition))
                     {
                         this.m_SelectedLightIconIndex = i;
                         this.m_SelectedShadowInfo     = shadowInfo;
                         Undo.RecordObject(this.m_LookDevView.envLibrary, "Light Icon selection");
                         this.m_SelectedShadowInfo.latitude  = this.m_SelectedShadowInfo.latitude + 0.0001f;
                         this.m_SelectedShadowInfo.longitude = this.m_SelectedShadowInfo.longitude + 0.0001f;
                     }
                     if (this.m_SelectedShadowInfo == null)
                     {
                         Rect rect3 = rect2;
                         rect3.x     += 100f;
                         rect3.y     += 4f;
                         rect3.width  = 11f;
                         rect3.height = 11f;
                         if (this.m_LookDevView.config.enableShadowCubemap && rect3.Contains(Event.current.mousePosition))
                         {
                             Undo.RecordObject(this.m_LookDevView.envLibrary, "Update shadow cubemap");
                             hdriList[i].SetCubemapShadowInfo(hdriList[i]);
                             this.m_LookDevView.envLibrary.dirty = true;
                         }
                         else
                         {
                             if (this.m_LookDevView.config.enableShadowCubemap && textureRect.Contains(Event.current.mousePosition))
                             {
                                 this.m_SelectedShadowCubemapOwnerInfo = hdriList[i];
                                 this.m_SelectedCubemapInfo            = this.m_SelectedShadowCubemapOwnerInfo.cubemapShadowInfo;
                             }
                             else
                             {
                                 this.m_SelectedCubemapInfo = hdriList[i];
                             }
                             this.m_SelectedPositionOffset     = Event.current.mousePosition - new Vector2(rect.x, rect.y);
                             this.m_RenderOverlayThumbnailOnce = true;
                         }
                     }
                 }
                 else if (Event.current.control && Event.current.button == 0 && this.m_SelectedCubemapInfo == null && this.m_SelectedShadowInfo == null)
                 {
                     this.m_SelectedCubeMapOffsetIndex = i;
                     this.m_SelectedCubeMapOffsetValue = cubemapInfo.angleOffset - this.ComputeAngleOffsetFromMouseCoord(Event.current.mousePosition);
                 }
                 GUIUtility.hotControl = this.m_LookDevView.hotControl;
                 Event.current.Use();
             }
             if (Event.current.GetTypeForControl(this.m_LookDevView.hotControl) == EventType.MouseDrag)
             {
                 if (this.m_SelectedShadowInfo == shadowInfo && this.m_SelectedLightIconIndex == i)
                 {
                     Vector2 mousePosition = Event.current.mousePosition;
                     mousePosition.x = (mousePosition.x - rect.x) / rect.width * 2f - 1f;
                     mousePosition.y = (1f - (mousePosition.y - rect.y) / rect.height) * 2f - 1f;
                     Vector2 vector3 = LookDevEnvironmentWindow.PositionToLatLong(mousePosition);
                     this.m_SelectedShadowInfo.latitude  = vector3.x;
                     this.m_SelectedShadowInfo.longitude = vector3.y - cubemapInfo.angleOffset;
                     this.m_LookDevView.envLibrary.dirty = true;
                 }
             }
             if (Event.current.type == EventType.Repaint)
             {
                 this.DrawLatLongThumbnail(cubemapInfo, cubemapInfo.angleOffset, 1f, 1f, rect);
                 if (this.m_LookDevView.config.enableShadowCubemap)
                 {
                     if (cubemapInfo.cubemapShadowInfo != cubemapInfo || (this.m_HoveringCubeMapIndex == i && this.m_SelectedCubemapInfo != cubemapInfo))
                     {
                         CubemapInfo infos = cubemapInfo.cubemapShadowInfo;
                         if (this.m_HoveringCubeMapIndex == i && this.m_SelectedCubemapInfo != cubemapInfo)
                         {
                             infos = this.m_SelectedCubemapInfo;
                         }
                         float alpha = 1f;
                         if (this.m_SelectedShadowInfo == shadowInfo)
                         {
                             alpha = 0.1f;
                         }
                         else if (this.m_HoveringCubeMapIndex == i && this.m_SelectedCubemapInfo != cubemapInfo && cubemapInfo.cubemapShadowInfo != this.m_SelectedCubemapInfo)
                         {
                             alpha = 0.5f;
                         }
                         this.DrawLatLongThumbnail(infos, cubemapInfo.angleOffset, 0.3f, alpha, textureRect);
                         GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
                         GUI.DrawTexture(rect2, LookDevEnvironmentWindow.styles.sLatlongFrameTexture);
                         GL.sRGBWrite = false;
                     }
                     GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
                     GUI.DrawTexture(position2, LookDevEnvironmentWindow.styles.sLightTexture);
                     GL.sRGBWrite = false;
                 }
                 if (flag2)
                 {
                     this.DrawSelectionFeedback(rect, selectionColor, selectionColor2);
                 }
             }
             GUILayout.EndVertical();
         }
         GUILayout.BeginVertical(new GUILayoutOption[]
         {
             GUILayout.Width(250f)
         });
         if ((this.m_SelectedCubemap != null || this.m_DragBeingPerformed) && this.GetInsertionRect(hdriList.Count).Contains(Event.current.mousePosition))
         {
             GUILayout.Label(GUIContent.none, LookDevEnvironmentWindow.styles.sSeparatorStyle, new GUILayoutOption[0]);
             GUILayoutUtility.GetRect(250f, 16f);
             GUILayout.Label(GUIContent.none, LookDevEnvironmentWindow.styles.sSeparatorStyle, new GUILayoutOption[0]);
         }
         GUILayout.EndVertical();
         if (flag)
         {
             EditorGUILayout.EndScrollView();
         }
         this.HandleMouseInput();
         this.RenderOverlayThumbnailIfNeeded();
         if (Event.current.type == EventType.Repaint)
         {
             if (this.m_SelectedCubemap != null)
             {
                 this.m_LookDevView.Repaint();
             }
         }
     }
 }
Example #15
0
        private void HandleMouseInput()
        {
            List <CubemapInfo> hdriList = this.m_LookDevView.envLibrary.hdriList;
            Vector2            vector   = new Vector2(Event.current.mousePosition.x, Event.current.mousePosition.y + this.m_ScrollPosition.y);
            Event     current           = Event.current;
            EventType typeForControl    = current.GetTypeForControl(this.m_LookDevView.hotControl);

            switch (typeForControl)
            {
            case EventType.MouseUp:
                if (this.m_SelectedCubemap != null)
                {
                    Rect gUIRect = this.m_GUIRect;
                    gUIRect.yMax += 16f;
                    if (gUIRect.Contains(Event.current.mousePosition))
                    {
                        int num = this.IsPositionInInsertionArea(vector);
                        if (num != -1)
                        {
                            this.ResetShadowCubemap();
                            this.m_LookDevView.envLibrary.InsertHDRI(this.m_SelectedCubemap, num);
                        }
                        else
                        {
                            int num2 = this.IsPositionInThumbnailArea(vector);
                            if (num2 != -1 && this.m_LookDevView.config.enableShadowCubemap)
                            {
                                Undo.RecordObject(this.m_LookDevView.envLibrary, "Update shadow cubemap");
                                CubemapInfo cubemapInfo = this.m_LookDevView.envLibrary.hdriList[num2];
                                if (cubemapInfo != this.m_SelectedCubemapInfo)
                                {
                                    cubemapInfo.SetCubemapShadowInfo(this.m_SelectedCubemapInfo);
                                }
                                this.m_LookDevView.envLibrary.dirty = true;
                            }
                        }
                        this.CancelSelection();
                    }
                }
                this.m_LookDevView.Repaint();
                if (this.m_SelectedCubeMapOffsetIndex != -1)
                {
                    if (Mathf.Abs(hdriList[this.m_SelectedCubeMapOffsetIndex].angleOffset) <= 10f)
                    {
                        Undo.RecordObject(this.m_LookDevView.envLibrary, "");
                        hdriList[this.m_SelectedCubeMapOffsetIndex].angleOffset = 0f;
                        this.m_LookDevView.envLibrary.dirty = true;
                    }
                }
                this.m_SelectedCubemapInfo            = null;
                this.m_SelectedShadowCubemapOwnerInfo = null;
                this.m_SelectedLightIconIndex         = -1;
                this.m_SelectedShadowInfo             = null;
                this.m_SelectedCubeMapOffsetIndex     = -1;
                this.m_HoveringCubeMapIndex           = -1;
                this.m_SelectedCubeMapOffsetValue     = 0f;
                GUIUtility.hotControl = 0;
                return;

            case EventType.MouseMove:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
            case EventType.Layout:
IL_95:
                if (typeForControl != EventType.DragExited)
                {
                    return;
                }
                return;

            case EventType.MouseDrag:
                if (this.m_SelectedCubeMapOffsetIndex != -1)
                {
                    Undo.RecordObject(this.m_LookDevView.envLibrary, "");
                    CubemapInfo cubemapInfo2 = hdriList[this.m_SelectedCubeMapOffsetIndex];
                    cubemapInfo2.angleOffset            = this.ComputeAngleOffsetFromMouseCoord(vector) + this.m_SelectedCubeMapOffsetValue;
                    this.m_LookDevView.envLibrary.dirty = true;
                    Event.current.Use();
                }
                if (this.m_SelectedCubemapInfo != null)
                {
                    if (this.IsPositionInInsertionArea(vector) == -1)
                    {
                        this.m_HoveringCubeMapIndex = this.IsPositionInThumbnailArea(vector);
                    }
                    else
                    {
                        this.m_HoveringCubeMapIndex = -1;
                    }
                }
                this.m_LookDevView.Repaint();
                return;

            case EventType.KeyDown:
                if (Event.current.keyCode == KeyCode.Escape)
                {
                    this.CancelSelection();
                    this.m_LookDevView.Repaint();
                }
                return;

            case EventType.Repaint:
                if (this.m_SelectedCubeMapOffsetIndex != -1)
                {
                    EditorGUIUtility.AddCursorRect(this.m_displayRect, MouseCursor.SlideArrow);
                }
                return;

            case EventType.DragUpdated:
            {
                bool flag = false;
                UnityEngine.Object[] objectReferences = DragAndDrop.objectReferences;
                for (int i = 0; i < objectReferences.Length; i++)
                {
                    UnityEngine.Object @object = objectReferences[i];
                    Cubemap            exists  = @object as Cubemap;
                    if (exists)
                    {
                        flag = true;
                    }
                }
                DragAndDrop.visualMode = ((!flag) ? DragAndDropVisualMode.Rejected : DragAndDropVisualMode.Link);
                if (flag)
                {
                    this.m_DragBeingPerformed = true;
                }
                current.Use();
                return;
            }

            case EventType.DragPerform:
            {
                int insertionIndex = this.IsPositionInInsertionArea(vector);
                UnityEngine.Object[] objectReferences2 = DragAndDrop.objectReferences;
                for (int j = 0; j < objectReferences2.Length; j++)
                {
                    UnityEngine.Object object2 = objectReferences2[j];
                    Cubemap            cubemap = object2 as Cubemap;
                    if (cubemap)
                    {
                        this.m_LookDevView.envLibrary.InsertHDRI(cubemap, insertionIndex);
                    }
                }
                DragAndDrop.AcceptDrag();
                this.m_DragBeingPerformed = false;
                current.Use();
                return;
            }
            }
            goto IL_95;
        }
Example #16
0
 public EnvSettingsWindow(LookDevView lookDevView, CubemapInfo infos)
 {
     this.m_LookDevView = lookDevView;
     this.m_CubemapInfo = infos;
 }
Example #17
0
 public void SetCubemapShadowInfo(CubemapInfo newCubemapShadowInfo)
 {
     this.cubemapShadowInfo          = newCubemapShadowInfo;
     this.shadowInfo.shadowIntensity = ((newCubemapShadowInfo != this) ? 1f : 0.3f);
     this.shadowInfo.shadowColor     = Color.white;
 }
Example #18
0
        public void OnGUI(int windowID)
        {
            if (m_LookDevView == null)
            {
                return;
            }

            List <CubemapInfo> cubemapList = m_LookDevView.envLibrary.hdriList;

            // Enable the ScrollView component only if there is enough HDRI (else HDRI will display on top of a scrollbar when moved)
            bool drawScrollBar = LookDevEnvironmentWindow.m_HDRIHeight * cubemapList.Count > m_PositionInLookDev.height;

            if (drawScrollBar)
            {
                m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);
            }
            else
            {
                m_ScrollPosition = new Vector2(0.0f, 0.0f);
            }

            if (cubemapList.Count == 1)
            {
                // Draw text
                Color oldColor = GUI.color;
                GUI.color = Color.gray;
                Vector2 textSize  = GUI.skin.label.CalcSize(styles.sDragAndDropHDRIText);
                Rect    labelRect = new Rect(m_PositionInLookDev.width * .5f - textSize.x * .5f, m_PositionInLookDev.height * .5f - textSize.y * .5f, textSize.x, textSize.y);
                GUI.Label(labelRect, styles.sDragAndDropHDRIText);
                GUI.color = oldColor;
            }

            {
                for (int i = 0; i < cubemapList.Count; ++i)
                {
                    CubemapInfo infos       = cubemapList[i];
                    ShadowInfo  shadowInfos = infos.shadowInfo;

                    int firstSelectionIndex  = m_LookDevView.config.GetIntProperty(LookDevProperty.HDRI, LookDevEditionContext.Left);
                    int secondSelectionIndex = m_LookDevView.config.GetIntProperty(LookDevProperty.HDRI, LookDevEditionContext.Right);

                    // Disable the drawing of second selection if we are in single view
                    if (m_LookDevView.config.lookDevMode == LookDevMode.Single1 || m_LookDevView.config.lookDevMode == LookDevMode.Single2)
                    {
                        secondSelectionIndex = -1;
                    }

                    bool isSelection = (i == firstSelectionIndex || i == secondSelectionIndex);

                    Color    selectionColor1     = Color.black;
                    Color    selectionColor2     = Color.black;
                    GUIStyle selectionLabelStyle = EditorStyles.miniLabel;

                    if (isSelection)
                    {
                        if (i == firstSelectionIndex)
                        {
                            selectionColor1     = LookDevView.m_FirstViewGizmoColor;
                            selectionColor2     = LookDevView.m_FirstViewGizmoColor;
                            selectionLabelStyle = styles.sLabelStyleFirstContext;
                        }
                        else if (i == secondSelectionIndex)
                        {
                            selectionColor1     = LookDevView.m_SecondViewGizmoColor;
                            selectionColor2     = LookDevView.m_SecondViewGizmoColor;
                            selectionLabelStyle = styles.sLabelStyleSecondContext;
                        }
                        if (firstSelectionIndex == secondSelectionIndex)
                        {
                            selectionColor1     = LookDevView.m_FirstViewGizmoColor;
                            selectionColor2     = LookDevView.m_SecondViewGizmoColor;
                            selectionLabelStyle = styles.sLabelStyleBothContext;
                        }
                    }

                    Rect textureRect;
                    Rect lightIconRect;
                    Rect lightIconSelectionRect;
                    Rect frameTextureRect;
                    Rect shadowTextureRect;
                    GUILayout.BeginVertical(GUILayout.Width(m_HDRIWidth));
                    {
                        // Find index of current selection if it exist
                        int selectedCubeMapIndex = cubemapList.FindIndex(x => x == m_SelectedCubemapInfo);

                        // User is dragging another environment, we need to show the space for insertion
                        if ((m_SelectedCubemap != null || m_DragBeingPerformed) && GetInsertionRect(i).Contains(Event.current.mousePosition)
                            // Following test allow to not propose a slot that is neutral, i.e current position or next one
                            && (((selectedCubeMapIndex - i) != 0 && (selectedCubeMapIndex - i) != -1) || selectedCubeMapIndex == -1)
                            )
                        {
                            GUILayout.Label(GUIContent.none, styles.sSeparatorStyle);
                            GUILayoutUtility.GetRect(m_HDRIWidth, EditorGUI.kSingleLineHeight);
                        }

                        // Header for one HDRI: label + remove button
                        GUILayout.Label(GUIContent.none, styles.sSeparatorStyle);
                        GUILayout.BeginHorizontal(GUILayout.Width(m_HDRIWidth), GUILayout.Height(m_HDRIHeaderHeight));
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append(i.ToString());
                            sb.Append(" - ");
                            sb.Append(infos.cubemap.name);

                            GUILayout.Label(sb.ToString(), selectionLabelStyle, GUILayout.Height(m_HDRIHeaderHeight), GUILayout.MaxWidth(m_HDRIWidth - 75));

                            GUILayout.FlexibleSpace();

                            if (GUILayout.Button(styles.sEnvControlIcon, LookDevView.styles.sToolBarButton))
                            {
                                Rect rect = GUILayoutUtility.topLevel.GetLast();
                                PopupWindow.Show(rect, new EnvSettingsWindow(m_LookDevView, infos));
                                GUIUtility.ExitGUI();
                            }

                            using (new EditorGUI.DisabledScope(infos.cubemap == LookDevResources.m_DefaultHDRI))
                            {
                                if (GUILayout.Button(styles.sCloseIcon, LookDevView.styles.sToolBarButton))
                                {
                                    m_LookDevView.envLibrary.RemoveHDRI(infos.cubemap);
                                }
                            }
                        }
                        GUILayout.EndHorizontal();

                        // We don't want to handle any control inside the label, following code disable mouseDown event in this case.
                        Rect lastRect = GUILayoutUtility.GetLastRect();
                        if (Event.current.type == EventType.MouseDown && lastRect.Contains(Event.current.mousePosition))
                        {
                            Event.current.Use(); // Avoid camera movement and focus change in main view
                        }

                        textureRect       = GUILayoutUtility.GetRect(m_HDRIWidth, m_latLongHeight);
                        textureRect.width = m_HDRIWidth + 3; // Sometimes GUILayoutUtility.GetRect returns width as m_HDRIWidth, sometimes at m_HDRIWidth + 3 ...

                        float iconSize     = 24.0f;
                        float iconHalfSize = iconSize * 0.5f;

                        // Convert from latlong to normalized coordinate to pixel coordinates.
                        float   latitude     = shadowInfos.latitude;
                        float   longitude    = shadowInfos.longitude;
                        Vector2 iconPosition = LatLongToPosition(latitude, longitude + infos.angleOffset) * 0.5f + new Vector2(0.5f, 0.5f);

                        lightIconRect        = textureRect;
                        lightIconRect.x      = lightIconRect.x + iconPosition.x * textureRect.width - iconHalfSize;
                        lightIconRect.y      = lightIconRect.y + (1.0f - iconPosition.y) * textureRect.height - iconHalfSize; // Coordinates start from the bottom
                        lightIconRect.width  = iconSize;
                        lightIconRect.height = iconSize;

                        // Selection rect of light is a bit smaller than the texture
                        lightIconSelectionRect        = textureRect;
                        lightIconSelectionRect.x      = lightIconSelectionRect.x + iconPosition.x * textureRect.width - iconHalfSize * 0.5f;
                        lightIconSelectionRect.y      = lightIconSelectionRect.y + (1.0f - iconPosition.y) * textureRect.height - iconHalfSize * 0.5f; // Coordinates start from the bottom
                        lightIconSelectionRect.width  = iconSize * 0.5f;
                        lightIconSelectionRect.height = iconSize * 0.5f;

                        GetFrameAndShadowTextureRect(textureRect, out frameTextureRect, out shadowTextureRect);

                        if (m_LookDevView.config.enableShadowCubemap)
                        {
                            EditorGUIUtility.AddCursorRect(lightIconSelectionRect, MouseCursor.Pan);
                        }

                        if (Event.current.type == EventType.MouseDown && textureRect.Contains(Event.current.mousePosition))
                        {
                            // Left Button
                            if ((!Event.current.control && Event.current.button == 0) && m_SelectedCubeMapOffsetIndex == -1)
                            {
                                // Light icon handling - it is higher priority then shadowTexture thumbnail selection
                                if (m_LookDevView.config.enableShadowCubemap && lightIconSelectionRect.Contains(Event.current.mousePosition))
                                {
                                    m_SelectedLightIconIndex = i;
                                    m_SelectedShadowInfo     = shadowInfos;

                                    // We want to avoid to record object when draging the light icon, so save location here.
                                    // However the record need to be aware about what will change, so we perform an insignificant modification
                                    // to the lat/long position so it is record by the undo
                                    Undo.RecordObject(m_LookDevView.envLibrary, "Light Icon selection");
                                    m_SelectedShadowInfo.latitude  = m_SelectedShadowInfo.latitude + 0.0001f;
                                    m_SelectedShadowInfo.longitude = m_SelectedShadowInfo.longitude + 0.0001f;
                                }

                                // Environment selection handling
                                if (m_SelectedShadowInfo == null)
                                {
                                    Rect resetShadowIconRect;
                                    // All values are taken from the LookDevShadowFrame.png (hard coded)
                                    resetShadowIconRect        = frameTextureRect;
                                    resetShadowIconRect.x      = resetShadowIconRect.x + 100.0f;
                                    resetShadowIconRect.y      = resetShadowIconRect.y + 4.0f;
                                    resetShadowIconRect.width  = 11;
                                    resetShadowIconRect.height = 11f;

                                    // Close icon handling
                                    if (m_LookDevView.config.enableShadowCubemap && resetShadowIconRect.Contains(Event.current.mousePosition))
                                    {
                                        // Reset Shadow Cubemap
                                        Undo.RecordObject(m_LookDevView.envLibrary, "Update shadow cubemap");
                                        cubemapList[i].SetCubemapShadowInfo(cubemapList[i]);
                                        m_LookDevView.envLibrary.dirty = true;
                                    }
                                    else
                                    {
                                        // If we have selected the shadowTexture, let's swap the index of the current selected map
                                        if (m_LookDevView.config.enableShadowCubemap && shadowTextureRect.Contains(Event.current.mousePosition))
                                        {
                                            m_SelectedShadowCubemapOwnerInfo = cubemapList[i];
                                            // Current selected cubemap is the one without sun
                                            m_SelectedCubemapInfo = m_SelectedShadowCubemapOwnerInfo.cubemapShadowInfo;
                                        }
                                        else
                                        {
                                            m_SelectedCubemapInfo = cubemapList[i];
                                        }
                                        m_SelectedPositionOffset     = Event.current.mousePosition - new Vector2(textureRect.x, textureRect.y);
                                        m_RenderOverlayThumbnailOnce = true;
                                    }
                                }
                            }
                            // Left button with Ctrl - Rotate environment
                            else if ((Event.current.control && Event.current.button == 0) && m_SelectedCubemapInfo == null && m_SelectedShadowInfo == null)
                            {
                                m_SelectedCubeMapOffsetIndex = i;
                                m_SelectedCubeMapOffsetValue = infos.angleOffset - ComputeAngleOffsetFromMouseCoord(Event.current.mousePosition);
                            }

                            GUIUtility.hotControl = m_LookDevView.hotControl;

                            Event.current.Use(); // Avoid camera movement and focus change in main view
                        }


                        if (Event.current.GetTypeForControl(m_LookDevView.hotControl) == EventType.MouseDrag)
                        {
                            if (m_SelectedShadowInfo == shadowInfos && m_SelectedLightIconIndex == i)
                            {
                                Vector2 newLightPosition = Event.current.mousePosition;
                                newLightPosition.x = (newLightPosition.x - textureRect.x) / textureRect.width * 2.0f - 1.0f;
                                newLightPosition.y = (1.0f - (newLightPosition.y - textureRect.y) / textureRect.height) * 2.0f - 1.0f;

                                Vector2 newLatLongPos = PositionToLatLong(newLightPosition);
                                m_SelectedShadowInfo.latitude  = newLatLongPos.x;
                                m_SelectedShadowInfo.longitude = newLatLongPos.y - infos.angleOffset;

                                m_LookDevView.envLibrary.dirty = true;
                            }
                        }

                        if (Event.current.type == EventType.Repaint)
                        {
                            // Draw the latlong thumbnail
                            DrawLatLongThumbnail(infos, infos.angleOffset, 1.0f, 1.0f, textureRect);

                            if (m_LookDevView.config.enableShadowCubemap)
                            {
                                // Draw the shadow cubemap thumbnail if either:
                                if ((infos.cubemapShadowInfo != infos) ||                           // Shadows are enabled on this environment and shadow cubemap is not self
                                    (m_HoveringCubeMapIndex == i && m_SelectedCubemapInfo != infos) // user is dragging over the environment that is not itself
                                    )
                                {
                                    // By default, we want to display the shadow cubemap associated with the current environment
                                    CubemapInfo cubemapShadowInfo = infos.cubemapShadowInfo;
                                    // If we are dragging another environment we want to display instead of the current one unless we are dragging a cubemap over itself
                                    if (m_HoveringCubeMapIndex == i && m_SelectedCubemapInfo != infos)
                                    {
                                        cubemapShadowInfo = m_SelectedCubemapInfo;
                                    }

                                    float alpha = 1.0f;
                                    if (m_SelectedShadowInfo == shadowInfos) // We need to fade the thumbnail almost completely to see where we move the light
                                    {
                                        alpha = 0.1f;
                                    }
                                    else if (m_HoveringCubeMapIndex == i && m_SelectedCubemapInfo != infos && infos.cubemapShadowInfo != m_SelectedCubemapInfo) // Visual transparent feedback to show where you are going to drop your cubemap
                                    {
                                        alpha = 0.5f;
                                    }

                                    DrawLatLongThumbnail(cubemapShadowInfo, infos.angleOffset, 0.3f, alpha, shadowTextureRect);

                                    GUI.DrawTexture(frameTextureRect, styles.sLatlongFrameTexture);
                                }

                                GUI.DrawTexture(lightIconRect, styles.sLightTexture);
                            }

                            if (isSelection)
                            {
                                DrawSelectionFeedback(textureRect, selectionColor1, selectionColor2);
                            }
                        }
                    }
                    GUILayout.EndVertical();
                }

                // Last vertical slot when drag and drop HDRI
                GUILayout.BeginVertical(GUILayout.Width(m_HDRIWidth));
                {
                    // User is dragging another environment, we need to show the space for insertion
                    if ((m_SelectedCubemap != null || m_DragBeingPerformed) && GetInsertionRect(cubemapList.Count).Contains(Event.current.mousePosition))
                    {
                        GUILayout.Label(GUIContent.none, styles.sSeparatorStyle);
                        GUILayoutUtility.GetRect(m_HDRIWidth, EditorGUI.kSingleLineHeight);
                        GUILayout.Label(GUIContent.none, styles.sSeparatorStyle);
                    }
                }
                GUILayout.EndVertical();
            }

            if (drawScrollBar)
            {
                EditorGUILayout.EndScrollView();
            }

            HandleMouseInput();
            RenderOverlayThumbnailIfNeeded();

            if (Event.current.type == EventType.Repaint)
            {
                if (m_SelectedCubemap != null)
                {
                    m_LookDevView.Repaint();
                }
            }
        }
 public void OnGUI(int windowID)
 {
     if (this.m_LookDevView != null)
     {
         List <CubemapInfo> hdriList = this.m_LookDevView.envLibrary.hdriList;
         bool flag = (146f * hdriList.Count) > this.m_PositionInLookDev.height;
         if (flag)
         {
             this.m_ScrollPosition = EditorGUILayout.BeginScrollView(this.m_ScrollPosition, new GUILayoutOption[0]);
         }
         else
         {
             this.m_ScrollPosition = new Vector2(0f, 0f);
         }
         if (hdriList.Count == 1)
         {
             Color color = GUI.color;
             GUI.color = Color.gray;
             Vector2 vector   = GUI.skin.label.CalcSize(styles.sDragAndDropHDRIText);
             Rect    position = new Rect((this.m_PositionInLookDev.width * 0.5f) - (vector.x * 0.5f), (this.m_PositionInLookDev.height * 0.5f) - (vector.y * 0.5f), vector.x, vector.y);
             GUI.Label(position, styles.sDragAndDropHDRIText);
             GUI.color = color;
         }
         for (int i = 0; i < hdriList.Count; i++)
         {
             Rect        rect5;
             Rect        rect6;
             CubemapInfo infos       = hdriList[i];
             ShadowInfo  shadowInfo  = infos.shadowInfo;
             int         intProperty = this.m_LookDevView.config.GetIntProperty(LookDevProperty.HDRI, LookDevEditionContext.Left);
             int         num3        = this.m_LookDevView.config.GetIntProperty(LookDevProperty.HDRI, LookDevEditionContext.Right);
             if ((this.m_LookDevView.config.lookDevMode == LookDevMode.Single1) || (this.m_LookDevView.config.lookDevMode == LookDevMode.Single2))
             {
                 num3 = -1;
             }
             bool     flag2 = (i == intProperty) || (i == num3);
             Color    black = Color.black;
             Color    firstViewGizmoColor = Color.black;
             GUIStyle miniLabel           = EditorStyles.miniLabel;
             if (flag2)
             {
                 if (i == intProperty)
                 {
                     black = (Color)LookDevView.m_FirstViewGizmoColor;
                     firstViewGizmoColor = (Color)LookDevView.m_FirstViewGizmoColor;
                     miniLabel           = styles.sLabelStyleFirstContext;
                 }
                 else if (i == num3)
                 {
                     black = (Color)LookDevView.m_SecondViewGizmoColor;
                     firstViewGizmoColor = (Color)LookDevView.m_SecondViewGizmoColor;
                     miniLabel           = styles.sLabelStyleSecondContext;
                 }
                 if (intProperty == num3)
                 {
                     black = (Color)LookDevView.m_FirstViewGizmoColor;
                     firstViewGizmoColor = (Color)LookDevView.m_SecondViewGizmoColor;
                     miniLabel           = styles.sLabelStyleBothContext;
                 }
             }
             GUILayoutOption[] optionArray1 = new GUILayoutOption[] { GUILayout.Width(250f) };
             GUILayout.BeginVertical(optionArray1);
             int num4 = hdriList.FindIndex(x => x == this.m_SelectedCubemapInfo);
             if ((((this.m_SelectedCubemap != null) || this.m_DragBeingPerformed) && this.GetInsertionRect(i).Contains(Event.current.mousePosition)) && ((((num4 - i) != 0) && ((num4 - i) != -1)) || (num4 == -1)))
             {
                 GUILayout.Label(GUIContent.none, styles.sSeparatorStyle, new GUILayoutOption[0]);
                 GUILayoutUtility.GetRect((float)250f, (float)16f);
             }
             GUILayout.Label(GUIContent.none, styles.sSeparatorStyle, new GUILayoutOption[0]);
             GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.Width(250f), GUILayout.Height(18f) };
             GUILayout.BeginHorizontal(optionArray2);
             StringBuilder builder = new StringBuilder();
             builder.Append(i.ToString());
             builder.Append(" - ");
             builder.Append(infos.cubemap.name);
             GUILayoutOption[] optionArray3 = new GUILayoutOption[] { GUILayout.Height(18f), GUILayout.MaxWidth(175f) };
             GUILayout.Label(builder.ToString(), miniLabel, optionArray3);
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(styles.sEnvControlIcon, LookDevView.styles.sToolBarButton, new GUILayoutOption[0]))
             {
                 PopupWindow.Show(GUILayoutUtility.topLevel.GetLast(), new EnvSettingsWindow(this.m_LookDevView, infos));
                 GUIUtility.ExitGUI();
             }
             using (new EditorGUI.DisabledScope(infos.cubemap == LookDevResources.m_DefaultHDRI))
             {
                 if (GUILayout.Button(styles.sCloseIcon, LookDevView.styles.sToolBarButton, new GUILayoutOption[0]))
                 {
                     this.m_LookDevView.envLibrary.RemoveHDRI(infos.cubemap);
                 }
             }
             GUILayout.EndHorizontal();
             Rect lastRect = GUILayoutUtility.GetLastRect();
             if ((Event.current.type == EventType.MouseDown) && lastRect.Contains(Event.current.mousePosition))
             {
                 Event.current.Use();
             }
             Rect rect = GUILayoutUtility.GetRect((float)250f, (float)125f);
             rect.width = 253f;
             float   num5      = 24f;
             float   num6      = num5 * 0.5f;
             float   latitude  = shadowInfo.latitude;
             float   longitude = shadowInfo.longitude;
             Vector2 vector2   = ((Vector2)(this.LatLongToPosition(latitude, longitude + infos.angleOffset) * 0.5f)) + new Vector2(0.5f, 0.5f);
             Rect    rect3     = rect;
             rect3.x      = (rect3.x + (vector2.x * rect.width)) - num6;
             rect3.y      = (rect3.y + ((1f - vector2.y) * rect.height)) - num6;
             rect3.width  = num5;
             rect3.height = num5;
             Rect rect4 = rect;
             rect4.x      = (rect4.x + (vector2.x * rect.width)) - (num6 * 0.5f);
             rect4.y      = (rect4.y + ((1f - vector2.y) * rect.height)) - (num6 * 0.5f);
             rect4.width  = num5 * 0.5f;
             rect4.height = num5 * 0.5f;
             this.GetFrameAndShadowTextureRect(rect, out rect5, out rect6);
             if (this.m_LookDevView.config.enableShadowCubemap)
             {
                 EditorGUIUtility.AddCursorRect(rect4, MouseCursor.Pan);
             }
             if ((Event.current.type == EventType.MouseDown) && rect.Contains(Event.current.mousePosition))
             {
                 if ((!Event.current.control && (Event.current.button == 0)) && (this.m_SelectedCubeMapOffsetIndex == -1))
                 {
                     if (this.m_LookDevView.config.enableShadowCubemap && rect4.Contains(Event.current.mousePosition))
                     {
                         this.m_SelectedLightIconIndex = i;
                         this.m_SelectedShadowInfo     = shadowInfo;
                         Undo.RecordObject(this.m_LookDevView.envLibrary, "Light Icon selection");
                         this.m_SelectedShadowInfo.latitude  += 0.0001f;
                         this.m_SelectedShadowInfo.longitude += 0.0001f;
                     }
                     if (this.m_SelectedShadowInfo == null)
                     {
                         Rect rect10 = rect5;
                         rect10.x     += 100f;
                         rect10.y     += 4f;
                         rect10.width  = 11f;
                         rect10.height = 11f;
                         if (this.m_LookDevView.config.enableShadowCubemap && rect10.Contains(Event.current.mousePosition))
                         {
                             Undo.RecordObject(this.m_LookDevView.envLibrary, "Update shadow cubemap");
                             hdriList[i].SetCubemapShadowInfo(hdriList[i]);
                             this.m_LookDevView.envLibrary.dirty = true;
                         }
                         else
                         {
                             if (this.m_LookDevView.config.enableShadowCubemap && rect6.Contains(Event.current.mousePosition))
                             {
                                 this.m_SelectedShadowCubemapOwnerInfo = hdriList[i];
                                 this.m_SelectedCubemapInfo            = this.m_SelectedShadowCubemapOwnerInfo.cubemapShadowInfo;
                             }
                             else
                             {
                                 this.m_SelectedCubemapInfo = hdriList[i];
                             }
                             this.m_SelectedPositionOffset     = Event.current.mousePosition - new Vector2(rect.x, rect.y);
                             this.m_RenderOverlayThumbnailOnce = true;
                         }
                     }
                 }
                 else if ((Event.current.control && (Event.current.button == 0)) && ((this.m_SelectedCubemapInfo == null) && (this.m_SelectedShadowInfo == null)))
                 {
                     this.m_SelectedCubeMapOffsetIndex = i;
                     this.m_SelectedCubeMapOffsetValue = infos.angleOffset - this.ComputeAngleOffsetFromMouseCoord(Event.current.mousePosition);
                 }
                 GUIUtility.hotControl = this.m_LookDevView.hotControl;
                 Event.current.Use();
             }
             if ((Event.current.GetTypeForControl(this.m_LookDevView.hotControl) == EventType.MouseDrag) && ((this.m_SelectedShadowInfo == shadowInfo) && (this.m_SelectedLightIconIndex == i)))
             {
                 Vector2 mousePosition = Event.current.mousePosition;
                 mousePosition.x = (((mousePosition.x - rect.x) / rect.width) * 2f) - 1f;
                 mousePosition.y = ((1f - ((mousePosition.y - rect.y) / rect.height)) * 2f) - 1f;
                 Vector2 vector4 = PositionToLatLong(mousePosition);
                 this.m_SelectedShadowInfo.latitude  = vector4.x;
                 this.m_SelectedShadowInfo.longitude = vector4.y - infos.angleOffset;
                 this.m_LookDevView.envLibrary.dirty = true;
             }
             if (Event.current.type == EventType.Repaint)
             {
                 this.DrawLatLongThumbnail(infos, infos.angleOffset, 1f, 1f, rect);
                 if (this.m_LookDevView.config.enableShadowCubemap)
                 {
                     if ((infos.cubemapShadowInfo != infos) || ((this.m_HoveringCubeMapIndex == i) && (this.m_SelectedCubemapInfo != infos)))
                     {
                         CubemapInfo cubemapShadowInfo = infos.cubemapShadowInfo;
                         if ((this.m_HoveringCubeMapIndex == i) && (this.m_SelectedCubemapInfo != infos))
                         {
                             cubemapShadowInfo = this.m_SelectedCubemapInfo;
                         }
                         float alpha = 1f;
                         if (this.m_SelectedShadowInfo == shadowInfo)
                         {
                             alpha = 0.1f;
                         }
                         else if (((this.m_HoveringCubeMapIndex == i) && (this.m_SelectedCubemapInfo != infos)) && (infos.cubemapShadowInfo != this.m_SelectedCubemapInfo))
                         {
                             alpha = 0.5f;
                         }
                         this.DrawLatLongThumbnail(cubemapShadowInfo, infos.angleOffset, 0.3f, alpha, rect6);
                         GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
                         GUI.DrawTexture(rect5, styles.sLatlongFrameTexture);
                         GL.sRGBWrite = false;
                     }
                     GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
                     GUI.DrawTexture(rect3, styles.sLightTexture);
                     GL.sRGBWrite = false;
                 }
                 if (flag2)
                 {
                     this.DrawSelectionFeedback(rect, black, firstViewGizmoColor);
                 }
             }
             GUILayout.EndVertical();
         }
         GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(250f) };
         GUILayout.BeginVertical(options);
         if (((this.m_SelectedCubemap != null) || this.m_DragBeingPerformed) && this.GetInsertionRect(hdriList.Count).Contains(Event.current.mousePosition))
         {
             GUILayout.Label(GUIContent.none, styles.sSeparatorStyle, new GUILayoutOption[0]);
             GUILayoutUtility.GetRect((float)250f, (float)16f);
             GUILayout.Label(GUIContent.none, styles.sSeparatorStyle, new GUILayoutOption[0]);
         }
         GUILayout.EndVertical();
         if (flag)
         {
             EditorGUILayout.EndScrollView();
         }
         this.HandleMouseInput();
         this.RenderOverlayThumbnailIfNeeded();
         if ((Event.current.type == EventType.Repaint) && (this.m_SelectedCubemap != null))
         {
             this.m_LookDevView.Repaint();
         }
     }
 }
        private void HandleMouseInput()
        {
            List <CubemapInfo> hdriList = this.m_LookDevView.envLibrary.hdriList;
            Vector2            pos      = new Vector2(Event.current.mousePosition.x, Event.current.mousePosition.y + this.m_ScrollPosition.y);
            Event     current           = Event.current;
            EventType typeForControl    = current.GetTypeForControl(this.m_LookDevView.hotControl);

            switch (typeForControl)
            {
            case EventType.MouseUp:
                if (this.m_SelectedCubemap != null)
                {
                    Rect gUIRect = this.m_GUIRect;
                    gUIRect.yMax += 16f;
                    if (!gUIRect.Contains(Event.current.mousePosition))
                    {
                        break;
                    }
                    int insertionIndex = this.IsPositionInInsertionArea(pos);
                    if (insertionIndex == -1)
                    {
                        int num2 = this.IsPositionInThumbnailArea(pos);
                        if ((num2 != -1) && this.m_LookDevView.config.enableShadowCubemap)
                        {
                            Undo.RecordObject(this.m_LookDevView.envLibrary, "Update shadow cubemap");
                            CubemapInfo info2 = this.m_LookDevView.envLibrary.hdriList[num2];
                            if (info2 != this.m_SelectedCubemapInfo)
                            {
                                info2.SetCubemapShadowInfo(this.m_SelectedCubemapInfo);
                            }
                            this.m_LookDevView.envLibrary.dirty = true;
                        }
                    }
                    else
                    {
                        this.ResetShadowCubemap();
                        this.m_LookDevView.envLibrary.InsertHDRI(this.m_SelectedCubemap, insertionIndex);
                    }
                    this.CancelSelection();
                }
                break;

            case EventType.MouseDrag:
                if (this.m_SelectedCubeMapOffsetIndex != -1)
                {
                    Undo.RecordObject(this.m_LookDevView.envLibrary, "");
                    CubemapInfo info = hdriList[this.m_SelectedCubeMapOffsetIndex];
                    info.angleOffset = this.ComputeAngleOffsetFromMouseCoord(pos) + this.m_SelectedCubeMapOffsetValue;
                    this.m_LookDevView.envLibrary.dirty = true;
                    Event.current.Use();
                }
                if (this.m_SelectedCubemapInfo != null)
                {
                    if (this.IsPositionInInsertionArea(pos) == -1)
                    {
                        this.m_HoveringCubeMapIndex = this.IsPositionInThumbnailArea(pos);
                    }
                    else
                    {
                        this.m_HoveringCubeMapIndex = -1;
                    }
                }
                this.m_LookDevView.Repaint();
                return;

            case EventType.KeyDown:
                if (Event.current.keyCode == KeyCode.Escape)
                {
                    this.CancelSelection();
                    this.m_LookDevView.Repaint();
                }
                return;

            case EventType.Repaint:
                if (this.m_SelectedCubeMapOffsetIndex != -1)
                {
                    EditorGUIUtility.AddCursorRect(this.m_displayRect, MouseCursor.SlideArrow);
                }
                return;

            case EventType.DragUpdated:
            {
                bool flag = false;
                foreach (UnityEngine.Object obj3 in DragAndDrop.objectReferences)
                {
                    Cubemap cubemap2 = obj3 as Cubemap;
                    if (cubemap2 != null)
                    {
                        flag = true;
                    }
                }
                DragAndDrop.visualMode = !flag ? DragAndDropVisualMode.Rejected : DragAndDropVisualMode.Link;
                if (flag)
                {
                    this.m_DragBeingPerformed = true;
                }
                current.Use();
                return;
            }

            case EventType.DragPerform:
            {
                int num3 = this.IsPositionInInsertionArea(pos);
                foreach (UnityEngine.Object obj2 in DragAndDrop.objectReferences)
                {
                    Cubemap cubemap = obj2 as Cubemap;
                    if (cubemap != null)
                    {
                        this.m_LookDevView.envLibrary.InsertHDRI(cubemap, num3);
                    }
                }
                DragAndDrop.AcceptDrag();
                this.m_DragBeingPerformed = false;
                current.Use();
                return;
            }

            default:
                if (typeForControl == EventType.DragExited)
                {
                }
                return;
            }
            this.m_LookDevView.Repaint();
            if ((this.m_SelectedCubeMapOffsetIndex != -1) && (Mathf.Abs(hdriList[this.m_SelectedCubeMapOffsetIndex].angleOffset) <= 10f))
            {
                Undo.RecordObject(this.m_LookDevView.envLibrary, "");
                hdriList[this.m_SelectedCubeMapOffsetIndex].angleOffset = 0f;
                this.m_LookDevView.envLibrary.dirty = true;
            }
            this.m_SelectedCubemapInfo            = null;
            this.m_SelectedShadowCubemapOwnerInfo = null;
            this.m_SelectedLightIconIndex         = -1;
            this.m_SelectedShadowInfo             = null;
            this.m_SelectedCubeMapOffsetIndex     = -1;
            this.m_HoveringCubeMapIndex           = -1;
            this.m_SelectedCubeMapOffsetValue     = 0f;
            GUIUtility.hotControl = 0;
        }
        private void HandleMouseInput()
        {
            List<CubemapInfo> hdriList = this.m_LookDevView.envLibrary.hdriList;
            Vector2 pos = new Vector2(Event.current.mousePosition.x, Event.current.mousePosition.y + this.m_ScrollPosition.y);
            Event current = Event.current;
            EventType typeForControl = current.GetTypeForControl(this.m_LookDevView.hotControl);
            switch (typeForControl)
            {
                case EventType.MouseUp:
                    if (this.m_SelectedCubemap != null)
                    {
                        Rect gUIRect = this.m_GUIRect;
                        gUIRect.yMax += 16f;
                        if (!gUIRect.Contains(Event.current.mousePosition))
                        {
                            break;
                        }
                        int insertionIndex = this.IsPositionInInsertionArea(pos);
                        if (insertionIndex == -1)
                        {
                            int num2 = this.IsPositionInThumbnailArea(pos);
                            if ((num2 != -1) && this.m_LookDevView.config.enableShadowCubemap)
                            {
                                Undo.RecordObject(this.m_LookDevView.envLibrary, "Update shadow cubemap");
                                CubemapInfo info2 = this.m_LookDevView.envLibrary.hdriList[num2];
                                if (info2 != this.m_SelectedCubemapInfo)
                                {
                                    info2.SetCubemapShadowInfo(this.m_SelectedCubemapInfo);
                                }
                                this.m_LookDevView.envLibrary.dirty = true;
                            }
                        }
                        else
                        {
                            this.ResetShadowCubemap();
                            this.m_LookDevView.envLibrary.InsertHDRI(this.m_SelectedCubemap, insertionIndex);
                        }
                        this.CancelSelection();
                    }
                    break;

                case EventType.MouseDrag:
                    if (this.m_SelectedCubeMapOffsetIndex != -1)
                    {
                        Undo.RecordObject(this.m_LookDevView.envLibrary, "");
                        CubemapInfo info = hdriList[this.m_SelectedCubeMapOffsetIndex];
                        info.angleOffset = this.ComputeAngleOffsetFromMouseCoord(pos) + this.m_SelectedCubeMapOffsetValue;
                        this.m_LookDevView.envLibrary.dirty = true;
                        Event.current.Use();
                    }
                    if (this.m_SelectedCubemapInfo != null)
                    {
                        if (this.IsPositionInInsertionArea(pos) == -1)
                        {
                            this.m_HoveringCubeMapIndex = this.IsPositionInThumbnailArea(pos);
                        }
                        else
                        {
                            this.m_HoveringCubeMapIndex = -1;
                        }
                    }
                    this.m_LookDevView.Repaint();
                    return;

                case EventType.KeyDown:
                    if (Event.current.keyCode == KeyCode.Escape)
                    {
                        this.CancelSelection();
                        this.m_LookDevView.Repaint();
                    }
                    return;

                case EventType.Repaint:
                    if (this.m_SelectedCubeMapOffsetIndex != -1)
                    {
                        EditorGUIUtility.AddCursorRect(this.m_displayRect, MouseCursor.SlideArrow);
                    }
                    return;

                case EventType.DragUpdated:
                {
                    bool flag = false;
                    foreach (Object obj3 in DragAndDrop.objectReferences)
                    {
                        Cubemap cubemap2 = obj3 as Cubemap;
                        if (cubemap2 != null)
                        {
                            flag = true;
                        }
                    }
                    DragAndDrop.visualMode = !flag ? DragAndDropVisualMode.Rejected : DragAndDropVisualMode.Link;
                    if (flag)
                    {
                        this.m_DragBeingPerformed = true;
                    }
                    current.Use();
                    return;
                }
                case EventType.DragPerform:
                {
                    int num3 = this.IsPositionInInsertionArea(pos);
                    foreach (Object obj2 in DragAndDrop.objectReferences)
                    {
                        Cubemap cubemap = obj2 as Cubemap;
                        if (cubemap != null)
                        {
                            this.m_LookDevView.envLibrary.InsertHDRI(cubemap, num3);
                        }
                    }
                    DragAndDrop.AcceptDrag();
                    this.m_DragBeingPerformed = false;
                    current.Use();
                    return;
                }
                default:
                    if (typeForControl == EventType.DragExited)
                    {
                    }
                    return;
            }
            this.m_LookDevView.Repaint();
            if ((this.m_SelectedCubeMapOffsetIndex != -1) && (Mathf.Abs(hdriList[this.m_SelectedCubeMapOffsetIndex].angleOffset) <= 10f))
            {
                Undo.RecordObject(this.m_LookDevView.envLibrary, "");
                hdriList[this.m_SelectedCubeMapOffsetIndex].angleOffset = 0f;
                this.m_LookDevView.envLibrary.dirty = true;
            }
            this.m_SelectedCubemapInfo = null;
            this.m_SelectedShadowCubemapOwnerInfo = null;
            this.m_SelectedLightIconIndex = -1;
            this.m_SelectedShadowInfo = null;
            this.m_SelectedCubeMapOffsetIndex = -1;
            this.m_HoveringCubeMapIndex = -1;
            this.m_SelectedCubeMapOffsetValue = 0f;
            GUIUtility.hotControl = 0;
        }
Example #22
0
        private void HandleMouseInput()
        {
            List <CubemapInfo> cubemapList = m_LookDevView.envLibrary.hdriList;

            Vector2 scrollFixedPosition = new Vector2(Event.current.mousePosition.x, Event.current.mousePosition.y + m_ScrollPosition.y);

            Event evt = Event.current;

            switch (evt.GetTypeForControl(m_LookDevView.hotControl))
            {
            // Update overlay position for next repaint event
            case EventType.MouseDrag:
            {
                if (m_SelectedCubeMapOffsetIndex != -1)
                {
                    Undo.RecordObject(m_LookDevView.envLibrary, "");
                    CubemapInfo info = cubemapList[m_SelectedCubeMapOffsetIndex];
                    info.angleOffset = ComputeAngleOffsetFromMouseCoord(scrollFixedPosition) + m_SelectedCubeMapOffsetValue;
                    m_LookDevView.envLibrary.dirty = true;
                    Event.current.Use();
                }

                if (m_SelectedCubemapInfo != null)
                {
                    if (IsPositionInInsertionArea(scrollFixedPosition) == -1)
                    {
                        m_HoveringCubeMapIndex = IsPositionInThumbnailArea(scrollFixedPosition);
                    }
                    else
                    {
                        m_HoveringCubeMapIndex = -1;
                    }
                }

                m_LookDevView.Repaint();
                break;
            }

            // Handles environment drop
            case EventType.MouseUp:
            {
                if (m_SelectedCubemap != null)
                {
                    // The rect needs to include an extra slot when moving to last position
                    Rect extendedGUIRect = m_GUIRect;
                    extendedGUIRect.yMax += EditorGUI.kSingleLineHeight;

                    if (extendedGUIRect.Contains(Event.current.mousePosition))
                    {
                        int insertionRectIndex = IsPositionInInsertionArea(scrollFixedPosition);
                        if (insertionRectIndex != -1)
                        {
                            // Must be called before we do any modification to HDRI list
                            ResetShadowCubemap();

                            m_LookDevView.envLibrary.InsertHDRI(m_SelectedCubemap, insertionRectIndex);
                        }
                        else
                        {
                            int thumbnailRectIndex = IsPositionInThumbnailArea(scrollFixedPosition);
                            if (thumbnailRectIndex != -1 && m_LookDevView.config.enableShadowCubemap)
                            {
                                Undo.RecordObject(m_LookDevView.envLibrary, "Update shadow cubemap");
                                CubemapInfo cubemapInfo = m_LookDevView.envLibrary.hdriList[thumbnailRectIndex];

                                // We don't want the user to drop a cubemap on itself and reset the shadows (it would happen all the time by mistake)
                                if (cubemapInfo != m_SelectedCubemapInfo)
                                {
                                    cubemapInfo.SetCubemapShadowInfo(m_SelectedCubemapInfo);
                                }
                                m_LookDevView.envLibrary.dirty = true;
                            }
                        }
                        CancelSelection();
                    }
                }

                m_LookDevView.Repaint();

                if (m_SelectedCubeMapOffsetIndex != -1)
                {
                    // Fall back to zero when near the center
                    if (Mathf.Abs(cubemapList[m_SelectedCubeMapOffsetIndex].angleOffset) <= 10.0f)
                    {
                        Undo.RecordObject(m_LookDevView.envLibrary, "");
                        cubemapList[m_SelectedCubeMapOffsetIndex].angleOffset = 0.0f;
                        m_LookDevView.envLibrary.dirty = true;
                    }
                }
                m_SelectedCubemapInfo            = null;
                m_SelectedShadowCubemapOwnerInfo = null;
                m_SelectedLightIconIndex         = -1;
                m_SelectedShadowInfo             = null;
                m_SelectedCubeMapOffsetIndex     = -1;
                m_HoveringCubeMapIndex           = -1;
                m_SelectedCubeMapOffsetValue     = 0.0f;

                GUIUtility.hotControl = 0;

                break;
            }

            // Escape closes the window
            case EventType.KeyDown:
            {
                if (Event.current.keyCode == KeyCode.Escape)
                {
                    CancelSelection();
                    m_LookDevView.Repaint();
                }
                break;
            }

            case EventType.DragPerform:
            {
                int insertionIndex = IsPositionInInsertionArea(scrollFixedPosition);

                foreach (UnityEngine.Object o in DragAndDrop.objectReferences)
                {
                    Cubemap cubemap = o as Cubemap;
                    if (cubemap)
                    {
                        // When insertion outside the list the index is -1 which mean in InsertHDRI that it will be add at the end
                        m_LookDevView.envLibrary.InsertHDRI(cubemap, insertionIndex);
                    }
                }

                DragAndDrop.AcceptDrag();
                m_DragBeingPerformed = false;
                evt.Use();
                break;
            }

            case EventType.DragUpdated:
            {
                bool hasCubemap = false;
                foreach (UnityEngine.Object o in DragAndDrop.objectReferences)
                {
                    Cubemap cubemap = o as Cubemap;
                    if (cubemap)
                    {
                        hasCubemap = true;
                    }
                }
                DragAndDrop.visualMode = hasCubemap ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected;
                if (hasCubemap)
                {
                    m_DragBeingPerformed = true;
                }
                evt.Use();
            }
            break;

            case EventType.DragExited:
                break;

            case EventType.Repaint:

                if (m_SelectedCubeMapOffsetIndex != -1)
                {
                    EditorGUIUtility.AddCursorRect(m_displayRect, MouseCursor.SlideArrow);
                }
                break;
            }
        }
 public void OnGUI(int windowID)
 {
     if (this.m_LookDevView != null)
     {
         List<CubemapInfo> hdriList = this.m_LookDevView.envLibrary.hdriList;
         bool flag = (146f * hdriList.Count) > this.m_PositionInLookDev.height;
         if (flag)
         {
             this.m_ScrollPosition = EditorGUILayout.BeginScrollView(this.m_ScrollPosition, new GUILayoutOption[0]);
         }
         else
         {
             this.m_ScrollPosition = new Vector2(0f, 0f);
         }
         if (hdriList.Count == 1)
         {
             Color color = GUI.color;
             GUI.color = Color.gray;
             Vector2 vector = GUI.skin.label.CalcSize(styles.sDragAndDropHDRIText);
             Rect position = new Rect((this.m_PositionInLookDev.width * 0.5f) - (vector.x * 0.5f), (this.m_PositionInLookDev.height * 0.5f) - (vector.y * 0.5f), vector.x, vector.y);
             GUI.Label(position, styles.sDragAndDropHDRIText);
             GUI.color = color;
         }
         for (int i = 0; i < hdriList.Count; i++)
         {
             Rect rect5;
             Rect rect6;
             CubemapInfo infos = hdriList[i];
             ShadowInfo shadowInfo = infos.shadowInfo;
             int intProperty = this.m_LookDevView.config.GetIntProperty(LookDevProperty.HDRI, LookDevEditionContext.Left);
             int num3 = this.m_LookDevView.config.GetIntProperty(LookDevProperty.HDRI, LookDevEditionContext.Right);
             if ((this.m_LookDevView.config.lookDevMode == LookDevMode.Single1) || (this.m_LookDevView.config.lookDevMode == LookDevMode.Single2))
             {
                 num3 = -1;
             }
             bool flag2 = (i == intProperty) || (i == num3);
             Color black = Color.black;
             Color firstViewGizmoColor = Color.black;
             GUIStyle miniLabel = EditorStyles.miniLabel;
             if (flag2)
             {
                 if (i == intProperty)
                 {
                     black = (Color) LookDevView.m_FirstViewGizmoColor;
                     firstViewGizmoColor = (Color) LookDevView.m_FirstViewGizmoColor;
                     miniLabel = styles.sLabelStyleFirstContext;
                 }
                 else if (i == num3)
                 {
                     black = (Color) LookDevView.m_SecondViewGizmoColor;
                     firstViewGizmoColor = (Color) LookDevView.m_SecondViewGizmoColor;
                     miniLabel = styles.sLabelStyleSecondContext;
                 }
                 if (intProperty == num3)
                 {
                     black = (Color) LookDevView.m_FirstViewGizmoColor;
                     firstViewGizmoColor = (Color) LookDevView.m_SecondViewGizmoColor;
                     miniLabel = styles.sLabelStyleBothContext;
                 }
             }
             GUILayoutOption[] optionArray1 = new GUILayoutOption[] { GUILayout.Width(250f) };
             GUILayout.BeginVertical(optionArray1);
             int num4 = hdriList.FindIndex(x => x == this.m_SelectedCubemapInfo);
             if ((((this.m_SelectedCubemap != null) || this.m_DragBeingPerformed) && this.GetInsertionRect(i).Contains(Event.current.mousePosition)) && ((((num4 - i) != 0) && ((num4 - i) != -1)) || (num4 == -1)))
             {
                 GUILayout.Label(GUIContent.none, styles.sSeparatorStyle, new GUILayoutOption[0]);
                 GUILayoutUtility.GetRect((float) 250f, (float) 16f);
             }
             GUILayout.Label(GUIContent.none, styles.sSeparatorStyle, new GUILayoutOption[0]);
             GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.Width(250f), GUILayout.Height(18f) };
             GUILayout.BeginHorizontal(optionArray2);
             StringBuilder builder = new StringBuilder();
             builder.Append(i.ToString());
             builder.Append(" - ");
             builder.Append(infos.cubemap.name);
             GUILayoutOption[] optionArray3 = new GUILayoutOption[] { GUILayout.Height(18f), GUILayout.MaxWidth(175f) };
             GUILayout.Label(builder.ToString(), miniLabel, optionArray3);
             GUILayout.FlexibleSpace();
             if (GUILayout.Button(styles.sEnvControlIcon, LookDevView.styles.sToolBarButton, new GUILayoutOption[0]))
             {
                 PopupWindow.Show(GUILayoutUtility.topLevel.GetLast(), new EnvSettingsWindow(this.m_LookDevView, infos));
                 GUIUtility.ExitGUI();
             }
             using (new EditorGUI.DisabledScope(infos.cubemap == LookDevResources.m_DefaultHDRI))
             {
                 if (GUILayout.Button(styles.sCloseIcon, LookDevView.styles.sToolBarButton, new GUILayoutOption[0]))
                 {
                     this.m_LookDevView.envLibrary.RemoveHDRI(infos.cubemap);
                 }
             }
             GUILayout.EndHorizontal();
             Rect lastRect = GUILayoutUtility.GetLastRect();
             if ((Event.current.type == EventType.MouseDown) && lastRect.Contains(Event.current.mousePosition))
             {
                 Event.current.Use();
             }
             Rect rect = GUILayoutUtility.GetRect((float) 250f, (float) 125f);
             rect.width = 253f;
             float num5 = 24f;
             float num6 = num5 * 0.5f;
             float latitude = shadowInfo.latitude;
             float longitude = shadowInfo.longitude;
             Vector2 vector2 = ((Vector2) (this.LatLongToPosition(latitude, longitude + infos.angleOffset) * 0.5f)) + new Vector2(0.5f, 0.5f);
             Rect rect3 = rect;
             rect3.x = (rect3.x + (vector2.x * rect.width)) - num6;
             rect3.y = (rect3.y + ((1f - vector2.y) * rect.height)) - num6;
             rect3.width = num5;
             rect3.height = num5;
             Rect rect4 = rect;
             rect4.x = (rect4.x + (vector2.x * rect.width)) - (num6 * 0.5f);
             rect4.y = (rect4.y + ((1f - vector2.y) * rect.height)) - (num6 * 0.5f);
             rect4.width = num5 * 0.5f;
             rect4.height = num5 * 0.5f;
             this.GetFrameAndShadowTextureRect(rect, out rect5, out rect6);
             if (this.m_LookDevView.config.enableShadowCubemap)
             {
                 EditorGUIUtility.AddCursorRect(rect4, MouseCursor.Pan);
             }
             if ((Event.current.type == EventType.MouseDown) && rect.Contains(Event.current.mousePosition))
             {
                 if ((!Event.current.control && (Event.current.button == 0)) && (this.m_SelectedCubeMapOffsetIndex == -1))
                 {
                     if (this.m_LookDevView.config.enableShadowCubemap && rect4.Contains(Event.current.mousePosition))
                     {
                         this.m_SelectedLightIconIndex = i;
                         this.m_SelectedShadowInfo = shadowInfo;
                         Undo.RecordObject(this.m_LookDevView.envLibrary, "Light Icon selection");
                         this.m_SelectedShadowInfo.latitude += 0.0001f;
                         this.m_SelectedShadowInfo.longitude += 0.0001f;
                     }
                     if (this.m_SelectedShadowInfo == null)
                     {
                         Rect rect10 = rect5;
                         rect10.x += 100f;
                         rect10.y += 4f;
                         rect10.width = 11f;
                         rect10.height = 11f;
                         if (this.m_LookDevView.config.enableShadowCubemap && rect10.Contains(Event.current.mousePosition))
                         {
                             Undo.RecordObject(this.m_LookDevView.envLibrary, "Update shadow cubemap");
                             hdriList[i].SetCubemapShadowInfo(hdriList[i]);
                             this.m_LookDevView.envLibrary.dirty = true;
                         }
                         else
                         {
                             if (this.m_LookDevView.config.enableShadowCubemap && rect6.Contains(Event.current.mousePosition))
                             {
                                 this.m_SelectedShadowCubemapOwnerInfo = hdriList[i];
                                 this.m_SelectedCubemapInfo = this.m_SelectedShadowCubemapOwnerInfo.cubemapShadowInfo;
                             }
                             else
                             {
                                 this.m_SelectedCubemapInfo = hdriList[i];
                             }
                             this.m_SelectedPositionOffset = Event.current.mousePosition - new Vector2(rect.x, rect.y);
                             this.m_RenderOverlayThumbnailOnce = true;
                         }
                     }
                 }
                 else if ((Event.current.control && (Event.current.button == 0)) && ((this.m_SelectedCubemapInfo == null) && (this.m_SelectedShadowInfo == null)))
                 {
                     this.m_SelectedCubeMapOffsetIndex = i;
                     this.m_SelectedCubeMapOffsetValue = infos.angleOffset - this.ComputeAngleOffsetFromMouseCoord(Event.current.mousePosition);
                 }
                 GUIUtility.hotControl = this.m_LookDevView.hotControl;
                 Event.current.Use();
             }
             if ((Event.current.GetTypeForControl(this.m_LookDevView.hotControl) == EventType.MouseDrag) && ((this.m_SelectedShadowInfo == shadowInfo) && (this.m_SelectedLightIconIndex == i)))
             {
                 Vector2 mousePosition = Event.current.mousePosition;
                 mousePosition.x = (((mousePosition.x - rect.x) / rect.width) * 2f) - 1f;
                 mousePosition.y = ((1f - ((mousePosition.y - rect.y) / rect.height)) * 2f) - 1f;
                 Vector2 vector4 = PositionToLatLong(mousePosition);
                 this.m_SelectedShadowInfo.latitude = vector4.x;
                 this.m_SelectedShadowInfo.longitude = vector4.y - infos.angleOffset;
                 this.m_LookDevView.envLibrary.dirty = true;
             }
             if (Event.current.type == EventType.Repaint)
             {
                 this.DrawLatLongThumbnail(infos, infos.angleOffset, 1f, 1f, rect);
                 if (this.m_LookDevView.config.enableShadowCubemap)
                 {
                     if ((infos.cubemapShadowInfo != infos) || ((this.m_HoveringCubeMapIndex == i) && (this.m_SelectedCubemapInfo != infos)))
                     {
                         CubemapInfo cubemapShadowInfo = infos.cubemapShadowInfo;
                         if ((this.m_HoveringCubeMapIndex == i) && (this.m_SelectedCubemapInfo != infos))
                         {
                             cubemapShadowInfo = this.m_SelectedCubemapInfo;
                         }
                         float alpha = 1f;
                         if (this.m_SelectedShadowInfo == shadowInfo)
                         {
                             alpha = 0.1f;
                         }
                         else if (((this.m_HoveringCubeMapIndex == i) && (this.m_SelectedCubemapInfo != infos)) && (infos.cubemapShadowInfo != this.m_SelectedCubemapInfo))
                         {
                             alpha = 0.5f;
                         }
                         this.DrawLatLongThumbnail(cubemapShadowInfo, infos.angleOffset, 0.3f, alpha, rect6);
                         GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
                         GUI.DrawTexture(rect5, styles.sLatlongFrameTexture);
                         GL.sRGBWrite = false;
                     }
                     GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
                     GUI.DrawTexture(rect3, styles.sLightTexture);
                     GL.sRGBWrite = false;
                 }
                 if (flag2)
                 {
                     this.DrawSelectionFeedback(rect, black, firstViewGizmoColor);
                 }
             }
             GUILayout.EndVertical();
         }
         GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(250f) };
         GUILayout.BeginVertical(options);
         if (((this.m_SelectedCubemap != null) || this.m_DragBeingPerformed) && this.GetInsertionRect(hdriList.Count).Contains(Event.current.mousePosition))
         {
             GUILayout.Label(GUIContent.none, styles.sSeparatorStyle, new GUILayoutOption[0]);
             GUILayoutUtility.GetRect((float) 250f, (float) 16f);
             GUILayout.Label(GUIContent.none, styles.sSeparatorStyle, new GUILayoutOption[0]);
         }
         GUILayout.EndVertical();
         if (flag)
         {
             EditorGUILayout.EndScrollView();
         }
         this.HandleMouseInput();
         this.RenderOverlayThumbnailIfNeeded();
         if ((Event.current.type == EventType.Repaint) && (this.m_SelectedCubemap != null))
         {
             this.m_LookDevView.Repaint();
         }
     }
 }
Example #24
0
 public void SetCubemapShadowInfo(CubemapInfo newCubemapShadowInfo)
 {
     this.cubemapShadowInfo = newCubemapShadowInfo;
     this.shadowInfo.shadowIntensity = (newCubemapShadowInfo != this) ? 1f : 0.3f;
     this.shadowInfo.shadowColor = Color.white;
 }
 public EnvSettingsWindow(LookDevView lookDevView, CubemapInfo infos)
 {
     this.m_LookDevView = lookDevView;
     this.m_CubemapInfo = infos;
 }