示例#1
0
        public void OnGUI()
        {
            base.ClearBackground();
            EditorGUIUtility.ResetGUIState();
            SplitView parent = base.parent as SplitView;

            if ((Event.current.type == EventType.Repaint) && (parent != null))
            {
                View child = this;
                while (parent != null)
                {
                    int controlID = parent.controlID;
                    if ((controlID == GUIUtility.hotControl) || (GUIUtility.hotControl == 0))
                    {
                        int num2 = parent.IndexOfChild(child);
                        if (parent.vertical)
                        {
                            if (num2 != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0f, 0f, base.position.width, 5f), MouseCursor.SplitResizeUpDown, controlID);
                            }
                            if (num2 != (parent.children.Length - 1))
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0f, base.position.height - 5f, base.position.width, 5f), MouseCursor.SplitResizeUpDown, controlID);
                            }
                        }
                        else
                        {
                            if (num2 != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0f, 0f, 5f, base.position.height), MouseCursor.SplitResizeLeftRight, controlID);
                            }
                            if (num2 != (parent.children.Length - 1))
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(base.position.width - 5f, 0f, 5f, base.position.height), MouseCursor.SplitResizeLeftRight, controlID);
                            }
                        }
                    }
                    child  = parent;
                    parent = parent.parent as SplitView;
                }
                parent = base.parent as SplitView;
            }
            bool flag = false;

            if (base.window.mainView.GetType() != typeof(MainWindow))
            {
                flag = true;
                if (base.windowPosition.y == 0f)
                {
                    base.background = "dockareaStandalone";
                }
                else
                {
                    base.background = "dockarea";
                }
            }
            else
            {
                base.background = "dockarea";
            }
            if (parent != null)
            {
                Event event2;
                event2 = new Event(Event.current)
                {
                    mousePosition = event2.mousePosition + new Vector2(base.position.x, base.position.y)
                };
                parent.SplitGUI(event2);
                if (event2.type == EventType.Used)
                {
                    Event.current.Use();
                }
            }
            GUIStyle style    = "dockareaoverlay";
            Rect     position = base.background.margin.Remove(new Rect(0f, 0f, base.position.width, base.position.height));

            position.x = base.background.margin.left;
            position.y = base.background.margin.top;
            Rect  windowPosition = base.windowPosition;
            float num3           = 2f;

            if (windowPosition.x == 0f)
            {
                position.x     -= num3;
                position.width += num3;
            }
            if (windowPosition.xMax == base.window.position.width)
            {
                position.width += num3;
            }
            if (windowPosition.yMax == base.window.position.height)
            {
                position.height += !flag ? 2f : 2f;
            }
            GUI.Box(position, GUIContent.none, base.background);
            if (this.tabStyle == null)
            {
                this.tabStyle = "dragtab";
            }
            this.DragTab(new Rect(position.x + 1f, position.y, position.width - 40f, 17f), this.tabStyle);
            this.tabStyle = "dragtab";
            base.ShowGenericMenu();
            base.DoWindowDecorationStart();
            if (this.m_Panes.Count > 0)
            {
                if (this.m_Panes[this.selected] is GameView)
                {
                    GUI.Box(position, GUIContent.none, style);
                }
                BeginOffsetArea(new Rect(position.x + 2f, position.y + 17f, position.width - 4f, (position.height - 17f) - 2f), GUIContent.none, "TabWindowBackground");
                Vector2 vector = GUIUtility.GUIToScreenPoint(Vector2.zero);
                Rect    rect3  = base.borderSize.Remove(base.position);
                rect3.x = vector.x;
                rect3.y = vector.y;
                this.m_Panes[this.selected].m_Pos = rect3;
                EditorGUIUtility.ResetGUIState();
                try
                {
                    base.Invoke("OnGUI");
                }
                catch (TargetInvocationException exception)
                {
                    throw exception.InnerException;
                }
                EditorGUIUtility.ResetGUIState();
                if (((base.actualView != null) && (base.actualView.m_FadeoutTime != 0f)) && ((Event.current != null) && (Event.current.type == EventType.Repaint)))
                {
                    base.actualView.DrawNotification();
                }
                EndOffsetArea();
            }
            base.DoWindowDecorationEnd();
            GUI.Box(position, GUIContent.none, style);
            EditorGUI.ShowRepaints();
            Highlighter.ControlHighlightGUI(this);
        }
示例#2
0
        private void OnGUI()
        {
            using (var rgv = new RenderingGameView(this))
            {
                if (position.size * EditorGUIUtility.pixelsPerPoint != m_LastWindowPixelSize) // pixelsPerPoint only reliable in OnGUI()
                {
                    UpdateZoomAreaAndParent();
                }

                DoToolbarGUI();

                // This isn't ideal. Custom Cursors set by editor extensions for other windows can leak into the game view.
                // To fix this we should probably stop using the global custom cursor (intended for runtime) for custom editor cursors.
                // This has been noted for Cursors tech debt.
                EditorGUIUtility.AddCursorRect(viewInWindow, MouseCursor.CustomCursor);

                EventType type = Event.current.type;

                // Gain mouse lock when clicking on game view content
                if (type == EventType.MouseDown && viewInWindow.Contains(Event.current.mousePosition))
                {
                    AllowCursorLockAndHide(true);
                }
                // Lose mouse lock when pressing escape
                else if (type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
                {
                    AllowCursorLockAndHide(false);
                }

                // We hide sliders when playing, and also when we are zoomed out beyond canvas edges
                var playing = EditorApplication.isPlaying && !EditorApplication.isPaused;
                var targetInContentCached = targetInContent;
                m_ZoomArea.hSlider          = !playing && m_ZoomArea.shownArea.width < targetInContentCached.width;
                m_ZoomArea.vSlider          = !playing && m_ZoomArea.shownArea.height < targetInContentCached.height;
                m_ZoomArea.enableMouseInput = !playing;
                ConfigureZoomArea();

                // We don't want controls inside the GameView (e.g. the toolbar) to have keyboard focus while playing.
                // The game should get the keyboard events.
                if (playing)
                {
                    EditorGUIUtility.keyboardControl = 0;
                }

                GUI.color = Color.white; // Get rid of play mode tint

                var originalEventType = Event.current.type;

                m_ZoomArea.BeginViewGUI();

                // Setup game view dimensions, so that player loop can use it for input
                var gameViewTarget = GUIClip.UnclipToWindow(m_ZoomArea.drawRect);
                if (m_Parent)
                {
                    var zoomedTarget = new Rect(targetInView.position + gameViewTarget.position, targetInView.size);
                    SetParentGameViewDimensions(zoomedTarget, gameViewTarget, targetSize);
                }

                var editorMousePosition = Event.current.mousePosition;
                var gameMousePosition   = (editorMousePosition + gameMouseOffset) * gameMouseScale;

                if (type == EventType.Repaint)
                {
                    GUI.Box(m_ZoomArea.drawRect, GUIContent.none, Styles.gameViewBackgroundStyle);

                    Vector2 oldOffset = GUIUtility.s_EditorScreenPointOffset;
                    GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                    SavedGUIState oldState = SavedGUIState.Create();

                    ConfigureTargetTexture((int)targetSize.x, (int)targetSize.y);

                    if (m_ClearInEditMode && !EditorApplication.isPlaying)
                    {
                        ClearTargetTexture();
                    }

                    var currentTargetDisplay = 0;
                    if (ModuleManager.ShouldShowMultiDisplayOption())
                    {
                        // Display Targets can have valid targets from 0 to 7.
                        System.Diagnostics.Debug.Assert(m_TargetDisplay < 8, "Display Target is Out of Range");
                        currentTargetDisplay = m_TargetDisplay;
                    }
                    if (m_TargetTexture.IsCreated())
                    {
                        var sendInput = true;
                        EditorGUIUtility.RenderGameViewCamerasInternal(m_TargetTexture, currentTargetDisplay, GUIClip.Unclip(viewInWindow), gameMousePosition, m_Gizmos, sendInput);
                        oldState.ApplyAndForget();
                        GUIUtility.s_EditorScreenPointOffset = oldOffset;

                        GUI.BeginGroup(m_ZoomArea.drawRect);
                        // Actually draw the game view to the screen, without alpha blending
                        Rect drawRect = deviceFlippedTargetInView;
                        drawRect.x = Mathf.Round(drawRect.x);
                        drawRect.y = Mathf.Round(drawRect.y);
                        Graphics.DrawTexture(drawRect, m_TargetTexture, new Rect(0, 0, 1, 1), 0, 0, 0, 0, GUI.color, GUI.blitMaterial);
                        GUI.EndGroup();
                    }
                }
                else if (type != EventType.Layout && type != EventType.Used)
                {
                    if (Event.current.isKey && (!EditorApplication.isPlaying || EditorApplication.isPaused))
                    {
                        return;
                    }

                    bool mousePosInGameViewRect = viewInWindow.Contains(Event.current.mousePosition);

                    // MouseDown events outside game view rect are not send to scripts but MouseUp events are (see below)
                    if (Event.current.rawType == EventType.MouseDown && !mousePosInGameViewRect)
                    {
                        return;
                    }

                    var originalDisplayIndex = Event.current.displayIndex;

                    // Transform events into local space, so the mouse position is correct
                    // Then queue it up for playback during playerloop
                    Event.current.mousePosition = gameMousePosition;
                    Event.current.displayIndex  = m_TargetDisplay;

                    EditorGUIUtility.QueueGameViewInputEvent(Event.current);

                    bool useEvent = true;

                    // Do not use mouse UP event if mousepos is outside game view rect (fix for case 380995: Gameview tab's context menu is not appearing on right click)
                    // Placed after event queueing above to ensure scripts can react on mouse up events.
                    if (Event.current.rawType == EventType.MouseUp && !mousePosInGameViewRect)
                    {
                        useEvent = false;
                    }

                    // Don't use command events, or they won't be sent to other views.
                    if (type == EventType.ExecuteCommand || type == EventType.ValidateCommand)
                    {
                        useEvent = false;
                    }

                    if (useEvent)
                    {
                        Event.current.Use();
                    }
                    else
                    {
                        Event.current.mousePosition = editorMousePosition;
                    }

                    // Reset display index
                    Event.current.displayIndex = originalDisplayIndex;
                }

                m_ZoomArea.EndViewGUI();

                if (originalEventType == EventType.ScrollWheel && Event.current.type == EventType.Used)
                {
                    EditorApplication.update -= SnapZoomDelayed;
                    EditorApplication.update += SnapZoomDelayed;
                    s_LastScrollTime          = EditorApplication.timeSinceStartup;
                }

                EnforceZoomAreaConstraints();

                if (m_TargetTexture)
                {
                    if (m_ZoomArea.scale.y < 1f)
                    {
                        m_TargetTexture.filterMode = FilterMode.Bilinear;
                    }
                    else
                    {
                        m_TargetTexture.filterMode = FilterMode.Point;
                    }
                }

                if (m_NoCameraWarning && !EditorGUIUtility.IsDisplayReferencedByCameras(m_TargetDisplay))
                {
                    GUI.Label(warningPosition, GUIContent.none, EditorStyles.notificationBackground);
                    var displayName   = ModuleManager.ShouldShowMultiDisplayOption() ? DisplayUtility.GetDisplayNames()[m_TargetDisplay].text : string.Empty;
                    var cameraWarning = string.Format("{0}\nNo cameras rendering", displayName);
                    EditorGUI.DoDropShadowLabel(warningPosition, EditorGUIUtility.TempContent(cameraWarning), EditorStyles.notificationText, .3f);
                }

                if (m_Stats)
                {
                    GameViewGUI.GameViewStatsGUI();
                }
            }
        }
示例#3
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();
                }
            }
        }
