Skip to content

Commit

Permalink
Updated Unity to 2018.2.5f1, added FPS counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Crowley2012 committed Aug 24, 2018
1 parent 9500bc2 commit 5b0c9ad
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 2 deletions.
91 changes: 90 additions & 1 deletion Tower Defense/Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 1526980366}
m_IndirectSpecularColor: {r: 0.28378698, g: 0.37033936, b: 0.5008427, a: 1}
m_IndirectSpecularColor: {r: 0.2837867, g: 0.37033898, b: 0.50084156, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -1113,6 +1113,94 @@ CanvasRenderer:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1213235077}
m_CullTransparentMesh: 0
--- !u!1 &1213519726
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1213519727}
- component: {fileID: 1213519729}
- component: {fileID: 1213519728}
- component: {fileID: 1213519730}
m_Layer: 5
m_Name: FPS
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1213519727
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1213519726}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1880660676}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 87, y: -20}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1213519728
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1213519726}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 8
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 0
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: FPS
--- !u!222 &1213519729
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1213519726}
m_CullTransparentMesh: 0
--- !u!114 &1213519730
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1213519726}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 71ff885770ad49f4e85668169dc4d4ff, type: 3}
m_Name:
m_EditorClassIdentifier:
updateInterval: 0.5
--- !u!1 &1309069309
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1756,6 +1844,7 @@ RectTransform:
- {fileID: 1213235078}
- {fileID: 1911657404}
- {fileID: 949381971}
- {fileID: 1213519727}
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down
53 changes: 53 additions & 0 deletions Tower Defense/Assets/Scripts/FPS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using UnityEngine;
using UnityEngine.UI;

public class FPS : MonoBehaviour
{
#region Public Fields

public float UpdateInterval = 0.5F;

#endregion Public Fields

#region Private Fields

private float _accumulatedTime = 0;
private int _frame;
private float _timeLeft;

#endregion Private Fields

#region Private Methods

private void Start()
{
_timeLeft = UpdateInterval;
}

private void Update()
{
_timeLeft -= Time.deltaTime;
_accumulatedTime += Time.timeScale / Time.deltaTime;
++_frame;

if (_timeLeft <= 0.0)
{
float fps = _accumulatedTime / _frame;
gameObject.GetComponent<Text>().text = System.String.Format("{0:F0} FPS", fps);

if (fps < 30)
gameObject.GetComponent<Text>().material.color = Color.yellow;
else
if (fps < 10)
gameObject.GetComponent<Text>().material.color = Color.red;
else
gameObject.GetComponent<Text>().material.color = Color.green;

_timeLeft = UpdateInterval;
_accumulatedTime = 0.0F;
_frame = 0;
}
}

#endregion Private Methods
}
11 changes: 11 additions & 0 deletions Tower Defense/Assets/Scripts/FPS.cs.meta

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

2 changes: 1 addition & 1 deletion Tower Defense/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 2018.2.4f1
m_EditorVersion: 2018.2.5f1

0 comments on commit 5b0c9ad

Please sign in to comment.