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; }
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(); } } } }
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; }
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 (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; }
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; }
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(); } } }
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; } }