示例#4
0
        public void OnGUI()
        {
            LoadLogos();
            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.Space(5);
            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            GUILayout.Label(s_Header, GUIStyle.none);

            ListenForSecretCodes();

            var licenseTypeString = "";

            if (InternalEditorUtility.HasFreeLicense())
            {
                licenseTypeString = " Personal";
            }
            if (InternalEditorUtility.HasEduLicense())
            {
                licenseTypeString = " Edu";
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(52f); // Ident version information

            string extensionVersion = FormatExtensionVersionString();

            m_ShowDetailedVersion |= Event.current.alt;
            if (m_ShowDetailedVersion)
            {
                int      t      = InternalEditorUtility.GetUnityVersionDate();
                DateTime dt     = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                string   branch = InternalEditorUtility.GetUnityBuildBranch();
                EditorGUILayout.SelectableLabel(
                    string.Format("Version: {0}{1}{2}\nRevision: {3} {4}\nBuilt: {5:r}",
                                  InternalEditorUtility.GetUnityDisplayVersionVerbose(), licenseTypeString, extensionVersion,
                                  branch, InternalEditorUtility.GetUnityBuildHash(), dt.AddSeconds(t)),
                    GUILayout.Width(550), GUILayout.Height(50));

                m_TextInitialYPos = 120 - 12;
            }
            else
            {
                GUILayout.Label(string.Format("Version {0}{1}{2}", InternalEditorUtility.GetUnityDisplayVersion(), licenseTypeString, extensionVersion));
            }

            if (Event.current.type == EventType.ValidateCommand)
            {
                return;
            }

            GUILayout.EndHorizontal();
            GUILayout.Space(4);
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();

            float creditsWidth = position.width - 10;
            float chunkOffset  = m_TextYPos;

            Rect scrollAreaRect = GUILayoutUtility.GetRect(10, m_TextInitialYPos);

            GUI.BeginGroup(scrollAreaRect);
            foreach (string nameChunk in AboutWindowNames.Names(null, true))
            {
                chunkOffset = DoCreditsNameChunk(nameChunk, creditsWidth, chunkOffset);
            }
            chunkOffset          = DoCreditsNameChunk(kSpecialThanksNames, creditsWidth, chunkOffset);
            m_TotalCreditsHeight = chunkOffset - m_TextYPos;
            GUI.EndGroup();

            HandleScrollEvents(scrollAreaRect);

            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();
            GUILayout.Label(s_MonoLogo);
            GUILayout.Label("Scripting powered by The Mono Project.\n\n(c) 2011 Novell, Inc.", "MiniLabel", GUILayout.Width(210));
            GUILayout.Label(s_AgeiaLogo);
            GUILayout.Label("Physics powered by PhysX.\n\n(c) 2019 NVIDIA Corporation.", "MiniLabel", GUILayout.Width(200));
            GUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.Space(5);
            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();

            var specialThanksRect = GUILayoutUtility.GetRect(Styles.thanksContent, Styles.thanksStyle);

            if (GUI.Button(specialThanksRect, Styles.thanksContent, Styles.thanksStyle))
            {
                Process.Start(Styles.thanksUri.AbsoluteUri);
            }

            EditorGUIUtility.AddCursorRect(specialThanksRect, MouseCursor.Link);

            var VSTUlabel = UnityVSSupport.GetAboutWindowLabel();

            if (VSTUlabel.Length > 0)
            {
                GUILayout.Label(VSTUlabel, "MiniLabel");
            }
            GUILayout.Label(InternalEditorUtility.GetUnityCopyright(), "MiniLabel");
            GUILayout.EndVertical();
            GUILayout.Space(10);
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            GUILayout.Label(InternalEditorUtility.GetLicenseInfo(), "AboutWindowLicenseLabel");
            GUILayout.EndVertical();
            GUILayout.Space(5);
            GUILayout.EndHorizontal();

            GUILayout.Space(5);
        }
示例#5
0
        public void DoEffectGUI(int effectIndex, AudioMixerGroupController group, List <AudioMixerGroupController> allGroups, Dictionary <AudioMixerEffectController, AudioMixerGroupController> effectMap, ref int highlightEffectIndex)
        {
            Event evt = Event.current;

            AudioMixerController       controller = group.controller;
            AudioMixerEffectController effect     = group.effects[effectIndex];

            MixerParameterDefinition[] paramDefs = MixerEffectDefinitions.GetEffectParameters(effect.effectName);

            // This rect is valid after every layout event
            Rect totalRect = EditorGUILayout.BeginVertical();

            bool      hovering = totalRect.Contains(evt.mousePosition);
            EventType evtType  = evt.GetTypeForControl(m_EffectDragging.dragControlID);

            if (evtType == EventType.MouseMove && hovering && highlightEffectIndex != effectIndex)
            {
                highlightEffectIndex = effectIndex;
                AudioMixerUtility.RepaintAudioMixerAndInspectors();
            }

            // Header
            const float colorCodeWidth = 6f;
            var         gearSize       = EditorStyles.iconButton.CalcSize(EditorGUI.GUIContents.titleSettingsIcon);
            Rect        headerRect     = GUILayoutUtility.GetRect(1, 17f);
            Rect        colorCodeRect  = new Rect(headerRect.x + 6f, headerRect.y + 5f, colorCodeWidth, colorCodeWidth);
            Rect        labelRect      = new Rect(headerRect.x + 8f + colorCodeWidth, headerRect.y, headerRect.width - 8f - colorCodeWidth - gearSize.x - 5f, headerRect.height);
            Rect        gearRect       = new Rect(labelRect.xMax, headerRect.y, gearSize.x, gearSize.y);
            Rect        dragRect       = new Rect(headerRect.x, headerRect.y, headerRect.width - gearSize.x - 5f, headerRect.height);

            {
                bool showCPU = EditorPrefs.GetBool(AudioMixerGroupEditor.kPrefKeyForShowCpuUsage, false) && EditorUtility.audioProfilingEnabled;

                float val         = EditorGUIUtility.isProSkin ? 0.1f : 1.0f;
                Color headerColor = new Color(val, val, val, 0.2f);
                Color origColor   = GUI.color;
                GUI.color = headerColor;
                GUI.DrawTexture(headerRect, EditorGUIUtility.whiteTexture);
                GUI.color = origColor;

                Color effectColorCode = AudioMixerDrawUtils.GetEffectColor(effect);
                EditorGUI.DrawRect(colorCodeRect, effectColorCode);
                GUI.Label(labelRect, showCPU ? effect.effectName + string.Format(Texts.cpuFormatString, effect.GetCPUUsage(controller)) : effect.effectName, EditorStyles.boldLabel);
                if (EditorGUI.DropdownButton(gearRect, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive, EditorStyles.iconButton))
                {
                    ShowEffectContextMenu(group, effect, effectIndex, controller, gearRect);
                }

                // Show context menu if right clicking in header rect (for convenience)
                if (evt.type == EventType.ContextClick && headerRect.Contains(evt.mousePosition))
                {
                    ShowEffectContextMenu(group, effect, effectIndex, controller, new Rect(evt.mousePosition.x, headerRect.y, 1, headerRect.height));
                    evt.Use();
                }

                if (evtType == EventType.Repaint)
                {
                    EditorGUIUtility.AddCursorRect(dragRect, MouseCursor.ResizeVertical, m_EffectDragging.dragControlID);
                }
            }

            using (new EditorGUI.DisabledScope(effect.bypass || group.bypassEffects))
            {
                EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);

                if (effect.IsAttenuation())
                {
                    EditorGUILayout.BeginVertical();
                    float value = group.GetValueForVolume(controller, controller.TargetSnapshot);
                    if (AudioMixerEffectGUI.Slider(Texts.volume, ref value, 1.0f, 1.0f, Texts.dB, AudioMixerController.kMinVolume, AudioMixerController.GetMaxVolume(), controller, new AudioGroupParameterPath(group, group.GetGUIDForVolume())))
                    {
                        Undo.RecordObject(controller.TargetSnapshot, "Change Volume Fader");
                        group.SetValueForVolume(controller, controller.TargetSnapshot, value);
                        AudioMixerUtility.RepaintAudioMixerAndInspectors();
                    }

                    //FIXME
                    // 1) The VUMeter used is not in the same style that fits the rest of the Audio UI
                    // 2) The layout of the VU meters is hacked together and a lot of magic numbers are used.
                    int     numChannels  = 0;
                    float[] vuinfo_level = new float[9];
                    float[] vuinfo_peak  = new float[9];

                    numChannels = group.controller.GetGroupVUInfo(group.groupID, true, vuinfo_level, vuinfo_peak);

                    if (evt.type == EventType.Layout)
                    {
                        m_LastNumChannels = numChannels;
                    }
                    else
                    {
                        if (numChannels != m_LastNumChannels)
                        {
                            HandleUtility.Repaint();      // Repaint to ensure correct rendered num channels
                        }
                        // Ensure same num channels as in layout event to not break IMGUI controlID handling
                        numChannels = m_LastNumChannels;
                    }

                    GUILayout.Space(4f);
                    for (int c = 0; c < numChannels; ++c)
                    {
                        float level = 1 - AudioMixerController.VolumeToScreenMapping(Mathf.Clamp(vuinfo_level[c], AudioMixerController.kMinVolume, AudioMixerController.GetMaxVolume()), 1, true);
                        float peak  = 1 - AudioMixerController.VolumeToScreenMapping(Mathf.Clamp(vuinfo_peak[c], AudioMixerController.kMinVolume, AudioMixerController.GetMaxVolume()), 1, true);
                        EditorGUILayout.VUMeterHorizontal(level, peak, GUILayout.Height(10));

                        //This allows the meters to drop to 0 after PlayMode has stopped.
                        if (!EditorApplication.isPlaying && peak > 0.0F)
                        {
                            AudioMixerUtility.RepaintAudioMixerAndInspectors();
                        }
                    }
                    GUILayout.Space(4f);
                    EditorGUILayout.EndVertical();
                }

                if (effect.IsSend())
                {
                    Rect       buttonRect;
                    GUIContent buttonContent = (effect.sendTarget == null) ? Texts.none : GUIContent.Temp(effect.GetSendTargetDisplayString(effectMap));
                    if (AudioMixerEffectGUI.PopupButton(Texts.bus, buttonContent, EditorStyles.popup, out buttonRect))
                    {
                        ShowBusPopupMenu(effectIndex, @group, allGroups, effectMap, effect, buttonRect);
                    }

                    if (effect.sendTarget != null)
                    {
                        float wetLevel = effect.GetValueForMixLevel(controller, controller.TargetSnapshot);
                        if (AudioMixerEffectGUI.Slider(Texts.sendLevel, ref wetLevel, 1.0f, 1.0f, Texts.dB, AudioMixerController.kMinVolume, AudioMixerController.kMaxEffect, controller, new AudioGroupParameterPath(group, group.GetGUIDForSend())))
                        {
                            Undo.RecordObject(controller.TargetSnapshot, "Change Send Level");
                            effect.SetValueForMixLevel(controller, controller.TargetSnapshot, wetLevel);
                            AudioMixerUtility.RepaintAudioMixerAndInspectors();
                        }
                    }
                }

                if (MixerEffectDefinitions.EffectCanBeSidechainTarget(effect))
                {
                    bool anyTargetsFound = false;
                    foreach (var g in allGroups)
                    {
                        foreach (var e in g.effects)
                        {
                            if (e.IsSend() && e.sendTarget == effect)
                            {
                                anyTargetsFound = true;
                                break;
                            }
                        }
                        if (anyTargetsFound)
                        {
                            break;
                        }
                    }
                    if (!anyTargetsFound)
                    {
                        GUILayout.Label(EditorGUIUtility.TrTextContent("No Send sources connected.", EditorGUIUtility.warningIcon));
                    }
                }

                // Wet mix
                if (effect.enableWetMix && !effect.IsReceive() && !effect.IsDuckVolume() && !effect.IsAttenuation() && !effect.IsSend())
                {
                    float wetLevel = effect.GetValueForMixLevel(controller, controller.TargetSnapshot);
                    if (AudioMixerEffectGUI.Slider(Texts.wet, ref wetLevel, 1.0f, 1.0f, Texts.dB, AudioMixerController.kMinVolume, AudioMixerController.kMaxEffect, controller, new AudioEffectParameterPath(group, effect, effect.GetGUIDForMixLevel())))
                    {
                        Undo.RecordObject(controller.TargetSnapshot, "Change Mix Level");
                        effect.SetValueForMixLevel(controller, controller.TargetSnapshot, wetLevel);
                        AudioMixerUtility.RepaintAudioMixerAndInspectors();
                    }
                }

                // All other effects
                bool drawDefaultGUI = true;
                if (m_CustomEffectGUIs.ContainsKey(effect.effectName))
                {
                    var customGUI = m_CustomEffectGUIs[effect.effectName];
                    m_SharedPlugin.m_Controller = controller;
                    m_SharedPlugin.m_Effect     = effect;
                    m_SharedPlugin.m_ParamDefs  = paramDefs;
                    drawDefaultGUI = customGUI.OnGUI(m_SharedPlugin);
                }
                if (drawDefaultGUI)
                {
                    foreach (var p in paramDefs)
                    {
                        float value = effect.GetValueForParameter(controller, controller.TargetSnapshot, p.name);
                        if (AudioMixerEffectGUI.Slider(GUIContent.Temp(p.name, p.description), ref value, p.displayScale, p.displayExponent, p.units, p.minRange, p.maxRange, controller, new AudioEffectParameterPath(group, effect, effect.GetGUIDForParameter(p.name))))
                        {
                            Undo.RecordObject(controller.TargetSnapshot, "Change " + p.name);
                            effect.SetValueForParameter(controller, controller.TargetSnapshot, p.name, value);
                        }
                    }
                    if (paramDefs.Length > 0)
                    {
                        GUILayout.Space(6f);
                    }
                }
            }

            m_EffectDragging.HandleDragElement(effectIndex, totalRect, dragRect, group, allGroups);

            EditorGUILayout.EndVertical(); // indented effect contents
            EditorGUILayout.EndVertical(); // calc total size

            AudioMixerDrawUtils.DrawSplitter();
        }
        private void DragTitleBar(Rect titleBarRect)
        {
            int   id  = GUIUtility.GetControlID(FocusType.Passive);
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Repaint:
                if (m_DraggingNativeTitleBarCaption)
                {
                    m_DraggingNativeTitleBarCaption = false;
                }
                EditorGUIUtility.AddCursorRect(titleBarRect, MouseCursor.Arrow);
                break;

            case EventType.MouseDown:
                // If the mouse is inside the title bar rect, we say that we're the hot control
                if (titleBarRect.Contains(evt.mousePosition) && GUIUtility.hotControl == 0 && evt.button == 0)
                {
                    Event.current.Use();
                    m_DraggingNativeTitleBarCaption = true;
                    SendCaptionEvent(m_DraggingNativeTitleBarCaption);
                }
                break;

            case EventType.MouseUp:
                if (m_DraggingNativeTitleBarCaption)
                {
                    break;
                }

                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                    Event.current.Use();
                    Unsupported.SetAllowCursorLock(true, Unsupported.DisallowCursorLockReasons.SizeMove);
                }
                break;

            case EventType.MouseDrag:
                if (m_DraggingNativeTitleBarCaption)
                {
                    break;
                }

                if (GUIUtility.hotControl == id)
                {
                    Vector2 mousePos = evt.mousePosition;
                    if (startDragDpi != GUIUtility.pixelsPerPoint)
                    {
                        // We ignore this mouse event when changing screens in multi monitor setups with
                        // different dpi scalings as funky things might/will happen
                        startDragDpi       = GUIUtility.pixelsPerPoint;
                        s_LastDragMousePos = mousePos;
                    }
                    else
                    {
                        Vector2 movement = mousePos - s_LastDragMousePos;

                        float minimumDelta = 1.0f / GUIUtility.pixelsPerPoint;

                        if (Mathf.Abs(movement.x) >= minimumDelta || Mathf.Abs(movement.y) >= minimumDelta)
                        {
                            Rect dragPosition = position;
                            dragPosition.x += movement.x;
                            dragPosition.y += movement.y;
                            position        = dragPosition;

                            GUI.changed = true;
                        }
                    }
                }
                break;
            }
        }
