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

This commit is contained in:
2026-02-16 01:55:18 +08:00
parent 3a7a0b4669
commit 9f7c1c57b7
206 changed files with 112684 additions and 857 deletions
@@ -0,0 +1,197 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 15-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using Tayx.Graphy.Graph;
using UnityEngine;
using UnityEngine.UI;
namespace Tayx.Graphy.Fps
{
public class G_FpsGraph : G_Graph
{
#region Variables -> Serialized Private
[SerializeField] private Image m_imageGraph = null;
[SerializeField] private Shader ShaderFull = null;
[SerializeField] private Shader ShaderLight = null;
// This keeps track of whether Init() has run or not
[SerializeField] private bool m_isInitialized = false;
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_FpsMonitor m_fpsMonitor = null;
private int m_resolution = 150;
private G_GraphShader m_shaderGraph = null;
private int[] m_fpsArray;
private int m_highestFps;
#endregion
#region Methods -> Unity Callbacks
private void Update()
{
UpdateGraph();
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
if( m_shaderGraph == null )
{
// While Graphy is disabled (e.g. by default via Ctrl+H) and while in Editor after a Hot-Swap,
// the OnApplicationFocus calls this while m_shaderGraph == null, throwing a NullReferenceException
return;
}
switch( m_graphyManager.GraphyMode )
{
case GraphyManager.Mode.FULL:
m_shaderGraph.ArrayMaxSize = G_GraphShader.ArrayMaxSizeFull;
m_shaderGraph.Image.material = new Material( ShaderFull );
break;
case GraphyManager.Mode.LIGHT:
m_shaderGraph.ArrayMaxSize = G_GraphShader.ArrayMaxSizeLight;
m_shaderGraph.Image.material = new Material( ShaderLight );
break;
}
m_shaderGraph.InitializeShader();
m_resolution = m_graphyManager.FpsGraphResolution;
CreatePoints();
}
#endregion
#region Methods -> Protected Override
protected override void UpdateGraph()
{
// Since we no longer initialize by default OnEnable(),
// we need to check here, and Init() if needed
if( !m_isInitialized )
{
Init();
}
short fps = (short) (1 / Time.unscaledDeltaTime);
int currentMaxFps = 0;
for( int i = 0; i <= m_resolution - 1; i++ )
{
if( i >= m_resolution - 1 )
{
m_fpsArray[ i ] = fps;
}
else
{
m_fpsArray[ i ] = m_fpsArray[ i + 1 ];
}
// Store the highest fps to use as the highest point in the graph
if( currentMaxFps < m_fpsArray[ i ] )
{
currentMaxFps = m_fpsArray[ i ];
}
}
m_highestFps = m_highestFps < 1 || m_highestFps <= currentMaxFps ? currentMaxFps : m_highestFps - 1;
m_highestFps = m_highestFps > 0 ? m_highestFps : 1;
if( m_shaderGraph.ShaderArrayValues == null )
{
m_fpsArray = new int[m_resolution];
m_shaderGraph.ShaderArrayValues = new float[m_resolution];
}
for( int i = 0; i <= m_resolution - 1; i++ )
{
m_shaderGraph.ShaderArrayValues[ i ] = m_fpsArray[ i ] / (float) m_highestFps;
}
// Update the material values
m_shaderGraph.UpdatePoints();
m_shaderGraph.Average = m_fpsMonitor.AverageFPS / m_highestFps;
m_shaderGraph.UpdateAverage();
m_shaderGraph.GoodThreshold = (float) m_graphyManager.GoodFPSThreshold / m_highestFps;
m_shaderGraph.CautionThreshold = (float) m_graphyManager.CautionFPSThreshold / m_highestFps;
m_shaderGraph.UpdateThresholds();
}
protected override void CreatePoints()
{
if( m_shaderGraph.ShaderArrayValues == null || m_fpsArray.Length != m_resolution )
{
m_fpsArray = new int[m_resolution];
m_shaderGraph.ShaderArrayValues = new float[m_resolution];
}
for( int i = 0; i < m_resolution; i++ )
{
m_shaderGraph.ShaderArrayValues[ i ] = 0;
}
m_shaderGraph.GoodColor = m_graphyManager.GoodFPSColor;
m_shaderGraph.CautionColor = m_graphyManager.CautionFPSColor;
m_shaderGraph.CriticalColor = m_graphyManager.CriticalFPSColor;
m_shaderGraph.UpdateColors();
m_shaderGraph.UpdateArrayValuesLength();
}
#endregion
#region Methods -> Private
private void Init()
{
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_fpsMonitor = GetComponent<G_FpsMonitor>();
m_shaderGraph = new G_GraphShader
{
Image = m_imageGraph
};
UpdateParameters();
m_isInitialized = true;
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 2e119c7747ac400478c7cfcaea03214e
timeCreated: 1511794194
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Fps/G_FpsGraph.cs
uploadId: 626547
@@ -0,0 +1,258 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 03-Jan-18
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using Tayx.Graphy.UI;
using Tayx.Graphy.Utils;
namespace Tayx.Graphy.Fps
{
public class G_FpsManager : MonoBehaviour, IMovable, IModifiableState
{
#region Variables -> Serialized Private
[SerializeField] private GameObject m_fpsGraphGameObject = null;
[SerializeField] private List<GameObject> m_nonBasicTextGameObjects = new List<GameObject>();
[SerializeField] private List<Image> m_backgroundImages = new List<Image>();
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_FpsGraph m_fpsGraph = null;
private G_FpsMonitor m_fpsMonitor = null;
private G_FpsText m_fpsText = null;
private RectTransform m_rectTransform = null;
private Vector2 m_origPosition = Vector2.zero;
private List<GameObject> m_childrenGameObjects = new List<GameObject>();
private GraphyManager.ModuleState m_previousModuleState = GraphyManager.ModuleState.FULL;
private GraphyManager.ModuleState m_currentModuleState = GraphyManager.ModuleState.FULL;
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Start()
{
UpdateParameters();
}
#endregion
#region Methods -> Public
public void SetPosition( GraphyManager.ModulePosition newModulePosition, Vector2 offset )
{
if ( newModulePosition == GraphyManager.ModulePosition.FREE )
return;
m_rectTransform.anchoredPosition = m_origPosition;
float xSideOffset = Mathf.Abs( m_rectTransform.anchoredPosition.x ) + offset.x;
float ySideOffset = Mathf.Abs( m_rectTransform.anchoredPosition.y ) + offset.y;
switch( newModulePosition )
{
case GraphyManager.ModulePosition.TOP_LEFT:
m_rectTransform.anchorMax = Vector2.up;
m_rectTransform.anchorMin = Vector2.up;
m_rectTransform.anchoredPosition = new Vector2( xSideOffset, -ySideOffset );
break;
case GraphyManager.ModulePosition.TOP_RIGHT:
m_rectTransform.anchorMax = Vector2.one;
m_rectTransform.anchorMin = Vector2.one;
m_rectTransform.anchoredPosition = new Vector2( -xSideOffset, -ySideOffset );
break;
case GraphyManager.ModulePosition.BOTTOM_LEFT:
m_rectTransform.anchorMax = Vector2.zero;
m_rectTransform.anchorMin = Vector2.zero;
m_rectTransform.anchoredPosition = new Vector2( xSideOffset, ySideOffset );
break;
case GraphyManager.ModulePosition.BOTTOM_RIGHT:
m_rectTransform.anchorMax = Vector2.right;
m_rectTransform.anchorMin = Vector2.right;
m_rectTransform.anchoredPosition = new Vector2( -xSideOffset, ySideOffset );
break;
case GraphyManager.ModulePosition.FREE:
break;
}
}
public void SetState( GraphyManager.ModuleState state, bool silentUpdate = false )
{
if( !silentUpdate )
{
m_previousModuleState = m_currentModuleState;
}
m_currentModuleState = state;
switch( state )
{
case GraphyManager.ModuleState.FULL:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( true );
SetGraphActive( true );
if( m_graphyManager.Background )
{
m_backgroundImages.SetOneActive( 0 );
}
else
{
m_backgroundImages.SetAllActive( false );
}
break;
case GraphyManager.ModuleState.TEXT:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( true );
SetGraphActive( false );
if( m_graphyManager.Background )
{
m_backgroundImages.SetOneActive( 1 );
}
else
{
m_backgroundImages.SetAllActive( false );
}
break;
case GraphyManager.ModuleState.BASIC:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( true );
m_nonBasicTextGameObjects.SetAllActive( false );
SetGraphActive( false );
if( m_graphyManager.Background )
{
m_backgroundImages.SetOneActive( 2 );
}
else
{
m_backgroundImages.SetAllActive( false );
}
break;
case GraphyManager.ModuleState.BACKGROUND:
gameObject.SetActive( true );
m_childrenGameObjects.SetAllActive( false );
SetGraphActive( false );
m_backgroundImages.SetAllActive( false );
break;
case GraphyManager.ModuleState.OFF:
gameObject.SetActive( false );
break;
}
}
public void RestorePreviousState()
{
SetState( m_previousModuleState );
}
public void UpdateParameters()
{
foreach( var image in m_backgroundImages )
{
image.color = m_graphyManager.BackgroundColor;
}
m_fpsGraph.UpdateParameters();
m_fpsMonitor.UpdateParameters();
m_fpsText.UpdateParameters();
SetState( m_graphyManager.FpsModuleState );
}
public void RefreshParameters()
{
foreach( var image in m_backgroundImages )
{
image.color = m_graphyManager.BackgroundColor;
}
m_fpsGraph.UpdateParameters();
m_fpsMonitor.UpdateParameters();
m_fpsText.UpdateParameters();
SetState( m_currentModuleState, true );
}
#endregion
#region Methods -> Private
private void Init()
{
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_rectTransform = GetComponent<RectTransform>();
m_origPosition = m_rectTransform.anchoredPosition;
m_fpsGraph = GetComponent<G_FpsGraph>();
m_fpsMonitor = GetComponent<G_FpsMonitor>();
m_fpsText = GetComponent<G_FpsText>();
foreach( Transform child in transform )
{
if( child.parent == transform )
{
m_childrenGameObjects.Add( child.gameObject );
}
}
}
private void SetGraphActive( bool active )
{
m_fpsGraph.enabled = active;
m_fpsGraphGameObject.SetActive( active );
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 221dc0b3655ddb749ace6bad55f0159f
timeCreated: 1514998359
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Fps/G_FpsManager.cs
uploadId: 626547
@@ -0,0 +1,146 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 15-Dec-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using System;
using UnityEngine;
namespace Tayx.Graphy.Fps
{
public class G_FpsMonitor : MonoBehaviour
{
#region Variables -> Private
private short[] m_fpsSamples;
private short[] m_fpsSamplesSorted;
private short m_fpsSamplesCapacity = 1024;
private short m_onePercentSamples = 10;
private short m_zero1PercentSamples = 1;
private short m_fpsSamplesCount = 0;
private short m_indexSample = 0;
private float m_unscaledDeltaTime = 0f;
#endregion
#region Properties -> Public
public short CurrentFPS { get; private set; } = 0;
public short AverageFPS { get; private set; } = 0;
public short OnePercentFPS { get; private set; } = 0;
public short Zero1PercentFps { get; private set; } = 0;
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Update()
{
m_unscaledDeltaTime = Time.unscaledDeltaTime;
// Update fps and ms
CurrentFPS = (short) (Mathf.RoundToInt( 1f / m_unscaledDeltaTime ));
// Update avg fps
uint averageAddedFps = 0;
m_indexSample++;
if( m_indexSample >= m_fpsSamplesCapacity ) m_indexSample = 0;
m_fpsSamples[ m_indexSample ] = CurrentFPS;
if( m_fpsSamplesCount < m_fpsSamplesCapacity )
{
m_fpsSamplesCount++;
}
for( int i = 0; i < m_fpsSamplesCount; i++ )
{
averageAddedFps += (uint) m_fpsSamples[ i ];
}
AverageFPS = (short) ((float) averageAddedFps / (float) m_fpsSamplesCount);
// Update percent lows
m_fpsSamples.CopyTo( m_fpsSamplesSorted, 0 );
/*
* TODO: Find a faster way to do this.
* We can probably avoid copying the full array every time
* and insert the new item already sorted in the list.
*/
Array.Sort( m_fpsSamplesSorted,
( x, y ) => x.CompareTo( y ) ); // The lambda expression avoids garbage generation
bool zero1PercentCalculated = false;
uint totalAddedFps = 0;
short samplesToIterateThroughForOnePercent = m_fpsSamplesCount < m_onePercentSamples
? m_fpsSamplesCount
: m_onePercentSamples;
short samplesToIterateThroughForZero1Percent = m_fpsSamplesCount < m_zero1PercentSamples
? m_fpsSamplesCount
: m_zero1PercentSamples;
short sampleToStartIn = (short) (m_fpsSamplesCapacity - m_fpsSamplesCount);
for( short i = sampleToStartIn; i < sampleToStartIn + samplesToIterateThroughForOnePercent; i++ )
{
totalAddedFps += (ushort) m_fpsSamplesSorted[ i ];
if( !zero1PercentCalculated && i >= samplesToIterateThroughForZero1Percent - 1 )
{
zero1PercentCalculated = true;
Zero1PercentFps = (short) ((float) totalAddedFps / (float) m_zero1PercentSamples);
}
}
OnePercentFPS = (short) ((float) totalAddedFps / (float) m_onePercentSamples);
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
m_onePercentSamples = (short) (m_fpsSamplesCapacity / 100);
m_zero1PercentSamples = (short) (m_fpsSamplesCapacity / 1000);
}
#endregion
#region Methods -> Private
private void Init()
{
m_fpsSamples = new short[m_fpsSamplesCapacity];
m_fpsSamplesSorted = new short[m_fpsSamplesCapacity];
UpdateParameters();
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: b205584e495e4634aa3a332a78102a19
timeCreated: 1513376950
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Fps/G_FpsMonitor.cs
uploadId: 626547
@@ -0,0 +1,156 @@
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@martinTayx)
* Contributors: https://github.com/Tayx94/graphy/graphs/contributors
* Project: Graphy - Ultimate Stats Monitor
* Date: 22-Nov-17
* Studio: Tayx
*
* Git repo: https://github.com/Tayx94/graphy
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using UnityEngine;
using UnityEngine.UI;
using Tayx.Graphy.Utils.NumString;
namespace Tayx.Graphy.Fps
{
public class G_FpsText : MonoBehaviour
{
#region Variables -> Serialized Private
[SerializeField] private Text m_fpsText = null;
[SerializeField] private Text m_msText = null;
[SerializeField] private Text m_avgFpsText = null;
[SerializeField] private Text m_onePercentFpsText = null;
[SerializeField] private Text m_zero1PercentFpsText = null;
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_FpsMonitor m_fpsMonitor = null;
private int m_updateRate = 4; // 4 updates per sec.
private int m_frameCount = 0;
private float m_deltaTime = 0f;
private float m_fps = 0f;
private float m_ms = 0f;
private const string m_msStringFormat = "0.0";
#endregion
#region Methods -> Unity Callbacks
private void Awake()
{
Init();
}
private void Update()
{
m_deltaTime += Time.unscaledDeltaTime;
m_frameCount++;
// Only update texts 'm_updateRate' times per second
if( m_deltaTime > 1f / m_updateRate )
{
m_fps = m_frameCount / m_deltaTime;
m_ms = m_deltaTime / m_frameCount * 1000f;
// Update fps
m_fpsText.text = Mathf.RoundToInt( m_fps ).ToStringNonAlloc();
SetFpsRelatedTextColor( m_fpsText, m_fps );
// Update ms
m_msText.text = m_ms.ToStringNonAlloc( m_msStringFormat );
SetFpsRelatedTextColor( m_msText, m_fps );
// Update 1% fps
m_onePercentFpsText.text = ((int) (m_fpsMonitor.OnePercentFPS)).ToStringNonAlloc();
SetFpsRelatedTextColor( m_onePercentFpsText, m_fpsMonitor.OnePercentFPS );
// Update 0.1% fps
m_zero1PercentFpsText.text = ((int) (m_fpsMonitor.Zero1PercentFps)).ToStringNonAlloc();
SetFpsRelatedTextColor( m_zero1PercentFpsText, m_fpsMonitor.Zero1PercentFps );
// Update avg fps
m_avgFpsText.text = ((int) (m_fpsMonitor.AverageFPS)).ToStringNonAlloc();
SetFpsRelatedTextColor( m_avgFpsText, m_fpsMonitor.AverageFPS );
// Reset variables
m_deltaTime = 0f;
m_frameCount = 0;
}
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
m_updateRate = m_graphyManager.FpsTextUpdateRate;
}
#endregion
#region Methods -> Private
/// <summary>
/// Assigns color to a text according to their fps numeric value and
/// the colors specified in the 3 categories (Good, Caution, Critical).
/// </summary>
///
/// <param name="text">
/// UI Text component to change its color
/// </param>
///
/// <param name="fps">
/// Numeric fps value
/// </param>
private void SetFpsRelatedTextColor( Text text, float fps )
{
int roundedFps = Mathf.RoundToInt( fps );
if( roundedFps >= m_graphyManager.GoodFPSThreshold )
{
text.color = m_graphyManager.GoodFPSColor;
}
else if( roundedFps >= m_graphyManager.CautionFPSThreshold )
{
text.color = m_graphyManager.CautionFPSColor;
}
else
{
text.color = m_graphyManager.CriticalFPSColor;
}
}
private void Init()
{
G_IntString.Init( 0, 2000 ); // Max fps expected
G_FloatString.Init( 0, 100 ); // Max ms expected per frame
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_fpsMonitor = GetComponent<G_FpsMonitor>();
UpdateParameters();
}
#endregion
}
}
@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: f74bbf307d92b0d4e81ae60b9eb1e42f
timeCreated: 1511555604
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 105778
packageName: '[Graphy] - Ultimate FPS Counter - Stats Monitor & Debugger'
packageVersion: 3.0.5
assetPath: Assets/Graphy - Ultimate Stats Monitor/Runtime/Fps/G_FpsText.cs
uploadId: 626547