Skip to content

Commit 979d6ca

Browse files
authored
Merge pull request #5 from wotakuro/feature/v1.2
Feature/v1.2
2 parents 9a9f9b8 + d59cf90 commit 979d6ca

20 files changed

+474
-55
lines changed

Documentation~/ScreenShotPrefab.png

65.2 KB
Loading

Editor/ProfilerScreenShotWindow.cs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ private struct TagInfo
1919
public int height;
2020
public int originWidth;
2121
public int originHeight;
22+
public ScreenShotToProfiler.TextureCompress compress;
2223
}
2324
private enum OutputMode:int
2425
{
@@ -51,7 +52,7 @@ public static void Create()
5152
private void OnEnable()
5253
{
5354
drawTextureInfo = new FlipYTextureResolver();
54-
Reflesh(GetProfilerActiveFrame());
55+
Refresh(GetProfilerActiveFrame());
5556
}
5657
private void OnDisable()
5758
{
@@ -66,15 +67,15 @@ private void OnDisable()
6667
}
6768
}
6869

69-
private void Reflesh(int frameIdx,bool force = false)
70+
private void Refresh(int frameIdx,bool force = false)
7071
{
7172
if(lastPreviewFrameIdx == frameIdx && !force)
7273
{
7374
return;
7475
}
7576
HierarchyFrameDataView hierarchyFrameDataView =
7677
ProfilerDriver.GetHierarchyFrameDataView(frameIdx, 0, HierarchyFrameDataView.ViewModes.Default, 0, false); ;
77-
if(hierarchyFrameDataView == null) { return; }
78+
if(hierarchyFrameDataView == null || !hierarchyFrameDataView.valid) { return; }
7879
NativeArray<byte> bytes =
7980
hierarchyFrameDataView.GetFrameMetaData<byte>(ScreenShotToProfiler.MetadataGuid, ScreenShotToProfiler.InfoTag);
8081
if (bytes != null && bytes.Length >= 12)
@@ -127,6 +128,14 @@ private TagInfo GenerateTagInfo(NativeArray<byte> data)
127128
info.height = GetShortData(data, 6);
128129
info.originWidth = GetShortData(data, 8);
129130
info.originHeight = GetShortData(data, 10);
131+
if (data.Length > 12)
132+
{
133+
info.compress = (ScreenShotToProfiler.TextureCompress)data[12];
134+
}
135+
else
136+
{
137+
info.compress = ScreenShotToProfiler.TextureCompress.None;
138+
}
130139
return info;
131140
}
132141
private int GetIntData(NativeArray<byte> data, int idx)
@@ -152,31 +161,43 @@ private Texture2D GenerateTagTexture(TagInfo info,int idx)
152161
{
153162
HierarchyFrameDataView hierarchyFrameDataView =
154163
ProfilerDriver.GetHierarchyFrameDataView(i, 0, HierarchyFrameDataView.ViewModes.Default, 0, false);
155-
if( hierarchyFrameDataView == null)
164+
if( hierarchyFrameDataView == null || !hierarchyFrameDataView.valid)
156165
{
157166
continue;
158167
}
159168
NativeArray<byte> bytes =
160169
hierarchyFrameDataView.GetFrameMetaData<byte>(ScreenShotToProfiler.MetadataGuid, info.id);
161-
162-
if( bytes.IsCreated && bytes.Length > 16 )
170+
171+
if (bytes.IsCreated && bytes.Length > 16)
163172
{
164-
texture = new Texture2D(info.width, info.height,TextureFormat.RGBA32,false);
165-
texture.LoadRawTextureData(bytes);
166-
texture.Apply();
173+
texture = new Texture2D(info.width, info.height, ScreenShotProfilerUtil.GetTextureFormat(info.compress), false);
174+
switch (info.compress) {
175+
case ScreenShotToProfiler.TextureCompress.None:
176+
case ScreenShotToProfiler.TextureCompress.RGB_565:
177+
texture.LoadRawTextureData(bytes);
178+
texture.Apply();
179+
break;
180+
case ScreenShotToProfiler.TextureCompress.PNG:
181+
case ScreenShotToProfiler.TextureCompress.JPG_BufferRGB565:
182+
case ScreenShotToProfiler.TextureCompress.JPG_BufferRGBA:
183+
texture.LoadImage(bytes.ToArray());
184+
texture.Apply();
185+
break;
186+
}
167187
break;
168188
}
169189
}
170190
return texture;
171191
}
172192