示例#7
0
        protected override void OldOnGUI()
        {
            ClearBackground();
            // Call reset GUI state as first thing so GUI.color is correct when drawing window decoration.
            EditorGUIUtility.ResetGUIState();

            // Exit if the window was destroyed after entering play mode or on domain-reload.
            if (window == null)
            {
                return;
            }

            // Add CursorRects
            SplitView sp = parent as SplitView;

            if (Event.current.type == EventType.Repaint && sp)
            {
                View view = this;
                while (sp)
                {
                    int id = sp.controlID;

                    if (id == GUIUtility.hotControl || GUIUtility.hotControl == 0)
                    {
                        int idx = sp.IndexOfChild(view);
                        if (sp.vertical)
                        {
                            if (idx != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0, 0, position.width, SplitView.kGrabDist), MouseCursor.SplitResizeUpDown, id);
                            }
                            if (idx != sp.children.Length - 1)
                            {
                                EditorGUIUtility.AddCursorRect(
                                    new Rect(0, position.height - SplitView.kGrabDist, position.width, SplitView.kGrabDist),
                                    MouseCursor.SplitResizeUpDown, id);
                            }
                        }
                        else // horizontal
                        {
                            if (idx != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0, 0, SplitView.kGrabDist, position.height), MouseCursor.SplitResizeLeftRight,
                                                               id);
                            }
                            if (idx != sp.children.Length - 1)
                            {
                                EditorGUIUtility.AddCursorRect(
                                    new Rect(position.width - SplitView.kGrabDist, 0, SplitView.kGrabDist, position.height),
                                    MouseCursor.SplitResizeLeftRight, id);
                            }
                        }
                    }

                    view = sp;
                    sp   = sp.parent as SplitView;
                }

                // reset
                sp = parent as SplitView;
            }
            bool customBorder = false;

            if (window.rootView.GetType() != typeof(MainView))
            {
                customBorder = true;
                if (windowPosition.y == 0)
                {
                    background = "dockareaStandalone";
                }
                else
                {
                    background = "dockarea";
                }
            }
            else
            {
                background = "dockarea";
            }

            if (sp)
            {
                Event e = new Event(Event.current);
                e.mousePosition += new Vector2(position.x, position.y);
                sp.SplitGUI(e);
                if (e.type == EventType.Used)
                {
                    Event.current.Use();
                }
            }
            Rect r = background.margin.Remove(new Rect(0, 0, position.width, position.height));

            r.x = background.margin.left;
            r.y = background.margin.top;
            Rect wPos = windowPosition;
            Rect containerWindowPosition = window.position;

            containerWindowPosition.width  = Mathf.FloorToInt(containerWindowPosition.width);
            containerWindowPosition.height = Mathf.FloorToInt(containerWindowPosition.height);

            float sideBorder = kSideBorders;

            if (wPos.x == 0)
            {
                r.x     -= sideBorder;
                r.width += sideBorder;
            }
            if (wPos.xMax == containerWindowPosition.width)
            {
                r.width += sideBorder;
            }

            if (wPos.yMax == containerWindowPosition.height)
            {
                r.height += customBorder ? 2f : kBottomBorders;
            }

            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, GUIContent.none, 0);
            }

            if (tabStyle == null)
            {
                tabStyle = "dragtab";
            }

            if (m_Panes.Count > 0)
            {
                // Set up the pane's position, so its GUI can use this

                // Contents:
                // scroll it by -1, -1 so we top & left 1px gets culled (they are drawn already by the us, so we want to
                // not have them here (thing that the default skin relies on)
                BeginOffsetArea(new Rect(r.x + 2, r.y + kTabHeight, r.width - 4, r.height - kTabHeight - 2), GUIContent.none, "TabWindowBackground");

                Vector2 basePos = GUIUtility.GUIToScreenPoint(Vector2.zero);
                Rect    p       = borderSize.Remove(position);
                p.x = basePos.x;
                p.y = basePos.y;

                if (selected >= 0 && selected < m_Panes.Count)
                {
                    m_Panes[selected].m_Pos = p;
                }

                EndOffsetArea();
            }

            DragTab(new Rect(r.x + 1, r.y, r.width - kWindowButtonsWidth, kTabHeight), tabStyle);

            // TODO: Make this nice - right now this is meant to be overridden by Panes in Layout if they want something else. Inspector does this
            tabStyle = "dragtab";

            ShowGenericMenu();

            if (m_Panes.Count > 0)
            {
                RenderToHMDIfNecessary(r);
                InvokeOnGUI(r);
            }

            EditorGUI.ShowRepaints();
            Highlighter.ControlHighlightGUI(this);
        }
示例#8
0
 private static void DrawLODButton(LODInfo currentLOD)
 {
     // Make the lod button areas a horizonal resizer
     EditorGUIUtility.AddCursorRect(currentLOD.m_ButtonPosition, MouseCursor.ResizeHorizontal);
 }
