/// <summary> /// Draw a header similar to the one used for the post-process stack /// </summary> static public Rect DrawHeader(ref bool expanded, ref bool activeField, string title, Color feedbackColor, System.Action <GenericMenu> fillGenericMenu, float startedAt, float duration, MMFeedbackTiming timing, bool pause) { var e = Event.current; // Initialize Rects var backgroundRect = GUILayoutUtility.GetRect(1f, 17f); var progressRect = GUILayoutUtility.GetRect(1f, 2f); var offset = 4f; var reorderRect = backgroundRect; reorderRect.xMin -= 8f; reorderRect.y += 5f; reorderRect.width = 9f; reorderRect.height = 9f; var labelRect = backgroundRect; labelRect.xMin += 32f + offset; labelRect.xMax -= 20f; var foldoutRect = backgroundRect; foldoutRect.y += 1f; foldoutRect.xMin += offset; foldoutRect.width = 13f; foldoutRect.height = 13f; var toggleRect = backgroundRect; toggleRect.x += 16f; toggleRect.xMin += offset; toggleRect.y += 2f; toggleRect.width = 13f; toggleRect.height = 13f; var menuIcon = PaneOptionsIcon; var menuRect = new Rect(labelRect.xMax + 4f, labelRect.y + 4f, menuIcon.width, menuIcon.height); _timingStyle.normal.textColor = EditorGUIUtility.isProSkin ? _timingDark : _timingLight; _timingStyle.alignment = TextAnchor.MiddleRight; var colorRect = new Rect(labelRect.xMin, labelRect.yMin, 5f, 17f); colorRect.xMin = 0f; colorRect.xMax = 5f; EditorGUI.DrawRect(colorRect, feedbackColor); // Background rect should be full-width backgroundRect.xMin = 0f; backgroundRect.width += 4f; progressRect.xMin = 0f; progressRect.width += 4f; Color headerBackgroundColor = Color.white; // Background - if color is white we draw the default color if (!pause) { headerBackgroundColor = HeaderBackground; } else { headerBackgroundColor = feedbackColor; } EditorGUI.DrawRect(backgroundRect, headerBackgroundColor); // Foldout expanded = GUI.Toggle(foldoutRect, expanded, GUIContent.none, EditorStyles.foldout); // Title using (new EditorGUI.DisabledScope(!activeField)) { EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel); } float timingRectWidth = 150f; //string fullTimingInfo = "[ "; float totalTime = 0f; if (timing.InitialDelay != 0) { //fullTimingInfo += timing.InitialDelay.ToString() + "s + "; totalTime += timing.InitialDelay; } //fullTimingInfo += duration.ToString("F2") + "s"; totalTime += duration; if (timing.NumberOfRepeats != 0) { totalTime += timing.NumberOfRepeats * (duration + timing.DelayBetweenRepeats); /*fullTimingInfo += " + "+ timing.NumberOfRepeats.ToString() + " x "; * if (timing.DelayBetweenRepeats > 0) * { * fullTimingInfo += "("; * } * fullTimingInfo += duration + "s"; * if (timing.DelayBetweenRepeats > 0) * { * fullTimingInfo += " + " + timing.DelayBetweenRepeats + "s )"; * }*/ } //fullTimingInfo += " ]"; string timingInfo = "[ " + totalTime.ToString("F2") + "s ]"; //"[ 2s + 3 x (4s + 1s) ]" var timingRect = new Rect(labelRect.xMax - timingRectWidth, labelRect.yMin, timingRectWidth, 17f); timingRect.xMin = labelRect.xMax - timingRectWidth; timingRect.xMax = labelRect.xMax; EditorGUI.LabelField(timingRect, timingInfo, _timingStyle); // Progress bar if (duration == 0f) { duration = 0.1f; } if ((startedAt > 0f) && (Time.time - startedAt < duration + 0.05f)) { float fullWidth = progressRect.width; if (duration == 0f) { duration = 0.1f; } float percent = ((Time.time - startedAt) / duration) * 100f; progressRect.width = percent * fullWidth / 100f; Color barColor = Color.white; if (Time.time - startedAt > duration) { barColor = Color.yellow; } EditorGUI.DrawRect(progressRect, barColor); } else { EditorGUI.DrawRect(progressRect, headerBackgroundColor); } // Active checkbox activeField = GUI.Toggle(toggleRect, activeField, GUIContent.none, SmallTickbox); // Dropdown menu icon GUI.DrawTexture(menuRect, menuIcon); for (int i = 0; i < 3; i++) { Rect r = reorderRect; r.height = 1; r.y = reorderRect.y + reorderRect.height * (i / 3.0f); EditorGUI.DrawRect(r, Reorder); } // Handle events if (e.type == EventType.MouseDown) { if (menuRect.Contains(e.mousePosition)) { var menu = new GenericMenu(); fillGenericMenu(menu); menu.DropDown(new Rect(new Vector2(menuRect.x, menuRect.yMax), Vector2.zero)); e.Use(); } } if (e.type == EventType.MouseDown && labelRect.Contains(e.mousePosition) && e.button == 0) { expanded = !expanded; e.Use(); } return(backgroundRect); }
/// <summary> /// Draw a header similar to the one used for the post-process stack /// </summary> static public Rect DrawHeader(ref bool expanded, ref bool activeField, string title, Color feedbackColor, System.Action <GenericMenu> fillGenericMenu, float startedAt, float duration, float totalDuration, MMFeedbackTiming timing, bool pause, MMFeedbacks host) { var e = Event.current; // Initialize Rects var backgroundRect = GUILayoutUtility.GetRect(1f, 17f); var progressRect = GUILayoutUtility.GetRect(1f, 2f); var offset = 4f; var reorderRect = backgroundRect; reorderRect.xMin -= 8f; reorderRect.y += 5f; reorderRect.width = 9f; reorderRect.height = 9f; var labelRect = backgroundRect; labelRect.xMin += 32f + offset; labelRect.xMax -= 20f; var foldoutRect = backgroundRect; foldoutRect.y += 1f; foldoutRect.xMin += offset; foldoutRect.width = 13f; foldoutRect.height = 13f; var toggleRect = backgroundRect; toggleRect.x += 16f; toggleRect.xMin += offset; toggleRect.y += 2f; toggleRect.width = 13f; toggleRect.height = 13f; var menuIcon = PaneOptionsIcon; var menuRect = new Rect(labelRect.xMax + 4f, labelRect.y + 4f, menuIcon.width, menuIcon.height); _timingStyle.normal.textColor = EditorGUIUtility.isProSkin ? _timingDark : _timingLight; _timingStyle.alignment = TextAnchor.MiddleRight; var colorRect = new Rect(labelRect.xMin, labelRect.yMin, 5f, 17f); colorRect.xMin = 0f; colorRect.xMax = 5f; EditorGUI.DrawRect(colorRect, feedbackColor); // Background rect should be full-width backgroundRect.xMin = 0f; backgroundRect.width += 4f; progressRect.xMin = 0f; progressRect.width += 4f; Color headerBackgroundColor = Color.white; // Background - if color is white we draw the default color if (!pause) { headerBackgroundColor = HeaderBackground; } else { headerBackgroundColor = feedbackColor; } EditorGUI.DrawRect(backgroundRect, headerBackgroundColor); // Foldout expanded = GUI.Toggle(foldoutRect, expanded, GUIContent.none, EditorStyles.foldout); // Title ---------------------------------------------------------------------------------------------------- using (new EditorGUI.DisabledScope(!activeField)) { EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel); } // Direction ---------------------------------------------------------------------------------------------- float directionRectWidth = 70f; var directionRect = new Rect(labelRect.xMax - directionRectWidth, labelRect.yMin, directionRectWidth, 17f); directionRect.xMin = labelRect.xMax - directionRectWidth; directionRect.xMax = labelRect.xMax; if (timing.MMFeedbacksDirectionCondition == MMFeedbackTiming.MMFeedbacksDirectionConditions.OnlyWhenBackwards) { GUIContent directionIcon = EditorGUIUtility.IconContent("vcs_change", "Only play when backwards"); EditorGUI.LabelField(directionRect, directionIcon); } if (timing.MMFeedbacksDirectionCondition == MMFeedbackTiming.MMFeedbacksDirectionConditions.OnlyWhenForwards) { float rotationAngle = 180f; var pivotPoint = new Vector2(directionRect.xMin + 9, directionRect.yMin + 8); var matrixBackup = GUI.matrix; GUIUtility.RotateAroundPivot(rotationAngle, pivotPoint); GUIContent directionIcon = EditorGUIUtility.IconContent("vcs_incoming", "Only play when forwards"); EditorGUI.LabelField(directionRect, directionIcon); GUI.matrix = matrixBackup; } // Time ----------------------------------------------------------------------------------------------------- string timingInfo = ""; bool displayTotal = false; if (host.DisplayFullDurationDetails) { if (timing.InitialDelay != 0) { timingInfo += host.ApplyTimeMultiplier(timing.InitialDelay).ToString() + "s + "; displayTotal = true; } timingInfo += duration.ToString("F2") + "s"; if (timing.NumberOfRepeats != 0) { float delayBetweenRepeats = host.ApplyTimeMultiplier(timing.DelayBetweenRepeats); timingInfo += " + " + timing.NumberOfRepeats.ToString() + " x "; if (timing.DelayBetweenRepeats > 0) { timingInfo += "("; } timingInfo += duration + "s"; if (timing.DelayBetweenRepeats > 0) { timingInfo += " + " + host.ApplyTimeMultiplier(timing.DelayBetweenRepeats) + "s )"; } displayTotal = true; } if (displayTotal) { timingInfo += " = " + totalDuration.ToString("F2") + "s"; } } else { timingInfo = totalDuration.ToString("F2") + "s"; } //"[ 2s + 3 x (4s + 1s) ]" float timingRectWidth = 150f; var timingRect = new Rect(labelRect.xMax - timingRectWidth, labelRect.yMin, timingRectWidth, 17f); timingRect.xMin = labelRect.xMax - timingRectWidth; timingRect.xMax = labelRect.xMax; EditorGUI.LabelField(timingRect, timingInfo, _timingStyle); // Progress bar if (totalDuration == 0f) { totalDuration = 0.1f; } if ((startedAt > 0f) && (Time.time - startedAt < totalDuration + 0.05f)) { float fullWidth = progressRect.width; if (totalDuration == 0f) { totalDuration = 0.1f; } float percent = ((Time.time - startedAt) / totalDuration) * 100f; progressRect.width = percent * fullWidth / 100f; Color barColor = Color.white; if (Time.time - startedAt > totalDuration) { barColor = Color.yellow; } EditorGUI.DrawRect(progressRect, barColor); } else { EditorGUI.DrawRect(progressRect, headerBackgroundColor); } // Active checkbox activeField = GUI.Toggle(toggleRect, activeField, GUIContent.none, SmallTickbox); // Dropdown menu icon GUI.DrawTexture(menuRect, menuIcon); for (int i = 0; i < 3; i++) { Rect r = reorderRect; r.height = 1; r.y = reorderRect.y + reorderRect.height * (i / 3.0f); EditorGUI.DrawRect(r, Reorder); } // Handle events if (e.type == EventType.MouseDown) { if (menuRect.Contains(e.mousePosition)) { var menu = new GenericMenu(); fillGenericMenu(menu); menu.DropDown(new Rect(new Vector2(menuRect.x, menuRect.yMax), Vector2.zero)); e.Use(); } } if (e.type == EventType.MouseDown && labelRect.Contains(e.mousePosition) && e.button == 0) { expanded = !expanded; e.Use(); } return(backgroundRect); }
/// <summary> /// Draw a header similar to the one used for the post-process stack /// </summary> static public Rect DrawHeader(ref bool expanded, ref bool activeField, string title, Color feedbackColor, System.Action <GenericMenu> fillGenericMenu, float startedAt, float duration, float totalDuration, MMFeedbackTiming timing, bool pause, bool requiresSetup, string requiredTarget, Color displayColor, MMF_Player host) { float thisTime = timing.TimescaleMode == TimescaleModes.Scaled ? Time.time : Time.unscaledTime; float thisDeltaTime = timing.TimescaleMode == TimescaleModes.Scaled ? Time.deltaTime : Time.unscaledDeltaTime; if (host.ForceTimescaleMode) { thisTime = host.ForcedTimescaleMode == TimescaleModes.Scaled ? Time.time : Time.unscaledTime; thisDeltaTime = host.ForcedTimescaleMode == TimescaleModes.Scaled ? Time.deltaTime : Time.unscaledDeltaTime; } var e = Event.current; // Initialize Rects _backgroundRect = GUILayoutUtility.GetRect(1f, 17f); _progressRect = GUILayoutUtility.GetRect(1f, 2f); var offset = 4f; _reorderRect = _backgroundRect; _reorderRect.xMin -= 8f; _reorderRect.y += 5f; _reorderRect.width = 9f; _reorderRect.height = 9f; _labelRect = _backgroundRect; _labelRect.xMin += 32f + offset; _labelRect.xMax -= 20f; _foldoutRect = _backgroundRect; _foldoutRect.y += 1f; _foldoutRect.xMin += offset; _foldoutRect.width = 13f; _foldoutRect.height = 13f; _toggleRect = _backgroundRect; _toggleRect.x += 16f; _toggleRect.xMin += offset; _toggleRect.y += 2f; _toggleRect.width = 13f; _toggleRect.height = 13f; _timingStyle.normal.textColor = EditorGUIUtility.isProSkin ? _timingDark : _timingLight; _timingStyle.alignment = TextAnchor.MiddleRight; _colorRect.x = _labelRect.xMin; _colorRect.y = _labelRect.yMin; _colorRect.width = 5f; _colorRect.height = 17f; _colorRect.xMin = 0f; _colorRect.xMax = 5f; EditorGUI.DrawRect(_colorRect, feedbackColor); // Background rect should be full-width _backgroundRect.xMin = 0f; _backgroundRect.width += 4f; _progressRect.xMin = 0f; _progressRect.width += 4f; _headerBackgroundColor = Color.white; // Background - if color is white we draw the default color if (!pause) { _headerBackgroundColor = HeaderBackground; } else { _headerBackgroundColor = feedbackColor; } if (displayColor != Color.black) { _headerBackgroundColor = displayColor; } EditorGUI.DrawRect(_backgroundRect, _headerBackgroundColor); // Foldout expanded = GUI.Toggle(_foldoutRect, expanded, GUIContent.none, EditorStyles.foldout); // Title ---------------------------------------------------------------------------------------------------- using (new EditorGUI.DisabledScope(!activeField)) { EditorGUI.LabelField(_labelRect, title, EditorStyles.boldLabel); } // Direction ---------------------------------------------------------------------------------------------- float directionRectWidth = 70f; _directionRect.x = _labelRect.xMax - directionRectWidth; _directionRect.y = _labelRect.yMin; _directionRect.width = directionRectWidth; _directionRect.height = 17f; _directionRect.xMin = _labelRect.xMax - directionRectWidth; _directionRect.xMax = _labelRect.xMax; if (timing.MMFeedbacksDirectionCondition == MMFeedbackTiming.MMFeedbacksDirectionConditions.OnlyWhenBackwards) { EditorGUI.LabelField(_directionRect, _directionUpIcon); } if (timing.MMFeedbacksDirectionCondition == MMFeedbackTiming.MMFeedbacksDirectionConditions.OnlyWhenForwards) { EditorGUI.LabelField(_directionRect, _directionDownIcon); } if (requiresSetup) { float setupRectWidth = 90f; _setupRect.x = _labelRect.xMax - setupRectWidth; _setupRect.y = _labelRect.yMin; _setupRect.width = setupRectWidth; _setupRect.height = 17f; _setupRect.xMin = _labelRect.xMax - setupRectWidth; _setupRect.xMax = _labelRect.xMax; EditorGUI.LabelField(_setupRect, _setupRequiredIcon); } else { // otherwise we draw the name of our target float setupRectWidth = _labelRect.width / 2f; _setupRect.x = _labelRect.xMax - setupRectWidth - 73f; _setupRect.y = _labelRect.yMin; _setupRect.width = setupRectWidth; _setupRect.height = 17f; EditorGUI.LabelField(_setupRect, requiredTarget, _targetLabelStyle); } // Time ----------------------------------------------------------------------------------------------------- string timingInfo = ""; bool displayTotal = false; if (host.DisplayFullDurationDetails) { if (timing.InitialDelay != 0) { timingInfo += host.ApplyTimeMultiplier(timing.InitialDelay).ToString() + "s + "; displayTotal = true; } timingInfo += duration.ToString("F2") + "s"; if (timing.NumberOfRepeats != 0) { float delayBetweenRepeats = host.ApplyTimeMultiplier(timing.DelayBetweenRepeats); timingInfo += " + " + timing.NumberOfRepeats.ToString() + " x "; if (timing.DelayBetweenRepeats > 0) { timingInfo += "("; } timingInfo += duration + "s"; if (timing.DelayBetweenRepeats > 0) { timingInfo += " + " + host.ApplyTimeMultiplier(timing.DelayBetweenRepeats) + "s )"; } displayTotal = true; } if (displayTotal) { timingInfo += " = " + totalDuration.ToString("F2") + "s"; } } else { timingInfo = totalDuration.ToString("F2") + "s"; } float timingRectWidth = 150f; _timingRect.x = _labelRect.xMax - timingRectWidth; _timingRect.y = _labelRect.yMin; _timingRect.width = timingRectWidth; _timingRect.height = 17f; _timingRect.xMin = _labelRect.xMax - timingRectWidth; _timingRect.xMax = _labelRect.xMax; EditorGUI.LabelField(_timingRect, timingInfo, _timingStyle); // Progress bar if (totalDuration == 0f) { totalDuration = 0.1f; } if (startedAt == 0f) { startedAt = 0.001f; } if (host.IsPlaying && (startedAt > 0f) && (thisTime - startedAt < totalDuration + 0.05f)) { float fullWidth = _progressRect.width; if (totalDuration == 0f) { totalDuration = 0.1f; } float percent = ((thisTime - startedAt) / totalDuration) * 100f; _progressRect.width = percent * fullWidth / 100f; _barColor = Color.white; if (thisTime - startedAt > totalDuration) { _barColor = Color.yellow; } EditorGUI.DrawRect(_progressRect, _barColor); } else { EditorGUI.DrawRect(_progressRect, _headerBackgroundColor); } // Active checkbox activeField = GUI.Toggle(_toggleRect, activeField, GUIContent.none, SmallTickbox); _menuRect.x = _labelRect.xMax + 4f; _menuRect.y = _labelRect.y + 4f; _menuRect.width = _menuIcon.width; _menuRect.height = _menuIcon.height; // Dropdown menu icon GUI.DrawTexture(_menuRect, _menuIcon); for (int i = 0; i < 3; i++) { _workRect = _reorderRect; _workRect.height = 1; _workRect.y = _reorderRect.y + _reorderRect.height * (i / 3.0f); EditorGUI.DrawRect(_workRect, Reorder); } // Handle events if (e.type == EventType.MouseDown) { if (_menuRect.Contains(e.mousePosition)) { fillGenericMenu(_genericMenu); _genericMenuRect.x = _menuRect.x; _genericMenuRect.y = _menuRect.yMax; _genericMenuRect.width = 0f; _genericMenuRect.height = 0f; _genericMenu.DropDown(_genericMenuRect); e.Use(); } } if (e.type == EventType.MouseDown && _labelRect.Contains(e.mousePosition) && e.button == 0) { expanded = !expanded; e.Use(); } return(_backgroundRect); }