193+
173194
private void Update()
174195
{
175196
if(!this.isAutoReflesh) { return; }
176197
var frameIdx = this.GetProfilerActiveFrame();
177198
if( lastPreviewFrameIdx != frameIdx)
178199
{
179-
this.Reflesh(frameIdx);
200+
this.Refresh(frameIdx);
180201
this.Repaint();
181202
}
182203
}
@@ -189,7 +210,7 @@ private void OnGUI()
189210
{
190211
if (GUILayout.Button("Reflesh",GUILayout.Width(100)))
191212
{
192-
this.Reflesh(GetProfilerActiveFrame(),true);
213+
this.Refresh(GetProfilerActiveFrame(),true);
193214
}
194215
}
195216
EditorGUILayout.BeginHorizontal();

Editor/UTJ.SS2Profiler.Editor.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "UTJ.SS2Profiler.Editor",
3+
"rootNamespace": "",
34
"references": [
45
"GUID:3db63a1584877264096a156196217854"
56
],
@@ -10,7 +11,7 @@
1011
"allowUnsafeCode": false,
1112
"overrideReferences": false,
1213
"precompiledReferences": [],
13-
"autoReferenced": true,
14+
"autoReferenced": false,
1415
"defineConstraints": [],
1516
"versionDefines": [],
1617
"noEngineReferences": false

Prefabs.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.

Prefabs/ScreenShotProfiler.prefab

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &4496574549671356130
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
10+
m_Component:
11+
- component: {fileID: 6245396818765985779}
12+
- component: {fileID: 2977541739708315537}
13+
m_Layer: 0
14+
m_Name: ScreenShotProfiler
15+
m_TagString: Untagged
16+
m_Icon: {fileID: 0}
17+
m_NavMeshLayer: 0
18+
m_StaticEditorFlags: 0
19+
m_IsActive: 1
20+
--- !u!4 &6245396818765985779
21+
Transform:
22+
m_ObjectHideFlags: 0
23+
m_CorrespondingSourceObject: {fileID: 0}
24+
m_PrefabInstance: {fileID: 0}
25+
m_PrefabAsset: {fileID: 0}
26+
m_GameObject: {fileID: 4496574549671356130}
27+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
28+
m_LocalPosition: {x: 0, y: 0, z: 0}
29+
m_LocalScale: {x: 1, y: 1, z: 1}
30+
m_ConstrainProportionsScale: 0
31+
m_Children: []
32+
m_Father: {fileID: 0}
33+
m_RootOrder: 0
34+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
35+
--- !u!114 &2977541739708315537
36+
MonoBehaviour:
37+
m_ObjectHideFlags: 0
38+
m_CorrespondingSourceObject: {fileID: 0}
39+
m_PrefabInstance: {fileID: 0}
40+
m_PrefabAsset: {fileID: 0}
41+
m_GameObject: {fileID: 4496574549671356130}
42+
m_Enabled: 1
43+
m_EditorHideFlags: 0
44+
m_Script: {fileID: 11500000, guid: f743d7f51342eed4fbac873918ba7873, type: 3}
45+
m_Name:
46+
m_EditorClassIdentifier:
47+
width: 192
48+
height: 128
49+
textureCompress: 1
50+
allowSync: 1

Prefabs/ScreenShotProfiler.prefab.meta

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