示例#9
0
        public override void OnGUI(Rect rect)
        {
            if (FlexibleMenu.s_Styles == null)
            {
                FlexibleMenu.s_Styles = new FlexibleMenu.Styles();
            }
            Event current  = Event.current;
            Rect  viewRect = new Rect(0f, 0f, 1f, this.CalcSize().y);

            this.m_ScrollPosition = GUI.BeginScrollView(rect, this.m_ScrollPosition, viewRect);
            float num = 0f;

            for (int i = 0; i <= this.maxIndex; i++)
            {
                int  num2  = i + 1000000;
                Rect rect2 = new Rect(0f, num, rect.width, 18f);
                bool flag  = Array.IndexOf <int>(this.m_SeperatorIndices, i) >= 0;
                if (this.m_ShowAddNewPresetItem && i == this.m_ItemProvider.Count())
                {
                    this.CreateNewItemButton(rect2);
                }
                else
                {
                    if (this.m_ShowEditWindowForIndex == i)
                    {
                        this.m_ShowEditWindowForIndex = -1;
                        this.EditExistingItem(rect2, i);
                    }
                    EventType type = current.type;
                    switch (type)
                    {
                    case EventType.MouseDown:
                        if (current.button == 0 && rect2.Contains(current.mousePosition))
                        {
                            GUIUtility.hotControl = num2;
                            if (!this.IsDeleteModiferPressed() && current.clickCount == 1)
                            {
                                GUIUtility.hotControl = 0;
                                this.SelectItem(i);
                                base.editorWindow.Close();
                                current.Use();
                            }
                        }
                        goto IL_3B9;

                    case EventType.MouseUp:
                        if (GUIUtility.hotControl == num2)
                        {
                            GUIUtility.hotControl = 0;
                            if (current.button == 0 && rect2.Contains(current.mousePosition))
                            {
                                if (this.AllowDeleteClick(i))
                                {
                                    this.DeleteItem(i);
                                    current.Use();
                                }
                            }
                        }
                        goto IL_3B9;

                    case EventType.MouseMove:
                        if (rect2.Contains(current.mousePosition))
                        {
                            if (this.m_HoverIndex != i)
                            {
                                this.m_HoverIndex = i;
                                this.Repaint();
                            }
                        }
                        else if (this.m_HoverIndex == i)
                        {
                            this.m_HoverIndex = -1;
                            this.Repaint();
                        }
                        goto IL_3B9;

                    case EventType.MouseDrag:
                    case EventType.KeyDown:
                    case EventType.KeyUp:
                    case EventType.ScrollWheel:
IL_114:
                        if (type != EventType.ContextClick)
                        {
                            goto IL_3B9;
                        }
                        if (rect2.Contains(current.mousePosition))
                        {
                            current.Use();
                            if (this.m_ModifyItemUI != null && this.m_ItemProvider.IsModificationAllowed(i))
                            {
                                FlexibleMenu.ItemContextMenu.Show(i, this);
                            }
                        }
                        goto IL_3B9;

                    case EventType.Repaint:
                    {
                        bool isHover = false;
                        if (this.m_HoverIndex == i)
                        {
                            if (rect2.Contains(current.mousePosition))
                            {
                                isHover = true;
                            }
                            else
                            {
                                this.m_HoverIndex = -1;
                            }
                        }
                        if (this.m_ModifyItemUI != null && this.m_ModifyItemUI.IsShowing())
                        {
                            isHover = (this.m_ItemProvider.GetItem(i) == this.m_ModifyItemUI.m_Object);
                        }
                        FlexibleMenu.s_Styles.menuItem.Draw(rect2, GUIContent.Temp(this.m_ItemProvider.GetName(i)), isHover, false, i == this.selectedIndex, false);
                        if (flag)
                        {
                            Rect rect3 = new Rect(rect2.x + 4f, rect2.y + rect2.height + 4f, rect2.width - 8f, 1f);
                            FlexibleMenu.DrawRect(rect3, (!EditorGUIUtility.isProSkin) ? new Color(0.6f, 0.6f, 0.6f, 1.333f) : new Color(0.32f, 0.32f, 0.32f, 1.333f));
                        }
                        if (this.AllowDeleteClick(i))
                        {
                            EditorGUIUtility.AddCursorRect(rect2, MouseCursor.ArrowMinus);
                        }
                        goto IL_3B9;
                    }
                    }
                    goto IL_114;
IL_3B9:
                    num += 18f;
                    if (flag)
                    {
                        num += 8f;
                    }
                }
            }
            GUI.EndScrollView();
        }
        // This is the slider behavior for resizing the preview area
        public static float PixelPreciseCollapsibleSlider(int id, Rect position, float value, float min, float max, ref bool expanded)
        {
            Event evt = Event.current;

            if (evt.type == EventType.Layout)
            {
                return(value);
            }

            var mousePosition = GUIClip.UnclipToWindow(evt.mousePosition);

            mousePosition.y -= Editor.k_HeaderHeight;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (GUIUtility.hotControl == 0 && evt.button == 0 && position.Contains(mousePosition))
                {
                    GUIUtility.hotControl = id;
                    s_MouseDownLocation   = mousePosition.y;
                    s_MouseDownValue      = value;
                    s_MouseDragged        = false;
                    evt.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    value          = Mathf.Clamp(mousePosition.y - s_MouseDownLocation + s_MouseDownValue, min, max - 1);
                    GUI.changed    = true;
                    s_MouseDragged = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                    if (!s_MouseDragged)
                    {
                        expanded = !expanded;
                    }
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                const float x = 0f;
                const float y = 0f;

                if (GUIUtility.hotControl == 0)
                {
                    EditorGUIUtility.AddCursorRect(new Rect(x, y, position.width, position.height), MouseCursor.SplitResizeUpDown);
                }

                if (GUIUtility.hotControl == id)
                {
                    const int yMove      = 100;
                    const int heightMove = yMove * 2;
                    EditorGUIUtility.AddCursorRect(new Rect(x, y - yMove, position.width, position.height + heightMove), MouseCursor.SplitResizeUpDown);
                }
                break;
            }
            return(value);
        }
示例#11
0
        /**
         *  Static function to handle the GUI and User input related to the cascade slider.
         *
         *  @param  normalizedCascadePartition      The array of partition sizes in the range 0.0f - 1.0f; expects ONE entry if cascades = 2, and THREE if cascades=4
         *                                          The last entry will be automatically determined by summing up the array, and doing 1.0f - sum
         */
        public static void HandleCascadeSliderGUI(ref float[] normalizedCascadePartitions)
        {
            GUILayout.Label("Cascade splits");

            // get the inspector width since we need it while drawing the partition rects.
            // Only way currently is to reserve the block in the layout using GetRect(), and then immediately drawing the empty box
            // to match the call to GetRect.
            // From this point on, we move to non-layout based code.
            var sliderRect = GUILayoutUtility.GetRect(GUIContent.none
                                                      , s_CascadeSliderBG
                                                      , GUILayout.Height(kSliderbarTopMargin + kSliderbarHeight + kSliderbarBottomMargin)
                                                      , GUILayout.ExpandWidth(true));

            GUI.Box(sliderRect, GUIContent.none);

            float currentX            = sliderRect.x;
            float cascadeBoxStartY    = sliderRect.y + kSliderbarTopMargin;
            float cascadeSliderWidth  = sliderRect.width - (normalizedCascadePartitions.Length * kPartitionHandleWidth);
            Color origTextColor       = GUI.color;
            Color origBackgroundColor = GUI.backgroundColor;
            int   colorIndex          = -1;

            // setup the array locally with the last partition
            float[] adjustedCascadePartitions = new float[normalizedCascadePartitions.Length + 1];
            Array.Copy(normalizedCascadePartitions, adjustedCascadePartitions, normalizedCascadePartitions.Length);
            adjustedCascadePartitions[adjustedCascadePartitions.Length - 1] = 1.0f - normalizedCascadePartitions.Sum();


            // check for user input on any of the partition handles
            // this mechanism gets the current event in the queue... make sure that the mouse is over our control before consuming the event
            int   sliderControlId         = GUIUtility.GetControlID(s_CascadeSliderId, FocusType.Passive);
            Event currentEvent            = Event.current;
            int   hotPartitionHandleIndex = -1; // the index of any partition handle that we are hovering over or dragging

            // draw each cascade partition
            for (int i = 0; i < adjustedCascadePartitions.Length; ++i)
            {
                float currentPartition = adjustedCascadePartitions[i];

                colorIndex          = (colorIndex + 1) % kCascadeColors.Length;
                GUI.backgroundColor = kCascadeColors[colorIndex];
                float boxLength = (cascadeSliderWidth * currentPartition);

                // main cascade box
                Rect partitionRect = new Rect(currentX, cascadeBoxStartY, boxLength, kSliderbarHeight);
                GUI.Box(partitionRect, GUIContent.none, s_CascadeSliderBG);
                currentX += boxLength;

                // cascade box percentage text
                GUI.color = Color.white;
                Rect textRect    = partitionRect;
                var  cascadeText = string.Format("{0}\n{1:F1}%", i, currentPartition * 100.0f);

                GUI.Label(textRect, GUIContent.Temp(cascadeText, cascadeText), s_TextCenteredStyle);

                // no need to draw the partition handle for last box
                if (i == adjustedCascadePartitions.Length - 1)
                {
                    break;
                }

                // partition handle
                GUI.backgroundColor = Color.black;
                Rect handleRect = partitionRect;
                handleRect.x     = currentX;
                handleRect.width = kPartitionHandleWidth;
                GUI.Box(handleRect, GUIContent.none, s_CascadeSliderBG);
                // we want a thin handle visually (since wide black bar looks bad), but a slightly larger
                // hit area for easier manipulation
                Rect handleHitRect = handleRect;
                handleHitRect.xMin -= kPartitionHandleExtraHitAreaWidth;
                handleHitRect.xMax += kPartitionHandleExtraHitAreaWidth;
                if (handleHitRect.Contains(currentEvent.mousePosition))
                {
                    hotPartitionHandleIndex = i;
                }

                // add regions to slider where the cursor changes to Resize-Horizontal
                if (s_DragCache == null)
                {
                    EditorGUIUtility.AddCursorRect(handleHitRect, MouseCursor.ResizeHorizontal, sliderControlId);
                }

                currentX += kPartitionHandleWidth;
            }

            GUI.color           = origTextColor;
            GUI.backgroundColor = origBackgroundColor;

            EventType eventType = currentEvent.GetTypeForControl(sliderControlId);

            switch (eventType)
            {
            case EventType.MouseDown:
                if (hotPartitionHandleIndex >= 0)
                {
                    s_DragCache = new DragCache(hotPartitionHandleIndex, normalizedCascadePartitions[hotPartitionHandleIndex], currentEvent.mousePosition);
                    if (GUIUtility.hotControl == 0)
                    {
                        GUIUtility.hotControl = sliderControlId;
                    }
                    currentEvent.Use();

                    // Switch active scene view into shadow cascades visualization mode, once we start
                    // tweaking cascade splits.
                    if (s_RestoreSceneView == null)
                    {
                        s_RestoreSceneView = SceneView.lastActiveSceneView;
                        if (s_RestoreSceneView != null)
                        {
                            s_OldSceneDrawMode            = s_RestoreSceneView.cameraMode;
                            s_OldSceneLightingMode        = s_RestoreSceneView.m_SceneLighting;
                            s_RestoreSceneView.cameraMode = SceneView.GetBuiltinCameraMode(DrawCameraMode.ShadowCascades);
                        }
                    }
                }
                break;

            case EventType.MouseUp:
                // mouseUp event anywhere should release the hotcontrol (if it belongs to us), drags (if any)
                if (GUIUtility.hotControl == sliderControlId)
                {
                    GUIUtility.hotControl = 0;
                    currentEvent.Use();
                }
                s_DragCache = null;

                // Restore previous scene view drawing mode once we stop tweaking cascade splits.
                if (s_RestoreSceneView != null)
                {
                    s_RestoreSceneView.cameraMode      = s_OldSceneDrawMode;
                    s_RestoreSceneView.m_SceneLighting = s_OldSceneLightingMode;
                    s_RestoreSceneView = null;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != sliderControlId)
                {
                    break;
                }

                // convert the mouse movement to normalized cascade width. Make sure that we are safe to apply the delta before using it.
                float delta = (currentEvent.mousePosition - s_DragCache.m_LastCachedMousePosition).x / cascadeSliderWidth;
                bool  isLeftPartitionHappy  = ((adjustedCascadePartitions[s_DragCache.m_ActivePartition] + delta) > 0.0f);
                bool  isRightPartitionHappy = ((adjustedCascadePartitions[s_DragCache.m_ActivePartition + 1] - delta) > 0.0f);
                if (isLeftPartitionHappy && isRightPartitionHappy)
                {
                    s_DragCache.m_NormalizedPartitionSize += delta;
                    normalizedCascadePartitions[s_DragCache.m_ActivePartition] = s_DragCache.m_NormalizedPartitionSize;
                    if (s_DragCache.m_ActivePartition < normalizedCascadePartitions.Length - 1)
                    {
                        normalizedCascadePartitions[s_DragCache.m_ActivePartition + 1] -= delta;
                    }
                    GUI.changed = true;
                }
                s_DragCache.m_LastCachedMousePosition = currentEvent.mousePosition;
                currentEvent.Use();
                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();
         }
     }
 }
        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 override void OnInspectorGUI()
        {
            if (AssetStoreAssetInspector.styles == null)
            {
                AssetStoreAssetInspector.s_SharedAssetStoreAssetInspector = this;
                AssetStoreAssetInspector.styles = new AssetStoreAssetInspector.Styles();
            }
            AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset();

            AssetStoreAsset.PreviewInfo previewInfo = null;
            if (firstAsset != null)
            {
                previewInfo = firstAsset.previewInfo;
            }
            if (firstAsset != null)
            {
                this.target.name = string.Format("Asset Store: {0}", firstAsset.name);
            }
            else
            {
                this.target.name = "Asset Store";
            }
            EditorGUILayout.BeginVertical(new GUILayoutOption[0]);
            bool enabled = GUI.enabled;

            GUI.enabled = (firstAsset != null && firstAsset.packageID != 0);
            if (AssetStoreAssetInspector.OfflineNoticeEnabled)
            {
                Color color = GUI.color;
                GUI.color = Color.yellow;
                GUILayout.Label("Network is offline", new GUILayoutOption[0]);
                GUI.color = color;
            }
            if (firstAsset != null)
            {
                string label = (firstAsset.className != null) ? firstAsset.className.Split(new char[]
                {
                    ' '
                }, 2)[0] : string.Empty;
                bool flag = firstAsset.id == -firstAsset.packageID;
                if (flag)
                {
                    label = "Package";
                }
                if (firstAsset.HasLivePreview)
                {
                    label = firstAsset.Preview.GetType().Name;
                }
                EditorGUILayout.LabelField("Type", label, new GUILayoutOption[0]);
                if (flag)
                {
                    this.packageInfoShown = true;
                }
                else
                {
                    EditorGUILayout.Separator();
                    this.packageInfoShown = EditorGUILayout.Foldout(this.packageInfoShown, "Part of package");
                }
                if (this.packageInfoShown)
                {
                    EditorGUILayout.LabelField("Name", (previewInfo != null) ? previewInfo.packageName : "-", new GUILayoutOption[0]);
                    EditorGUILayout.LabelField("Version", (previewInfo != null) ? previewInfo.packageVersion : "-", new GUILayoutOption[0]);
                    string label2 = (previewInfo != null) ? ((firstAsset.price == null || !(firstAsset.price != string.Empty)) ? "free" : firstAsset.price) : "-";
                    EditorGUILayout.LabelField("Price", label2, new GUILayoutOption[0]);
                    string label3 = (previewInfo == null || previewInfo.packageRating < 0) ? "-" : (previewInfo.packageRating.ToString() + " of 5");
                    EditorGUILayout.LabelField("Rating", label3, new GUILayoutOption[0]);
                    EditorGUILayout.LabelField("Size", (previewInfo != null) ? AssetStoreAssetInspector.intToSizeString(previewInfo.packageSize) : "-", new GUILayoutOption[0]);
                    string label4 = (previewInfo == null || previewInfo.packageAssetCount < 0) ? "-" : previewInfo.packageAssetCount.ToString();
                    EditorGUILayout.LabelField("Asset count", label4, new GUILayoutOption[0]);
                    GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    EditorGUILayout.PrefixLabel("Web page");
                    bool flag2    = previewInfo != null && previewInfo.packageShortUrl != null && previewInfo.packageShortUrl != string.Empty;
                    bool enabled2 = GUI.enabled;
                    GUI.enabled = flag2;
                    if (GUILayout.Button((!flag2) ? EditorGUIUtility.TempContent("-") : new GUIContent(previewInfo.packageShortUrl, "View in browser"), AssetStoreAssetInspector.styles.link, new GUILayoutOption[0]))
                    {
                        Application.OpenURL(previewInfo.packageShortUrl);
                    }
                    if (GUI.enabled)
                    {
                        EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
                    }
                    GUI.enabled = enabled2;
                    GUILayout.EndHorizontal();
                    EditorGUILayout.LabelField("Publisher", (previewInfo != null) ? previewInfo.publisherName : "-", new GUILayoutOption[0]);
                }
                if (firstAsset.id != 0)
                {
                    GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    GUILayout.FlexibleSpace();
                    string text;
                    if (previewInfo != null && previewInfo.isDownloadable)
                    {
                        text = "Import package";
                    }
                    else
                    {
                        text = "Buy for " + firstAsset.price;
                    }
                    bool enabled3 = GUI.enabled;
                    bool flag3    = previewInfo != null && previewInfo.buildProgress >= 0f;
                    bool flag4    = previewInfo != null && previewInfo.downloadProgress >= 0f;
                    if (flag3 || flag4 || previewInfo == null)
                    {
                        text        = string.Empty;
                        GUI.enabled = false;
                    }
                    if (GUILayout.Button(text, new GUILayoutOption[]
                    {
                        GUILayout.Height(40f),
                        GUILayout.Width(120f)
                    }))
                    {
                        if (previewInfo.isDownloadable)
                        {
                            this.ImportPackage(firstAsset);
                        }
                        else
                        {
                            this.InitiateBuySelected();
                        }
                        GUIUtility.ExitGUI();
                    }
                    if (Event.current.type == EventType.Repaint)
                    {
                        Rect lastRect = GUILayoutUtility.GetLastRect();
                        lastRect.height -= 4f;
                        float width = lastRect.width;
                        lastRect.width = lastRect.height;
                        lastRect.y    += 2f;
                        lastRect.x    += 2f;
                        if (flag3 || flag4)
                        {
                            lastRect.width = width - lastRect.height - 4f;
                            lastRect.x    += lastRect.height;
                            EditorGUI.ProgressBar(lastRect, (!flag4) ? previewInfo.buildProgress : previewInfo.downloadProgress, (!flag4) ? "Building" : "Downloading");
                        }
                    }
                    GUI.enabled = enabled3;
                    GUILayout.Space(4f);
                    if (GUILayout.Button("Open Asset Store", new GUILayoutOption[]
                    {
                        GUILayout.Height(40f),
                        GUILayout.Width(120f)
                    }))
                    {
                        AssetStoreAssetInspector.OpenItemInAssetStore(firstAsset);
                        GUIUtility.ExitGUI();
                    }
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }
                GUILayout.FlexibleSpace();
            }
            EditorWrapper previewEditor = this.previewEditor;

            if (previewEditor != null && firstAsset != null && firstAsset.HasLivePreview)
            {
                previewEditor.OnAssetStoreInspectorGUI();
            }
            GUI.enabled = enabled;
            EditorGUILayout.EndVertical();
        }
