The fucking 3rd time i had to upload this project to git
This commit is contained in:
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ac38d39b5dd9f442a088b7284b58236
|
||||
folderAsset: yes
|
||||
timeCreated: 1513377123
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,347 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Tayx.Graphy.UI;
|
||||
using Tayx.Graphy.Utils;
|
||||
using Tayx.Graphy.Utils.NumString;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
#endif
|
||||
|
||||
namespace Tayx.Graphy.Advanced
|
||||
{
|
||||
public class G_AdvancedData : MonoBehaviour, IMovable, IModifiableState
|
||||
{
|
||||
#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>();
|
||||
|
||||
#region Section -> Text
|
||||
|
||||
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;
|
||||
|
||||
var res = Screen.currentResolution;
|
||||
|
||||
m_screenResolutionText.text
|
||||
= "Screen: "
|
||||
+ res.width
|
||||
+ "x"
|
||||
+ res.height
|
||||
+ "@"
|
||||
+ res.refreshRate
|
||||
+ "Hz";
|
||||
|
||||
m_operatingSystemText.text
|
||||
= "OS: "
|
||||
+ SystemInfo.operatingSystem
|
||||
+ " ["
|
||||
+ SystemInfo.deviceType
|
||||
+ "]";
|
||||
|
||||
float preferredWidth = 0;
|
||||
|
||||
// Resize the background overlay
|
||||
|
||||
var texts = new List<Text>
|
||||
{
|
||||
m_graphicsDeviceVersionText,
|
||||
m_processorTypeText,
|
||||
m_systemMemoryText,
|
||||
m_graphicsDeviceNameText,
|
||||
m_graphicsMemorySizeText,
|
||||
m_screenResolutionText,
|
||||
m_gameWindowResolutionText,
|
||||
m_operatingSystemText
|
||||
};
|
||||
|
||||
foreach (var text in texts)
|
||||
if (text.preferredWidth > preferredWidth)
|
||||
preferredWidth = text.preferredWidth;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Section -> Background Images
|
||||
|
||||
m_backgroundImages[0].rectTransform.SetSizeWithCurrentAnchors
|
||||
(
|
||||
RectTransform.Axis.Horizontal,
|
||||
preferredWidth + 25
|
||||
);
|
||||
|
||||
m_backgroundImages[0].rectTransform.anchoredPosition = new Vector2
|
||||
(
|
||||
(preferredWidth + 25) / 2 * Mathf.Sign(m_backgroundImages[0].rectTransform.anchoredPosition.x),
|
||||
m_backgroundImages[0].rectTransform.anchoredPosition.y
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
UpdateParameters();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private List<Image> m_backgroundImages = new();
|
||||
|
||||
[SerializeField] private Text m_graphicsDeviceVersionText;
|
||||
|
||||
[SerializeField] private Text m_processorTypeText;
|
||||
|
||||
[SerializeField] private Text m_operatingSystemText;
|
||||
|
||||
[SerializeField] private Text m_systemMemoryText;
|
||||
|
||||
[SerializeField] private Text m_graphicsDeviceNameText;
|
||||
[SerializeField] private Text m_graphicsMemorySizeText;
|
||||
[SerializeField] private Text m_screenResolutionText;
|
||||
[SerializeField] private Text m_gameWindowResolutionText;
|
||||
|
||||
[Range(1, 60)] [SerializeField] private float m_updateRate = 1f; // 1 update per sec.
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private GraphyManager m_graphyManager;
|
||||
|
||||
private RectTransform m_rectTransform;
|
||||
|
||||
private float m_deltaTime;
|
||||
|
||||
private StringBuilder m_sb;
|
||||
|
||||
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]"
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods -> Unity Callbacks
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
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(Screen.currentResolution.refreshRate.ToStringNonAlloc())
|
||||
.Append(m_windowStrings[3])
|
||||
.Append(m_windowStrings[4]).Append(((int)Screen.dpi).ToStringNonAlloc())
|
||||
.Append(m_windowStrings[5]);
|
||||
|
||||
m_gameWindowResolutionText.text = m_sb.ToString();
|
||||
|
||||
// Reset variables
|
||||
m_deltaTime = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods -> Public
|
||||
|
||||
public void SetPosition(GraphyManager.ModulePosition newModulePosition)
|
||||
{
|
||||
var xSideOffsetBackgroundImage = Mathf.Abs(m_backgroundImages[0].rectTransform.anchoredPosition.x);
|
||||
var ySideOffset = Mathf.Abs(m_rectTransform.anchoredPosition.y);
|
||||
|
||||
switch (newModulePosition)
|
||||
{
|
||||
case GraphyManager.ModulePosition.TOP_LEFT:
|
||||
|
||||
m_rectTransform.anchorMax = Vector2.one;
|
||||
m_rectTransform.anchorMin = Vector2.up;
|
||||
m_rectTransform.anchoredPosition = new Vector2(0, -ySideOffset);
|
||||
|
||||
|
||||
m_backgroundImages[0].rectTransform.anchorMax = Vector2.up;
|
||||
m_backgroundImages[0].rectTransform.anchorMin = Vector2.zero;
|
||||
m_backgroundImages[0].rectTransform.anchoredPosition = new Vector2(xSideOffsetBackgroundImage, 0);
|
||||
|
||||
break;
|
||||
|
||||
case GraphyManager.ModulePosition.TOP_RIGHT:
|
||||
|
||||
m_rectTransform.anchorMax = Vector2.one;
|
||||
m_rectTransform.anchorMin = Vector2.up;
|
||||
m_rectTransform.anchoredPosition = new Vector2(0, -ySideOffset);
|
||||
|
||||
m_backgroundImages[0].rectTransform.anchorMax = Vector2.one;
|
||||
m_backgroundImages[0].rectTransform.anchorMin = Vector2.right;
|
||||
m_backgroundImages[0].rectTransform.anchoredPosition = new Vector2(-xSideOffsetBackgroundImage, 0);
|
||||
|
||||
break;
|
||||
|
||||
case GraphyManager.ModulePosition.BOTTOM_LEFT:
|
||||
|
||||
m_rectTransform.anchorMax = Vector2.right;
|
||||
m_rectTransform.anchorMin = Vector2.zero;
|
||||
m_rectTransform.anchoredPosition = new Vector2(0, ySideOffset);
|
||||
|
||||
m_backgroundImages[0].rectTransform.anchorMax = Vector2.up;
|
||||
m_backgroundImages[0].rectTransform.anchorMin = Vector2.zero;
|
||||
m_backgroundImages[0].rectTransform.anchoredPosition = new Vector2(xSideOffsetBackgroundImage, 0);
|
||||
|
||||
break;
|
||||
|
||||
case GraphyManager.ModulePosition.BOTTOM_RIGHT:
|
||||
|
||||
m_rectTransform.anchorMax = Vector2.right;
|
||||
m_rectTransform.anchorMin = Vector2.zero;
|
||||
m_rectTransform.anchoredPosition = new Vector2(0, ySideOffset);
|
||||
|
||||
m_backgroundImages[0].rectTransform.anchorMax = Vector2.one;
|
||||
m_backgroundImages[0].rectTransform.anchorMin = Vector2.right;
|
||||
m_backgroundImages[0].rectTransform.anchoredPosition = new Vector2(-xSideOffsetBackgroundImage, 0);
|
||||
|
||||
break;
|
||||
|
||||
case GraphyManager.ModulePosition.FREE:
|
||||
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_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_operatingSystemText.alignment = TextAnchor.UpperRight;
|
||||
|
||||
break;
|
||||
|
||||
case GraphyManager.ModulePosition.FREE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(GraphyManager.ModuleState state, bool silentUpdate = false)
|
||||
{
|
||||
if (!silentUpdate) m_previousModuleState = m_currentModuleState;
|
||||
|
||||
m_currentModuleState = state;
|
||||
|
||||
var 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);
|
||||
SetState(m_graphyManager.AdvancedModuleState);
|
||||
}
|
||||
|
||||
public void RefreshParameters()
|
||||
{
|
||||
foreach (var image in m_backgroundImages) image.color = m_graphyManager.BackgroundColor;
|
||||
|
||||
SetPosition(m_graphyManager.AdvancedModulePosition);
|
||||
SetState(m_currentModuleState, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c1019d31db77fd468164577146737ad
|
||||
timeCreated: 1512484835
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2523395741efc1c48822a27d9fcb57d2
|
||||
folderAsset: yes
|
||||
timeCreated: 1513377094
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,276 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 Methods -> Public
|
||||
|
||||
public void UpdateParameters()
|
||||
{
|
||||
if (m_shaderGraph == null)
|
||||
// TODO: 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 -> 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
|
||||
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private Image m_imageGraph;
|
||||
[SerializeField] private Image m_imageGraphHighestValues;
|
||||
|
||||
[SerializeField] private Shader ShaderFull;
|
||||
[SerializeField] private Shader ShaderLight;
|
||||
|
||||
[SerializeField] private bool m_isInitialized;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private GraphyManager m_graphyManager;
|
||||
|
||||
private G_AudioMonitor m_audioMonitor;
|
||||
|
||||
private int m_resolution = 40;
|
||||
|
||||
private G_GraphShader m_shaderGraph;
|
||||
private G_GraphShader m_shaderGraphHighestValues;
|
||||
|
||||
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 -> 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();
|
||||
|
||||
var incrementPerIteration = Mathf.FloorToInt(m_audioMonitor.Spectrum.Length / (float)m_resolution);
|
||||
|
||||
// Current values -------------------------
|
||||
|
||||
for (var i = 0; i <= m_resolution - 1; i++)
|
||||
{
|
||||
float currentValue = 0;
|
||||
|
||||
for (var 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)
|
||||
{
|
||||
var 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 (var i = 0; i <= m_resolution - 1; i++) m_shaderGraph.ShaderArrayValues[i] = m_graphArray[i];
|
||||
|
||||
m_shaderGraph.UpdatePoints();
|
||||
|
||||
|
||||
// Highest values -------------------------
|
||||
|
||||
for (var i = 0; i <= m_resolution - 1; i++)
|
||||
{
|
||||
float currentValue = 0;
|
||||
|
||||
for (var 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)
|
||||
{
|
||||
var 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 (var 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 (var 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.UpdateArray();
|
||||
m_shaderGraphHighestValues.UpdateArray();
|
||||
|
||||
// Average
|
||||
m_shaderGraph.Average = 0;
|
||||
m_shaderGraph.UpdateAverage();
|
||||
|
||||
m_shaderGraphHighestValues.Average = 0;
|
||||
m_shaderGraphHighestValues.UpdateAverage();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2d6ca19dafe21b4b983441274e7f12a
|
||||
timeCreated: 1513169449
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,214 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 System.Collections.Generic;
|
||||
using Tayx.Graphy.UI;
|
||||
using Tayx.Graphy.Utils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Tayx.Graphy.Audio
|
||||
{
|
||||
public class G_AudioManager : MonoBehaviour, IMovable, IModifiableState
|
||||
{
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private GameObject m_audioGraphGameObject;
|
||||
[SerializeField] private Text m_audioDbText;
|
||||
|
||||
[SerializeField] private List<Image> m_backgroundImages = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private GraphyManager m_graphyManager;
|
||||
|
||||
private G_AudioGraph m_audioGraph;
|
||||
private G_AudioMonitor m_audioMonitor;
|
||||
private G_AudioText m_audioText;
|
||||
|
||||
private RectTransform m_rectTransform;
|
||||
|
||||
private readonly List<GameObject> m_childrenGameObjects = new();
|
||||
|
||||
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)
|
||||
{
|
||||
var xSideOffset = Mathf.Abs(m_rectTransform.anchoredPosition.x);
|
||||
var ySideOffset = Mathf.Abs(m_rectTransform.anchoredPosition.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;
|
||||
|
||||
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:
|
||||
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_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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c0448d8db852b54480670d291c04f1a
|
||||
timeCreated: 1514998347
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,195 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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;
|
||||
|
||||
private AudioListener m_audioListener;
|
||||
|
||||
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 (var i = 0; i < Spectrum.Length; i++) sum += Spectrum[i] * Spectrum[i]; // sum squared samples
|
||||
|
||||
var 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 (var 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
|
||||
(
|
||||
SpectrumHighestValues[i] - SpectrumHighestValues[i] * Time.deltaTime * 2,
|
||||
0,
|
||||
1
|
||||
);
|
||||
}
|
||||
else if (m_audioListener == null
|
||||
&& m_findAudioListenerInCameraIfNull == GraphyManager.LookForAudioListener.ALWAYS)
|
||||
{
|
||||
m_audioListener = FindAudioListener();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
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()
|
||||
{
|
||||
var 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();
|
||||
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2216f4eff6a7a8a43b38b180fdd2fd9e
|
||||
timeCreated: 1513377074
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,90 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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.Utils.NumString;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Tayx.Graphy.Audio
|
||||
{
|
||||
public class G_AudioText : MonoBehaviour
|
||||
{
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private Text m_DBText;
|
||||
|
||||
#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
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private GraphyManager m_graphyManager;
|
||||
|
||||
private G_AudioMonitor m_audioMonitor;
|
||||
|
||||
private int m_updateRate = 4;
|
||||
|
||||
private float m_deltaTimeOffset;
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 766a588f9a6cb55499c66ea772072e11
|
||||
timeCreated: 1513377063
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3232b12a3422d1a4d8ff3eaa000c43ae
|
||||
folderAsset: yes
|
||||
timeCreated: 1513377102
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,179 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 Methods -> Unity Callbacks
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateGraph();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods -> Public
|
||||
|
||||
public void UpdateParameters()
|
||||
{
|
||||
if (m_shaderGraph == null)
|
||||
// TODO: 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 -> 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
|
||||
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private Image m_imageGraph;
|
||||
|
||||
[SerializeField] private Shader ShaderFull;
|
||||
[SerializeField] private Shader ShaderLight;
|
||||
|
||||
// This keeps track of whether Init() has run or not
|
||||
[SerializeField] private bool m_isInitialized;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private GraphyManager m_graphyManager;
|
||||
|
||||
private G_FpsMonitor m_fpsMonitor;
|
||||
|
||||
private int m_resolution = 150;
|
||||
|
||||
private G_GraphShader m_shaderGraph;
|
||||
|
||||
private int[] m_fpsArray;
|
||||
|
||||
private int m_highestFps;
|
||||
|
||||
#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();
|
||||
|
||||
var fps = (short)(1 / Time.unscaledDeltaTime);
|
||||
|
||||
var currentMaxFps = 0;
|
||||
|
||||
for (var 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 (var 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 (var 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.UpdateArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e119c7747ac400478c7cfcaea03214e
|
||||
timeCreated: 1511794194
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,224 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 System.Collections.Generic;
|
||||
using Tayx.Graphy.UI;
|
||||
using Tayx.Graphy.Utils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Tayx.Graphy.Fps
|
||||
{
|
||||
public class G_FpsManager : MonoBehaviour, IMovable, IModifiableState
|
||||
{
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private GameObject m_fpsGraphGameObject;
|
||||
|
||||
[SerializeField] private List<GameObject> m_nonBasicTextGameObjects = new();
|
||||
|
||||
[SerializeField] private List<Image> m_backgroundImages = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private GraphyManager m_graphyManager;
|
||||
|
||||
private G_FpsGraph m_fpsGraph;
|
||||
private G_FpsMonitor m_fpsMonitor;
|
||||
private G_FpsText m_fpsText;
|
||||
|
||||
private RectTransform m_rectTransform;
|
||||
|
||||
private readonly List<GameObject> m_childrenGameObjects = new();
|
||||
|
||||
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)
|
||||
{
|
||||
var xSideOffset = Mathf.Abs(m_rectTransform.anchoredPosition.x);
|
||||
var ySideOffset = Mathf.Abs(m_rectTransform.anchoredPosition.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_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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 221dc0b3655ddb749ace6bad55f0159f
|
||||
timeCreated: 1514998359
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,139 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 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
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private short[] m_fpsSamples;
|
||||
private short[] m_fpsSamplesSorted;
|
||||
private readonly short m_fpsSamplesCapacity = 1024;
|
||||
private short m_onePercentSamples = 10;
|
||||
private short m_zero1PercentSamples = 1;
|
||||
private short m_fpsSamplesCount;
|
||||
private short m_indexSample;
|
||||
|
||||
private float m_unscaledDeltaTime;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties -> Public
|
||||
|
||||
public short CurrentFPS { get; private set; }
|
||||
public short AverageFPS { get; private set; }
|
||||
public short OnePercentFPS { get; private set; }
|
||||
public short Zero1PercentFps { get; private set; }
|
||||
|
||||
#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 (var i = 0; i < m_fpsSamplesCount; i++) averageAddedFps += (uint)m_fpsSamples[i];
|
||||
|
||||
AverageFPS = (short)(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
|
||||
|
||||
var zero1PercentCalculated = false;
|
||||
|
||||
uint totalAddedFps = 0;
|
||||
|
||||
var samplesToIterateThroughForOnePercent = m_fpsSamplesCount < m_onePercentSamples
|
||||
? m_fpsSamplesCount
|
||||
: m_onePercentSamples;
|
||||
|
||||
var samplesToIterateThroughForZero1Percent = m_fpsSamplesCount < m_zero1PercentSamples
|
||||
? m_fpsSamplesCount
|
||||
: m_zero1PercentSamples;
|
||||
|
||||
var sampleToStartIn = (short)(m_fpsSamplesCapacity - m_fpsSamplesCount);
|
||||
|
||||
for (var i = sampleToStartIn; i < sampleToStartIn + samplesToIterateThroughForOnePercent; i++)
|
||||
{
|
||||
totalAddedFps += (ushort)m_fpsSamplesSorted[i];
|
||||
|
||||
if (!zero1PercentCalculated && i >= samplesToIterateThroughForZero1Percent - 1)
|
||||
{
|
||||
zero1PercentCalculated = true;
|
||||
|
||||
Zero1PercentFps = (short)(totalAddedFps / (float)m_zero1PercentSamples);
|
||||
}
|
||||
}
|
||||
|
||||
OnePercentFPS = (short)(totalAddedFps / (float)m_onePercentSamples);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b205584e495e4634aa3a332a78102a19
|
||||
timeCreated: 1513376950
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,146 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 Tayx.Graphy.Utils.NumString;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Tayx.Graphy.Fps
|
||||
{
|
||||
public class G_FpsText : MonoBehaviour
|
||||
{
|
||||
#region Methods -> Public
|
||||
|
||||
public void UpdateParameters()
|
||||
{
|
||||
m_updateRate = m_graphyManager.FpsTextUpdateRate;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private Text m_fpsText;
|
||||
[SerializeField] private Text m_msText;
|
||||
|
||||
[SerializeField] private Text m_avgFpsText;
|
||||
[SerializeField] private Text m_onePercentFpsText;
|
||||
[SerializeField] private Text m_zero1PercentFpsText;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private GraphyManager m_graphyManager;
|
||||
|
||||
private G_FpsMonitor m_fpsMonitor;
|
||||
|
||||
private int m_updateRate = 4; // 4 updates per sec.
|
||||
|
||||
private int m_frameCount;
|
||||
|
||||
private float m_deltaTime;
|
||||
|
||||
private float m_fps;
|
||||
|
||||
private float m_ms;
|
||||
|
||||
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 -> 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)
|
||||
{
|
||||
if (fps > m_graphyManager.GoodFPSThreshold)
|
||||
text.color = m_graphyManager.GoodFPSColor;
|
||||
else if (fps > 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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f74bbf307d92b0d4e81ae60b9eb1e42f
|
||||
timeCreated: 1511555604
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -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) (@tayx94)
|
||||
* 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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67969a520b115cd47a7d955c9b2abfa6
|
||||
timeCreated: 1516716468
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,542 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Tayx.Graphy.Audio;
|
||||
using Tayx.Graphy.Fps;
|
||||
using Tayx.Graphy.Ram;
|
||||
using Tayx.Graphy.Utils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Tayx.Graphy
|
||||
{
|
||||
/// <summary>
|
||||
/// Main class to access the Graphy Debugger API.
|
||||
/// </summary>
|
||||
public class GraphyDebugger : G_Singleton<GraphyDebugger>
|
||||
{
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private List<DebugPacket> m_debugPackets = new();
|
||||
|
||||
#endregion
|
||||
|
||||
/* ----- TODO: ----------------------------
|
||||
* Add summaries to the variables.
|
||||
* Add summaries to the functions.
|
||||
* Ask why we're not using System.Serializable instead for the helper class.
|
||||
* Simplify the initializers of the DebugPackets, but check wether we should as some wont work with certain lists.
|
||||
* --------------------------------------*/
|
||||
|
||||
protected GraphyDebugger()
|
||||
{
|
||||
}
|
||||
|
||||
#region Structs -> Public
|
||||
|
||||
[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
|
||||
|
||||
[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();
|
||||
|
||||
// Actions on conditions met
|
||||
|
||||
public MessageType MessageType;
|
||||
|
||||
[Multiline] public string Message = string.Empty;
|
||||
|
||||
public bool TakeScreenshot;
|
||||
public string ScreenshotFileName = "Graphy_Screenshot";
|
||||
|
||||
[Tooltip("If true, it pauses the editor")]
|
||||
public bool DebugBreak;
|
||||
|
||||
public UnityEvent UnityEvents;
|
||||
public List<Action> Callbacks = new();
|
||||
|
||||
|
||||
private bool executed;
|
||||
|
||||
private float timePassed;
|
||||
|
||||
public bool Check { get; private set; }
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!Check)
|
||||
{
|
||||
timePassed += Time.deltaTime;
|
||||
|
||||
if ((executed && timePassed >= ExecuteSleepTime)
|
||||
|| (!executed && timePassed >= InitSleepTime))
|
||||
{
|
||||
Check = true;
|
||||
|
||||
timePassed = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Executed()
|
||||
{
|
||||
Check = false;
|
||||
executed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#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 Variables -> Private
|
||||
|
||||
private G_FpsMonitor m_fpsMonitor;
|
||||
private G_RamMonitor m_ramMonitor;
|
||||
private G_AudioMonitor m_audioMonitor;
|
||||
|
||||
#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 Public Methods
|
||||
|
||||
/// <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,
|
||||
Action newCallback
|
||||
)
|
||||
{
|
||||
var 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,
|
||||
Action newCallback
|
||||
)
|
||||
{
|
||||
var 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<Action> newCallbacks
|
||||
)
|
||||
{
|
||||
var 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<Action> newCallbacks
|
||||
)
|
||||
{
|
||||
var 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(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(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 (var i = 0; i < m_debugPackets.Count; i++)
|
||||
{
|
||||
var packet = m_debugPackets[i];
|
||||
|
||||
if (packet != null && packet.Active)
|
||||
{
|
||||
packet.Update();
|
||||
|
||||
if (packet.Check)
|
||||
switch (packet.ConditionEvaluation)
|
||||
{
|
||||
case ConditionEvaluation.All_conditions_must_be_met:
|
||||
var 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 != "")
|
||||
{
|
||||
var message = "[Graphy] (" + 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)
|
||||
{
|
||||
var path = debugPacket.ScreenshotFileName + "_" + DateTime.Now + ".png";
|
||||
path = path.Replace("/", "-").Replace(" ", "_").Replace(":", "-");
|
||||
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
ScreenCapture.CaptureScreenshot(path);
|
||||
#else
|
||||
Application.CaptureScreenshot(path);
|
||||
#endif
|
||||
}
|
||||
|
||||
debugPacket.UnityEvents.Invoke();
|
||||
|
||||
foreach (var callback in debugPacket.Callbacks)
|
||||
if (callback != null)
|
||||
callback();
|
||||
|
||||
debugPacket.Executed();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb8428f1f208dcc49b6c04976d44cbc9
|
||||
timeCreated: 1514034949
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c80e6d63202cef44ca3ffdaccec693be
|
||||
timeCreated: 1512508924
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 839df5cf44c5c6f43b1a846e73f3e498
|
||||
folderAsset: yes
|
||||
timeCreated: 1513377097
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,262 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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;
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
#endif
|
||||
|
||||
namespace Tayx.Graphy.Ram
|
||||
{
|
||||
public class G_RamGraph : G_Graph
|
||||
{
|
||||
#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 -> 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
|
||||
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private Image m_imageAllocated;
|
||||
[SerializeField] private Image m_imageReserved;
|
||||
[SerializeField] private Image m_imageMono;
|
||||
|
||||
[SerializeField] private Shader ShaderFull;
|
||||
[SerializeField] private Shader ShaderLight;
|
||||
|
||||
[SerializeField] private bool m_isInitialized;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private GraphyManager m_graphyManager;
|
||||
|
||||
private G_RamMonitor m_ramMonitor;
|
||||
|
||||
private int m_resolution = 150;
|
||||
|
||||
private G_GraphShader m_shaderGraphAllocated;
|
||||
private G_GraphShader m_shaderGraphReserved;
|
||||
private G_GraphShader m_shaderGraphMono;
|
||||
|
||||
private float[] m_allocatedArray;
|
||||
private float[] m_reservedArray;
|
||||
private float[] m_monoArray;
|
||||
|
||||
private float m_highestMemory;
|
||||
|
||||
#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();
|
||||
|
||||
var allocatedMemory = m_ramMonitor.AllocatedRam;
|
||||
var reservedMemory = m_ramMonitor.ReservedRam;
|
||||
var monoMemory = m_ramMonitor.MonoRam;
|
||||
|
||||
m_highestMemory = 0;
|
||||
|
||||
for (var 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 (var 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 (var 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.UpdateArray();
|
||||
m_shaderGraphReserved.UpdateArray();
|
||||
m_shaderGraphMono.UpdateArray();
|
||||
|
||||
// Average
|
||||
|
||||
m_shaderGraphAllocated.Average = 0;
|
||||
m_shaderGraphReserved.Average = 0;
|
||||
m_shaderGraphMono.Average = 0;
|
||||
|
||||
m_shaderGraphAllocated.UpdateAverage();
|
||||
m_shaderGraphReserved.UpdateAverage();
|
||||
m_shaderGraphMono.UpdateAverage();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9c49f1e95f2dab428b3a0ed56328a1c
|
||||
timeCreated: 1512484813
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,216 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 System.Collections.Generic;
|
||||
using Tayx.Graphy.UI;
|
||||
using Tayx.Graphy.Utils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Tayx.Graphy.Ram
|
||||
{
|
||||
public class G_RamManager : MonoBehaviour, IMovable, IModifiableState
|
||||
{
|
||||
/* ----- TODO: ----------------------------
|
||||
* Add summaries to the variables.
|
||||
* Add summaries to the functions.
|
||||
* Check if we should add a "RequireComponent" for "RectTransform".
|
||||
* Check if we should add a "RequireComponent" for "RamGraph".
|
||||
* Check why this manager doesnt use RamMonitor, as all the other managers have a monitor script.
|
||||
* Check if we should add a "RequireComponent" for "RamText".
|
||||
* --------------------------------------*/
|
||||
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private GameObject m_ramGraphGameObject;
|
||||
|
||||
[SerializeField] private List<Image> m_backgroundImages = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private GraphyManager m_graphyManager;
|
||||
|
||||
private G_RamGraph m_ramGraph;
|
||||
private G_RamText m_ramText;
|
||||
|
||||
private RectTransform m_rectTransform;
|
||||
|
||||
private readonly List<GameObject> m_childrenGameObjects = new();
|
||||
|
||||
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)
|
||||
{
|
||||
var xSideOffset = Mathf.Abs(m_rectTransform.anchoredPosition.x);
|
||||
var ySideOffset = Mathf.Abs(m_rectTransform.anchoredPosition.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:
|
||||
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>();
|
||||
|
||||
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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84f7591c01b7f1a4ab82f1a0038491da
|
||||
timeCreated: 1514998367
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,42 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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;
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
using UnityEngine.Profiling;
|
||||
#endif
|
||||
|
||||
namespace Tayx.Graphy.Ram
|
||||
{
|
||||
public class G_RamMonitor : MonoBehaviour
|
||||
{
|
||||
#region Methods -> Unity Callbacks
|
||||
|
||||
private void Update()
|
||||
{
|
||||
AllocatedRam = Profiler.GetTotalAllocatedMemoryLong() / 1048576f;
|
||||
ReservedRam = Profiler.GetTotalReservedMemoryLong() / 1048576f;
|
||||
MonoRam = Profiler.GetMonoUsedSizeLong() / 1048576f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties -> Public
|
||||
|
||||
public float AllocatedRam { get; private set; }
|
||||
public float ReservedRam { get; private set; }
|
||||
public float MonoRam { get; private set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2494656f0dd693144be1306d5551e544
|
||||
timeCreated: 1513377000
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,96 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 Tayx.Graphy.Utils.NumString;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Tayx.Graphy.Ram
|
||||
{
|
||||
public class G_RamText : MonoBehaviour
|
||||
{
|
||||
#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
|
||||
|
||||
#region Variables -> Serialized Private
|
||||
|
||||
[SerializeField] private Text m_allocatedSystemMemorySizeText;
|
||||
[SerializeField] private Text m_reservedSystemMemorySizeText;
|
||||
[SerializeField] private Text m_monoSystemMemorySizeText;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables -> Private
|
||||
|
||||
private GraphyManager m_graphyManager;
|
||||
|
||||
private G_RamMonitor m_ramMonitor;
|
||||
|
||||
private float m_updateRate = 4f; // 4 updates per sec.
|
||||
|
||||
private float m_deltaTime;
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28d32ee74b6e6d24ea89d1b477060318
|
||||
timeCreated: 1512484799
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d11ec87c6db49d40af874a49810f377
|
||||
folderAsset: yes
|
||||
timeCreated: 1513377085
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,136 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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;
|
||||
|
||||
|
||||
private readonly string Name = "GraphValues"; // The name of the array
|
||||
private readonly string Name_Length = "GraphValues_Length";
|
||||
|
||||
|
||||
public float Average = 0;
|
||||
private int m_averagePropertyId;
|
||||
|
||||
|
||||
public float GoodThreshold = 0;
|
||||
public float CautionThreshold = 0;
|
||||
|
||||
private int m_goodThresholdPropertyId;
|
||||
private int m_cautionThresholdPropertyId;
|
||||
|
||||
|
||||
public Color GoodColor = Color.white;
|
||||
public Color CautionColor = Color.white;
|
||||
public Color CriticalColor = Color.white;
|
||||
|
||||
private int m_goodColorPropertyId;
|
||||
private int m_cautionColorPropertyId;
|
||||
private int m_criticalColorPropertyId;
|
||||
|
||||
#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(Name, new float[ArrayMaxSize]);
|
||||
|
||||
m_averagePropertyId = Shader.PropertyToID("Average");
|
||||
|
||||
m_goodThresholdPropertyId = Shader.PropertyToID("_GoodThreshold");
|
||||
m_cautionThresholdPropertyId = Shader.PropertyToID("_CautionThreshold");
|
||||
|
||||
m_goodColorPropertyId = Shader.PropertyToID("_GoodColor");
|
||||
m_cautionColorPropertyId = Shader.PropertyToID("_CautionColor");
|
||||
m_criticalColorPropertyId = Shader.PropertyToID("_CriticalColor");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the material linked with this shader graph with the values in the float[] array.
|
||||
/// </summary>
|
||||
public void UpdateArray()
|
||||
{
|
||||
Image.material.SetInt(Name_Length, ShaderArrayValues.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the average parameter in the material.
|
||||
/// </summary>
|
||||
public void UpdateAverage()
|
||||
{
|
||||
Image.material.SetFloat(m_averagePropertyId, Average);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the thresholds in the material.
|
||||
/// </summary>
|
||||
public void UpdateThresholds()
|
||||
{
|
||||
Image.material.SetFloat(m_goodThresholdPropertyId, GoodThreshold);
|
||||
Image.material.SetFloat(m_cautionThresholdPropertyId, CautionThreshold);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the colors in the material.
|
||||
/// </summary>
|
||||
public void UpdateColors()
|
||||
{
|
||||
Image.material.SetColor(m_goodColorPropertyId, GoodColor);
|
||||
Image.material.SetColor(m_cautionColorPropertyId, CautionColor);
|
||||
Image.material.SetColor(m_criticalColorPropertyId, CriticalColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the points in the graph with the set array of values.
|
||||
/// </summary>
|
||||
public void UpdatePoints()
|
||||
{
|
||||
// Requires an array called "name"
|
||||
// and another one called "name_Length"
|
||||
|
||||
Image.material.SetFloatArray(Name, ShaderArrayValues);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ddb605ced1369e409812b4f405221cd
|
||||
timeCreated: 1511903341
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18e5109d897e1b244ab2dfeaf5482c7b
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6a45022ef0b3654a9d036efed540b32
|
||||
folderAsset: yes
|
||||
timeCreated: 1514998503
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,26 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbc1852edf51f8046aed2f13ea532ea9
|
||||
timeCreated: 1514998527
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,26 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 IMovable
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the position of the module.
|
||||
/// </summary>
|
||||
/// <param name="newModulePosition">
|
||||
/// The new position of the module.
|
||||
/// </param>
|
||||
void SetPosition(GraphyManager.ModulePosition newModulePosition);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a935302390075f45843775173889f94
|
||||
timeCreated: 1514998535
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 931159fac06489e4aac42c90c50e8598
|
||||
folderAsset: yes
|
||||
timeCreated: 1512413960
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,56 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
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 (var 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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5aef4337f2241ec4d9a2ea5883fd1828
|
||||
timeCreated: 1515099756
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,180 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Started by David Mkrtchyan, modified by Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 readonly 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)
|
||||
{
|
||||
var negativeLength = minNegativeValue.ToIndex();
|
||||
var positiveLength = maxPositiveValue.ToIndex();
|
||||
|
||||
if (MinValue > minNegativeValue && negativeLength >= 0)
|
||||
{
|
||||
m_negativeBuffer = new string[negativeLength];
|
||||
for (var 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 (var 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)
|
||||
{
|
||||
var 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();
|
||||
}
|
||||
|
||||
//TODO: Convert this to use m_floatFormat instead, but investigate which functions require and dont require one first.
|
||||
/// <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)
|
||||
{
|
||||
var 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 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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7eaf0f83a3530240a97ac1c51d6f2e6
|
||||
timeCreated: 1538651101
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,105 @@
|
||||
/* ---------------------------------------
|
||||
* Author: Started by David Mkrtchyan, modified by Martin Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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)
|
||||
{
|
||||
var length = Mathf.Abs(minNegativeValue);
|
||||
|
||||
m_negativeBuffer = new string[length];
|
||||
|
||||
for (var i = 0; i < length; i++) m_negativeBuffer[i] = (-i - 1).ToString();
|
||||
}
|
||||
|
||||
if (MaxValue < maxPositiveValue && maxPositiveValue >= 0)
|
||||
{
|
||||
m_positiveBuffer = new string[maxPositiveValue + 1];
|
||||
|
||||
for (var 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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2584aec3ab9f9af49bbdb1477908274e
|
||||
timeCreated: 1526634575
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,75 @@
|
||||
/* ---------------------------------------
|
||||
* Sourced from: https://wiki.unity3d.com/index.php/Singleton
|
||||
* Modified by: Martín Pane (martintayx@gmail.com) (@tayx94)
|
||||
* 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 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 Variables -> Private
|
||||
|
||||
private static T _instance;
|
||||
|
||||
private static readonly object _lock = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods -> Unity Callbacks
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_instance != null)
|
||||
Destroy(gameObject);
|
||||
else
|
||||
_instance = GetComponent<T>();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_instance == this) _instance = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbf324bd9d0eaf7408f3b72ed03e2588
|
||||
timeCreated: 1512413989
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user