README.ja.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# ScreenshotToUnityProfiler
2+
3+
[![openupm](https://img.shields.io/npm/v/com.utj.screenshot2profiler?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.utj.screenshot2profiler/)
4+
5+
## このツールについて
6+
Unity Profiler上に、Screenshotを載せることが出来ます.<br />
7+
![ScreenshotToUnityProfiler](Documentation~/image.gif "ScreenshotToUnityProfiler")
8+
9+
## 必要な環境
10+
- Unity 2019.3以上.<br />
11+
12+
## 推奨環境
13+
- System.supportsAsyncGPUReadbackをサポートしている環境 (モバイルでは vulkan または metal。※2021.2以降であればGLES3でも可)<br />
14+
supportsAsyncGPUReadbackが未対応でも動作はしますが、非常に思いため推奨できません。<br />
15+
16+
## インストールについて
17+
18+
[OpenUPM](https://openupm.com/packages/com.utj.screenshot2profiler/) (requires [openupm-cli](https://github.com/openupm/openupm-cli#openupm-cli)) 経由について
19+
20+
```
21+
openupm add com.utj.screenshot2profiler
22+
```
23+
24+
## 利用方法
25+
1.初期化方法について. <br />
26+
"ScreenShotProfiler.prefab" をシーン上に配置してください.<br />
27+
![ScreenshotToUnityProfiler](Documentation~/ScreenShotPrefab.png "Place Prefab")<br />
28+
(Inspector上で設定変更が可能です。)<br />
29+
30+
もしくは下記の初期化メソッドを呼び出してください
31+
UTJ.SS2Profiler.ScreenShotToProfiler.Instance.Initialize(); <br />
32+
もしくは <br />
33+
UTJ.SS2Profiler.ScreenShotToProfiler.Instance.Initialize(w,h);<br />
34+
( w,h はレコードするテクスチャサイズです).
35+
36+
2."Tools -> ProfilerScreenshot" をメニューから呼び出してください。 <br />
37+
スクリーンショットが表示されるウィンドウが現れます
38+
39+
### スクリーンキャプチャの代わりに任意の画像を表示する方法
40+
下記はRenderTextureをScreenShotに載せるサンプルです
41+
```
42+
RenderTexture captureRenderTexture;
43+
44+
ScreenShotToProfiler.Instance.captureBehaviour = (target) => {
45+
CommandBuffer commandBuffer = new CommandBuffer();
46+
commandBuffer.name = "ScreenCapture";
47+
commandBuffer.Blit(captureRenderTexture, target);
48+
Graphics.ExecuteCommandBuffer(commandBuffer);
49+
};
50+
```
51+
[サンプルC#コード](Sample~/SwitchSample.cs)<br />
52+
53+
## 変更履歴
54+
<pre>
55+
version 1.2.0
56+
Profilerデータがないときに、NullReference Exceptionが出る問題を修正
57+
テクスチャ圧縮の追加
58+
Screenshotではなく任意の画像を載せるInterfaceの追加
59+
"ScreenshotToUnityProfiler.prefab"の追加
60+
61+
version 1.1.0
62+
supportsAsyncGPUReadbackに対応していないケースへの対応
63+
</pre>

README.ja.md.meta

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

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# ScreenshotToUnityProfiler
22

33
[![openupm](https://img.shields.io/npm/v/com.utj.screenshot2profiler?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.utj.screenshot2profiler/)
4+
<br />
5+
[日本語はコチラ](README.ja.md)<br />
46

57
## about
68
Embed Screenshot to Unity Profiler protocol.<br />
@@ -11,7 +13,7 @@ Embed Screenshot to Unity Profiler protocol.<br />
1113

1214
## reccomend
1315
- the platforms that supports System.supportsAsyncGPUReadback (Mobile vulkan or metal....)<br />
14-
Support sync readback from 1.1.0 , however it's very slow....
16+
Support sync readback from 1.1.0 , however it's very slow....<br />
1517

1618
## install
1719

@@ -22,8 +24,12 @@ openupm add com.utj.screenshot2profiler
2224
```
2325

2426
## how to use
25-
1.calling this at Runtime. <br />
27+
1.Initialize. <br />
28+
Place the "ScreenShotProfiler.prefab" to the scene.<br />
29+
![ScreenshotToUnityProfiler](Documentation~/ScreenShotPrefab.png "Place Prefab")<br />
30+
(You can customize the settings at Inspector.)<br />
2631

32+
or callling this method to Initialize.
2733
UTJ.SS2Profiler.ScreenShotToProfiler.Instance.Initialize(); <br />
2834
or <br />
2935
UTJ.SS2Profiler.ScreenShotToProfiler.Instance.Initialize(w,h);<br />
@@ -32,7 +38,29 @@ UTJ.SS2Profiler.ScreenShotToProfiler.Instance.Initialize(w,h);<br />
3238
2.call "Tools -> ProfilerScreenshot" from Menu. <br />
3339
And then window will be displayed.
3440

41+
### Capture specific image instead of ScreenCapture
42+
This is a sample that use RenderTexture instead of ScreenCapture.
43+
```
44+
RenderTexture captureRenderTexture;
45+
46+
ScreenShotToProfiler.Instance.captureBehaviour = (target) => {
47+
CommandBuffer commandBuffer = new CommandBuffer();
48+
commandBuffer.name = "ScreenCapture";
49+
commandBuffer.Blit(captureRenderTexture, target);
50+
Graphics.ExecuteCommandBuffer(commandBuffer);
51+
};
52+
```
53+
[Whole Sample Code](Sample~/SwitchSample.cs)<br />
54+
3555

3656
## change
3757
<pre>
38-
version 1.1.0 -> add sync readback option for gles.
58+
version 1.2.0
59+
fix NullError when there is no data in Profiler.
60+
add Texture compress option.
61+
add RenderTexture capture instead of Screenshot.
62+
add "ScreenshotToUnityProfiler.prefab"
63+
64+
version 1.1.0
65+
add sync readback option for gles.
66+
</pre>

Runtime/ScreenShotBehaviour.cs renamed to Runtime/BehaviourProxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#if DEBUG
66
namespace UTJ.SS2Profiler
77
{
8-
internal class ScreenShotBehaviour : MonoBehaviour
8+
internal class BehaviourProxy : MonoBehaviour
99
{
1010
public System.Action captureFunc { get; set; }
1111
public System.Action updateFunc { get; set; }

Runtime/ScreenShotBehaviour.cs.meta renamed to Runtime/BehaviourProxy.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)