示例#15
0
        internal static void DoMinMaxSlider(Rect position, int id, ref float value, ref float size, float visualStart, float visualEnd, float startLimit, float endLimit, GUIStyle slider, GUIStyle thumb, bool horiz)
        {
            Event evt = Event.current;
            bool  usePageScrollbars = size == 0;

            float minVisual = Mathf.Min(visualStart, visualEnd);
            float maxVisual = Mathf.Max(visualStart, visualEnd);
            float minLimit  = Mathf.Min(startLimit, endLimit);
            float maxLimit  = Mathf.Max(startLimit, endLimit);

            MinMaxSliderState state = s_MinMaxSliderState;

            if (GUIUtility.hotControl == id && state != null)
            {
                minVisual = state.dragStartLimit;
                minLimit  = state.dragStartLimit;
                maxVisual = state.dragEndLimit;
                maxLimit  = state.dragEndLimit;
            }

            float minSize = 0;

            float displayValue = Mathf.Clamp(value, minVisual, maxVisual);
            float displaySize  = Mathf.Clamp(value + size, minVisual, maxVisual) - displayValue;

            float sign = visualStart > visualEnd ? -1 : 1;


            if (slider == null || thumb == null)
            {
                return;
            }

            // Figure out the rects
            float pixelsPerValue;
            float mousePosition;
            Rect  thumbRect;
            Rect  thumbMinRect, thumbMaxRect;
            Rect  contentRect = thumb.margin.Remove(slider.padding.Remove(position));
            float thumbSize   = ThumbSize(horiz, thumb);

            if (horiz)
            {
                float thumbHeight = (thumb.fixedHeight != 0 ? thumb.fixedHeight : contentRect.height);

                pixelsPerValue = (position.width - slider.padding.horizontal - thumbSize) / (maxVisual - minVisual);
                thumbRect      = new Rect(
                    (displayValue - minVisual) * pixelsPerValue + contentRect.x,
                    contentRect.y,
                    displaySize * pixelsPerValue + thumbSize,
                    thumbHeight);
                thumbMinRect  = new Rect(thumbRect.x, thumbRect.y, thumb.padding.left, thumbRect.height);
                thumbMaxRect  = new Rect(thumbRect.xMax - thumb.padding.right, thumbRect.y, thumb.padding.right, thumbRect.height);
                mousePosition = evt.mousePosition.x - position.x;
            }
            else
            {
                float thumbWidth = (thumb.fixedWidth != 0 ? thumb.fixedWidth : contentRect.width);

                pixelsPerValue = (position.height - slider.padding.vertical - thumbSize) / (maxVisual - minVisual);
                thumbRect      = new Rect(
                    contentRect.x,
                    (displayValue - minVisual) * pixelsPerValue + contentRect.y,
                    thumbWidth,
                    displaySize * pixelsPerValue + thumbSize);
                thumbMinRect  = new Rect(thumbRect.x, thumbRect.y, thumbRect.width, thumb.padding.top);
                thumbMaxRect  = new Rect(thumbRect.x, thumbRect.yMax - thumb.padding.bottom, thumbRect.width, thumb.padding.bottom);
                mousePosition = evt.mousePosition.y - position.y;
            }

            float mousePos;
            float thumbPos;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                // if the click is outside this control, just bail out...
                if (evt.button != 0 || !position.Contains(evt.mousePosition) || minVisual - maxVisual == 0)
                {
                    return;
                }
                if (state == null)
                {
                    state = s_MinMaxSliderState = new MinMaxSliderState();
                }

                // These are required to be set whenever we grab hotcontrol, regardless of if we actually drag or not. (case 585577)
                state.dragStartLimit = startLimit;
                state.dragEndLimit   = endLimit;

                if (thumbRect.Contains(evt.mousePosition))
                {
                    // We have a mousedown on the thumb
                    // Record where we're draging from, so the user can get back.
                    state.dragStartPos            = mousePosition;
                    state.dragStartValue          = value;
                    state.dragStartSize           = size;
                    state.dragStartValuesPerPixel = pixelsPerValue;
                    if (thumbMinRect.Contains(evt.mousePosition))
                    {
                        state.whereWeDrag = 1;
                    }
                    else if (thumbMaxRect.Contains(evt.mousePosition))
                    {
                        state.whereWeDrag = 2;
                    }
                    else
                    {
                        state.whereWeDrag = 0;
                    }

                    GUIUtility.hotControl = id;
                    evt.Use();
                    return;
                }
                else
                {
                    // We're outside the thumb, but inside the trough.
                    // If we have no background, we just bail out.
                    if (slider == GUIStyle.none)
                    {
                        return;
                    }

                    // If we have a scrollSize, we do pgup/pgdn style movements
                    // if not, we just snap to the current position and begin tracking
                    if (size != 0 && usePageScrollbars)
                    {
                        if (horiz)
                        {
                            if (mousePosition > thumbRect.xMax - position.x)
                            {
                                value += size * sign * .9f;
                            }
                            else
                            {
                                value -= size * sign * .9f;
                            }
                        }
                        else
                        {
                            if (mousePosition > thumbRect.yMax - position.y)
                            {
                                value += size * sign * .9f;
                            }
                            else
                            {
                                value -= size * sign * .9f;
                            }
                        }
                        state.whereWeDrag    = 0;
                        GUI.changed          = true;
                        s_NextScrollStepTime = System.DateTime.Now.AddMilliseconds(kFirstScrollWait);

                        mousePos = horiz ? evt.mousePosition.x : evt.mousePosition.y;
                        thumbPos = horiz ? thumbRect.x : thumbRect.y;

                        state.whereWeDrag = mousePos > thumbPos ? 4 : 3;
                    }
                    else
                    {
                        if (horiz)
                        {
                            value = ((float)mousePosition - thumbRect.width * .5f) / pixelsPerValue + minVisual - size * .5f;
                        }
                        else
                        {
                            value = ((float)mousePosition - thumbRect.height * .5f) / pixelsPerValue + minVisual - size * .5f;
                        }
                        state.dragStartPos            = mousePosition;
                        state.dragStartValue          = value;
                        state.dragStartSize           = size;
                        state.dragStartValuesPerPixel = pixelsPerValue;
                        state.whereWeDrag             = 0;
                        GUI.changed = true;
                    }
                    GUIUtility.hotControl = id;
                    value = Mathf.Clamp(value, minLimit, maxLimit - size);
                    evt.Use();
                    return;
                }

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != id)
                {
                    return;
                }

                // Recalculate the value from the mouse position. this has the side effect that values are relative to the
                // click point - no matter where inside the trough the original value was. Also means user can get back original value
                // if he drags back to start position.
                float deltaVal = (mousePosition - state.dragStartPos) / state.dragStartValuesPerPixel;
                switch (state.whereWeDrag)
                {
                case 0:         // normal drag
                    value = Mathf.Clamp(state.dragStartValue + deltaVal, minLimit, maxLimit - size);
                    break;

                case 1:        // min size drag
                    value = state.dragStartValue + deltaVal;
                    size  = state.dragStartSize - deltaVal;
                    if (value < minLimit)
                    {
                        size -= minLimit - value;
                        value = minLimit;
                    }
                    if (size < minSize)
                    {
                        value -= minSize - size;
                        size   = minSize;
                    }
                    break;

                case 2:        // max size drag
                    size = state.dragStartSize + deltaVal;
                    if (value + size > maxLimit)
                    {
                        size = maxLimit - value;
                    }
                    if (size < minSize)
                    {
                        size = minSize;
                    }
                    break;
                }
                GUI.changed = true;
                evt.Use();
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    evt.Use();
                    GUIUtility.hotControl = 0;
                }
                break;

            case EventType.Repaint:
                slider.Draw(position, GUIContent.none, id);
                thumb.Draw(thumbRect, GUIContent.none, id);

                EditorGUIUtility.AddCursorRect(thumbMinRect, horiz ? MouseCursor.ResizeHorizontal : MouseCursor.ResizeVertical, state != null && state.whereWeDrag == 1 ? id : -1);
                EditorGUIUtility.AddCursorRect(thumbMaxRect, horiz ? MouseCursor.ResizeHorizontal : MouseCursor.ResizeVertical, state != null && state.whereWeDrag == 2 ? id : -1);

                // if the mouse is outside this control, just bail out...
                if (GUIUtility.hotControl != id ||
                    !position.Contains(evt.mousePosition) || minVisual - maxVisual == 0)
                {
                    return;
                }

                if (thumbRect.Contains(evt.mousePosition))
                {
                    if (state != null && (state.whereWeDrag == 3 || state.whereWeDrag == 4))     // if was scrolling with "through" and the thumb reached mouse - sliding action over
                    {
                        GUIUtility.hotControl = 0;
                    }
                    return;
                }


                if (System.DateTime.Now < s_NextScrollStepTime)
                {
                    return;
                }

                mousePos = horiz ? evt.mousePosition.x : evt.mousePosition.y;
                thumbPos = horiz ? thumbRect.x : thumbRect.y;

                int currentSide = mousePos > thumbPos ? 4 : 3;
                if (state != null && currentSide != state.whereWeDrag)
                {
                    return;
                }

                // If we have a scrollSize, we do pgup/pgdn style movements
                if (size != 0 && usePageScrollbars)
                {
                    if (horiz)
                    {
                        if (mousePosition > thumbRect.xMax - position.x)
                        {
                            value += size * sign * .9f;
                        }
                        else
                        {
                            value -= size * sign * .9f;
                        }
                    }
                    else
                    {
                        if (mousePosition > thumbRect.yMax - position.y)
                        {
                            value += size * sign * .9f;
                        }
                        else
                        {
                            value -= size * sign * .9f;
                        }
                    }
                    if (state != null)
                    {
                        state.whereWeDrag = -1;
                    }
                    GUI.changed = true;
                }
                value = Mathf.Clamp(value, minLimit, maxLimit - size);

                s_NextScrollStepTime = System.DateTime.Now.AddMilliseconds(kScrollWait);
                break;
            }
        }
        public static void HandleCascadeSliderGUI(ref float[] normalizedCascadePartitions)
        {
            GUILayout.Label("Cascade splits", new GUILayoutOption[0]);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Height(28f), GUILayout.ExpandWidth(true) };
            Rect position             = GUILayoutUtility.GetRect(GUIContent.none, s_CascadeSliderBG, options);

            GUI.Box(position, GUIContent.none);
            float x               = position.x;
            float y               = position.y + 2f;
            float num3            = position.width - (normalizedCascadePartitions.Length * 2);
            Color color           = GUI.color;
            Color backgroundColor = GUI.backgroundColor;
            int   index           = -1;

            float[] destinationArray = new float[normalizedCascadePartitions.Length + 1];
            Array.Copy(normalizedCascadePartitions, destinationArray, normalizedCascadePartitions.Length);
            destinationArray[destinationArray.Length - 1] = 1f - normalizedCascadePartitions.Sum();
            int   controlID       = GUIUtility.GetControlID(s_CascadeSliderId, FocusType.Passive);
            Event current         = Event.current;
            int   activePartition = -1;

            for (int i = 0; i < destinationArray.Length; i++)
            {
                float num8 = destinationArray[i];
                index = (index + 1) % kCascadeColors.Length;
                GUI.backgroundColor = kCascadeColors[index];
                float width = num3 * num8;
                Rect  rect2 = new Rect(x, y, width, 24f);
                GUI.Box(rect2, GUIContent.none, s_CascadeSliderBG);
                x        += width;
                GUI.color = Color.white;
                Rect   rect3 = rect2;
                string t     = $"{i}
{num8 * 100f:F1}%";
                GUI.Label(rect3, GUIContent.Temp(t, t), s_TextCenteredStyle);
                if (i == (destinationArray.Length - 1))
                {
                    break;
                }
                GUI.backgroundColor = Color.black;
                Rect rect4 = rect2;
                rect4.x     = x;
                rect4.width = 2f;
                GUI.Box(rect4, GUIContent.none, s_CascadeSliderBG);
                Rect rect5 = rect4;
                rect5.xMin -= 2f;
                rect5.xMax += 2f;
                if (rect5.Contains(current.mousePosition))
                {
                    activePartition = i;
                }
                if (s_DragCache == null)
                {
                    EditorGUIUtility.AddCursorRect(rect5, MouseCursor.ResizeHorizontal, controlID);
                }
                x += 2f;
            }
            GUI.color           = color;
            GUI.backgroundColor = backgroundColor;
            EventType typeForControl = current.GetTypeForControl(controlID);

            if (typeForControl == EventType.MouseDown)
            {
                if (activePartition >= 0)
                {
                    s_DragCache = new DragCache(activePartition, normalizedCascadePartitions[activePartition], current.mousePosition);
                    if (GUIUtility.hotControl == 0)
                    {
                        GUIUtility.hotControl = controlID;
                    }
                    current.Use();
                    if (s_RestoreSceneView == null)
                    {
                        s_RestoreSceneView = SceneView.lastActiveSceneView;
                        if (s_RestoreSceneView != null)
                        {
                            s_OldSceneDrawMode            = s_RestoreSceneView.renderMode;
                            s_OldSceneLightingMode        = s_RestoreSceneView.m_SceneLighting;
                            s_RestoreSceneView.renderMode = DrawCameraMode.ShadowCascades;
                        }
                    }
                }
            }
            else if (typeForControl == EventType.MouseUp)
            {
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                }
                s_DragCache = null;
                if (s_RestoreSceneView != null)
                {
                    s_RestoreSceneView.renderMode      = s_OldSceneDrawMode;
                    s_RestoreSceneView.m_SceneLighting = s_OldSceneLightingMode;
                    s_RestoreSceneView = null;
                }
            }
            else if ((typeForControl == EventType.MouseDrag) && (GUIUtility.hotControl == controlID))
            {
                Vector2 vector = current.mousePosition - s_DragCache.m_LastCachedMousePosition;
                float   num10  = vector.x / num3;
                bool    flag   = (destinationArray[s_DragCache.m_ActivePartition] + num10) > 0f;
                bool    flag2  = (destinationArray[s_DragCache.m_ActivePartition + 1] - num10) > 0f;
                if (flag && flag2)
                {
                    s_DragCache.m_NormalizedPartitionSize += num10;
                    normalizedCascadePartitions[s_DragCache.m_ActivePartition] = s_DragCache.m_NormalizedPartitionSize;
                    if (s_DragCache.m_ActivePartition < (normalizedCascadePartitions.Length - 1))
                    {
                        normalizedCascadePartitions[s_DragCache.m_ActivePartition + 1] -= num10;
                    }
                    GUI.changed = true;
                }
                s_DragCache.m_LastCachedMousePosition = current.mousePosition;
                current.Use();
            }
        }
