The fucking 3rd time i had to upload this project to git

This commit is contained in:
Madhav Kapa
2023-10-06 20:18:29 -04:00
commit 5658acfe16
2689 changed files with 1259400 additions and 0 deletions

View File

@ -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
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2e119c7747ac400478c7cfcaea03214e
timeCreated: 1511794194
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 221dc0b3655ddb749ace6bad55f0159f
timeCreated: 1514998359
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b205584e495e4634aa3a332a78102a19
timeCreated: 1513376950
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f74bbf307d92b0d4e81ae60b9eb1e42f
timeCreated: 1511555604
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: