forked from GameBuildingBlocks/PerfAssist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gulu_office
committed
Mar 20, 2018
1 parent
d3865c8
commit 4700a3b
Showing
8 changed files
with
893 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
public class UIHighlightWidget | ||
{ | ||
public string name; | ||
public Vector3[] screenPos; | ||
public float timeChanged; | ||
} | ||
|
||
public class UIDebugDraw : MonoBehaviour | ||
{ | ||
public static UIDebugDraw Instance = null; | ||
|
||
Texture m_debugTexture; | ||
List<UIHighlightWidget> m_highlightedWidgets = new List<UIHighlightWidget>(); | ||
|
||
Dictionary<string, int> m_widgetHighlightCount = new Dictionary<string, int>(100); | ||
|
||
public void HighlightWidget(string widgetName, Vector3[] widgetScreenPos) | ||
{ | ||
if (!GlobalSwitches.UIDebuggingDrawBlocks) | ||
return; | ||
|
||
UIHighlightWidget widget = new UIHighlightWidget(); | ||
widget.name = widgetName; | ||
widget.screenPos = widgetScreenPos; | ||
widget.timeChanged = Time.time; | ||
m_highlightedWidgets.Add(widget); | ||
|
||
if (m_widgetHighlightCount.ContainsKey(widgetName)) | ||
{ | ||
m_widgetHighlightCount[widgetName]++; | ||
} | ||
else | ||
{ | ||
m_widgetHighlightCount.Add(widgetName, 1); | ||
} | ||
} | ||
|
||
public void StartStats() | ||
{ | ||
m_widgetHighlightCount.Clear(); | ||
} | ||
|
||
public void StopStats() | ||
{ | ||
List<KeyValuePair<string, int>> sortBuf = m_widgetHighlightCount.ToList(); | ||
sortBuf.Sort( | ||
delegate (KeyValuePair<string, int> pair1, | ||
KeyValuePair<string, int> pair2) | ||
{ | ||
return pair2.Value.CompareTo(pair1.Value); | ||
} | ||
); | ||
|
||
List<string> content = new List<string>(); | ||
foreach (var p in sortBuf) | ||
{ | ||
content.Add(string.Format("{0} {1}", p.Key, p.Value)); | ||
} | ||
string file = Path.Combine(Application.persistentDataPath, string.Format("TestTools/ui_stats_{0}_{1}.log", SysUtil.FormatDateAsFileNameString(DateTime.Now), SysUtil.FormatTimeAsFileNameString(DateTime.Now))) ; | ||
System.IO.File.WriteAllLines(file, content.ToArray()); | ||
} | ||
|
||
// Use this for initialization | ||
void Start() | ||
{ | ||
Texture2D texture = new Texture2D(1, 1); | ||
Color c = Color.magenta; | ||
c.a = 0.2f; | ||
texture.SetPixel(0, 0, c); | ||
texture.Apply(); | ||
m_debugTexture = texture; | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
//Debug.DrawLine(gameObject.transform.position, gameObject.transform.position + new Vector3(100, 0, 0), Color.red); | ||
//Debug.DrawLine(gameObject.transform.position, gameObject.transform.position + new Vector3(100, 100, -50), Color.red); | ||
//Debug.DrawLine(gameObject.transform.position, gameObject.transform.position + new Vector3(0, 100, 0), Color.red); | ||
} | ||
|
||
void OnGUI() | ||
{ | ||
if (!GlobalSwitches.UIDebuggingDrawBlocks) | ||
return; | ||
|
||
var savedColor = GUI.color; | ||
var texColor = GUI.color; | ||
for (int k = 0; k < m_highlightedWidgets.Count; ++k) | ||
{ | ||
texColor.a = 1.0f - (Time.time - m_highlightedWidgets[k].timeChanged) * 2; | ||
GUI.color = texColor; | ||
|
||
Vector3[] widgetScreenPos = m_highlightedWidgets[k].screenPos; | ||
float height = widgetScreenPos[2].y - widgetScreenPos[0].y; | ||
var r = new Rect( | ||
widgetScreenPos[0].x, | ||
Screen.height - widgetScreenPos[0].y - height, | ||
widgetScreenPos[2].x - widgetScreenPos[0].x, | ||
height); | ||
|
||
GUI.DrawTexture(r, m_debugTexture, ScaleMode.StretchToFill); | ||
|
||
r.width = Math.Max(r.width, 200); // make sure the space is enough for text dispalaying | ||
r.height = Math.Max(r.height, 50); | ||
GUI.Label(r, m_highlightedWidgets[k].name); | ||
} | ||
|
||
GUI.color = savedColor; | ||
|
||
m_highlightedWidgets.RemoveAll((w) => { return Time.time - w.timeChanged > 0.5f; }); | ||
} | ||
|
||
void OnDrawGizmos() | ||
{ | ||
//if (m_debugTexture != null) | ||
//{ | ||
// Gizmos.DrawGUITexture(new Rect(10, 10, 20, 20), m_debugTexture); | ||
//} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class UIDebugScreenOutput : MonoBehaviour | ||
{ | ||
public static UIDebugScreenOutput Instance = null; | ||
|
||
// Use this for initialization | ||
void Start () { | ||
|
||
} | ||
|
||
// Update is called once per frame | ||
void Update () { | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.