示例#17
0
        private void OnGUI()
        {
            if (base.position.size * EditorGUIUtility.pixelsPerPoint != this.m_LastWindowPixelSize)
            {
                this.UpdateZoomAreaAndParent();
            }
            this.DoToolbarGUI();
            this.CopyDimensionsToParentView();
            EditorGUIUtility.AddCursorRect(this.viewInWindow, MouseCursor.CustomCursor);
            EventType type = Event.current.type;

            if (type == EventType.MouseDown && this.viewInWindow.Contains(Event.current.mousePosition))
            {
                this.AllowCursorLockAndHide(true);
            }
            else if (type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                Unsupported.SetAllowCursorLock(false);
            }
            bool flag = !EditorApplication.isPlaying || EditorApplication.isPaused;

            this.m_ZoomArea.hSlider          = (flag && this.m_ZoomArea.shownArea.width < this.targetInContent.width);
            this.m_ZoomArea.vSlider          = (flag && this.m_ZoomArea.shownArea.height < this.targetInContent.height);
            this.m_ZoomArea.enableMouseInput = flag;
            this.ConfigureZoomArea();
            Vector2 mousePosition  = Event.current.mousePosition;
            Vector2 mousePosition2 = this.WindowToGameMousePosition(mousePosition);

            GUI.color = Color.white;
            EventType type2 = Event.current.type;

            this.m_ZoomArea.BeginViewGUI();
            if (type == EventType.Repaint)
            {
                GUI.Box(this.m_ZoomArea.drawRect, GUIContent.none, GameView.Styles.gameViewBackgroundStyle);
                Vector2 s_EditorScreenPointOffset = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState savedGUIState = SavedGUIState.Create();
                this.ConfigureTargetTexture((int)this.targetSize.x, (int)this.targetSize.y);
                if (!EditorApplication.isPlaying)
                {
                    this.ClearTargetTexture();
                }
                int targetDisplay = 0;
                if (this.ShouldShowMultiDisplayOption())
                {
                    targetDisplay = this.m_TargetDisplay;
                }
                if (this.m_TargetTexture.IsCreated())
                {
                    EditorGUIUtility.RenderGameViewCamerasInternal(this.m_TargetTexture, targetDisplay, GUIClip.Unclip(this.viewInWindow), mousePosition2, this.m_Gizmos);
                    savedGUIState.ApplyAndForget();
                    GUIUtility.s_EditorScreenPointOffset = s_EditorScreenPointOffset;
                    GUI.BeginGroup(this.m_ZoomArea.drawRect);
                    GL.sRGBWrite = (this.m_CurrentColorSpace == ColorSpace.Linear);
                    GUI.DrawTexture(this.deviceFlippedTargetInView, this.m_TargetTexture, ScaleMode.StretchToFill, false);
                    GL.sRGBWrite = false;
                    GUI.EndGroup();
                }
            }
            else if (type != EventType.Layout && type != EventType.Used)
            {
                if (WindowLayout.s_MaximizeKey.activated && (!EditorApplication.isPlaying || EditorApplication.isPaused))
                {
                    return;
                }
                bool flag2 = this.viewInWindow.Contains(Event.current.mousePosition);
                if (Event.current.rawType == EventType.MouseDown && !flag2)
                {
                    return;
                }
                Event.current.mousePosition = mousePosition2;
                Event.current.displayIndex  = this.m_TargetDisplay;
                EditorGUIUtility.QueueGameViewInputEvent(Event.current);
                bool flag3 = true;
                if (Event.current.rawType == EventType.MouseUp && !flag2)
                {
                    flag3 = false;
                }
                if (type == EventType.ExecuteCommand || type == EventType.ValidateCommand)
                {
                    flag3 = false;
                }
                if (flag3)
                {
                    Event.current.Use();
                }
                else
                {
                    Event.current.mousePosition = mousePosition;
                }
            }
            this.m_ZoomArea.EndViewGUI();
            if (type2 == EventType.ScrollWheel && Event.current.type == EventType.Used)
            {
                EditorApplication.update  = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(this.SnapZoomDelayed));
                EditorApplication.update  = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(this.SnapZoomDelayed));
                GameView.s_LastScrollTime = EditorApplication.timeSinceStartup;
            }
            this.EnforceZoomAreaConstraints();
            if (this.m_TargetTexture)
            {
                if (this.m_ZoomArea.scale.y < 1f)
                {
                    this.m_TargetTexture.filterMode = FilterMode.Bilinear;
                }
                else
                {
                    this.m_TargetTexture.filterMode = FilterMode.Point;
                }
            }
            if (!EditorGUIUtility.IsDisplayReferencedByCameras(this.m_TargetDisplay))
            {
                GUI.Label(this.warningPosition, GUIContent.none, EditorStyles.notificationBackground);
                string arg = (!this.ShouldShowMultiDisplayOption()) ? string.Empty : DisplayUtility.GetDisplayNames()[this.m_TargetDisplay].text;
                string t   = string.Format("{0}\nNo cameras rendering", arg);
                EditorGUI.DoDropShadowLabel(this.warningPosition, EditorGUIUtility.TempContent(t), EditorStyles.notificationText, 0.3f);
            }
            if (this.m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }
