Skip to content

Commit

Permalink
Add FPS Stats and Remove lights
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptsengineer committed Dec 11, 2020
1 parent c0a2723 commit cce7aaa
Show file tree
Hide file tree
Showing 15 changed files with 376 additions and 141 deletions.
341 changes: 236 additions & 105 deletions Assets/Scenes/Main.unity

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Assets/Scripts/Actors/OpenKnife.Actors.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"name": "OpenKnife.Actors",
"references": [
"OpenKnife.Utils",
"OpenKnife",
"OpenKnife.UI"
"OpenKnife"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
6 changes: 6 additions & 0 deletions Assets/Scripts/Actors/Scorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public class Scorer : MonoBehaviour
public int Score => score;
public int Fruits => fruits;

private void Start()
{
score = 0;
fruits = 0;
}

public void AddScore(int value)
{
if (value < 0) return;
Expand Down
3 changes: 1 addition & 2 deletions Assets/Scripts/Actors/Shooter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using UnityEngine;
using OpenKnife;
using OpenKnife.UI;
using UnityEngine.Events;

namespace OpenKnife.Actors
Expand All @@ -16,6 +15,7 @@ public class Shooter : MonoBehaviour
{
private int shoots = 0;
public ShootEvent m_ShootEvent = new ShootEvent();
public ShootEvent m_NewShoots = new ShootEvent();

public ConstantForce2D mover;

Expand All @@ -27,7 +27,6 @@ public class Shooter : MonoBehaviour
public void SetNewShoots(int shoots)
{
this.shoots = shoots;
UIManager.instance.shootsPanel.SetNewShoots(shoots);
}

private void Update()
Expand Down
28 changes: 7 additions & 21 deletions Assets/Scripts/Levels/LevelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using UnityEngine.Events;
using OpenKnife.Actors;
using OpenKnife.States;
using OpenKnife.UI;

namespace OpenKnife.Levels
{

public class LevelManager : MonoBehaviour, GameStates
{
#region Public variables
Expand All @@ -25,7 +25,6 @@ public class LevelManager : MonoBehaviour, GameStates
public GameObject wood;
public Transform spawnShooter;


[Header("Events")]
public UnityEvent onKnifeHitOnWood;
public UnityEvent onKnifeHitOnKnife;
Expand All @@ -35,6 +34,11 @@ public class LevelManager : MonoBehaviour, GameStates
public UnityEvent onStageFinish;
public UnityEvent onShoot;

public int ActualStage => actualStage;
public int ActualScore => scorer.Score;
public int Fruits => scorer.Fruits;
public int Shoots => shooter.Shoots;

#endregion

#region Private variables
Expand Down Expand Up @@ -134,26 +138,9 @@ private void InitBuiltInEvents()
Destroy(go, 1f);

scorer.AddFruits(1);
UIManager.instance.UpdateFruitsText(scorer.Fruits);
});
onScore.AddListener(delegate
{
UIManager.instance.UpdateScoreText(scorer.Score);
});

onStageInit.AddListener(delegate
{
UIManager.instance.UpdateStageTitleText(actualStage);
});
onStageFinish.AddListener(delegate
{
UIManager.instance.stageTitle.gameObject.SetActive(false);
});

onShoot.AddListener(delegate
{
UIManager.instance.shootsPanel.Shoot();
});

}

// Prepare for next shooter
Expand Down Expand Up @@ -201,7 +188,6 @@ private void RequestNewShoot()
private void Next()
{
actualStage++;
UIManager.instance.UpdateStageText(actualStage);
if (stages.Length <= actualStage)
{
GameManager.instance.GameOver();
Expand Down
5 changes: 2 additions & 3 deletions Assets/Scripts/Levels/OpenKnife.Levels.asmdef
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"name": "OpenKnife.Levels",
"references": [
"OpenKnife.Actors",
"OpenKnife.States",
"OpenKnife",
"OpenKnife.UI"
"OpenKnife.Actors",
"OpenKnife.States"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/UI/OpenKnife.UI.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"references": [
"OpenKnife.States",
"OpenKnife",
"UnityEngine.UI"
"UnityEngine.UI",
"OpenKnife.Levels"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
30 changes: 30 additions & 0 deletions Assets/Scripts/UI/UIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using OpenKnife.States;
using UnityEngine;
using UnityEngine.UI;
using OpenKnife.Levels;

namespace OpenKnife.UI
{
Expand All @@ -15,6 +16,8 @@ public class UIManager : MonoBehaviour, GameStates
public GameObject inGamePanel;
public GameObject gameOverPanel;

private LevelManager levelManager;

[Header("References")]
public Text stageText;
public Text fruitsText;
Expand All @@ -36,10 +39,37 @@ private void Awake()

private void Start()
{
levelManager = GameManager.instance.GetComponent<LevelManager>();
GameManager.instance.gameStates.Add(this);
UpdateFruitsText(0);
UpdateScoreText(0);
UpdateStageText(0);

levelManager.onShoot.AddListener(delegate
{
shootsPanel.Shoot();
});
levelManager.onStageFinish.AddListener(delegate
{
stageTitle.gameObject.SetActive(false);
});
levelManager.onStageInit.AddListener(delegate
{
UpdateStageTitleText(levelManager.ActualStage);
shootsPanel.SetNewShoots(levelManager.Shoots);
});
levelManager.onScore.AddListener(delegate
{
UpdateScoreText(levelManager.ActualScore);
});
levelManager.onStageInit.AddListener(delegate
{
UpdateStageText(levelManager.ActualStage);
});
levelManager.onFruitSlice.AddListener(delegate
{
UpdateFruitsText(levelManager.Fruits);
});
}

private void OnDisable()
Expand Down
69 changes: 69 additions & 0 deletions Assets/Scripts/Utils/FPSStat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using UnityEngine;
using UnityEngine.UI;

namespace OpenKnife.Utils
{
public class FPSStat : MonoBehaviour
{

[Range(0.1f,1f)]
public float UpdateInterval = 0.5f;

public Text _infoFPS;
public Text _infoMS;

private float m_AccumulatedTime = 0f;
private int m_AccumulatedFrames = 0;
private float m_LastUpdateTime;
private float m_FrameTime = 0f;
private float m_FrameRate = 0f;

public static float MinTime = 0.000000001f;

private void Update()
{
float deltaTime = Time.unscaledDeltaTime;

m_AccumulatedTime += deltaTime;
m_AccumulatedFrames++;

float nowTime = Time.realtimeSinceStartup;
if (nowTime - m_LastUpdateTime < UpdateInterval) {
return;
}

m_FrameTime = m_AccumulatedTime / m_AccumulatedFrames;
m_FrameRate = 1.0f / m_FrameTime;

UpdateInfo();

ResetProbingData();
m_LastUpdateTime = nowTime;
}


private void UpdateInfo()
{
_infoFPS.text = string.Format(
"{0}"+" FPS ",
m_FrameRate.ToString("F0"));

_infoMS.text = string.Format(
"{0}"+" MS ",
(m_FrameTime*1000f).ToString("F1"));
}


private void ResetProbingData() {
m_AccumulatedTime = 0.0f;
m_AccumulatedFrames = 0;
}

private void Reset()
{
m_LastUpdateTime = Time.realtimeSinceStartup;
}


}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Utils/FPSStat.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Assets/Settings/ForwardRenderer.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ MonoBehaviour:
m_Name: ForwardRenderer
m_EditorClassIdentifier:
m_RendererFeatures: []
m_RendererFeatureMap:
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
shaders:
blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
Expand All @@ -34,3 +35,4 @@ MonoBehaviour:
passOperation: 0
failOperation: 0
zFailOperation: 0
m_ShadowTransparentReceive: 0
6 changes: 4 additions & 2 deletions Assets/Settings/UniversalRP-LowQuality.asset
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ MonoBehaviour:
m_RequireDepthTexture: 0
m_RequireOpaqueTexture: 0
m_OpaqueDownsampling: 1
m_SupportsTerrainHoles: 0
m_SupportsHDR: 0
m_MSAA: 1
m_RenderScale: 1
m_MainLightRenderingMode: 1
m_MainLightRenderingMode: 0
m_MainLightShadowsSupported: 0
m_MainLightShadowmapResolution: 2048
m_AdditionalLightsRenderingMode: 0
Expand All @@ -41,8 +42,9 @@ MonoBehaviour:
m_SoftShadowsSupported: 0
m_UseSRPBatcher: 1
m_SupportsDynamicBatching: 0
m_MixedLightingSupported: 1
m_MixedLightingSupported: 0
m_DebugLevel: 0
m_PostProcessingFeatureSet: 0
m_ColorGradingMode: 0
m_ColorGradingLutSize: 16
m_ShadowType: 1
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 0.2.21
bundleVersion: 0.2.5
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down
6 changes: 3 additions & 3 deletions ProjectSettings/QualitySettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
QualitySettings:
m_ObjectHideFlags: 0
serializedVersion: 5
m_CurrentQuality: 2
m_CurrentQuality: 0
m_QualitySettings:
- serializedVersion: 2
name: Low
Expand Down Expand Up @@ -118,13 +118,13 @@ QualitySettings:
type: 2}
excludedTargetPlatforms: []
m_PerPlatformDefaultQuality:
Android: 1
Android: 0
Lumin: 2
Nintendo Switch: 2
PS4: 2
Stadia: 2
Standalone: 2
WebGL: 1
WebGL: 0
Windows Store Apps: 2
XboxOne: 2
iPhone: 1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OpenKnife

# Bem-vindo ao Open Knife 👋
![Version](https://img.shields.io/badge/version-0.2.2-blue.svg?cacheSeconds=2592000)
![Version](https://img.shields.io/badge/version-0.2.5-blue.svg?cacheSeconds=2592000)
[![Documentation](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](todo-doc)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](MIT)
[![Twitter: ScriptsEngineer](https://img.shields.io/twitter/follow/ScriptsEngineer.svg?style=social)](https://twitter.com/ScriptsEngineer)
Expand Down

0 comments on commit cce7aaa

Please sign in to comment.