Skip to content

Commit 39dd740

Browse files
committed
Update sample scene
1 parent deb0328 commit 39dd740

File tree

10 files changed

+849
-2
lines changed

10 files changed

+849
-2
lines changed

Assets/CustomTextureRenderer.Samples/Scripts.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This code is modified version of FPSCounter implemented by baba_s.
2+
// The original source code is available in the following article.
3+
// https://baba-s.hatenablog.com/entry/2019/05/04/220500
4+
5+
using UnityEngine;
6+
7+
namespace UnityCustomTextureRenderer.Samples
8+
{
9+
public sealed class FPSCounter
10+
{
11+
public float FPS => _fps;
12+
private float _fps;
13+
14+
private int _frameCount;
15+
private float _deltaTime;
16+
17+
private readonly int _updateRate;
18+
19+
public FPSCounter(int updateRate = 4)
20+
{
21+
_updateRate = updateRate;
22+
}
23+
24+
public void Update()
25+
{
26+
_deltaTime += Time.unscaledDeltaTime;
27+
28+
_frameCount++;
29+
30+
if ( !( _deltaTime > 1f / _updateRate ) ) return;
31+
32+
_fps = _frameCount / _deltaTime;
33+
34+
_deltaTime = 0;
35+
_frameCount = 0;
36+
}
37+
}
38+
}

Assets/CustomTextureRenderer.Samples/Scripts/FPSCounter.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/CustomTextureRenderer.Samples/Test.cs renamed to Assets/CustomTextureRenderer.Samples/Scripts/Test.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ enum TextureSize
2222
[SerializeField] TextureSize _textureSize;
2323
[SerializeField] bool _useNonBlockingVersion;
2424

25+
public event Action<(int TextureWidth, int TextureHeight, bool UseNonBlockingVersion)> OnInitialized;
26+
2527
uint _frame;
2628

2729
Texture _texture;
@@ -78,6 +80,8 @@ void Start()
7880
var prop = new MaterialPropertyBlock();
7981
prop.SetTexture("_MainTex", _texture);
8082
GetComponent<Renderer>().SetPropertyBlock(prop);
83+
84+
OnInitialized?.Invoke((size, size, _useNonBlockingVersion));
8185
}
8286

8387
void OnDestroy()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using UnityEngine;
2+
3+
namespace UnityCustomTextureRenderer.Samples
4+
{
5+
public sealed class TestPresenter : MonoBehaviour
6+
{
7+
[SerializeField] Test _test;
8+
[SerializeField] TestUIView _uiView;
9+
10+
FPSCounter _fpsCounter = new FPSCounter(10);
11+
12+
void Awake()
13+
{
14+
_test.OnInitialized += (values) =>
15+
{
16+
var title = values.UseNonBlockingVersion ?
17+
nameof(UnityCustomTextureRenderer.NonBlockingCustomTextureRenderer) :
18+
nameof(UnityCustomTextureRenderer.CustomTextureRenderer);
19+
20+
_uiView.SetTitle(title);
21+
_uiView.SetTextureSize(values.TextureWidth, values.TextureHeight);
22+
};
23+
}
24+
25+
void Update()
26+
{
27+
_fpsCounter.Update();
28+
_uiView.SetFrameRate(_fpsCounter.FPS);
29+
}
30+
}
31+
}

Assets/CustomTextureRenderer.Samples/Scripts/TestPresenter.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
4+
namespace UnityCustomTextureRenderer.Samples
5+
{
6+
public sealed class TestUIView : MonoBehaviour
7+
{
8+
[SerializeField] Text _title;
9+
[SerializeField] Text _textureSize;
10+
[SerializeField] Text _frameRate;
11+
12+
public void SetTitle(string value)
13+
{
14+
_title.text = value;
15+
}
16+
17+
public void SetTextureSize(int width, int height)
18+
{
19+
_textureSize.text = $"{width}x{height}";
20+
}
21+
22+
public void SetFrameRate(float value)
23+
{
24+
_frameRate.text = $"{value:F2}";
25+
}
26+
}
27+
}

Assets/CustomTextureRenderer.Samples/Scripts/TestUIView.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)