示例#18
0
        public void OnGUI()
        {
            var evt             = Event.current;
            var mainLayoutWidth = position.width - Styles.mainLayout.margin.horizontal;

            using (new GUILayout.VerticalScope(Styles.mainLayout))
            {
                GUILayout.Label(Styles.HeaderLogo, Styles.HeaderLayout);

                using (new GUILayout.HorizontalScope(Styles.versionLayout))
                {
                    ListenForSecretCodes();

                    string extensionVersion = FormatExtensionVersionString();

                    m_ShowDetailedVersion |= evt.alt;
                    if (m_ShowDetailedVersion)
                    {
                        int      t      = InternalEditorUtility.GetUnityVersionDate();
                        DateTime dt     = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                        string   branch = InternalEditorUtility.GetUnityBuildBranch();
                        EditorGUILayout.SelectableLabel(
                            string.Format("{0}{1}\nRevision: {2} {3}\nBuilt: {4:r}",
                                          InternalEditorUtility.GetUnityDisplayVersionVerbose(), extensionVersion,
                                          branch, InternalEditorUtility.GetUnityBuildHash(), dt.AddSeconds(t)),
                            Styles.versionStyle, GUILayout.MaxWidth(mainLayoutWidth), GUILayout.Height(38f));
                    }
                    else
                    {
                        GUILayout.Label(string.Format("{0}{1}", InternalEditorUtility.GetUnityDisplayVersion(), extensionVersion), Styles.versionStyle);
                    }

                    if (evt.type == EventType.ValidateCommand)
                    {
                        return;
                    }
                }

                using (new GUILayout.HorizontalScope(Styles.creditsLayout))
                {
                    float chunkOffset    = m_TextYPos;
                    Rect  scrollAreaRect = GUILayoutUtility.GetRect(0, mainLayoutWidth, 75f, position.height, GUILayout.ExpandHeight(true));
                    GUI.BeginGroup(scrollAreaRect);
                    foreach (string nameChunk in AboutWindowNames.Names(null, true))
                    {
                        chunkOffset = DoCreditsNameChunk(nameChunk, mainLayoutWidth, chunkOffset);
                    }
                    chunkOffset          = DoCreditsNameChunk(kSpecialThanksNames, mainLayoutWidth, chunkOffset);
                    m_TotalCreditsHeight = chunkOffset - m_TextYPos;
                    GUI.EndGroup();

                    HandleScrollEvents(evt, scrollAreaRect);
                }

                using (new GUILayout.HorizontalScope(Styles.poweredLayout))
                {
                    var poweredBySectionMaxWidth = (mainLayoutWidth - Styles.poweredSectionLayout.margin.horizontal * 2) / 2f;
                    using (new GUILayout.VerticalScope(Styles.poweredSectionLayout, GUILayout.MaxWidth(poweredBySectionMaxWidth)))
                    {
                        GUILayout.Label("Scripting powered by The Mono Project.\n\u00A9 2011 Novell, Inc.", Styles.aboutWindowLicenseLabel);
                        GUILayout.FlexibleSpace();
                        GUILayout.Label(Styles.MonoLogo, Styles.MonoLogoLayout);
                        GUILayout.FlexibleSpace();
                        if (!InternalEditorUtility.IsUnityBeta())
                        {
                            var specialThanksRect = GUILayoutUtility.GetRect(Styles.thanksContent, Styles.thanksStyle);
                            if (GUI.Button(specialThanksRect, Styles.thanksContent, Styles.thanksStyle))
                            {
                                Process.Start(Styles.thanksUri.AbsoluteUri);
                            }
                            EditorGUIUtility.AddCursorRect(specialThanksRect, MouseCursor.Link);
                        }
                        GUILayout.Label(InternalEditorUtility.GetUnityCopyright().Replace("(c)", "\u00A9"), Styles.aboutWindowLicenseLabel);
                    }

                    GUILayout.FlexibleSpace();

                    using (new GUILayout.VerticalScope(Styles.poweredSectionLayout, GUILayout.MaxWidth(poweredBySectionMaxWidth)))
                    {
                        GUILayout.Label("Physics powered by PhysX.\n\u00A9 2019 NVIDIA Corporation.", Styles.aboutWindowLicenseLabel);
                        GUILayout.FlexibleSpace();
                        GUILayout.Label(Styles.AgeiaLogo, Styles.AgeiaLogoLayout);
                        GUILayout.FlexibleSpace();
                        GUILayout.Label(InternalEditorUtility.GetLicenseInfo().Replace("(c)", "\u00A9"), Styles.aboutWindowLicenseLabel);
                    }
                }
            }
        }
示例#19
0
 private static void DrawLODButton(LODInfo currentLOD)
 {
     EditorGUIUtility.AddCursorRect(currentLOD.m_ButtonPosition, MouseCursor.ResizeHorizontal);
 }
示例#20
0
        private void HandleSplitView()
        {
            // Add CursorRects
            SplitView sp = parent as SplitView;

            if (Event.current.type == EventType.Repaint && sp)
            {
                View view = this;
                while (sp)
                {
                    int id = sp.controlID;

                    if (id == GUIUtility.hotControl || GUIUtility.hotControl == 0)
                    {
                        int idx = sp.IndexOfChild(view);
                        if (sp.vertical)
                        {
                            if (idx != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0, 0, position.width, SplitView.kGrabDist), MouseCursor.SplitResizeUpDown, id);
                            }
                            if (idx != sp.children.Length - 1)
                            {
                                EditorGUIUtility.AddCursorRect(
                                    new Rect(0, position.height - SplitView.kGrabDist, position.width, SplitView.kGrabDist),
                                    MouseCursor.SplitResizeUpDown, id);
                            }
                        }
                        else // horizontal
                        {
                            if (idx != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0, 0, SplitView.kGrabDist, position.height), MouseCursor.SplitResizeLeftRight,
                                                               id);
                            }
                            if (idx != sp.children.Length - 1)
                            {
                                EditorGUIUtility.AddCursorRect(
                                    new Rect(position.width - SplitView.kGrabDist, 0, SplitView.kGrabDist, position.height),
                                    MouseCursor.SplitResizeLeftRight, id);
                            }
                        }
                    }

                    view = sp;
                    sp   = sp.parent as SplitView;
                }

                // reset
                sp = (SplitView)parent;
            }

            if (sp)
            {
                Event e = new Event(Event.current);
                e.mousePosition += new Vector2(position.x, position.y);
                sp.SplitGUI(e);
                if (e.type == EventType.Used)
                {
                    Event.current.Use();
                }
            }
        }
        public override void OnInspectorGUI()
        {
            if (styles == null)
            {
                // Set the singleton in case the DrawEditors() has created this window
                s_SharedAssetStoreAssetInspector = this;
                styles = new Styles();
            }

            AssetStoreAsset activeAsset = AssetStoreAssetSelection.GetFirstAsset();

            AssetStoreAsset.PreviewInfo info = null;
            if (activeAsset != null)
            {
                info = activeAsset.previewInfo;
            }

            if (activeAsset != null)
            {
                target.name = string.Format("Asset Store: {0}", activeAsset.name);
            }
            else
            {
                target.name = "Asset Store";
            }

            EditorGUILayout.BeginVertical();

            bool guiEnabled = GUI.enabled;

            GUI.enabled = activeAsset != null && activeAsset.packageID != 0;

            if (OfflineNoticeEnabled)
            {
                Color col = GUI.color;
                GUI.color = Color.yellow;
                GUILayout.Label("Network is offline");
                GUI.color = col;
            }

            if (activeAsset != null)
            {
                string typeName  = activeAsset.className == null ? "" : activeAsset.className.Split(new char[] { ' ' }, 2)[0];
                bool   isPackage = activeAsset.id == -activeAsset.packageID;
                if (isPackage)
                {
                    typeName = "Package";
                }
                if (activeAsset.HasLivePreview)
                {
                    typeName = activeAsset.Preview.GetType().Name;
                }
                EditorGUILayout.LabelField("Type", typeName);

                if (isPackage)
                {
                    packageInfoShown = true;
                }
                else
                {
                    EditorGUILayout.Separator();
                    packageInfoShown = EditorGUILayout.Foldout(packageInfoShown, "Part of package", true);
                }
                if (packageInfoShown)
                {
                    EditorGUILayout.LabelField("Name", info == null ? "-" : info.packageName);
                    EditorGUILayout.LabelField("Version", info == null ? "-" : info.packageVersion);
                    string price = info == null ? "-" : (activeAsset.price != null && activeAsset.price != "" ? activeAsset.price : "free");
                    EditorGUILayout.LabelField("Price", price);
                    string rating = info != null && info.packageRating >= 0 ? info.packageRating.ToString() + " of 5" : "-";
                    EditorGUILayout.LabelField("Rating", rating);
                    EditorGUILayout.LabelField("Size", info == null ? "-" : intToSizeString(info.packageSize));
                    string assetCount = info != null && info.packageAssetCount >= 0 ? info.packageAssetCount.ToString() : "-";
                    EditorGUILayout.LabelField("Asset count", assetCount);
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Web page");
                    bool hasPageUrl = info != null && info.packageShortUrl != null && info.packageShortUrl != "";
                    bool guiBefore  = GUI.enabled;
                    GUI.enabled = hasPageUrl;

                    if (GUILayout.Button(hasPageUrl ? new GUIContent(info.packageShortUrl, "View in browser") : EditorGUIUtility.TempContent("-"), styles.link))
                    {
                        Application.OpenURL(info.packageShortUrl);
                    }
                    if (GUI.enabled)
                    {
                        EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
                    }
                    GUI.enabled = guiBefore;
                    GUILayout.EndHorizontal();
                    EditorGUILayout.LabelField("Publisher", info == null ? "-" : info.publisherName);
                }

                if (activeAsset.id != 0)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();

                    string actionLabel;
                    if (info != null && info.isDownloadable)
                    {
                        actionLabel = "Import package";
                    }
                    else
                    {
                        actionLabel = "Buy for " + activeAsset.price;
                    }

                    bool lastEnabled = GUI.enabled;
                    bool building    = info != null && info.buildProgress >= 0;
                    bool downloading = info != null && info.downloadProgress >= 0;
                    if (building || downloading || info == null)
                    {
                        actionLabel = "";
                        GUI.enabled = false;
                    }

                    if (GUILayout.Button(actionLabel, GUILayout.Height(40), GUILayout.Width(120)))
                    {
                        if (info.isDownloadable)
                        {
                            ImportPackage(activeAsset);
                        }
                        else
                        {
                            InitiateBuySelected();
                        }
                        GUIUtility.ExitGUI();
                    }

                    Rect r;
                    if (Event.current.type == EventType.Repaint)
                    {
                        r         = GUILayoutUtility.GetLastRect();
                        r.height -= 4;
                        float width = r.width;
                        r.width = r.height;
                        r.y    += 2;
                        r.x    += 2;

                        if (building || downloading)
                        {
                            r.width = width - r.height - 4;
                            r.x    += r.height;
                            EditorGUI.ProgressBar(r,
                                                  downloading ? info.downloadProgress : info.buildProgress,
                                                  downloading ? "Downloading" : "Building");
                        }
                    }

                    GUI.enabled = lastEnabled;
                    GUILayout.Space(4);

                    if (GUILayout.Button("Open Asset Store", GUILayout.Height(40), GUILayout.Width(120)))
                    {
                        OpenItemInAssetStore(activeAsset);
                        GUIUtility.ExitGUI();
                    }
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }
                GUILayout.FlexibleSpace();
            }
            EditorWrapper editor = previewEditor;

            if (editor != null && activeAsset != null && activeAsset.HasLivePreview)
            {
                editor.OnAssetStoreInspectorGUI();
            }

            GUI.enabled = guiEnabled;

            EditorGUILayout.EndVertical();
        }
