1
- using UnityEngine ;
2
- using System . Collections ;
3
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
2
+ using UnityEngine ;
4
3
5
4
namespace NatCorderWithOpenCVForUnityExample
6
5
{
@@ -48,12 +47,13 @@ public enum Alignment
48
47
int oldScrWidth ;
49
48
int oldScrHeight ;
50
49
51
- Dictionary < string , string > outputDict = new Dictionary < string , string > ( ) ;
50
+ Dictionary < string , string > outputDict = new Dictionary < string , string > ( ) ;
52
51
public string consoleText ;
53
52
54
53
// Use this for initialization
55
- void Start ( ) {
56
- console_labelStyle = new GUIStyle ( ) ;
54
+ void Start ( )
55
+ {
56
+ console_labelStyle = new GUIStyle ( ) ;
57
57
console_labelStyle . fontSize = 32 ;
58
58
console_labelStyle . fontStyle = FontStyle . Normal ;
59
59
console_labelStyle . wordWrap = true ;
@@ -65,104 +65,123 @@ void Start () {
65
65
}
66
66
67
67
// Update is called once per frame
68
- void Update ( ) {
68
+ void Update ( )
69
+ {
69
70
tick ++ ;
70
71
elapsed += Time . deltaTime ;
71
- if ( elapsed >= 1f ) {
72
+ if ( elapsed >= 1f )
73
+ {
72
74
fps = tick / elapsed ;
73
75
tick = 0 ;
74
76
elapsed = 0 ;
75
77
}
76
78
}
77
79
78
- void OnGUI ( ) {
79
- if ( oldScrWidth != Screen . width || oldScrHeight != Screen . height ) {
80
+ void OnGUI ( )
81
+ {
82
+ if ( oldScrWidth != Screen . width || oldScrHeight != Screen . height )
83
+ {
80
84
LocateGUI ( ) ;
81
85
}
82
86
oldScrWidth = Screen . width ;
83
87
oldScrHeight = Screen . height ;
84
88
85
- if ( boxVisible ) {
89
+ if ( boxVisible )
90
+ {
86
91
GUI . Box ( outer , "" ) ;
87
92
}
88
93
89
94
GUILayout . BeginArea ( inner ) ;
90
95
{
91
96
GUILayout . BeginVertical ( ) ;
92
97
GUILayout . Label ( "fps : " + fps . ToString ( "F1" ) ) ;
93
- foreach ( KeyValuePair < string , string > pair in outputDict ) {
98
+ foreach ( KeyValuePair < string , string > pair in outputDict )
99
+ {
94
100
GUILayout . Label ( pair . Key + " : " + pair . Value ) ;
95
101
}
96
102
GUILayout . EndVertical ( ) ;
97
103
}
98
- GUILayout . EndArea ( ) ;
104
+ GUILayout . EndArea ( ) ;
99
105
100
- if ( ! string . IsNullOrEmpty ( consoleText ) ) {
101
- if ( boxVisible ) {
102
- GUI . Box ( console_outer , "" ) ;
106
+ if ( ! string . IsNullOrEmpty ( consoleText ) )
107
+ {
108
+ if ( boxVisible )
109
+ {
110
+ GUI . Box ( console_outer , "" ) ;
103
111
}
104
112
105
- GUILayout . BeginArea ( console_inner ) ;
113
+ GUILayout . BeginArea ( console_inner ) ;
106
114
{
107
- GUILayout . BeginVertical ( ) ;
108
- GUILayout . Label ( consoleText , console_labelStyle ) ;
109
- GUILayout . EndVertical ( ) ;
115
+ GUILayout . BeginVertical ( ) ;
116
+ GUILayout . Label ( consoleText , console_labelStyle ) ;
117
+ GUILayout . EndVertical ( ) ;
110
118
}
111
- GUILayout . EndArea ( ) ;
119
+ GUILayout . EndArea ( ) ;
112
120
}
113
121
}
114
122
115
- public void Add ( string key , string value ) {
116
- if ( outputDict . ContainsKey ( key ) ) {
117
- outputDict [ key ] = value ;
118
- } else {
119
- outputDict . Add ( key , value ) ;
123
+ public void Add ( string key , string value )
124
+ {
125
+ if ( outputDict . ContainsKey ( key ) )
126
+ {
127
+ outputDict [ key ] = value ;
128
+ }
129
+ else
130
+ {
131
+ outputDict . Add ( key , value ) ;
120
132
}
121
133
}
122
134
123
- public void Remove ( string key ) {
124
- outputDict . Remove ( key ) ;
135
+ public void Remove ( string key )
136
+ {
137
+ outputDict . Remove ( key ) ;
125
138
}
126
139
127
- public void Clear ( ) {
128
- outputDict . Clear ( ) ;
140
+ public void Clear ( )
141
+ {
142
+ outputDict . Clear ( ) ;
129
143
}
130
-
131
- public void LocateGUI ( ) {
144
+
145
+ public void LocateGUI ( )
146
+ {
132
147
x = GetAlignedX ( alignment , boxWidth ) ;
133
148
y = GetAlignedY ( alignment , boxHeight ) ;
134
149
outer = new Rect ( x , y , boxWidth , boxHeight ) ;
135
150
inner = new Rect ( x + padding . x , y + padding . y , boxWidth , boxHeight ) ;
136
151
137
152
console_x = GetAlignedX ( Alignment . LeftBottom , Screen . width ) ;
138
153
console_y = GetAlignedY ( Alignment . LeftBottom , consoleHeight ) ;
139
- console_outer = new Rect ( console_x , console_y , Screen . width - offset . x * 2 , consoleHeight ) ;
140
- console_inner = new Rect ( console_x + padding . x , console_y + padding . y , Screen . width - offset . x * 2 - padding . x , consoleHeight ) ;
154
+ console_outer = new Rect ( console_x , console_y , Screen . width - offset . x * 2 , consoleHeight ) ;
155
+ console_inner = new Rect ( console_x + padding . x , console_y + padding . y , Screen . width - offset . x * 2 - padding . x , consoleHeight ) ;
141
156
}
142
-
143
- float GetAlignedX ( Alignment anchor , float w ) {
144
- switch ( anchor ) {
145
- default :
146
- case Alignment . LeftTop :
147
- case Alignment . LeftBottom :
148
- return offset . x ;
149
-
150
- case Alignment . RightTop :
151
- case Alignment . RightBottom :
152
- return Screen . width - w - offset . x ;
157
+
158
+ float GetAlignedX ( Alignment anchor , float w )
159
+ {
160
+ switch ( anchor )
161
+ {
162
+ default :
163
+ case Alignment . LeftTop :
164
+ case Alignment . LeftBottom :
165
+ return offset . x ;
166
+
167
+ case Alignment . RightTop :
168
+ case Alignment . RightBottom :
169
+ return Screen . width - w - offset . x ;
153
170
}
154
171
}
155
172
156
- float GetAlignedY ( Alignment anchor , float h ) {
157
- switch ( anchor ) {
158
- default :
159
- case Alignment . LeftTop :
160
- case Alignment . RightTop :
161
- return offset . y ;
162
-
163
- case Alignment . LeftBottom :
164
- case Alignment . RightBottom :
165
- return Screen . height - h - offset . y ;
173
+ float GetAlignedY ( Alignment anchor , float h )
174
+ {
175
+ switch ( anchor )
176
+ {
177
+ default :
178
+ case Alignment . LeftTop :
179
+ case Alignment . RightTop :
180
+ return offset . y ;
181
+
182
+ case Alignment . LeftBottom :
183
+ case Alignment . RightBottom :
184
+ return Screen . height - h - offset . y ;
166
185
}
167
186
}
168
187
}
0 commit comments