特效新内容。修复gameplay致命bug和分数保存bug

This commit is contained in:
2026-02-16 01:55:18 +08:00
parent 3a7a0b4669
commit 9f7c1c57b7
206 changed files with 112684 additions and 857 deletions
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1ac38d39b5dd9f442a088b7284b58236
folderAsset: yes
timeCreated: 1513377123
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,397 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 05-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.UI;
#if GRAPHY_XR
using UnityEngine.XR;
#endif
using System.Collections.Generic;
using System.Text;
using Tayx.Graphy.UI;
using Tayx.Graphy.Utils;
using Tayx.Graphy.Utils.NumString;
namespace Tayx.Graphy.Advanced
{
public class G_AdvancedData : MonoBehaviour, IMovable, IModifiableState
{
#region Variables -> Serialized Private
[SerializeField] private List<Image> m_backgroundImages = new List<Image>();
[SerializeField] private Text m_graphicsDeviceVersionText = null;
[SerializeField] private Text m_processorTypeText = null;
[SerializeField] private Text m_operatingSystemText = null;
[SerializeField] private Text m_systemMemoryText = null;
[SerializeField] private Text m_graphicsDeviceNameText = null;
[SerializeField] private Text m_graphicsMemorySizeText = null;
[SerializeField] private Text m_screenResolutionText = null;
[SerializeField] private Text m_gameWindowResolutionText = null;
[SerializeField] private Text m_gameVRResolutionText = null;
#if GRAPHY_XR
private readonly List<XRDisplaySubsystem> m_displaySubsystems = new List<XRDisplaySubsystem>();
#endif
[Range( 1, 60 )] [SerializeField] private float m_updateRate = 1f; // 1 update per sec.
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private RectTransform m_rectTransform = null;
private Vector2 m_origPosition = Vector2.zero;
private float m_deltaTime = 0.0f;
private StringBuilder m_sb = null;
private GraphyManager.ModuleState m_previousModuleState = GraphyManager.ModuleState.FULL;
private GraphyManager.ModuleState m_currentModuleState = GraphyManager.ModuleState.FULL;
private readonly string[] m_windowStrings =
{
"Window: ",
"x",
"@",
"Hz",
"[",
"dpi]"
};
private readonly string[] m_vrStrings =
{
"VR: (",
"*2)x",
"@",
"Hz"
};
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Update()
{
m_deltaTime += Time.unscaledDeltaTime;
if( m_deltaTime > 1f / m_updateRate )
{
// Update screen window resolution
m_sb.Length = 0;
m_sb.Append( m_windowStrings[ 0 ] ).Append( Screen.width.ToStringNonAlloc() )
.Append( m_windowStrings[ 1 ] ).Append( Screen.height.ToStringNonAlloc() )
.Append( m_windowStrings[ 2 ] ).Append(
#if UNITY_2022_2_OR_NEWER
((int)Screen.currentResolution.refreshRateRatio.value).ToStringNonAlloc()
#else
Screen.currentResolution.refreshRate.ToStringNonAlloc()
#endif
)
.Append( m_windowStrings[ 3 ] )
.Append( m_windowStrings[ 4 ] ).Append( ((int) Screen.dpi).ToStringNonAlloc() )
.Append( m_windowStrings[ 5 ] );
m_gameWindowResolutionText.text = m_sb.ToString();
#if GRAPHY_XR
// If XR enabled, update screen XR resolution
if( XRSettings.enabled )
{
m_sb.Length = 0;
#if UNITY_2020_2_OR_NEWER
SubsystemManager.GetSubsystems( m_displaySubsystems );
#else
SubsystemManager.GetInstances( m_displaySubsystems );
#endif
float refreshRate = -1;
if( m_displaySubsystems.Count > 0 )
{
m_displaySubsystems[ 0 ].TryGetDisplayRefreshRate( out refreshRate );
}
m_sb.Append( m_vrStrings[ 0 ] ).Append( XRSettings.eyeTextureWidth.ToStringNonAlloc() )
.Append( m_vrStrings[ 1 ] ).Append( XRSettings.eyeTextureHeight.ToStringNonAlloc() )
.Append( m_vrStrings[ 2 ] ).Append( Mathf.RoundToInt( refreshRate ).ToStringNonAlloc() )
.Append( m_vrStrings[ 3 ] );
m_gameVRResolutionText.text = m_sb.ToString();
}
#endif
// Reset variables
m_deltaTime = 0f;
}
}
#endregion
#region Methods -> Public
public void SetPosition( GraphyManager.ModulePosition newModulePosition, Vector2 offset )
{
if ( newModulePosition == GraphyManager.ModulePosition.FREE )
return;
m_rectTransform.anchoredPosition = m_origPosition;
float xSideOffset = Mathf.Abs( m_rectTransform.anchoredPosition.x ) + offset.x;
float ySideOffset = Mathf.Abs( m_rectTransform.anchoredPosition.y ) + offset.y;
switch( newModulePosition )
{
case GraphyManager.ModulePosition.TOP_LEFT:
m_rectTransform.anchorMax = Vector2.up;
m_rectTransform.anchorMin = Vector2.up;
m_rectTransform.anchoredPosition = new Vector2( xSideOffset, -ySideOffset );
break;
case GraphyManager.ModulePosition.TOP_RIGHT:
m_rectTransform.anchorMax = Vector2.one;
m_rectTransform.anchorMin = Vector2.one;
m_rectTransform.anchoredPosition = new Vector2( -xSideOffset, -ySideOffset );
break;
case GraphyManager.ModulePosition.BOTTOM_LEFT:
m_rectTransform.anchorMax = Vector2.zero;
m_rectTransform.anchorMin = Vector2.zero;
m_rectTransform.anchoredPosition = new Vector2( xSideOffset, ySideOffset );
break;
case GraphyManager.ModulePosition.BOTTOM_RIGHT:
m_rectTransform.anchorMax = Vector2.right;
m_rectTransform.anchorMin = Vector2.right;
m_rectTransform.anchoredPosition = new Vector2( -xSideOffset, ySideOffset );
break;
}
switch( newModulePosition )
{
case GraphyManager.ModulePosition.TOP_LEFT:
case GraphyManager.ModulePosition.BOTTOM_LEFT:
m_processorTypeText.alignment = TextAnchor.UpperLeft;
m_systemMemoryText.alignment = TextAnchor.UpperLeft;
m_graphicsDeviceNameText.alignment = TextAnchor.UpperLeft;
m_graphicsDeviceVersionText.alignment = TextAnchor.UpperLeft;
m_graphicsMemorySizeText.alignment = TextAnchor.UpperLeft;
m_screenResolutionText.alignment = TextAnchor.UpperLeft;
m_gameWindowResolutionText.alignment = TextAnchor.UpperLeft;
m_gameVRResolutionText.alignment = TextAnchor.UpperLeft;
m_operatingSystemText.alignment = TextAnchor.UpperLeft;
break;
case GraphyManager.ModulePosition.TOP_RIGHT:
case GraphyManager.ModulePosition.BOTTOM_RIGHT:
m_processorTypeText.alignment = TextAnchor.UpperRight;
m_systemMemoryText.alignment = TextAnchor.UpperRight;
m_graphicsDeviceNameText.alignment = TextAnchor.UpperRight;
m_graphicsDeviceVersionText.alignment = TextAnchor.UpperRight;
m_graphicsMemorySizeText.alignment = TextAnchor.UpperRight;
m_screenResolutionText.alignment = TextAnchor.UpperRight;
m_gameWindowResolutionText.alignment = TextAnchor.UpperRight;
m_gameVRResolutionText.alignment = TextAnchor.UpperRight;
m_operatingSystemText.alignment = TextAnchor.UpperRight;
break;
}
}
public void SetState( GraphyManager.ModuleState state, bool silentUpdate = false )
{
if( !silentUpdate )
{
m_previousModuleState = m_currentModuleState;
}
m_currentModuleState = state;
bool active = state == GraphyManager.ModuleState.FULL
|| state == GraphyManager.ModuleState.TEXT
|| state == GraphyManager.ModuleState.BASIC;
gameObject.SetActive( active );
m_backgroundImages.SetAllActive( active && m_graphyManager.Background );
}
/// <summary>
/// Restores state to the previous one.
/// </summary>
public void RestorePreviousState()
{
SetState( m_previousModuleState );
}
public void UpdateParameters()
{
foreach( var image in m_backgroundImages )
{
image.color = m_graphyManager.BackgroundColor;
}
SetPosition( m_graphyManager.AdvancedModulePosition, Vector2.zero );
SetState( m_graphyManager.AdvancedModuleState );
}
public void RefreshParameters()
{
foreach( var image in m_backgroundImages )
{
image.color = m_graphyManager.BackgroundColor;
}
SetPosition( m_graphyManager.AdvancedModulePosition, Vector2.zero );
SetState( m_currentModuleState, true );
}
#endregion
#region Methods -> Private
private void Init()
{
G_IntString.Init( 0, 7680 );
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_sb = new StringBuilder();
m_rectTransform = GetComponent<RectTransform>();
m_processorTypeText.text
= "CPU: "
+ SystemInfo.processorType
+ " ["
+ SystemInfo.processorCount
+ " cores]";
m_systemMemoryText.text
= "RAM: "
+ SystemInfo.systemMemorySize
+ " MB";
m_graphicsDeviceVersionText.text
= "Graphics API: "
+ SystemInfo.graphicsDeviceVersion;
m_graphicsDeviceNameText.text
= "GPU: "
+ SystemInfo.graphicsDeviceName;
m_graphicsMemorySizeText.text
= "VRAM: "
+ SystemInfo.graphicsMemorySize
+ "MB. Max texture size: "
+ SystemInfo.maxTextureSize
+ "px. Shader level: "
+ SystemInfo.graphicsShaderLevel;
Resolution res = Screen.currentResolution;
m_screenResolutionText.text
= "Screen: "
+ res.width
+ "x"
+ res.height
+ "@"
#if UNITY_2022_2_OR_NEWER
+ ((int)Screen.currentResolution.refreshRateRatio.value).ToStringNonAlloc()
#else
+ res.refreshRate
#endif
+ "Hz";
m_operatingSystemText.text
= "OS: "
+ SystemInfo.operatingSystem
+ " ["
+ SystemInfo.deviceType
+ "]";
m_gameVRResolutionText.text = "VR: Not active";
float preferredWidth = 0;
// Resize the background overlay
List<Text> texts = new List<Text>()
{
m_graphicsDeviceVersionText,
m_processorTypeText,
m_systemMemoryText,
m_graphicsDeviceNameText,
m_graphicsMemorySizeText,
m_screenResolutionText,
m_gameWindowResolutionText,
m_gameVRResolutionText,
m_operatingSystemText
};
foreach( var text in texts )
{
if( text.preferredWidth > preferredWidth )
{
preferredWidth = text.preferredWidth;
}
}
m_rectTransform.SetSizeWithCurrentAnchors
(
axis: RectTransform.Axis.Horizontal,
size: preferredWidth + 25
);
m_rectTransform.anchoredPosition = new Vector2
(
x: m_rectTransform.anchoredPosition.x - m_rectTransform.rect.width / 2
+ m_rectTransform.rect.width / 2 * Mathf.Sign( m_rectTransform.anchoredPosition.x ),
y: m_rectTransform.anchoredPosition.y
);
m_origPosition = m_rectTransform.anchoredPosition;
UpdateParameters();
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 5c1019d31db77fd468164577146737ad
timeCreated: 1512484835
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Advanced/G_AdvancedData.cs
uploadId: 626547
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2523395741efc1c48822a27d9fcb57d2
folderAsset: yes
timeCreated: 1513377094
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,294 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 15-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using Tayx.Graphy.Graph;
using UnityEngine;
using UnityEngine.UI;
namespace Tayx.Graphy.Audio
{
public class G_AudioGraph : G_Graph
{
#region Variables -> Serialized Private
[SerializeField] private Image m_imageGraph = null;
[SerializeField] private Image m_imageGraphHighestValues = null;
[SerializeField] private Shader ShaderFull = null;
[SerializeField] private Shader ShaderLight = null;
[SerializeField] private bool m_isInitialized = false;
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_AudioMonitor m_audioMonitor = null;
private int m_resolution = 40;
private G_GraphShader m_shaderGraph = null;
private G_GraphShader m_shaderGraphHighestValues = null;
private float[] m_graphArray;
private float[] m_graphArrayHighestValue;
#endregion
#region Methods -> Unity Callbacks
private void OnEnable()
{
/* ----- NOTE: ----------------------------
* We used to Init() here regardless of
* whether this module was enabled.
* The reason we don't Init() here
* anymore is that some users are on
* platforms that do not support the arrays
* in the Shaders.
*
* See: https://github.com/Tayx94/graphy/issues/17
*
* Even though we don't Init() competely
* here anymore, we still need
* m_audioMonitor for in Update()
* --------------------------------------*/
m_audioMonitor = GetComponent<G_AudioMonitor>();
}
private void Update()
{
if( m_audioMonitor.SpectrumDataAvailable )
{
UpdateGraph();
}
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
if( m_shaderGraph == null )
{
// While Graphy is disabled (e.g. by default via Ctrl+H) and while in Editor after a Hot-Swap,
// the OnApplicationFocus calls this while m_shaderGraph == null, throwing a NullReferenceException
return;
}
switch( m_graphyManager.GraphyMode )
{
case GraphyManager.Mode.FULL:
m_shaderGraph.ArrayMaxSize = G_GraphShader.ArrayMaxSizeFull;
m_shaderGraph.Image.material = new Material( ShaderFull );
m_shaderGraphHighestValues.ArrayMaxSize = G_GraphShader.ArrayMaxSizeFull;
m_shaderGraphHighestValues.Image.material = new Material( ShaderFull );
break;
case GraphyManager.Mode.LIGHT:
m_shaderGraph.ArrayMaxSize = G_GraphShader.ArrayMaxSizeLight;
m_shaderGraph.Image.material = new Material( ShaderLight );
m_shaderGraphHighestValues.ArrayMaxSize = G_GraphShader.ArrayMaxSizeLight;
m_shaderGraphHighestValues.Image.material = new Material( ShaderLight );
break;
}
m_shaderGraph.InitializeShader();
m_shaderGraphHighestValues.InitializeShader();
m_resolution = m_graphyManager.AudioGraphResolution;
CreatePoints();
}
#endregion
#region Methods -> Protected Override
protected override void UpdateGraph()
{
// Since we no longer initialize by default OnEnable(),
// we need to check here, and Init() if needed
if( !m_isInitialized )
{
Init();
}
int incrementPerIteration = Mathf.FloorToInt( m_audioMonitor.Spectrum.Length / (float) m_resolution );
// Current values -------------------------
for( int i = 0; i <= m_resolution - 1; i++ )
{
float currentValue = 0;
for( int j = 0; j < incrementPerIteration; j++ )
{
currentValue += m_audioMonitor.Spectrum[ i * incrementPerIteration + j ];
}
// Uses 3 values for each bar to accomplish that look
if( (i + 1) % 3 == 0 && i > 1 )
{
float value =
(
m_audioMonitor.dBNormalized( m_audioMonitor.lin2dB( currentValue / incrementPerIteration ) )
+ m_graphArray[ i - 1 ]
+ m_graphArray[ i - 2 ]
) / 3;
m_graphArray[ i ] = value;
m_graphArray[ i - 1 ] = value;
m_graphArray[ i - 2 ] =
-1; // Always set the third one to -1 to leave gaps in the graph and improve readability
}
else
{
m_graphArray[ i ] =
m_audioMonitor.dBNormalized( m_audioMonitor.lin2dB( currentValue / incrementPerIteration ) );
}
}
for( int i = 0; i <= m_resolution - 1; i++ )
{
m_shaderGraph.ShaderArrayValues[ i ] = m_graphArray[ i ];
}
m_shaderGraph.UpdatePoints();
// Highest values -------------------------
for( int i = 0; i <= m_resolution - 1; i++ )
{
float currentValue = 0;
for( int j = 0; j < incrementPerIteration; j++ )
{
currentValue += m_audioMonitor.SpectrumHighestValues[ i * incrementPerIteration + j ];
}
// Uses 3 values for each bar to accomplish that look
if( (i + 1) % 3 == 0 && i > 1 )
{
float value =
(
m_audioMonitor.dBNormalized( m_audioMonitor.lin2dB( currentValue / incrementPerIteration ) )
+ m_graphArrayHighestValue[ i - 1 ]
+ m_graphArrayHighestValue[ i - 2 ]
) / 3;
m_graphArrayHighestValue[ i ] = value;
m_graphArrayHighestValue[ i - 1 ] = value;
m_graphArrayHighestValue[ i - 2 ] =
-1; // Always set the third one to -1 to leave gaps in the graph and improve readability
}
else
{
m_graphArrayHighestValue[ i ] =
m_audioMonitor.dBNormalized( m_audioMonitor.lin2dB( currentValue / incrementPerIteration ) );
}
}
for( int i = 0; i <= m_resolution - 1; i++ )
{
m_shaderGraphHighestValues.ShaderArrayValues[ i ] = m_graphArrayHighestValue[ i ];
}
m_shaderGraphHighestValues.UpdatePoints();
}
protected override void CreatePoints()
{
// Init Arrays
if( m_shaderGraph.ShaderArrayValues == null || m_shaderGraph.ShaderArrayValues.Length != m_resolution )
{
m_graphArray = new float[m_resolution];
m_graphArrayHighestValue = new float[m_resolution];
m_shaderGraph.ShaderArrayValues = new float[m_resolution];
m_shaderGraphHighestValues.ShaderArrayValues = new float[m_resolution];
}
for( int i = 0; i < m_resolution; i++ )
{
m_shaderGraph.ShaderArrayValues[ i ] = 0;
m_shaderGraphHighestValues.ShaderArrayValues[ i ] = 0;
}
// Color
m_shaderGraph.GoodColor = m_graphyManager.AudioGraphColor;
m_shaderGraph.CautionColor = m_graphyManager.AudioGraphColor;
m_shaderGraph.CriticalColor = m_graphyManager.AudioGraphColor;
m_shaderGraph.UpdateColors();
m_shaderGraphHighestValues.GoodColor = m_graphyManager.AudioGraphColor;
m_shaderGraphHighestValues.CautionColor = m_graphyManager.AudioGraphColor;
m_shaderGraphHighestValues.CriticalColor = m_graphyManager.AudioGraphColor;
m_shaderGraphHighestValues.UpdateColors();
// Threshold
m_shaderGraph.GoodThreshold = 0;
m_shaderGraph.CautionThreshold = 0;
m_shaderGraph.UpdateThresholds();
m_shaderGraphHighestValues.GoodThreshold = 0;
m_shaderGraphHighestValues.CautionThreshold = 0;
m_shaderGraphHighestValues.UpdateThresholds();
// Update Array
m_shaderGraph.UpdateArrayValuesLength();
m_shaderGraphHighestValues.UpdateArrayValuesLength();
// Average
m_shaderGraph.Average = 0;
m_shaderGraph.UpdateAverage();
m_shaderGraphHighestValues.Average = 0;
m_shaderGraphHighestValues.UpdateAverage();
}
#endregion
#region Methods -> Private
private void Init()
{
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_audioMonitor = GetComponent<G_AudioMonitor>();
m_shaderGraph = new G_GraphShader
{
Image = m_imageGraph
};
m_shaderGraphHighestValues = new G_GraphShader
{
Image = m_imageGraphHighestValues
};
UpdateParameters();
m_isInitialized = true;
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: f2d6ca19dafe21b4b983441274e7f12a
timeCreated: 1513169449
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Audio/G_AudioGraph.cs
uploadId: 626547
@@ -0,0 +1,239 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 03-Jan-18
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using Tayx.Graphy.UI;
using Tayx.Graphy.Utils;
namespace Tayx.Graphy.Audio
{
public class G_AudioManager : MonoBehaviour, IMovable, IModifiableState
{
#region Variables -> Serialized Private
[SerializeField] private GameObject m_audioGraphGameObject = null;
[SerializeField] private Text m_audioDbText = null;
[SerializeField] private List<Image> m_backgroundImages = new List<Image>();
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_AudioGraph m_audioGraph = null;
private G_AudioMonitor m_audioMonitor = null;
private G_AudioText m_audioText = null;
private RectTransform m_rectTransform = null;
private Vector2 m_origPosition = Vector2.zero;
private List<GameObject> m_childrenGameObjects = new List<GameObject>();
private GraphyManager.ModuleState m_previousModuleState = GraphyManager.ModuleState.FULL;
private GraphyManager.ModuleState m_currentModuleState = GraphyManager.ModuleState.FULL;
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Start()
{
UpdateParameters();
}
#endregion
#region Methods -> Public
public void SetPosition( GraphyManager.ModulePosition newModulePosition, Vector2 offset )
{
if ( newModulePosition == GraphyManager.ModulePosition.FREE )
return;
m_rectTransform.anchoredPosition = m_origPosition;
float xSideOffset = Mathf.Abs( m_rectTransform.anchoredPosition.x ) + offset.x;
float ySideOffset = Mathf.Abs( m_rectTransform.anchoredPosition.y ) + offset.y;
m_audioDbText.alignment = TextAnchor.UpperRight;
switch( newModulePosition )
{
case GraphyManager.ModulePosition.TOP_LEFT:
m_rectTransform.anchorMax = Vector2.up;
m_rectTransform.anchorMin = Vector2.up;
m_rectTransform.anchoredPosition = new Vector2( xSideOffset, -ySideOffset );
break;
case GraphyManager.ModulePosition.TOP_RIGHT:
m_rectTransform.anchorMax = Vector2.one;
m_rectTransform.anchorMin = Vector2.one;
m_rectTransform.anchoredPosition = new Vector2( -xSideOffset, -ySideOffset );
break;
case GraphyManager.ModulePosition.BOTTOM_LEFT:
m_rectTransform.anchorMax = Vector2.zero;
m_rectTransform.anchorMin = Vector2.zero;
m_rectTransform.anchoredPosition = new Vector2( xSideOffset, ySideOffset );
break;
case GraphyManager.ModulePosition.BOTTOM_RIGHT:
m_rectTransform.anchorMax = Vector2.right;
m_rectTransform.anchorMin = Vector2.right;
m_rectTransform.anchoredPosition = new Vector2( -xSideOffset, ySideOffset );
break;
}
}
public void SetState( GraphyManager.ModuleState state, bool silentUpdate = false )
{
if( !silentUpdate )
{
m_previousModuleState = m_currentModuleState;
}
m_currentModuleState = state;
switch( state )
{
case GraphyManager.ModuleState.FULL:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( true );
SetGraphActive( true );
if( m_graphyManager.Background )
{
m_backgroundImages.SetOneActive( 0 );
}
else
{
m_backgroundImages.SetAllActive( false );
}
break;
case GraphyManager.ModuleState.TEXT:
case GraphyManager.ModuleState.BASIC:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( true );
SetGraphActive( false );
if( m_graphyManager.Background )
{
m_backgroundImages.SetOneActive( 1 );
}
else
{
m_backgroundImages.SetAllActive( false );
}
break;
case GraphyManager.ModuleState.BACKGROUND:
gameObject.SetActive( true );
SetGraphActive( false );
m_childrenGameObjects.SetAllActive( false );
m_backgroundImages.SetAllActive( false );
break;
case GraphyManager.ModuleState.OFF:
gameObject.SetActive( false );
break;
}
}
public void RestorePreviousState()
{
SetState( m_previousModuleState );
}
public void UpdateParameters()
{
foreach( var image in m_backgroundImages )
{
image.color = m_graphyManager.BackgroundColor;
}
m_audioGraph.UpdateParameters();
m_audioMonitor.UpdateParameters();
m_audioText.UpdateParameters();
SetState( m_graphyManager.AudioModuleState );
}
public void RefreshParameters()
{
foreach( var image in m_backgroundImages )
{
image.color = m_graphyManager.BackgroundColor;
}
m_audioGraph.UpdateParameters();
m_audioMonitor.UpdateParameters();
m_audioText.UpdateParameters();
SetState( m_currentModuleState, true );
}
#endregion
#region Methods -> Private
private void Init()
{
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_rectTransform = GetComponent<RectTransform>();
m_origPosition = m_rectTransform.anchoredPosition;
m_audioGraph = GetComponent<G_AudioGraph>();
m_audioMonitor = GetComponent<G_AudioMonitor>();
m_audioText = GetComponent<G_AudioText>();
foreach( Transform child in transform )
{
if( child.parent == transform )
{
m_childrenGameObjects.Add( child.gameObject );
}
}
}
private void SetGraphActive( bool active )
{
m_audioGraph.enabled = active;
m_audioGraphGameObject.SetActive( active );
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 8c0448d8db852b54480670d291c04f1a
timeCreated: 1514998347
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Audio/G_AudioManager.cs
uploadId: 626547
@@ -0,0 +1,211 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 15-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Tayx.Graphy.Audio
{
/// <summary>
/// Note: this class only works with Unity's AudioListener.
/// If you're using a custom audio engine (like FMOD or WWise) it won't work,
/// although you can always adapt it.
/// </summary>
public class G_AudioMonitor : MonoBehaviour
{
#region Variables -> Private
private const float m_refValue = 1f;
private GraphyManager m_graphyManager = null;
private AudioListener m_audioListener = null;
private GraphyManager.LookForAudioListener m_findAudioListenerInCameraIfNull =
GraphyManager.LookForAudioListener.ON_SCENE_LOAD;
private FFTWindow m_FFTWindow = FFTWindow.Blackman;
private int m_spectrumSize = 512;
#endregion
#region Properties -> Public
/// <summary>
/// Current audio spectrum from the specified AudioListener.
/// </summary>
public float[] Spectrum { get; private set; }
/// <summary>
/// Highest audio spectrum from the specified AudioListener in the last few seconds.
/// </summary>
public float[] SpectrumHighestValues { get; private set; }
/// <summary>
/// Maximum DB registered in the current spectrum.
/// </summary>
public float MaxDB { get; private set; }
/// <summary>
/// Returns true if there is a reference to the audio listener.
/// </summary>
public bool SpectrumDataAvailable => m_audioListener != null;
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Update()
{
if( m_audioListener != null )
{
// Use this data to calculate the dB value
AudioListener.GetOutputData( Spectrum, 0 );
float sum = 0;
for( int i = 0; i < Spectrum.Length; i++ )
{
sum += Spectrum[ i ] * Spectrum[ i ]; // sum squared samples
}
float rmsValue = Mathf.Sqrt( sum / Spectrum.Length ); // rms = square root of average
MaxDB = 20 * Mathf.Log10( rmsValue / m_refValue ); // calculate dB
if( MaxDB < -80 ) MaxDB = -80; // clamp it to -80dB min
// Use this data to draw the spectrum in the graphs
AudioListener.GetSpectrumData( Spectrum, 0, m_FFTWindow );
for( int i = 0; i < Spectrum.Length; i++ )
{
// Update the highest value if its lower than the current one
if( Spectrum[ i ] > SpectrumHighestValues[ i ] )
{
SpectrumHighestValues[ i ] = Spectrum[ i ];
}
// Slowly lower the value
else
{
SpectrumHighestValues[ i ] = Mathf.Clamp
(
value: SpectrumHighestValues[ i ] - SpectrumHighestValues[ i ] * Time.deltaTime * 2,
min: 0,
max: 1
);
}
}
}
else if( m_audioListener == null
&& m_findAudioListenerInCameraIfNull == GraphyManager.LookForAudioListener.ALWAYS )
{
m_audioListener = FindAudioListener();
}
}
private void OnDestroy()
{
UnityEngine.SceneManagement.SceneManager.sceneLoaded -= OnSceneLoaded;
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
m_findAudioListenerInCameraIfNull = m_graphyManager.FindAudioListenerInCameraIfNull;
m_audioListener = m_graphyManager.AudioListener;
m_FFTWindow = m_graphyManager.FftWindow;
m_spectrumSize = m_graphyManager.SpectrumSize;
if( m_audioListener == null
&& m_findAudioListenerInCameraIfNull != GraphyManager.LookForAudioListener.NEVER )
{
m_audioListener = FindAudioListener();
}
Spectrum = new float[m_spectrumSize];
SpectrumHighestValues = new float[m_spectrumSize];
}
/// <summary>
/// Converts spectrum values to decibels using logarithms.
/// </summary>
/// <param name="linear"></param>
/// <returns></returns>
public float lin2dB( float linear )
{
return Mathf.Clamp( Mathf.Log10( linear ) * 20.0f, -160.0f, 0.0f );
}
/// <summary>
/// Normalizes a value in decibels between 0-1.
/// </summary>
/// <param name="db"></param>
/// <returns></returns>
public float dBNormalized( float db )
{
return (db + 160f) / 160f;
}
#endregion
#region Methods -> Private
/// <summary>
/// Tries to find an audio listener in the main camera.
/// </summary>
private AudioListener FindAudioListener()
{
Camera mainCamera = Camera.main;
if( mainCamera != null && mainCamera.TryGetComponent( out AudioListener audioListener ) )
{
return audioListener;
}
return null;
}
private void OnSceneLoaded( Scene scene, LoadSceneMode loadSceneMode )
{
if( m_findAudioListenerInCameraIfNull == GraphyManager.LookForAudioListener.ON_SCENE_LOAD )
{
m_audioListener = FindAudioListener();
}
}
private void Init()
{
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
UpdateParameters();
UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoaded;
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 2216f4eff6a7a8a43b38b180fdd2fd9e
timeCreated: 1513377074
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Audio/G_AudioMonitor.cs
uploadId: 626547
@@ -0,0 +1,90 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 15-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.UI;
using Tayx.Graphy.Utils.NumString;
namespace Tayx.Graphy.Audio
{
public class G_AudioText : MonoBehaviour
{
#region Variables -> Serialized Private
[SerializeField] private Text m_DBText = null;
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_AudioMonitor m_audioMonitor = null;
private int m_updateRate = 4;
private float m_deltaTimeOffset = 0;
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Update()
{
if( m_audioMonitor.SpectrumDataAvailable )
{
if( m_deltaTimeOffset > 1f / m_updateRate )
{
m_deltaTimeOffset = 0f;
m_DBText.text = Mathf.Clamp( (int) m_audioMonitor.MaxDB, -80, 0 ).ToStringNonAlloc();
}
else
{
m_deltaTimeOffset += Time.deltaTime;
}
}
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
m_updateRate = m_graphyManager.AudioTextUpdateRate;
}
#endregion
#region Methods -> Private
private void Init()
{
G_IntString.Init( -80, 0 ); // dB range
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_audioMonitor = GetComponent<G_AudioMonitor>();
UpdateParameters();
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 766a588f9a6cb55499c66ea772072e11
timeCreated: 1513377063
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Audio/G_AudioText.cs
uploadId: 626547
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3232b12a3422d1a4d8ff3eaa000c43ae
folderAsset: yes
timeCreated: 1513377102
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,197 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 15-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using Tayx.Graphy.Graph;
using UnityEngine;
using UnityEngine.UI;
namespace Tayx.Graphy.Fps
{
public class G_FpsGraph : G_Graph
{
#region Variables -> Serialized Private
[SerializeField] private Image m_imageGraph = null;
[SerializeField] private Shader ShaderFull = null;
[SerializeField] private Shader ShaderLight = null;
// This keeps track of whether Init() has run or not
[SerializeField] private bool m_isInitialized = false;
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_FpsMonitor m_fpsMonitor = null;
private int m_resolution = 150;
private G_GraphShader m_shaderGraph = null;
private int[] m_fpsArray;
private int m_highestFps;
#endregion
#region Methods -> Unity Callbacks
private void Update()
{
UpdateGraph();
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
if( m_shaderGraph == null )
{
// While Graphy is disabled (e.g. by default via Ctrl+H) and while in Editor after a Hot-Swap,
// the OnApplicationFocus calls this while m_shaderGraph == null, throwing a NullReferenceException
return;
}
switch( m_graphyManager.GraphyMode )
{
case GraphyManager.Mode.FULL:
m_shaderGraph.ArrayMaxSize = G_GraphShader.ArrayMaxSizeFull;
m_shaderGraph.Image.material = new Material( ShaderFull );
break;
case GraphyManager.Mode.LIGHT:
m_shaderGraph.ArrayMaxSize = G_GraphShader.ArrayMaxSizeLight;
m_shaderGraph.Image.material = new Material( ShaderLight );
break;
}
m_shaderGraph.InitializeShader();
m_resolution = m_graphyManager.FpsGraphResolution;
CreatePoints();
}
#endregion
#region Methods -> Protected Override
protected override void UpdateGraph()
{
// Since we no longer initialize by default OnEnable(),
// we need to check here, and Init() if needed
if( !m_isInitialized )
{
Init();
}
short fps = (short) (1 / Time.unscaledDeltaTime);
int currentMaxFps = 0;
for( int i = 0; i <= m_resolution - 1; i++ )
{
if( i >= m_resolution - 1 )
{
m_fpsArray[ i ] = fps;
}
else
{
m_fpsArray[ i ] = m_fpsArray[ i + 1 ];
}
// Store the highest fps to use as the highest point in the graph
if( currentMaxFps < m_fpsArray[ i ] )
{
currentMaxFps = m_fpsArray[ i ];
}
}
m_highestFps = m_highestFps < 1 || m_highestFps <= currentMaxFps ? currentMaxFps : m_highestFps - 1;
m_highestFps = m_highestFps > 0 ? m_highestFps : 1;
if( m_shaderGraph.ShaderArrayValues == null )
{
m_fpsArray = new int[m_resolution];
m_shaderGraph.ShaderArrayValues = new float[m_resolution];
}
for( int i = 0; i <= m_resolution - 1; i++ )
{
m_shaderGraph.ShaderArrayValues[ i ] = m_fpsArray[ i ] / (float) m_highestFps;
}
// Update the material values
m_shaderGraph.UpdatePoints();
m_shaderGraph.Average = m_fpsMonitor.AverageFPS / m_highestFps;
m_shaderGraph.UpdateAverage();
m_shaderGraph.GoodThreshold = (float) m_graphyManager.GoodFPSThreshold / m_highestFps;
m_shaderGraph.CautionThreshold = (float) m_graphyManager.CautionFPSThreshold / m_highestFps;
m_shaderGraph.UpdateThresholds();
}
protected override void CreatePoints()
{
if( m_shaderGraph.ShaderArrayValues == null || m_fpsArray.Length != m_resolution )
{
m_fpsArray = new int[m_resolution];
m_shaderGraph.ShaderArrayValues = new float[m_resolution];
}
for( int i = 0; i < m_resolution; i++ )
{
m_shaderGraph.ShaderArrayValues[ i ] = 0;
}
m_shaderGraph.GoodColor = m_graphyManager.GoodFPSColor;
m_shaderGraph.CautionColor = m_graphyManager.CautionFPSColor;
m_shaderGraph.CriticalColor = m_graphyManager.CriticalFPSColor;
m_shaderGraph.UpdateColors();
m_shaderGraph.UpdateArrayValuesLength();
}
#endregion
#region Methods -> Private
private void Init()
{
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_fpsMonitor = GetComponent<G_FpsMonitor>();
m_shaderGraph = new G_GraphShader
{
Image = m_imageGraph
};
UpdateParameters();
m_isInitialized = true;
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 2e119c7747ac400478c7cfcaea03214e
timeCreated: 1511794194
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Fps/G_FpsGraph.cs
uploadId: 626547
@@ -0,0 +1,258 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 03-Jan-18
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using Tayx.Graphy.UI;
using Tayx.Graphy.Utils;
namespace Tayx.Graphy.Fps
{
public class G_FpsManager : MonoBehaviour, IMovable, IModifiableState
{
#region Variables -> Serialized Private
[SerializeField] private GameObject m_fpsGraphGameObject = null;
[SerializeField] private List<GameObject> m_nonBasicTextGameObjects = new List<GameObject>();
[SerializeField] private List<Image> m_backgroundImages = new List<Image>();
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_FpsGraph m_fpsGraph = null;
private G_FpsMonitor m_fpsMonitor = null;
private G_FpsText m_fpsText = null;
private RectTransform m_rectTransform = null;
private Vector2 m_origPosition = Vector2.zero;
private List<GameObject> m_childrenGameObjects = new List<GameObject>();
private GraphyManager.ModuleState m_previousModuleState = GraphyManager.ModuleState.FULL;
private GraphyManager.ModuleState m_currentModuleState = GraphyManager.ModuleState.FULL;
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Start()
{
UpdateParameters();
}
#endregion
#region Methods -> Public
public void SetPosition( GraphyManager.ModulePosition newModulePosition, Vector2 offset )
{
if ( newModulePosition == GraphyManager.ModulePosition.FREE )
return;
m_rectTransform.anchoredPosition = m_origPosition;
float xSideOffset = Mathf.Abs( m_rectTransform.anchoredPosition.x ) + offset.x;
float ySideOffset = Mathf.Abs( m_rectTransform.anchoredPosition.y ) + offset.y;
switch( newModulePosition )
{
case GraphyManager.ModulePosition.TOP_LEFT:
m_rectTransform.anchorMax = Vector2.up;
m_rectTransform.anchorMin = Vector2.up;
m_rectTransform.anchoredPosition = new Vector2( xSideOffset, -ySideOffset );
break;
case GraphyManager.ModulePosition.TOP_RIGHT:
m_rectTransform.anchorMax = Vector2.one;
m_rectTransform.anchorMin = Vector2.one;
m_rectTransform.anchoredPosition = new Vector2( -xSideOffset, -ySideOffset );
break;
case GraphyManager.ModulePosition.BOTTOM_LEFT:
m_rectTransform.anchorMax = Vector2.zero;
m_rectTransform.anchorMin = Vector2.zero;
m_rectTransform.anchoredPosition = new Vector2( xSideOffset, ySideOffset );
break;
case GraphyManager.ModulePosition.BOTTOM_RIGHT:
m_rectTransform.anchorMax = Vector2.right;
m_rectTransform.anchorMin = Vector2.right;
m_rectTransform.anchoredPosition = new Vector2( -xSideOffset, ySideOffset );
break;
case GraphyManager.ModulePosition.FREE:
break;
}
}
public void SetState( GraphyManager.ModuleState state, bool silentUpdate = false )
{
if( !silentUpdate )
{
m_previousModuleState = m_currentModuleState;
}
m_currentModuleState = state;
switch( state )
{
case GraphyManager.ModuleState.FULL:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( true );
SetGraphActive( true );
if( m_graphyManager.Background )
{
m_backgroundImages.SetOneActive( 0 );
}
else
{
m_backgroundImages.SetAllActive( false );
}
break;
case GraphyManager.ModuleState.TEXT:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( true );
SetGraphActive( false );
if( m_graphyManager.Background )
{
m_backgroundImages.SetOneActive( 1 );
}
else
{
m_backgroundImages.SetAllActive( false );
}
break;
case GraphyManager.ModuleState.BASIC:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( true );
m_nonBasicTextGameObjects.SetAllActive( false );
SetGraphActive( false );
if( m_graphyManager.Background )
{
m_backgroundImages.SetOneActive( 2 );
}
else
{
m_backgroundImages.SetAllActive( false );
}
break;
case GraphyManager.ModuleState.BACKGROUND:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( false );
SetGraphActive( false );
m_backgroundImages.SetAllActive( false );
break;
case GraphyManager.ModuleState.OFF:
gameObject.SetActive( false );
break;
}
}
public void RestorePreviousState()
{
SetState( m_previousModuleState );
}
public void UpdateParameters()
{
foreach( var image in m_backgroundImages )
{
image.color = m_graphyManager.BackgroundColor;
}
m_fpsGraph.UpdateParameters();
m_fpsMonitor.UpdateParameters();
m_fpsText.UpdateParameters();
SetState( m_graphyManager.FpsModuleState );
}
public void RefreshParameters()
{
foreach( var image in m_backgroundImages )
{
image.color = m_graphyManager.BackgroundColor;
}
m_fpsGraph.UpdateParameters();
m_fpsMonitor.UpdateParameters();
m_fpsText.UpdateParameters();
SetState( m_currentModuleState, true );
}
#endregion
#region Methods -> Private
private void Init()
{
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_rectTransform = GetComponent<RectTransform>();
m_origPosition = m_rectTransform.anchoredPosition;
m_fpsGraph = GetComponent<G_FpsGraph>();
m_fpsMonitor = GetComponent<G_FpsMonitor>();
m_fpsText = GetComponent<G_FpsText>();
foreach( Transform child in transform )
{
if( child.parent == transform )
{
m_childrenGameObjects.Add( child.gameObject );
}
}
}
private void SetGraphActive( bool active )
{
m_fpsGraph.enabled = active;
m_fpsGraphGameObject.SetActive( active );
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 221dc0b3655ddb749ace6bad55f0159f
timeCreated: 1514998359
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Fps/G_FpsManager.cs
uploadId: 626547
@@ -0,0 +1,146 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 15-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using System;
using UnityEngine;
namespace Tayx.Graphy.Fps
{
public class G_FpsMonitor : MonoBehaviour
{
#region Variables -> Private
private short[] m_fpsSamples;
private short[] m_fpsSamplesSorted;
private short m_fpsSamplesCapacity = 1024;
private short m_onePercentSamples = 10;
private short m_zero1PercentSamples = 1;
private short m_fpsSamplesCount = 0;
private short m_indexSample = 0;
private float m_unscaledDeltaTime = 0f;
#endregion
#region Properties -> Public
public short CurrentFPS { get; private set; } = 0;
public short AverageFPS { get; private set; } = 0;
public short OnePercentFPS { get; private set; } = 0;
public short Zero1PercentFps { get; private set; } = 0;
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Update()
{
m_unscaledDeltaTime = Time.unscaledDeltaTime;
// Update fps and ms
CurrentFPS = (short) (Mathf.RoundToInt( 1f / m_unscaledDeltaTime ));
// Update avg fps
uint averageAddedFps = 0;
m_indexSample++;
if( m_indexSample >= m_fpsSamplesCapacity ) m_indexSample = 0;
m_fpsSamples[ m_indexSample ] = CurrentFPS;
if( m_fpsSamplesCount < m_fpsSamplesCapacity )
{
m_fpsSamplesCount++;
}
for( int i = 0; i < m_fpsSamplesCount; i++ )
{
averageAddedFps += (uint) m_fpsSamples[ i ];
}
AverageFPS = (short) ((float) averageAddedFps / (float) m_fpsSamplesCount);
// Update percent lows
m_fpsSamples.CopyTo( m_fpsSamplesSorted, 0 );
/*
* TODO: Find a faster way to do this.
* We can probably avoid copying the full array every time
* and insert the new item already sorted in the list.
*/
Array.Sort( m_fpsSamplesSorted,
( x, y ) => x.CompareTo( y ) ); // The lambda expression avoids garbage generation
bool zero1PercentCalculated = false;
uint totalAddedFps = 0;
short samplesToIterateThroughForOnePercent = m_fpsSamplesCount < m_onePercentSamples
? m_fpsSamplesCount
: m_onePercentSamples;
short samplesToIterateThroughForZero1Percent = m_fpsSamplesCount < m_zero1PercentSamples
? m_fpsSamplesCount
: m_zero1PercentSamples;
short sampleToStartIn = (short) (m_fpsSamplesCapacity - m_fpsSamplesCount);
for( short i = sampleToStartIn; i < sampleToStartIn + samplesToIterateThroughForOnePercent; i++ )
{
totalAddedFps += (ushort) m_fpsSamplesSorted[ i ];
if( !zero1PercentCalculated && i >= samplesToIterateThroughForZero1Percent - 1 )
{
zero1PercentCalculated = true;
Zero1PercentFps = (short) ((float) totalAddedFps / (float) m_zero1PercentSamples);
}
}
OnePercentFPS = (short) ((float) totalAddedFps / (float) m_onePercentSamples);
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
m_onePercentSamples = (short) (m_fpsSamplesCapacity / 100);
m_zero1PercentSamples = (short) (m_fpsSamplesCapacity / 1000);
}
#endregion
#region Methods -> Private
private void Init()
{
m_fpsSamples = new short[m_fpsSamplesCapacity];
m_fpsSamplesSorted = new short[m_fpsSamplesCapacity];
UpdateParameters();
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: b205584e495e4634aa3a332a78102a19
timeCreated: 1513376950
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Fps/G_FpsMonitor.cs
uploadId: 626547
@@ -0,0 +1,156 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 22-Nov-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.UI;
using Tayx.Graphy.Utils.NumString;
namespace Tayx.Graphy.Fps
{
public class G_FpsText : MonoBehaviour
{
#region Variables -> Serialized Private
[SerializeField] private Text m_fpsText = null;
[SerializeField] private Text m_msText = null;
[SerializeField] private Text m_avgFpsText = null;
[SerializeField] private Text m_onePercentFpsText = null;
[SerializeField] private Text m_zero1PercentFpsText = null;
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_FpsMonitor m_fpsMonitor = null;
private int m_updateRate = 4; // 4 updates per sec.
private int m_frameCount = 0;
private float m_deltaTime = 0f;
private float m_fps = 0f;
private float m_ms = 0f;
private const string m_msStringFormat = "0.0";
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Update()
{
m_deltaTime += Time.unscaledDeltaTime;
m_frameCount++;
// Only update texts 'm_updateRate' times per second
if( m_deltaTime > 1f / m_updateRate )
{
m_fps = m_frameCount / m_deltaTime;
m_ms = m_deltaTime / m_frameCount * 1000f;
// Update fps
m_fpsText.text = Mathf.RoundToInt( m_fps ).ToStringNonAlloc();
SetFpsRelatedTextColor( m_fpsText, m_fps );
// Update ms
m_msText.text = m_ms.ToStringNonAlloc( m_msStringFormat );
SetFpsRelatedTextColor( m_msText, m_fps );
// Update 1% fps
m_onePercentFpsText.text = ((int) (m_fpsMonitor.OnePercentFPS)).ToStringNonAlloc();
SetFpsRelatedTextColor( m_onePercentFpsText, m_fpsMonitor.OnePercentFPS );
// Update 0.1% fps
m_zero1PercentFpsText.text = ((int) (m_fpsMonitor.Zero1PercentFps)).ToStringNonAlloc();
SetFpsRelatedTextColor( m_zero1PercentFpsText, m_fpsMonitor.Zero1PercentFps );
// Update avg fps
m_avgFpsText.text = ((int) (m_fpsMonitor.AverageFPS)).ToStringNonAlloc();
SetFpsRelatedTextColor( m_avgFpsText, m_fpsMonitor.AverageFPS );
// Reset variables
m_deltaTime = 0f;
m_frameCount = 0;
}
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
m_updateRate = m_graphyManager.FpsTextUpdateRate;
}
#endregion
#region Methods -> Private
/// <summary>
/// Assigns color to a text according to their fps numeric value and
/// the colors specified in the 3 categories (Good, Caution, Critical).
/// </summary>
///
/// <param name="text">
/// UI Text component to change its color
/// </param>
///
/// <param name="fps">
/// Numeric fps value
/// </param>
private void SetFpsRelatedTextColor( Text text, float fps )
{
int roundedFps = Mathf.RoundToInt( fps );
if( roundedFps >= m_graphyManager.GoodFPSThreshold )
{
text.color = m_graphyManager.GoodFPSColor;
}
else if( roundedFps >= m_graphyManager.CautionFPSThreshold )
{
text.color = m_graphyManager.CautionFPSColor;
}
else
{
text.color = m_graphyManager.CriticalFPSColor;
}
}
private void Init()
{
G_IntString.Init( 0, 2000 ); // Max fps expected
G_FloatString.Init( 0, 100 ); // Max ms expected per frame
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_fpsMonitor = GetComponent<G_FpsMonitor>();
UpdateParameters();
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: f74bbf307d92b0d4e81ae60b9eb1e42f
timeCreated: 1511555604
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Fps/G_FpsText.cs
uploadId: 626547
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: aca40e3cb2846db40ad6d970f36d4a7f
folderAsset: yes
timeCreated: 1516716444
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 23-Jan-18
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
namespace Tayx.Graphy.Graph
{
public abstract class G_Graph : MonoBehaviour
{
#region Methods -> Protected
/// <summary>
/// Updates the graph/s.
/// </summary>
protected abstract void UpdateGraph();
/// <summary>
/// Creates the points for the graph/s.
/// </summary>
protected abstract void CreatePoints();
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 67969a520b115cd47a7d955c9b2abfa6
timeCreated: 1516716468
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Graph/G_Graph.cs
uploadId: 626547
@@ -0,0 +1,567 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 23-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using System;
using UnityEngine;
using UnityEngine.Events;
using Debug = UnityEngine.Debug;
using System.Collections.Generic;
using System.Linq;
using Tayx.Graphy.Audio;
using Tayx.Graphy.Fps;
using Tayx.Graphy.Ram;
using Tayx.Graphy.Utils;
namespace Tayx.Graphy
{
/// <summary>
/// Main class to access the Graphy Debugger API.
/// </summary>
public class GraphyDebugger : G_Singleton<GraphyDebugger>
{
protected GraphyDebugger()
{
}
#region Enums -> Public
public enum DebugVariable
{
Fps,
Fps_Min,
Fps_Max,
Fps_Avg,
Ram_Allocated,
Ram_Reserved,
Ram_Mono,
Audio_DB
}
public enum DebugComparer
{
Less_than,
Equals_or_less_than,
Equals,
Equals_or_greater_than,
Greater_than
}
public enum ConditionEvaluation
{
All_conditions_must_be_met,
Only_one_condition_has_to_be_met,
}
public enum MessageType
{
Log,
Warning,
Error
}
#endregion
#region Structs -> Public
[System.Serializable]
public struct DebugCondition
{
[Tooltip( "Variable to compare against" )]
public DebugVariable Variable;
[Tooltip( "Comparer operator to use" )]
public DebugComparer Comparer;
[Tooltip( "Value to compare against the chosen variable" )]
public float Value;
}
#endregion
#region Helper Classes
[System.Serializable]
public class DebugPacket
{
[Tooltip( "If false, it won't be checked" )]
public bool Active = true;
[Tooltip( "Optional Id. It's used to get or remove DebugPackets in runtime" )]
public int Id;
[Tooltip( "If true, once the actions are executed, this DebugPacket will delete itself" )]
public bool ExecuteOnce = true;
[Tooltip( "Time to wait before checking if conditions are met (use this to avoid low fps drops triggering the conditions when loading the game)" )]
public float InitSleepTime = 2;
[Tooltip( "Time to wait before checking if conditions are met again (once they have already been met and if ExecuteOnce is false)" )]
public float ExecuteSleepTime = 2;
public ConditionEvaluation ConditionEvaluation = ConditionEvaluation.All_conditions_must_be_met;
[Tooltip( "List of conditions that will be checked each frame" )]
public List<DebugCondition> DebugConditions = new List<DebugCondition>();
// Actions on conditions met
public MessageType MessageType;
[Multiline] public string Message = string.Empty;
public bool TakeScreenshot = false;
public string ScreenshotFileName = "Graphy_Screenshot";
[Tooltip( "If true, it pauses the editor" )]
public bool DebugBreak = false;
public UnityEvent UnityEvents;
public List<System.Action> Callbacks = new List<System.Action>();
private bool canBeChecked = false;
private bool executed = false;
private float timePassed = 0;
public bool Check => canBeChecked;
public void Update()
{
if( !canBeChecked )
{
timePassed += Time.deltaTime;
if( (executed && timePassed >= ExecuteSleepTime)
|| (!executed && timePassed >= InitSleepTime) )
{
canBeChecked = true;
timePassed = 0;
}
}
}
public void Executed()
{
canBeChecked = false;
executed = true;
}
}
#endregion
#region Variables -> Serialized Private
[SerializeField] private List<DebugPacket> m_debugPackets = new List<DebugPacket>();
#endregion
#region Variables -> Private
private G_FpsMonitor m_fpsMonitor = null;
private G_RamMonitor m_ramMonitor = null;
private G_AudioMonitor m_audioMonitor = null;
#endregion
#region Methods -> Unity Callbacks
private void Start()
{
m_fpsMonitor = GetComponentInChildren<G_FpsMonitor>();
m_ramMonitor = GetComponentInChildren<G_RamMonitor>();
m_audioMonitor = GetComponentInChildren<G_AudioMonitor>();
}
private void Update()
{
CheckDebugPackets();
}
#endregion
#region Methods -> Public
/// <summary>
/// Add a new DebugPacket.
/// </summary>
public void AddNewDebugPacket( DebugPacket newDebugPacket )
{
m_debugPackets?.Add( newDebugPacket );
}
/// <summary>
/// Add a new DebugPacket.
/// </summary>
public void AddNewDebugPacket
(
int newId,
DebugCondition newDebugCondition,
MessageType newMessageType,
string newMessage,
bool newDebugBreak,
System.Action newCallback
)
{
DebugPacket newDebugPacket = new DebugPacket();
newDebugPacket.Id = newId;
newDebugPacket.DebugConditions.Add( newDebugCondition );
newDebugPacket.MessageType = newMessageType;
newDebugPacket.Message = newMessage;
newDebugPacket.DebugBreak = newDebugBreak;
newDebugPacket.Callbacks.Add( newCallback );
AddNewDebugPacket( newDebugPacket );
}
/// <summary>
/// Add a new DebugPacket.
/// </summary>
public void AddNewDebugPacket
(
int newId,
List<DebugCondition> newDebugConditions,
MessageType newMessageType,
string newMessage,
bool newDebugBreak,
System.Action newCallback
)
{
DebugPacket newDebugPacket = new DebugPacket();
newDebugPacket.Id = newId;
newDebugPacket.DebugConditions = newDebugConditions;
newDebugPacket.MessageType = newMessageType;
newDebugPacket.Message = newMessage;
newDebugPacket.DebugBreak = newDebugBreak;
newDebugPacket.Callbacks.Add( newCallback );
AddNewDebugPacket( newDebugPacket );
}
/// <summary>
/// Add a new DebugPacket.
/// </summary>
public void AddNewDebugPacket
(
int newId,
DebugCondition newDebugCondition,
MessageType newMessageType,
string newMessage,
bool newDebugBreak,
List<System.Action> newCallbacks
)
{
DebugPacket newDebugPacket = new DebugPacket();
newDebugPacket.Id = newId;
newDebugPacket.DebugConditions.Add( newDebugCondition );
newDebugPacket.MessageType = newMessageType;
newDebugPacket.Message = newMessage;
newDebugPacket.DebugBreak = newDebugBreak;
newDebugPacket.Callbacks = newCallbacks;
AddNewDebugPacket( newDebugPacket );
}
/// <summary>
/// Add a new DebugPacket.
/// </summary>
public void AddNewDebugPacket
(
int newId,
List<DebugCondition> newDebugConditions,
MessageType newMessageType,
string newMessage,
bool newDebugBreak,
List<System.Action> newCallbacks
)
{
DebugPacket newDebugPacket = new DebugPacket();
newDebugPacket.Id = newId;
newDebugPacket.DebugConditions = newDebugConditions;
newDebugPacket.MessageType = newMessageType;
newDebugPacket.Message = newMessage;
newDebugPacket.DebugBreak = newDebugBreak;
newDebugPacket.Callbacks = newCallbacks;
AddNewDebugPacket( newDebugPacket );
}
/// <summary>
/// Returns the first Packet with the specified ID in the DebugPacket list.
/// </summary>
/// <param name="packetId"></param>
/// <returns></returns>
public DebugPacket GetFirstDebugPacketWithId( int packetId )
{
return m_debugPackets.First( x => x.Id == packetId );
}
/// <summary>
/// Returns a list with all the Packets with the specified ID in the DebugPacket list.
/// </summary>
/// <param name="packetId"></param>
/// <returns></returns>
public List<DebugPacket> GetAllDebugPacketsWithId( int packetId )
{
return m_debugPackets.FindAll( x => x.Id == packetId );
}
/// <summary>
/// Removes the first Packet with the specified ID in the DebugPacket list.
/// </summary>
/// <param name="packetId"></param>
/// <returns></returns>
public void RemoveFirstDebugPacketWithId( int packetId )
{
if( m_debugPackets != null && GetFirstDebugPacketWithId( packetId ) != null )
{
m_debugPackets.Remove( GetFirstDebugPacketWithId( packetId ) );
}
}
/// <summary>
/// Removes all the Packets with the specified ID in the DebugPacket list.
/// </summary>
/// <param name="packetId"></param>
/// <returns></returns>
public void RemoveAllDebugPacketsWithId( int packetId )
{
if( m_debugPackets != null )
{
m_debugPackets.RemoveAll( x => x.Id == packetId );
}
}
/// <summary>
/// Add an Action callback to the first Packet with the specified ID in the DebugPacket list.
/// </summary>
/// <param name="callback"></param>
/// <param name="id"></param>
public void AddCallbackToFirstDebugPacketWithId( System.Action callback, int id )
{
if( GetFirstDebugPacketWithId( id ) != null )
{
GetFirstDebugPacketWithId( id ).Callbacks.Add( callback );
}
}
/// <summary>
/// Add an Action callback to all the Packets with the specified ID in the DebugPacket list.
/// </summary>
/// <param name="callback"></param>
/// <param name="id"></param>
public void AddCallbackToAllDebugPacketWithId( System.Action callback, int id )
{
if( GetAllDebugPacketsWithId( id ) != null )
{
foreach( var debugPacket in GetAllDebugPacketsWithId( id ) )
{
if( callback != null )
{
debugPacket.Callbacks.Add( callback );
}
}
}
}
#endregion
#region Methods -> Private
/// <summary>
/// Checks all the Debug Packets to see if they have to be executed.
/// </summary>
private void CheckDebugPackets()
{
if( m_debugPackets == null )
{
return;
}
for( int i = 0; i < m_debugPackets.Count; i++ )
{
DebugPacket packet = m_debugPackets[ i ];
if( packet != null && packet.Active )
{
packet.Update();
if( packet.Check )
{
switch( packet.ConditionEvaluation )
{
case ConditionEvaluation.All_conditions_must_be_met:
int count = 0;
foreach( var packetDebugCondition in packet.DebugConditions )
{
if( CheckIfConditionIsMet( packetDebugCondition ) )
{
count++;
}
}
if( count >= packet.DebugConditions.Count )
{
ExecuteOperationsInDebugPacket( packet );
if( packet.ExecuteOnce )
{
m_debugPackets[ i ] = null;
}
}
break;
case ConditionEvaluation.Only_one_condition_has_to_be_met:
foreach( var packetDebugCondition in packet.DebugConditions )
{
if( CheckIfConditionIsMet( packetDebugCondition ) )
{
ExecuteOperationsInDebugPacket( packet );
if( packet.ExecuteOnce )
{
m_debugPackets[ i ] = null;
}
break;
}
}
break;
}
}
}
}
m_debugPackets.RemoveAll( ( packet ) => packet == null );
}
/// <summary>
/// Returns true if a condition is met.
/// </summary>
/// <param name="debugCondition"></param>
/// <returns></returns>
private bool CheckIfConditionIsMet( DebugCondition debugCondition )
{
switch( debugCondition.Comparer )
{
case DebugComparer.Less_than:
return GetRequestedValueFromDebugVariable( debugCondition.Variable ) < debugCondition.Value;
case DebugComparer.Equals_or_less_than:
return GetRequestedValueFromDebugVariable( debugCondition.Variable ) <= debugCondition.Value;
case DebugComparer.Equals:
return Mathf.Approximately( GetRequestedValueFromDebugVariable( debugCondition.Variable ),
debugCondition.Value );
case DebugComparer.Equals_or_greater_than:
return GetRequestedValueFromDebugVariable( debugCondition.Variable ) >= debugCondition.Value;
case DebugComparer.Greater_than:
return GetRequestedValueFromDebugVariable( debugCondition.Variable ) > debugCondition.Value;
default:
return false;
}
}
/// <summary>
/// Obtains the requested value from the specified variable.
/// </summary>
/// <param name="debugVariable"></param>
/// <returns></returns>
private float GetRequestedValueFromDebugVariable( DebugVariable debugVariable )
{
switch( debugVariable )
{
case DebugVariable.Fps:
return m_fpsMonitor != null ? m_fpsMonitor.CurrentFPS : 0;
case DebugVariable.Fps_Min:
return m_fpsMonitor != null ? m_fpsMonitor.OnePercentFPS : 0;
case DebugVariable.Fps_Max:
return m_fpsMonitor != null ? m_fpsMonitor.Zero1PercentFps : 0;
case DebugVariable.Fps_Avg:
return m_fpsMonitor != null ? m_fpsMonitor.AverageFPS : 0;
case DebugVariable.Ram_Allocated:
return m_ramMonitor != null ? m_ramMonitor.AllocatedRam : 0;
case DebugVariable.Ram_Reserved:
return m_ramMonitor != null ? m_ramMonitor.AllocatedRam : 0;
case DebugVariable.Ram_Mono:
return m_ramMonitor != null ? m_ramMonitor.AllocatedRam : 0;
case DebugVariable.Audio_DB:
return m_audioMonitor != null ? m_audioMonitor.MaxDB : 0;
default:
return 0;
}
}
/// <summary>
/// Executes the operations in the DebugPacket specified.
/// </summary>
/// <param name="debugPacket"></param>
private void ExecuteOperationsInDebugPacket( DebugPacket debugPacket )
{
if( debugPacket != null )
{
if( debugPacket.DebugBreak )
{
Debug.Break();
}
if( debugPacket.Message != "" )
{
string message = "[Graphy] (" + System.DateTime.Now + "): " + debugPacket.Message;
switch( debugPacket.MessageType )
{
case MessageType.Log:
Debug.Log( message );
break;
case MessageType.Warning:
Debug.LogWarning( message );
break;
case MessageType.Error:
Debug.LogError( message );
break;
}
}
if( debugPacket.TakeScreenshot )
{
string path = debugPacket.ScreenshotFileName + "_" + System.DateTime.Now + ".png";
path = path.Replace( "/", "-" ).Replace( " ", "_" ).Replace( ":", "-" );
ScreenCapture.CaptureScreenshot( path );
}
debugPacket.UnityEvents?.Invoke();
foreach( Action callback in debugPacket.Callbacks )
{
callback?.Invoke();
}
debugPacket.Executed();
}
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: cb8428f1f208dcc49b6c04976d44cbc9
timeCreated: 1514034949
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/GraphyDebugger.cs
uploadId: 626547
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: c80e6d63202cef44ca3ffdaccec693be
timeCreated: 1512508924
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/GraphyManager.cs
uploadId: 626547
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 839df5cf44c5c6f43b1a846e73f3e498
folderAsset: yes
timeCreated: 1513377097
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,264 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 15-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using Tayx.Graphy.Graph;
using UnityEngine;
using UnityEngine.UI;
namespace Tayx.Graphy.Ram
{
public class G_RamGraph : G_Graph
{
#region Variables -> Serialized Private
[SerializeField] private Image m_imageAllocated = null;
[SerializeField] private Image m_imageReserved = null;
[SerializeField] private Image m_imageMono = null;
[SerializeField] private Shader ShaderFull = null;
[SerializeField] private Shader ShaderLight = null;
[SerializeField] private bool m_isInitialized = false;
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_RamMonitor m_ramMonitor = null;
private int m_resolution = 150;
private G_GraphShader m_shaderGraphAllocated = null;
private G_GraphShader m_shaderGraphReserved = null;
private G_GraphShader m_shaderGraphMono = null;
private float[] m_allocatedArray;
private float[] m_reservedArray;
private float[] m_monoArray;
private float m_highestMemory = 0;
#endregion
#region Methods -> Unity Callbacks
private void Update()
{
UpdateGraph();
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
if( m_shaderGraphAllocated == null
|| m_shaderGraphReserved == null
|| m_shaderGraphMono == null )
{
/*
* Note: this is fine, since we don't much care what granularity we use if the graph
* has not been initialized, i.e. it's disabled. There is no chance that for some reason
* parameters will not stay up to date if at some point in the future the graph is enabled:
* at the end of Init(), UpdateParameters() is called again.
*/
return;
}
switch( m_graphyManager.GraphyMode )
{
case GraphyManager.Mode.FULL:
m_shaderGraphAllocated.ArrayMaxSize = G_GraphShader.ArrayMaxSizeFull;
m_shaderGraphReserved.ArrayMaxSize = G_GraphShader.ArrayMaxSizeFull;
m_shaderGraphMono.ArrayMaxSize = G_GraphShader.ArrayMaxSizeFull;
m_shaderGraphAllocated.Image.material = new Material( ShaderFull );
m_shaderGraphReserved.Image.material = new Material( ShaderFull );
m_shaderGraphMono.Image.material = new Material( ShaderFull );
break;
case GraphyManager.Mode.LIGHT:
m_shaderGraphAllocated.ArrayMaxSize = G_GraphShader.ArrayMaxSizeLight;
m_shaderGraphReserved.ArrayMaxSize = G_GraphShader.ArrayMaxSizeLight;
m_shaderGraphMono.ArrayMaxSize = G_GraphShader.ArrayMaxSizeLight;
m_shaderGraphAllocated.Image.material = new Material( ShaderLight );
m_shaderGraphReserved.Image.material = new Material( ShaderLight );
m_shaderGraphMono.Image.material = new Material( ShaderLight );
break;
}
m_shaderGraphAllocated.InitializeShader();
m_shaderGraphReserved.InitializeShader();
m_shaderGraphMono.InitializeShader();
m_resolution = m_graphyManager.RamGraphResolution;
CreatePoints();
}
#endregion
#region Methods -> Protected Override
protected override void UpdateGraph()
{
// Since we no longer initialize by default OnEnable(),
// we need to check here, and Init() if needed
if( !m_isInitialized )
{
Init();
}
float allocatedMemory = m_ramMonitor.AllocatedRam;
float reservedMemory = m_ramMonitor.ReservedRam;
float monoMemory = m_ramMonitor.MonoRam;
m_highestMemory = 0;
for( int i = 0; i <= m_resolution - 1; i++ )
{
if( i >= m_resolution - 1 )
{
m_allocatedArray[ i ] = allocatedMemory;
m_reservedArray[ i ] = reservedMemory;
m_monoArray[ i ] = monoMemory;
}
else
{
m_allocatedArray[ i ] = m_allocatedArray[ i + 1 ];
m_reservedArray[ i ] = m_reservedArray[ i + 1 ];
m_monoArray[ i ] = m_monoArray[ i + 1 ];
}
if( m_highestMemory < m_reservedArray[ i ] )
{
m_highestMemory = m_reservedArray[ i ];
}
}
for( int i = 0; i <= m_resolution - 1; i++ )
{
m_shaderGraphAllocated.ShaderArrayValues[ i ] = m_allocatedArray[ i ] / m_highestMemory;
m_shaderGraphReserved.ShaderArrayValues[ i ] = m_reservedArray[ i ] / m_highestMemory;
m_shaderGraphMono.ShaderArrayValues[ i ] = m_monoArray[ i ] / m_highestMemory;
}
m_shaderGraphAllocated.UpdatePoints();
m_shaderGraphReserved.UpdatePoints();
m_shaderGraphMono.UpdatePoints();
}
protected override void CreatePoints()
{
if( m_shaderGraphAllocated.ShaderArrayValues == null ||
m_shaderGraphAllocated.ShaderArrayValues.Length != m_resolution )
{
m_allocatedArray = new float[m_resolution];
m_reservedArray = new float[m_resolution];
m_monoArray = new float[m_resolution];
m_shaderGraphAllocated.ShaderArrayValues = new float[m_resolution];
m_shaderGraphReserved.ShaderArrayValues = new float[m_resolution];
m_shaderGraphMono.ShaderArrayValues = new float[m_resolution];
}
for( int i = 0; i < m_resolution; i++ )
{
m_shaderGraphAllocated.ShaderArrayValues[ i ] = 0;
m_shaderGraphReserved.ShaderArrayValues[ i ] = 0;
m_shaderGraphMono.ShaderArrayValues[ i ] = 0;
}
// Initialize the material values
// Colors
m_shaderGraphAllocated.GoodColor = m_graphyManager.AllocatedRamColor;
m_shaderGraphAllocated.CautionColor = m_graphyManager.AllocatedRamColor;
m_shaderGraphAllocated.CriticalColor = m_graphyManager.AllocatedRamColor;
m_shaderGraphAllocated.UpdateColors();
m_shaderGraphReserved.GoodColor = m_graphyManager.ReservedRamColor;
m_shaderGraphReserved.CautionColor = m_graphyManager.ReservedRamColor;
m_shaderGraphReserved.CriticalColor = m_graphyManager.ReservedRamColor;
m_shaderGraphReserved.UpdateColors();
m_shaderGraphMono.GoodColor = m_graphyManager.MonoRamColor;
m_shaderGraphMono.CautionColor = m_graphyManager.MonoRamColor;
m_shaderGraphMono.CriticalColor = m_graphyManager.MonoRamColor;
m_shaderGraphMono.UpdateColors();
// Thresholds
m_shaderGraphAllocated.GoodThreshold = 0;
m_shaderGraphAllocated.CautionThreshold = 0;
m_shaderGraphAllocated.UpdateThresholds();
m_shaderGraphReserved.GoodThreshold = 0;
m_shaderGraphReserved.CautionThreshold = 0;
m_shaderGraphReserved.UpdateThresholds();
m_shaderGraphMono.GoodThreshold = 0;
m_shaderGraphMono.CautionThreshold = 0;
m_shaderGraphMono.UpdateThresholds();
m_shaderGraphAllocated.UpdateArrayValuesLength();
m_shaderGraphReserved.UpdateArrayValuesLength();
m_shaderGraphMono.UpdateArrayValuesLength();
// Average
m_shaderGraphAllocated.Average = 0;
m_shaderGraphReserved.Average = 0;
m_shaderGraphMono.Average = 0;
m_shaderGraphAllocated.UpdateAverage();
m_shaderGraphReserved.UpdateAverage();
m_shaderGraphMono.UpdateAverage();
}
#endregion
#region Methods -> Private
private void Init()
{
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_ramMonitor = GetComponent<G_RamMonitor>();
m_shaderGraphAllocated = new G_GraphShader();
m_shaderGraphReserved = new G_GraphShader();
m_shaderGraphMono = new G_GraphShader();
m_shaderGraphAllocated.Image = m_imageAllocated;
m_shaderGraphReserved.Image = m_imageReserved;
m_shaderGraphMono.Image = m_imageMono;
UpdateParameters();
m_isInitialized = true;
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: a9c49f1e95f2dab428b3a0ed56328a1c
timeCreated: 1512484813
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Ram/G_RamGraph.cs
uploadId: 626547
@@ -0,0 +1,232 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 03-Jan-18
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using System.Collections.Generic;
using Tayx.Graphy.UI;
using Tayx.Graphy.Utils;
using UnityEngine.UI;
namespace Tayx.Graphy.Ram
{
public class G_RamManager : MonoBehaviour, IMovable, IModifiableState
{
#region Variables -> Serialized Private
[SerializeField] private GameObject m_ramGraphGameObject = null;
[SerializeField] private List<Image> m_backgroundImages = new List<Image>();
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_RamGraph m_ramGraph = null;
private G_RamText m_ramText = null;
private RectTransform m_rectTransform = null;
private Vector2 m_origPosition = Vector2.zero;
private List<GameObject> m_childrenGameObjects = new List<GameObject>();
private GraphyManager.ModuleState m_previousModuleState = GraphyManager.ModuleState.FULL;
private GraphyManager.ModuleState m_currentModuleState = GraphyManager.ModuleState.FULL;
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Start()
{
UpdateParameters();
}
#endregion
#region Methods -> Public
public void SetPosition( GraphyManager.ModulePosition newModulePosition, Vector2 offset )
{
if ( newModulePosition == GraphyManager.ModulePosition.FREE )
return;
m_rectTransform.anchoredPosition = m_origPosition;
float xSideOffset = Mathf.Abs( m_rectTransform.anchoredPosition.x ) + offset.x;
float ySideOffset = Mathf.Abs( m_rectTransform.anchoredPosition.y ) + offset.y;
switch( newModulePosition )
{
case GraphyManager.ModulePosition.TOP_LEFT:
m_rectTransform.anchorMax = Vector2.up;
m_rectTransform.anchorMin = Vector2.up;
m_rectTransform.anchoredPosition = new Vector2( xSideOffset, -ySideOffset );
break;
case GraphyManager.ModulePosition.TOP_RIGHT:
m_rectTransform.anchorMax = Vector2.one;
m_rectTransform.anchorMin = Vector2.one;
m_rectTransform.anchoredPosition = new Vector2( -xSideOffset, -ySideOffset );
break;
case GraphyManager.ModulePosition.BOTTOM_LEFT:
m_rectTransform.anchorMax = Vector2.zero;
m_rectTransform.anchorMin = Vector2.zero;
m_rectTransform.anchoredPosition = new Vector2( xSideOffset, ySideOffset );
break;
case GraphyManager.ModulePosition.BOTTOM_RIGHT:
m_rectTransform.anchorMax = Vector2.right;
m_rectTransform.anchorMin = Vector2.right;
m_rectTransform.anchoredPosition = new Vector2( -xSideOffset, ySideOffset );
break;
}
}
public void SetState( GraphyManager.ModuleState state, bool silentUpdate = false )
{
if( !silentUpdate )
{
m_previousModuleState = m_currentModuleState;
}
m_currentModuleState = state;
switch( state )
{
case GraphyManager.ModuleState.FULL:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( true );
SetGraphActive( true );
if( m_graphyManager.Background )
{
m_backgroundImages.SetOneActive( 0 );
}
else
{
m_backgroundImages.SetAllActive( false );
}
break;
case GraphyManager.ModuleState.TEXT:
case GraphyManager.ModuleState.BASIC:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( true );
SetGraphActive( false );
if( m_graphyManager.Background )
{
m_backgroundImages.SetOneActive( 1 );
}
else
{
m_backgroundImages.SetAllActive( false );
}
break;
case GraphyManager.ModuleState.BACKGROUND:
gameObject.SetActive( true );
SetGraphActive( false );
m_childrenGameObjects.SetAllActive( false );
m_backgroundImages.SetAllActive( false );
break;
case GraphyManager.ModuleState.OFF:
gameObject.SetActive( false );
break;
}
}
public void RestorePreviousState()
{
SetState( m_previousModuleState );
}
public void UpdateParameters()
{
foreach( var image in m_backgroundImages )
{
image.color = m_graphyManager.BackgroundColor;
}
m_ramGraph.UpdateParameters();
m_ramText.UpdateParameters();
SetState( m_graphyManager.RamModuleState );
}
public void RefreshParameters()
{
foreach( var image in m_backgroundImages )
{
image.color = m_graphyManager.BackgroundColor;
}
m_ramGraph.UpdateParameters();
m_ramText.UpdateParameters();
SetState( m_currentModuleState, true );
}
#endregion
#region Methods -> Private
private void Init()
{
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_ramGraph = GetComponent<G_RamGraph>();
m_ramText = GetComponent<G_RamText>();
m_rectTransform = GetComponent<RectTransform>();
m_origPosition = m_rectTransform.anchoredPosition;
foreach( Transform child in transform )
{
if( child.parent == transform )
{
m_childrenGameObjects.Add( child.gameObject );
}
}
}
private void SetGraphActive( bool active )
{
m_ramGraph.enabled = active;
m_ramGraphGameObject.SetActive( active );
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 84f7591c01b7f1a4ab82f1a0038491da
timeCreated: 1514998367
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Ram/G_RamManager.cs
uploadId: 626547
@@ -0,0 +1,40 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 15-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.Profiling;
namespace Tayx.Graphy.Ram
{
public class G_RamMonitor : MonoBehaviour
{
#region Properties -> Public
public float AllocatedRam { get; private set; }
public float ReservedRam { get; private set; }
public float MonoRam { get; private set; }
#endregion
#region Methods -> Unity Callbacks
private void Update()
{
AllocatedRam = Profiler.GetTotalAllocatedMemoryLong() / 1048576f;
ReservedRam = Profiler.GetTotalReservedMemoryLong() / 1048576f;
MonoRam = Profiler.GetMonoUsedSizeLong() / 1048576f;
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 2494656f0dd693144be1306d5551e544
timeCreated: 1513377000
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Ram/G_RamMonitor.cs
uploadId: 626547
@@ -0,0 +1,96 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 05-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.UI;
using Tayx.Graphy.Utils.NumString;
namespace Tayx.Graphy.Ram
{
public class G_RamText : MonoBehaviour
{
#region Variables -> Serialized Private
[SerializeField] private Text m_allocatedSystemMemorySizeText = null;
[SerializeField] private Text m_reservedSystemMemorySizeText = null;
[SerializeField] private Text m_monoSystemMemorySizeText = null;
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_RamMonitor m_ramMonitor = null;
private float m_updateRate = 4f; // 4 updates per sec.
private float m_deltaTime = 0.0f;
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Update()
{
m_deltaTime += Time.unscaledDeltaTime;
if( m_deltaTime > 1f / m_updateRate )
{
// Update allocated, mono and reserved memory
m_allocatedSystemMemorySizeText.text = ((int) m_ramMonitor.AllocatedRam).ToStringNonAlloc();
m_reservedSystemMemorySizeText.text = ((int) m_ramMonitor.ReservedRam).ToStringNonAlloc();
m_monoSystemMemorySizeText.text = ((int) m_ramMonitor.MonoRam).ToStringNonAlloc();
m_deltaTime = 0f;
}
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
m_allocatedSystemMemorySizeText.color = m_graphyManager.AllocatedRamColor;
m_reservedSystemMemorySizeText.color = m_graphyManager.ReservedRamColor;
m_monoSystemMemorySizeText.color = m_graphyManager.MonoRamColor;
m_updateRate = m_graphyManager.RamTextUpdateRate;
}
#endregion
#region Methods -> Private
private void Init()
{
// We assume no game will consume more than 16GB of RAM.
// If it does, who cares about some minuscule garbage allocation lol.
G_IntString.Init( 0, 16386 );
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_ramMonitor = GetComponent<G_RamMonitor>();
UpdateParameters();
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 28d32ee74b6e6d24ea89d1b477060318
timeCreated: 1512484799
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Ram/G_RamText.cs
uploadId: 626547
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6d11ec87c6db49d40af874a49810f377
folderAsset: yes
timeCreated: 1513377085
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,121 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 22-Nov-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.UI;
namespace Tayx.Graphy
{
/// <summary>
/// This class communicates directly with the shader to draw the graphs. Performance here is very important
/// to reduce as much overhead as possible, as we are updating hundreds of values every frame.
/// </summary>
public class G_GraphShader
{
#region Variables
public const int ArrayMaxSizeFull = 512;
public const int ArrayMaxSizeLight = 128;
public int ArrayMaxSize = 128;
public float[] ShaderArrayValues;
public Image Image = null;
public float Average = 0;
public float GoodThreshold = 0;
public float CautionThreshold = 0;
public Color GoodColor = Color.white;
public Color CautionColor = Color.white;
public Color CriticalColor = Color.white;
private static readonly int AveragePropertyId = Shader.PropertyToID( "Average" );
private static readonly int GoodThresholdPropertyId = Shader.PropertyToID( "_GoodThreshold" );
private static readonly int CautionThresholdPropertyId = Shader.PropertyToID( "_CautionThreshold" );
private static readonly int GoodColorPropertyId = Shader.PropertyToID( "_GoodColor" );
private static readonly int CautionColorPropertyId = Shader.PropertyToID( "_CautionColor" );
private static readonly int CriticalColorPropertyId = Shader.PropertyToID( "_CriticalColor" );
private static readonly int GraphValues = Shader.PropertyToID( "GraphValues" );
private static readonly int GraphValuesLength = Shader.PropertyToID( "GraphValues_Length" );
#endregion
#region Methods -> Public
/// <summary>
/// This is done to avoid a design problem that arrays in shaders have,
/// and should be called before initializing any shader graph.
/// The first time that you use initialize an array, the size of the array in the shader is fixed.
/// This is why sometimes you will get a warning saying that the array size will be capped.
/// It shouldn't generate any issues, but in the worst case scenario just reset the Unity Editor
/// (if for some reason the shaders reload).
/// I also cache the Property IDs, that make access faster to modify shader parameters.
/// </summary>
public void InitializeShader()
{
Image.material.SetFloatArray( GraphValues, new float[ArrayMaxSize] );
}
/// <summary>
/// Updates the GraphValuesLength parameter in the material with the current length of the
/// ShaderArrayValues float[] array.
/// </summary>
public void UpdateArrayValuesLength()
{
Image.material.SetInt( GraphValuesLength, ShaderArrayValues.Length );
}
/// <summary>
/// Updates the average parameter in the material.
/// </summary>
public void UpdateAverage()
{
Image.material.SetFloat( AveragePropertyId, Average );
}
/// <summary>
/// Updates the thresholds in the material.
/// </summary>
public void UpdateThresholds()
{
Image.material.SetFloat( GoodThresholdPropertyId, GoodThreshold );
Image.material.SetFloat( CautionThresholdPropertyId, CautionThreshold );
}
/// <summary>
/// Updates the colors in the material.
/// </summary>
public void UpdateColors()
{
Image.material.SetColor( GoodColorPropertyId, GoodColor );
Image.material.SetColor( CautionColorPropertyId, CautionColor );
Image.material.SetColor( CriticalColorPropertyId, CriticalColor );
}
/// <summary>
/// Updates the points in the graph with the set array of values.
/// </summary>
public void UpdatePoints()
{
Image.material.SetFloatArray( GraphValues, ShaderArrayValues );
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 0ddb605ced1369e409812b4f405221cd
timeCreated: 1511903341
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Shader/G_GraphShader.cs
uploadId: 626547
@@ -0,0 +1,26 @@
{
"name": "Tayx.Graphy",
"references": [
"GUID:75469ad4d38634e559750d17036d5f7c"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.inputsystem",
"expression": "",
"define": "GRAPHY_NEW_INPUT"
},
{
"name": "com.unity.modules.xr",
"expression": "",
"define": "GRAPHY_XR"
}
],
"noEngineReferences": false
}
@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 18e5109d897e1b244ab2dfeaf5482c7b
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Tayx.Graphy.asmdef
uploadId: 626547
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a6a45022ef0b3654a9d036efed540b32
folderAsset: yes
timeCreated: 1514998503
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,88 @@
using UnityEngine;
namespace Graphy.Runtime.UI
{
[RequireComponent(typeof(RectTransform))]
public sealed class G_SafeArea : MonoBehaviour
{
[SerializeField] private bool m_conformX = true; // Conform to screen safe area on X-axis (default true, disable to ignore)
[SerializeField] private bool m_conformY = true; // Conform to screen safe area on Y-axis (default true, disable to ignore)
private RectTransform m_rectTransform;
private Rect m_lastSafeArea = new Rect (0, 0, 0, 0);
#if UNITY_EDITOR
private DrivenRectTransformTracker m_rectTransformTracker;
#endif
private void Awake()
{
m_rectTransform = GetComponent<RectTransform> ();
Refresh();
}
private void Update()
{
Refresh();
}
#if UNITY_EDITOR
private void OnDisable()
{
m_rectTransformTracker.Clear();
}
#endif
private void Refresh()
{
#if UNITY_EDITOR
// Make the rectTransform not editable in the inspector.
m_rectTransformTracker.Clear();
m_rectTransformTracker.Add(
this,
m_rectTransform,
DrivenTransformProperties.AnchoredPosition
| DrivenTransformProperties.SizeDelta
| DrivenTransformProperties.AnchorMin
| DrivenTransformProperties.AnchorMax
| DrivenTransformProperties.Pivot
);
#endif
Rect safeArea = Screen.safeArea;
if (safeArea != m_lastSafeArea)
ApplySafeArea (safeArea);
}
private void ApplySafeArea(Rect r)
{
m_lastSafeArea = r;
// Ignore x-axis?
if (!m_conformX)
{
r.x = 0;
r.width = Screen.width;
}
// Ignore y-axis?
if (!m_conformY)
{
r.y = 0;
r.height = Screen.height;
}
// Convert safe area rectangle from absolute pixels to normalised anchor coordinates
Vector2 anchorMin = r.position;
Vector2 anchorMax = r.position + r.size;
anchorMin.x /= Screen.width;
anchorMin.y /= Screen.height;
anchorMax.x /= Screen.width;
anchorMax.y /= Screen.height;
m_rectTransform.anchorMin = anchorMin;
m_rectTransform.anchorMax = anchorMax;
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 2f4bf9244f3564807b739e8f5138ce08
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/UI/G_SafeArea.cs
uploadId: 626547
@@ -0,0 +1,26 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 03-Jan-18
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
namespace Tayx.Graphy.UI
{
public interface IModifiableState
{
/// <summary>
/// Set the module state.
/// </summary>
/// <param name="newState">
/// The new state.
/// </param>
void SetState( GraphyManager.ModuleState newState, bool silentUpdate );
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: cbc1852edf51f8046aed2f13ea532ea9
timeCreated: 1514998527
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/UI/IModifiableState.cs
uploadId: 626547
@@ -0,0 +1,28 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 03-Jan-18
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
namespace Tayx.Graphy.UI
{
public interface IMovable
{
/// <summary>
/// Sets the position of the module.
/// </summary>
/// <param name="newModulePosition">
/// The new position of the module.
/// </param>
void SetPosition( GraphyManager.ModulePosition newModulePosition, Vector2 offset );
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 8a935302390075f45843775173889f94
timeCreated: 1514998535
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/UI/IMovable.cs
uploadId: 626547
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 931159fac06489e4aac42c90c50e8598
folderAsset: yes
timeCreated: 1512413960
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 04-Jan-18
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
namespace Tayx.Graphy.Utils
{
public static class G_ExtensionMethods
{
#region Methods -> Extension Methods
/// <summary>
/// Functions as the SetActive function in the GameObject class, but for a list of them.
/// </summary>
/// <param name="gameObjects">
/// List of GameObjects.
/// </param>
/// <param name="active">
/// Wether to turn them on or off.
/// </param>
public static List<GameObject> SetAllActive( this List<GameObject> gameObjects, bool active )
{
foreach( var gameObj in gameObjects )
{
gameObj.SetActive( active );
}
return gameObjects;
}
public static List<Image> SetOneActive( this List<Image> images, int active )
{
for( int i = 0; i < images.Count; i++ )
{
images[ i ].gameObject.SetActive( i == active );
}
return images;
}
public static List<Image> SetAllActive( this List<Image> images, bool active )
{
foreach( var image in images )
{
image.gameObject.SetActive( active );
}
return images;
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 5aef4337f2241ec4d9a2ea5883fd1828
timeCreated: 1515099756
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Util/G_ExtensionMethods.cs
uploadId: 626547
@@ -0,0 +1,179 @@
/* ---------------------------------------
* Author: Started by David Mkrtchyan, modified by Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 18-May-18
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
namespace Tayx.Graphy.Utils.NumString
{
public static class G_FloatString
{
#region Variables -> Private
/// <summary>
/// Float represented as a string, formatted.
/// </summary>
private const string m_floatFormat = "0.0";
/// <summary>
/// The currently defined, globally used decimal multiplier.
/// </summary>
private static float m_decimalMultiplier = 10f;
/// <summary>
/// List of negative floats casted to strings.
/// </summary>
private static string[] m_negativeBuffer = new string[0];
/// <summary>
/// List of positive floats casted to strings.
/// </summary>
private static string[] m_positiveBuffer = new string[0];
#endregion
#region Properties -> Public
/// <summary>
/// The lowest float value of the existing number buffer.
/// </summary>
public static float MinValue => -(m_negativeBuffer.Length - 1).FromIndex();
/// <summary>
/// The highest float value of the existing number buffer.
/// </summary>
public static float MaxValue => (m_positiveBuffer.Length - 1).FromIndex();
#endregion
#region Methods -> Public
/// <summary>
/// Initialize the buffers.
/// </summary>
/// <param name="minNegativeValue">
/// Lowest negative value allowed.
/// </param>
/// <param name="maxPositiveValue">
/// Highest positive value allowed.
/// </param>
public static void Init( float minNegativeValue, float maxPositiveValue )
{
int negativeLength = minNegativeValue.ToIndex();
int positiveLength = maxPositiveValue.ToIndex();
if( MinValue > minNegativeValue && negativeLength >= 0 )
{
m_negativeBuffer = new string[negativeLength];
for( int i = 0; i < negativeLength; i++ )
{
m_negativeBuffer[ i ] = (-i - 1).FromIndex().ToString( m_floatFormat );
}
}
if( MaxValue < maxPositiveValue && positiveLength >= 0 )
{
m_positiveBuffer = new string[positiveLength + 1];
for( int i = 0; i < positiveLength + 1; i++ )
{
m_positiveBuffer[ i ] = i.FromIndex().ToString( m_floatFormat );
}
}
}
public static void Dispose()
{
m_negativeBuffer = new string[0];
m_positiveBuffer = new string[0];
}
/// <summary>
/// Returns this float as a cached string.
/// </summary>
/// <param name="value">The required float.</param>
/// <returns>A cached number string.</returns>
public static string ToStringNonAlloc( this float value )
{
int valIndex = value.ToIndex();
if( value < 0 && valIndex < m_negativeBuffer.Length )
{
return m_negativeBuffer[ valIndex ];
}
if( value >= 0 && valIndex < m_positiveBuffer.Length )
{
return m_positiveBuffer[ valIndex ];
}
return value.ToString();
}
/// <summary>
/// Returns this float as a cached string.
/// </summary>
/// <param name="value">The required float.</param>
/// <returns>A cached number string.</returns>
public static string ToStringNonAlloc( this float value, string format )
{
int valIndex = value.ToIndex();
if( value < 0 && valIndex < m_negativeBuffer.Length )
{
return m_negativeBuffer[ valIndex ];
}
if( value >= 0 && valIndex < m_positiveBuffer.Length )
{
return m_positiveBuffer[ valIndex ];
}
return value.ToString( format );
}
/// <summary>
/// Returns a float as a casted int.
/// </summary>
/// <param name="f">The given float.</param>
/// <returns>The given float as an int.</returns>
public static int ToInt( this float f )
{
return (int) f;
}
/// <summary>
/// Returns an int as a casted float.
/// </summary>
/// <param name="f">The given int.</param>
/// <returns>The given int as a float.</returns>
public static float ToFloat( this int i )
{
return (float) i;
}
#endregion
#region Methods -> Private
private static int ToIndex( this float f )
{
return Mathf.Abs( (f * m_decimalMultiplier).ToInt() );
}
private static float FromIndex( this int i )
{
return (i.ToFloat() / m_decimalMultiplier);
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: c7eaf0f83a3530240a97ac1c51d6f2e6
timeCreated: 1538651101
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Util/G_FloatString.cs
uploadId: 626547
@@ -0,0 +1,117 @@
/* ---------------------------------------
* Author: Started by David Mkrtchyan, modified by Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 18-May-18
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
namespace Tayx.Graphy.Utils.NumString
{
public static class G_IntString
{
#region Variables -> Private
/// <summary>
/// List of negative ints casted to strings.
/// </summary>
private static string[] m_negativeBuffer = new string[0];
/// <summary>
/// List of positive ints casted to strings.
/// </summary>
private static string[] m_positiveBuffer = new string[0];
#endregion
#region Properties -> Public
/// <summary>
/// The lowest int value of the existing number buffer.
/// </summary>
public static int MinValue => -(m_negativeBuffer.Length - 1);
/// <summary>
/// The highest int value of the existing number buffer.
/// </summary>
public static int MaxValue => m_positiveBuffer.Length;
#endregion
#region Methods -> Public
/// <summary>
/// Initialize the buffers.
/// </summary>
/// <param name="minNegativeValue">
/// Lowest negative value allowed.
/// </param>
/// <param name="maxPositiveValue">
/// Highest positive value allowed.
/// </param>
public static void Init( int minNegativeValue, int maxPositiveValue )
{
if( MinValue > minNegativeValue && minNegativeValue <= 0 )
{
int length = Mathf.Abs( minNegativeValue );
m_negativeBuffer = new string[length];
for( int i = 0; i < length; i++ )
{
m_negativeBuffer[ i ] = (-i - 1).ToString();
}
}
if( MaxValue < maxPositiveValue && maxPositiveValue >= 0 )
{
m_positiveBuffer = new string[maxPositiveValue + 1];
for( int i = 0; i < maxPositiveValue + 1; i++ )
{
m_positiveBuffer[ i ] = i.ToString();
}
}
}
public static void Dispose()
{
m_negativeBuffer = new string[0];
m_positiveBuffer = new string[0];
}
/// <summary>
/// Returns this int as a cached string.
/// </summary>
/// <param name="value">
/// The required int.
/// </param>
/// <returns>
/// A cached number string if within the buffer ranges.
/// </returns>
public static string ToStringNonAlloc( this int value )
{
if( value < 0 && -value <= m_negativeBuffer.Length )
{
return m_negativeBuffer[ -value - 1 ];
}
if( value >= 0 && value < m_positiveBuffer.Length )
{
return m_positiveBuffer[ value ];
}
// If the value is not within the buffer ranges, just do a normal .ToString()
return value.ToString();
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 2584aec3ab9f9af49bbdb1477908274e
timeCreated: 1526634575
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Util/G_Intstring.cs
uploadId: 626547
@@ -0,0 +1,84 @@
/* ---------------------------------------
* Sourced from: https://wiki.unity3d.com/index.php/Singleton
* Modified by: Martín Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 07-Jul-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
namespace Tayx.Graphy.Utils
{
/// <summary>
/// Be aware this will not prevent a non singleton constructor
/// such as `T myT = new T();`
/// To prevent that, add `protected T () {}` to your singleton class.
/// </summary>
public class G_Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
#region Variables -> Private
private static T _instance;
private static object _lock = new object();
#endregion
#region Properties -> Public
public static T Instance
{
get
{
lock( _lock )
{
if( _instance == null )
{
Debug.Log
(
"[Singleton] An instance of " + typeof( T ) +
" is trying to be accessed, but it wasn't initialized first. " +
"Make sure to add an instance of " + typeof( T ) + " in the scene before " +
" trying to access it."
);
}
return _instance;
}
}
}
#endregion
#region Methods -> Unity Callbacks
void Awake()
{
if( _instance != null )
{
Destroy( gameObject );
}
else
{
_instance = GetComponent<T>();
}
}
void OnDestroy()
{
if( _instance == this )
{
_instance = null;
}
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: dbf324bd9d0eaf7408f3b72ed03e2588
timeCreated: 1512413989
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Util/G_Singleton.cs
uploadId: 626547