示例#22
0
        void ListArea(Rect rect, PresetLibrary lib, object newPresetObject)
        {
            if (lib == null)
            {
                return;
            }

            Event evt = Event.current;

            if (m_PresetLibraryFileLocation == PresetFileLocation.ProjectFolder && evt.type == EventType.Repaint)
            {
                m_IsOpenForEdit = AssetDatabase.IsOpenForEdit(pathWithExtension, StatusQueryOptions.UseCachedIfPossible);
            }
            else if (m_PresetLibraryFileLocation == PresetFileLocation.PreferencesFolder)
            {
                m_IsOpenForEdit = true;
            }

            if (!m_IsOpenForEdit)
            {
                Rect versionControlRect = new Rect(rect.x, rect.yMax - versionControlAreaHeight, rect.width, versionControlAreaHeight);
                VersionControlArea(versionControlRect);
                rect.height -= versionControlAreaHeight;
            }

            // To ensure we setup grid to visible rect we need to run once to check if scrollbar is taking up screen estate.
            // To optimize the first width is based on the last frame and we therefore most likely will only run once.
            for (int i = 0; i < 2; i++)
            {
                gridWidth = m_ShowedScrollBarLastFrame ? rect.width - 17 : rect.width;
                SetupGrid(gridWidth, lib.Count());
                bool isShowingScrollBar = m_Grid.height > rect.height;
                if (isShowingScrollBar == m_ShowedScrollBarLastFrame)
                {
                    break;
                }
                else
                {
                    m_ShowedScrollBarLastFrame = isShowingScrollBar;
                }
            }

            // Draw horizontal lines for scrollview content to clip against
            if ((m_ShowedScrollBarLastFrame || alwaysShowScrollAreaHorizontalLines) && Event.current.type == EventType.Repaint)
            {
                Rect scrollEdgeRect = new RectOffset(1, 1, 1, 1).Add(rect);
                scrollEdgeRect.height = 1;
                EditorGUI.DrawRect(scrollEdgeRect, new Color(0, 0, 0, 0.3f));
                scrollEdgeRect.y += rect.height + 1;
                EditorGUI.DrawRect(scrollEdgeRect, new Color(0, 0, 0, 0.3f));
            }

            Rect contentRect = new Rect(0, 0, 1, m_Grid.height);

            m_State.m_ScrollPosition = GUI.BeginScrollView(rect, m_State.m_ScrollPosition, contentRect);
            {
                int   startIndex, endIndex;
                float yOffset                 = 0f;
                int   maxIndex                = m_ShowAddNewPresetItem ? lib.Count() : lib.Count() - 1;
                bool  isGridVisible           = m_Grid.IsVisibleInScrollView(rect.height, m_State.m_ScrollPosition.y, yOffset, maxIndex, out startIndex, out endIndex);
                bool  drawDragInsertionMarker = false;
                if (isGridVisible)
                {
                    // Handle renaming overlay before item handling because its needs mouse input first to end renaming if clicked outside
                    if (GetRenameOverlay().IsRenaming() && !GetRenameOverlay().isWaitingForDelay)
                    {
                        if (!m_State.m_RenameOverlay.OnGUI())
                        {
                            EndRename();
                            evt.Use();
                        }
                        Repaint();
                    }

                    for (int i = startIndex; i <= endIndex; ++i)
                    {
                        int itemControlID = i + 1000000;

                        Rect itemRect    = m_Grid.CalcRect(i, yOffset);
                        Rect previewRect = itemRect;
                        Rect labelRect   = itemRect;
                        switch (m_State.itemViewMode)
                        {
                        case PresetLibraryEditorState.ItemViewMode.List:
                            previewRect.width = m_State.m_PreviewHeight * m_PreviewAspect;
                            labelRect.x      += previewRect.width + 8f;
                            labelRect.width  -= previewRect.width + 10f;
                            labelRect.height  = kGridLabelHeight;
                            labelRect.y       = itemRect.yMin + (itemRect.height - kGridLabelHeight) * 0.5f;
                            break;

                        case PresetLibraryEditorState.ItemViewMode.Grid:
                            // only preview is shown: no label
                            break;
                        }

                        // Add new preset button
                        if (m_ShowAddNewPresetItem && i == lib.Count())
                        {
                            CreateNewPresetButton(previewRect, newPresetObject, lib, m_IsOpenForEdit);
                            continue;
                        }

                        // Rename overlay
                        bool isRenamingThisItem = IsRenaming(i);
                        if (isRenamingThisItem)
                        {
                            Rect renameRect = labelRect;
                            renameRect.y -= 1f; renameRect.x -= 1f; // adjustment to fit perfectly
                            m_State.m_RenameOverlay.editFieldRect = renameRect;
                        }

                        // Handle event
                        switch (evt.type)
                        {
                        case EventType.Repaint:
                            if (m_State.m_HoverIndex == i)
                            {
                                if (itemRect.Contains(evt.mousePosition))
                                {
                                    // TODO: We need a better hover effect so disabling for now...
                                    //if (!GetRenameOverlay().IsRenaming ())
                                    //  DrawHoverEffect (itemRect, false);
                                }
                                else
                                {
                                    m_State.m_HoverIndex = -1;
                                }
                            }

                            if (m_DragState.draggingIndex == i || GUIUtility.hotControl == itemControlID)
                            {
                                DrawHoverEffect(itemRect, false);
                            }

                            lib.Draw(previewRect, i);
                            if (!isRenamingThisItem && drawLabels)
                            {
                                GUI.Label(labelRect, GUIContent.Temp(lib.GetName(i)));
                            }

                            if (m_DragState.dragUponIndex == i && m_DragState.draggingIndex != m_DragState.dragUponIndex)
                            {
                                drawDragInsertionMarker = true;
                            }

                            // We delete presets on alt-click
                            if (GUIUtility.hotControl == 0 && Event.current.alt && m_IsOpenForEdit)
                            {
                                EditorGUIUtility.AddCursorRect(itemRect, MouseCursor.ArrowMinus);
                            }

                            break;

                        case EventType.MouseDown:
                            if (evt.button == 0 && itemRect.Contains(evt.mousePosition))
                            {
                                GUIUtility.hotControl = itemControlID;
                                if (evt.clickCount == 1)
                                {
                                    m_ItemClickedCallback(evt.clickCount, lib.GetPreset(i));
                                    evt.Use();
                                }
                            }
                            break;

                        case EventType.MouseDrag:
                            if (GUIUtility.hotControl == itemControlID && m_IsOpenForEdit)
                            {
                                DragAndDropDelay delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), itemControlID);
                                if (delay.CanStartDrag())
                                {
                                    // Start drag
                                    DragAndDrop.PrepareStartDrag();
                                    DragAndDrop.SetGenericData("DraggingPreset", i);
                                    DragAndDrop.StartDrag("");
                                    m_DragState.draggingIndex = i;
                                    m_DragState.dragUponIndex = i;
                                    GUIUtility.hotControl     = 0;
                                }
                                evt.Use();
                            }
                            break;

                        case EventType.DragUpdated:
                        case EventType.DragPerform:
                        {
                            Rect dragRect = GetDragRect(itemRect);
                            if (dragRect.Contains(evt.mousePosition))
                            {
                                m_DragState.dragUponIndex = i;
                                m_DragState.dragUponRect  = itemRect;

                                if (m_State.itemViewMode == PresetLibraryEditorState.ItemViewMode.List)
                                {
                                    m_DragState.insertAfterIndex = ((evt.mousePosition.y - dragRect.y) / dragRect.height) > 0.5f;
                                }
                                else
                                {
                                    m_DragState.insertAfterIndex = ((evt.mousePosition.x - dragRect.x) / dragRect.width) > 0.5f;
                                }

                                bool perform = evt.type == EventType.DragPerform;
                                if (perform)
                                {
                                    if (m_DragState.draggingIndex >= 0)
                                    {
                                        MovePreset(m_DragState.draggingIndex, m_DragState.dragUponIndex, m_DragState.insertAfterIndex);
                                        DragAndDrop.AcceptDrag();
                                    }
                                    ClearDragState();
                                }
                                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                                evt.Use();
                            }
                        }
                        break;

                        case EventType.DragExited:
                            if (m_DragState.IsDragging())
                            {
                                ClearDragState();
                                evt.Use();
                            }
                            break;

                        case EventType.MouseUp:
                            if (GUIUtility.hotControl == itemControlID)
                            {
                                GUIUtility.hotControl = 0;
                                if (evt.button == 0 && itemRect.Contains(evt.mousePosition))
                                {
                                    if (Event.current.alt && m_IsOpenForEdit)
                                    {
                                        DeletePreset(i);
                                        evt.Use();
                                    }
                                }
                            }
                            break;

                        case EventType.ContextClick:
                            if (itemRect.Contains(evt.mousePosition))
                            {
                                PresetContextMenu.Show(m_IsOpenForEdit, i, newPresetObject, this);
                                evt.Use();
                            }
                            break;

                        case EventType.MouseMove:
                            if (itemRect.Contains(evt.mousePosition))
                            {
                                if (m_State.m_HoverIndex != i)
                                {
                                    m_State.m_HoverIndex = i;
                                    Repaint();
                                }
                            }
                            else if (m_State.m_HoverIndex == i)
                            {
                                m_State.m_HoverIndex = -1;
                                Repaint();
                            }

                            break;
                        }
                    } // end foreach item

                    // Draw above all items
                    if (drawDragInsertionMarker)
                    {
                        DrawDragInsertionMarker();
                    }
                }
            } GUI.EndScrollView();
        }
示例#23
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;
            }
        }