129 lines
4.0 KiB
C#
129 lines
4.0 KiB
C#
using Thousandto.Core.Framework;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.Code.Logic
|
|
{
|
|
/// <summary>
|
|
/// 游戏资源生命周期和使用情况监视面板
|
|
/// </summary>
|
|
public class PFAssetMainForm : MonoBehaviour
|
|
{
|
|
//标题栏内容
|
|
public static string[] TitleArray = PFAssetDefines.TitleArray;
|
|
|
|
public static Texture WhiteBlank = PFAssetDefines.WhiteBlank;
|
|
public static Texture BlackBlank = PFAssetDefines.BlackBlank;
|
|
|
|
//正在使用的资源
|
|
private static Dictionary<string, ProfilerInfo> _usingAssetDict = null;
|
|
//已经销毁的资源,同样的资源可能销毁多次
|
|
private static Dictionary<string, List<ProfilerInfo>> _destoryedAssetDict = null;
|
|
|
|
private static Rect position;
|
|
|
|
private static int _selectedTab = 0;
|
|
|
|
private float _timer;
|
|
|
|
|
|
|
|
void Awake()
|
|
{
|
|
PFAssetDefines.InitTexBlank();
|
|
position = new Rect(50, 50, UnityEngine.Screen.width - 50, UnityEngine.Screen.height - 50);
|
|
|
|
PFAssetDefines.ResetRectData(position);
|
|
|
|
_timer = Time.realtimeSinceStartup;
|
|
}
|
|
|
|
public float Duration = 0f;
|
|
|
|
void OnGUI()
|
|
{
|
|
if (Time.realtimeSinceStartup - _timer < Duration)
|
|
return;
|
|
_timer = Time.realtimeSinceStartup;
|
|
|
|
CheckSizeChange();
|
|
DrawBGColor();
|
|
DrawHeadTitle();
|
|
DrawCloseBtn();
|
|
if (_selectedTab == 0)
|
|
PFAssetRuntimePanel.OnGUI();
|
|
else
|
|
PFAssetHistoryPanel.OnGUI();
|
|
DrawTabBtn();
|
|
}
|
|
|
|
void DrawBGColor()
|
|
{
|
|
//GUI.DrawTexture(new Rect(0, 0, position.width, position.height), ProfilerSystem.CreateColorTex(Color.black, (int)position.width, (int)position.height));
|
|
GUI.DrawTexture(new Rect(0, 0, position.width, position.height), PFAssetDefines.BlackBlankAll, ScaleMode.StretchToFill);
|
|
}
|
|
|
|
//标题栏
|
|
void DrawHeadTitle()
|
|
{
|
|
GUILayout.BeginArea(PFAssetDefines.HeadTitleRect, PFAssetDefines.CreateColorTex(new Color((60f / 255f), (113f / 255f), 0, 1f), (int)PFAssetDefines.HeadTitleRect.width, (int)PFAssetDefines.HeadTitleRect.height));
|
|
var oldColor = GUI.color;
|
|
for (int i = 0; i < TitleArray.Length; ++i)
|
|
{
|
|
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
|
GUI.color = Color.red;
|
|
GUI.Label(new Rect(i * PFAssetDefines.CellWidth, PFAssetDefines.HeadTitleRect.y, PFAssetDefines.CellWidth, PFAssetDefines.HeadTitleRect.height), TitleArray[i]);
|
|
}
|
|
GUI.color = oldColor;
|
|
GUILayout.EndArea();
|
|
}
|
|
|
|
void DrawTabBtn()
|
|
{
|
|
if(_selectedTab == 0)
|
|
{
|
|
GUI.color = Color.green;
|
|
}
|
|
if(GUI.Button(new Rect(0, 0, 100, PFAssetDefines.HeadTitleRect.height), "Runtime"))
|
|
{
|
|
_selectedTab = 0;
|
|
}
|
|
GUI.color = Color.white;
|
|
|
|
if(_selectedTab == 1)
|
|
{
|
|
GUI.color = Color.green;
|
|
}
|
|
if (GUI.Button(new Rect(100, 0, 100, PFAssetDefines.HeadTitleRect.height), "History"))
|
|
{
|
|
_selectedTab = 1;
|
|
}
|
|
GUI.color = Color.white;
|
|
}
|
|
|
|
void DrawCloseBtn()
|
|
{
|
|
Rect rect = new Rect(PFAssetDefines.HeadTitleRect.x + PFAssetDefines.HeadTitleRect.width, PFAssetDefines.HeadTitleRect.y, 100, 50);
|
|
if(GUI.Button(rect, "Close"))
|
|
{
|
|
Destroy(this);
|
|
}
|
|
}
|
|
|
|
void CheckSizeChange()
|
|
{
|
|
if (PFAssetDefines.WindowSize != position)
|
|
{
|
|
PFAssetDefines.WindowSize = position;
|
|
OnWindowSizeChange();
|
|
}
|
|
}
|
|
|
|
void OnWindowSizeChange()
|
|
{
|
|
PFAssetDefines.ResetRectData(position);
|
|
}
|
|
}
|
|
}
|
|
|