Skip to content

Commit 465e5fc

Browse files
authored
Merge pull request #8 from wotakuro/feature/v1_5
Feature/v1 5
2 parents 667cace + e9da989 commit 465e5fc

File tree

7 files changed

+217
-7
lines changed

7 files changed

+217
-7
lines changed

Editor/ProfilerScreenShotWindow.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public static void Create()
3737
private bool isYFlip = false;
3838
private OutputMode outputMode;
3939
private ColorSpaceMode colorSpaceMode;
40+
private TagInfo tagInfo;
4041

4142
private Material drawMaterial;
4243

@@ -75,7 +76,6 @@ private void Refresh(int frameIdx,bool force = false)
7576
{
7677
return;
7778
}
78-
TagInfo tagInfo;
7979

8080
if (ProfilerScreenShotEditorLogic.TryGetTagInfo(frameIdx, out tagInfo))
8181
{
@@ -145,6 +145,9 @@ private void OnGUI()
145145
outputMode = (OutputMode)EditorGUILayout.Popup((int)outputMode, outputModeSelect);
146146
colorSpaceMode = (ColorSpaceMode)EditorGUILayout.Popup((int)colorSpaceMode, colorSpaceModeSelect);
147147
EditorGUILayout.EndHorizontal();
148+
149+
EditorGUILayout.LabelField( tagInfo.width + "x"+ tagInfo.height +
150+
" original:" + tagInfo.originWidth + "x" + tagInfo.originHeight + "::compress " + tagInfo.compress.ToString());
148151
EditorGUILayout.Space();
149152
//drawTextureInfo.SetFlip(this.isYFlip);
150153

Editor/ProfilerWindowScreenShotModule.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public override ProfilerModuleViewController CreateDetailsViewController()
5151
public class ScreenShotModuleDetailsViewController : ProfilerModuleViewController
5252
{
5353
private ProfilerWindowScreenShotModule screenShotModule;
54+
private Label originSize;
5455
private Toggle yFlipToggle;
5556
private DropdownField sizeField;
5657
private DropdownField colorSpaceField;
@@ -115,6 +116,8 @@ private void InitVisualElement(VisualElement ve)
115116

116117
imageBody = ve.Q<IMGUIContainer>("TextureOutIMGUI");
117118
imageBody.onGUIHandler += OnGUITextureOut;
119+
120+
originSize = ve.Q<Label>("OriginalSize");
118121
}
119122

120123
protected override void Dispose(bool disposing)
@@ -129,7 +132,7 @@ protected override void Dispose(bool disposing)
129132
private void OnGUITextureOut()
130133
{
131134
bool yFlip = this.yFlipToggle.value;
132-
var rect = new Rect(10, 10, currentTagInfo.width, currentTagInfo.height);
135+
var rect = new Rect(0, 0, currentTagInfo.width, currentTagInfo.height);
133136

134137
screenShotModule.yFlip = yFlipToggle.value;
135138
screenShotModule.sizeIndex = sizeField.index;
@@ -138,7 +141,7 @@ private void OnGUITextureOut()
138141
if (this.sizeField.index == (int)EOutputMode.FitWindow)
139142
{
140143
rect = FitWindowSize(currentTagInfo,
141-
new Rect(10, 10,
144+
new Rect(0, 0,
142145
this.imageBody.contentRect.width,
143146
this.imageBody.contentRect.height));
144147
}
@@ -188,8 +191,12 @@ private void OnSelectedFrameIndexChanged(long selectedFrameIndex) {
188191
UnityEngine.Object.DestroyImmediate(screenshotTexture);
189192
}
190193
screenshotTexture = ProfilerScreenShotEditorLogic.GenerateTagTexture(currentTagInfo, idx);
194+
if (originSize!=null)
195+
{
196+
originSize.text = currentTagInfo.width + "x" + currentTagInfo.height+" original:"+
197+
currentTagInfo.originWidth +"x"+currentTagInfo.originHeight + "::compress " + currentTagInfo.compress.ToString();
198+
}
191199
}
192-
193200
}
194201

195202

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
22
<ui:Label tabindex="-1" text="Screenshot Module" parse-escape-sequences="true" display-tooltip-when-elided="true" />
33
<ui:VisualElement style="flex-grow: 1; flex-direction: row; margin-top: 3px; margin-left: 5px;">
4-
<ui:DropdownField label="Size" index="-1" choices="System.Collections.Generic.List`1[System.String]" name="SizeMode" style="flex-wrap: nowrap; white-space: nowrap; -unity-text-align: upper-left;" />
4+
<ui:DropdownField label="ScaleMode" index="-1" choices="System.Collections.Generic.List`1[System.String]" name="SizeMode" style="flex-wrap: nowrap; white-space: nowrap; -unity-text-align: upper-left;" />
55
<ui:Toggle label="Flip Y" name="FlipYToggle" />
66
<ui:DropdownField label="ColorSpace" index="-1" choices="System.Collections.Generic.List`1[System.String]" name="ColorSpaceMode" style="flex-wrap: nowrap; white-space: nowrap; -unity-text-align: upper-left;" />
77
</ui:VisualElement>
8-
<ui:VisualElement name="ImageField" style="flex-wrap: wrap; flex-direction: column; align-items: center; height: 100%; justify-content: flex-start;">
8+
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" enable-rich-text="false" name="OriginalSize" text="size" style="margin-top: 1px; margin-left: 20px; margin-bottom: 2px;" />
9+
<ui:VisualElement name="ImageField" style="flex-wrap: wrap; flex-direction: column; align-items: center; height: 100%; justify-content: flex-start; margin-top: 0; margin-left: 20px; margin-bottom: 10px;">
910
<ui:IMGUIContainer name="TextureOutIMGUI" style="width: 100%; height: 100%;" />
1011
</ui:VisualElement>
1112
</ui:UXML>

README.ja.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,36 @@ ScreenShotToProfiler.Instance.captureBehaviour = (target) => {
5050
```
5151
[サンプルC#コード](Sample~/SwitchSample.cs)<br />
5252

53+
## コマンドラインオプション
54+
実行時にコマンドラインオプションを付けることで、強制的に挙動を変更する事が可能です。(Editor実行時は無効)
55+
56+
### "--profilerSS"による有効・無効
57+
"--profilerSS=enable"という形でオプションを付ける事で、Screenshotを起動直後から強制的に取るようにします。<br />
58+
"--profilerSS=disable"という形でオプションを付ける事で、Screenshotを強制的に無効化できます
59+
60+
### "--profilerSS-resolution"での解像度変更
61+
"--profilerSS-resolution=256x192"のように、Textureの"幅x高さ"を措定できるようになります。<br />
62+
63+
### "--profilerSS-format"でのフォーマット変更
64+
"--profilerSS-format=JPG_BUFFERRGB565"のようにすることで、TextureをJpg圧縮する事が可能です。<br />
65+
66+
オプションの値一覧
67+
- "NONE" → RGBA 32bit無圧縮設定
68+
- "RGB_565" → RGB565(16bit) 無圧縮設定
69+
- "PNG" → RGBA 32Bit PNG圧縮設定
70+
- "JPG_BUFFERRGBA" → RGBA 32bit JPEG圧縮設定
71+
- "JPG" / "JPG_BUFFERRGB565" → RGB565 JPEG圧縮設定
72+
73+
### オプション例
74+
例:Sample.exe --profilerSS=enable --profilerSS-resolution=640x480 --profilerSS-format=jpg <br />
75+
例:adb shell am start -n com.utj.test[パッケージ名]/com.unity3d.player.UnityPlayerActivity[アクティビティ名] -e "unity --profilerSS=disable"<br />
76+
5377
## 変更履歴
5478
<pre>
79+
version 1.5.0
80+
 コマンドラインオプションを追加
81+
 解像度の表示
82+
5583
version 1.4.0
5684
カラースペース変換機能を追加
5785

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,36 @@ ScreenShotToProfiler.Instance.captureBehaviour = (target) => {
5353
[Whole Sample Code](Sample~/SwitchSample.cs)<br />
5454

5555

56+
## command line options
57+
By adding command line options at runtime, you can forcefully change the behavior. (Disabled when running Editor)
58+
59+
### Enable/disable with "--profilerSS"
60+
By adding the option "--profilerSS=enable", you can force the screenshot to be taken immediately after startup. <br />
61+
Screenshot can be forcibly disabled by adding the option "--profilerSS=disable"
62+
63+
### Change resolution with "--profilerSS-resolution"
64+
You can now set the "width x height" of Texture, like "--profilerSS-resolution=256x192".
65+
66+
### Format change with "--profilerSS-format"
67+
Texture can be compressed into Jpg by using "--profilerSS-format=JPG_BUFFERRGB565".
68+
69+
Option value list
70+
- "NONE" → RGBA 32bit uncompressed setting
71+
- "RGB_565" → RGB565(16bit) uncompressed setting
72+
- "PNG" → RGBA 32Bit PNG compression setting
73+
- "JPG_BUFFERRGBA" → RGBA 32bit JPEG compression setting
74+
- "JPG" / "JPG_BUFFERRGB565" → RGB565 JPEG compression settings
75+
76+
### Option Examples
77+
Example: Sample.exe --profilerSS=enable --profilerSS-resolution=640x480 --profilerSS-format=jpg <br />
78+
Example: adb shell am start -n com.utj.test[package name]/com.unity3d.player.UnityPlayerActivity[activity name] -e "unity --profilerSS=disable"<br />
79+
5680
## change
5781
<pre>
82+
version 1.5.0
83+
Added command line option
84+
Display resolution
85+
5886
version 1.4.0
5987
Add ColorSpace convert.
6088

Runtime/ScreenShotToProfiler.cs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,122 @@ public Action<RenderTexture> captureBehaviour
4747

4848
private CustomSampler captureSampler;
4949
private CustomSampler updateSampler;
50+
51+
private bool isInitialize = false;
52+
53+
const string ArgForceOption = "--profilerSS";
54+
55+
const string ArgForceResolution = "--profilerSS-resolution";
56+
const string ArgForceFormat = "--profilerSS-format";
57+
58+
59+
const int Invalid = -1;
60+
61+
static int forceLaunchOption = Invalid;
62+
static int forceWidth = Invalid;
63+
static int forceHeight = Invalid;
64+
static int forceFormat = Invalid;
65+
5066
#endif
67+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
68+
private static void OnRuntimeInitialize()
69+
{
70+
var args = System.Environment.GetCommandLineArgs();
71+
int length = args.Length;
72+
73+
for(int i = 0; i < length; ++i)
74+
{
75+
if ( string.IsNullOrEmpty(args[i] ) )
76+
{
77+
continue;
78+
}
79+
80+
if(args[i].StartsWith( ArgForceResolution) )
81+
{
82+
var resolutionVal = GetParameter(args[i]);
83+
GetResolution(resolutionVal, out forceWidth, out forceHeight);
84+
}
85+
else if (args[i].StartsWith( ArgForceFormat) )
86+
{
87+
var formatParam = GetParameter(args[i]);
88+
forceFormat = GetFormat(formatParam);
89+
}
90+
else if (args[i].StartsWith(ArgForceOption))
91+
{
92+
var optionVal = GetParameter(args[i]);
93+
if (optionVal == "enable")
94+
{
95+
forceLaunchOption = 1;
96+
}
97+
else if (optionVal == "disable")
98+
{
99+
forceLaunchOption = 0;
100+
}
101+
}
102+
}
103+
if(forceLaunchOption == 1)
104+
{
105+
Instance.Initialize();
106+
}
107+
}
108+
109+
110+
private static int GetFormat(string param)
111+
{
112+
switch (param)
113+
{
114+
case "rgb_565":
115+
return (int)TextureCompress.RGB_565;
116+
case "png":
117+
return (int)TextureCompress.PNG;
118+
case "jpg_bufferrgb565":
119+
case "jpg":
120+
case "jpeg":
121+
return (int)TextureCompress.JPG_BufferRGB565;
122+
case "jpg_Bufferrgba":
123+
return (int)TextureCompress.JPG_BufferRGBA;
124+
case "none":
125+
return (int)TextureCompress.None;
126+
}
127+
return Invalid;
128+
}
129+
130+
private static void GetResolution(string param,out int width,out int height)
131+
{
132+
int paramIndex = 0;
133+
width = 0;
134+
height = 0;
135+
int length = param.Length;
136+
for(int i = 0; i < length; ++i)
137+
{
138+
if( '0' <= param[i] && param[i] <= '9')
139+
{
140+
switch(paramIndex)
141+
{
142+
case 0:
143+
width = width * 10 + (param[i]- '0');
144+
break;
145+
case 1:
146+
height = height * 10 + (param[i] - '0');
147+
break;
148+
}
149+
}
150+
else if (param[i] == 'x' )
151+
{
152+
paramIndex++;
153+
}
154+
}
155+
}
156+
157+
private static string GetParameter(string arg)
158+
{
159+
int eqIndex = arg.IndexOf('=');
160+
if(eqIndex == -1)
161+
{
162+
return "";
163+
}
164+
return arg.Substring(eqIndex+1).ToLower();
165+
}
51166

52167
public bool Initialize()
53168
{
@@ -72,6 +187,25 @@ public bool Initialize(int width , int height,bool allowSync = false)
72187
public bool Initialize(int width, int height, TextureCompress compress, bool allowSync)
73188
{
74189
#if DEBUG
190+
#if !UNITY_EDITOR
191+
if(forceLaunchOption == 0)
192+
{
193+
return false;
194+
}
195+
if (forceWidth != Invalid)
196+
{
197+
width = forceWidth;
198+
}
199+
if (forceHeight != Invalid)
200+
{
201+
height = forceHeight;
202+
}
203+
if(forceFormat != Invalid)
204+
{
205+
compress = (TextureCompress)forceFormat;
206+
}
207+
#endif
208+
75209
if (!SystemInfo.supportsAsyncGPUReadback)
76210
{
77211
if (!allowSync)
@@ -94,6 +228,13 @@ public bool Initialize(int width, int height, TextureCompress compress, bool all
94228
private void InitializeLogic(int width,int height,TextureCompress compress)
95229
{
96230
#if DEBUG
231+
if (isInitialize)
232+
{
233+
return;
234+
}
235+
if(width ==0 || height == 0) {
236+
return;
237+
}
97238
renderTextureBuffer = new ScreenShotLogic(width, height, compress);
98239
renderTextureBuffer.captureBehaviour = this.DefaultCaptureBehaviour;
99240
this.behaviourGmo = new GameObject();
@@ -105,6 +246,7 @@ private void InitializeLogic(int width,int height,TextureCompress compress)
105246
this.updateSampler = CustomSampler.Create("ScreenshotToProfiler.Update");
106247
behaviour.captureFunc += this.Capture;
107248
behaviour.updateFunc += this.Update;
249+
isInitialize = true;
108250
#endif
109251
}
110252

@@ -117,6 +259,7 @@ public void Destroy()
117259
}
118260
if (renderTextureBuffer != null) { renderTextureBuffer.Dispose(); }
119261
renderTextureBuffer = null;
262+
isInitialize = false;
120263
#endif
121264
}
122265

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.utj.screenshot2profiler",
33
"displayName": "Screenshot to Profiler",
4-
"version": "1.4.0",
4+
"version": "1.5.0",
55
"unity": "2019.3",
66
"description": "Embedded screenshot to profiler data",
77
"keywords": [

0 commit comments

Comments
 (0)