forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfilerFrameViewBase.cs
More file actions
147 lines (125 loc) · 5.52 KB
/
Copy pathProfilerFrameViewBase.cs
File metadata and controls
147 lines (125 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor.SceneManagement;
using System.Collections.Generic;
using System.Linq;
using System;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEditorInternal;
namespace UnityEditorInternal.Profiling
{
[Serializable]
internal class ProfilerFrameDataViewBase
{
protected static class BaseStyles
{
public static readonly GUIContent noData = EditorGUIUtility.TextContent("No frame data available");
public static GUIContent disabledSearchText = EditorGUIUtility.TextContent("Showing search results are disabled while recording with deep profiling.\nStop recording to view search results.");
public static readonly GUIStyle header = "OL title";
public static readonly GUIStyle label = "OL label";
public static readonly GUIStyle toolbar = EditorStyles.toolbar;
public static readonly GUIStyle tooltip = "AnimationEventTooltip";
public static readonly GUIStyle tooltipArrow = "AnimationEventTooltipArrow";
public static readonly GUIStyle viewTypeToolbarDropDown = EditorStyles.toolbarDropDown;
static BaseStyles()
{
toolbar.padding.left = 0;
//viewTypeToolbarDropDown.fixedWidth = 120;
viewTypeToolbarDropDown.stretchWidth = true;
}
}
static readonly GUIContent[] kCPUProfilerViewTypeNames = new GUIContent[]
{
EditorGUIUtility.TextContent("Hierarchy"),
EditorGUIUtility.TextContent("Timeline"),
EditorGUIUtility.TextContent("Raw Hierarchy")
};
static readonly int[] kCPUProfilerViewTypes = new int[]
{
(int)ProfilerViewType.Hierarchy,
(int)ProfilerViewType.Timeline,
(int)ProfilerViewType.RawHierarchy
};
static readonly GUIContent[] kGPUProfilerViewTypeNames = new GUIContent[]
{
EditorGUIUtility.TextContent("Hierarchy"),
EditorGUIUtility.TextContent("Raw Hierarchy")
};
static readonly int[] kGPUProfilerViewTypes = new int[]
{
(int)ProfilerViewType.Hierarchy,
(int)ProfilerViewType.RawHierarchy
};
public bool gpuView { get; set; }
public delegate void ViewTypeChangedCallback(ProfilerViewType viewType);
public event ViewTypeChangedCallback viewTypeChanged;
protected ProfilerFrameDataViewBase()
{
}
protected void DrawViewTypePopup(ProfilerViewType viewType)
{
ProfilerViewType newViewType;
if (!gpuView)
{
newViewType = (ProfilerViewType)EditorGUILayout.IntPopup((int)viewType, kCPUProfilerViewTypeNames, kCPUProfilerViewTypes, BaseStyles.viewTypeToolbarDropDown);
}
else
{
if (viewType == ProfilerViewType.Timeline)
viewType = ProfilerViewType.Hierarchy;
newViewType = (ProfilerViewType)EditorGUILayout.IntPopup((int)viewType, kGPUProfilerViewTypeNames, kGPUProfilerViewTypes, BaseStyles.viewTypeToolbarDropDown);
}
if (newViewType != viewType)
{
if (viewTypeChanged != null)
viewTypeChanged.Invoke(newViewType);
}
}
protected void ShowLargeTooltip(Vector2 pos, Rect fullRect, string text)
{
var textC = GUIContent.Temp(text);
var style = BaseStyles.tooltip;
var size = style.CalcSize(textC);
// Arrow of tooltip
var arrowRect = new Rect(pos.x - 32, pos.y, 64, 6);
// Label box
var rect = new Rect(pos.x, pos.y + 6, size.x, size.y);
// Ensure it doesn't go too far right
if (rect.xMax > fullRect.xMax + 16)
rect.x = fullRect.xMax - rect.width + 16;
if (arrowRect.xMax > fullRect.xMax + 20)
arrowRect.x = fullRect.xMax - arrowRect.width + 20;
// Adjust left to we can always see giant (STL) names.
if (rect.xMin < fullRect.xMin + 30)
rect.x = fullRect.xMin + 30;
if (arrowRect.xMin < fullRect.xMin - 20)
arrowRect.x = fullRect.xMin - 20;
// Flip tooltip if too close to bottom (but do not flip if flipping would mean the tooltip is too high up)
const float lineHeight = 16.0f;
var flipRectAdjust = (lineHeight + rect.height + 2 * arrowRect.height);
var flipped = (pos.y + size.y + 6 > fullRect.yMax) && (rect.y - flipRectAdjust > 0);
if (flipped)
{
rect.y -= flipRectAdjust;
arrowRect.y -= (lineHeight + 2 * arrowRect.height);
}
// Draw small arrow
GUI.BeginClip(arrowRect);
var oldMatrix = GUI.matrix;
if (flipped)
GUIUtility.ScaleAroundPivot(new Vector2(1.0f, -1.0f), new Vector2(arrowRect.width * 0.5f, arrowRect.height));
GUI.Label(new Rect(0, 0, arrowRect.width, arrowRect.height), GUIContent.none, BaseStyles.tooltipArrow);
GUI.matrix = oldMatrix;
GUI.EndClip();
// Draw tooltip
GUI.Label(rect, textC, style);
}
public virtual void Clear()
{
}
}
}