Skip to content

Commit 40501ae

Browse files
committed
v1.6.2
Updated NatCorder version to 1.6.2 (2019/09/16).
1 parent 16ffec6 commit 40501ae

File tree

9 files changed

+529
-430
lines changed

9 files changed

+529
-430
lines changed

Assets/NatCorderWithOpenCVForUnityExample/NatCorderWithOpenCVForUnityExample.cs

+20-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1-
using System;
2-
using System.Collections;
1+
using System.Collections;
32
using UnityEngine;
4-
using UnityEngine.UI;
53
using UnityEngine.SceneManagement;
4+
using UnityEngine.UI;
65

76
namespace NatCorderWithOpenCVForUnityExample
87
{
98
public class NatCorderWithOpenCVForUnityExample : MonoBehaviour
109
{
10+
public static string GetNatCorderVersion()
11+
{
12+
return "1.6.2";
13+
}
14+
1115
public Text exampleTitle;
1216
public Text versionInfo;
1317
public ScrollRect scrollRect;
14-
static float verticalNormalizedPosition = 1f;
18+
private static float verticalNormalizedPosition = 1f;
1519

16-
void Awake ()
20+
void Awake()
1721
{
1822
QualitySettings.vSyncCount = 0;
1923
Application.targetFrameRate = 60;
2024
}
2125

2226
// Use this for initialization
23-
IEnumerator Start ()
27+
IEnumerator Start()
2428
{
2529
exampleTitle.text = "NatCorderWithOpenCVForUnity Example " + Application.version;
2630

27-
versionInfo.text = OpenCVForUnity.CoreModule.Core.NATIVE_LIBRARY_NAME + " " + OpenCVForUnity.UnityUtils.Utils.getVersion () + " (" + OpenCVForUnity.CoreModule.Core.VERSION + ")";
31+
versionInfo.text = "NatCorder " + GetNatCorderVersion();
32+
versionInfo.text += " / " + OpenCVForUnity.CoreModule.Core.NATIVE_LIBRARY_NAME + " " + OpenCVForUnity.UnityUtils.Utils.getVersion() + " (" + OpenCVForUnity.CoreModule.Core.VERSION + ")";
2833
versionInfo.text += " / UnityEditor " + Application.unityVersion;
2934
versionInfo.text += " / ";
3035

@@ -68,30 +73,30 @@ IEnumerator Start ()
6873
}
6974

7075
// Update is called once per frame
71-
void Update ()
76+
void Update()
7277
{
7378

7479
}
7580

76-
public void OnScrollRectValueChanged ()
81+
public void OnScrollRectValueChanged()
7782
{
7883
verticalNormalizedPosition = scrollRect.verticalNormalizedPosition;
7984
}
8085

8186

82-
public void OnShowSystemInfoButtonClick ()
87+
public void OnShowSystemInfoButtonClick()
8388
{
84-
SceneManager.LoadScene ("ShowSystemInfo");
89+
SceneManager.LoadScene("ShowSystemInfo");
8590
}
8691

87-
public void OnShowLicenseButtonClick ()
92+
public void OnShowLicenseButtonClick()
8893
{
89-
SceneManager.LoadScene ("ShowLicense");
94+
SceneManager.LoadScene("ShowLicense");
9095
}
9196

92-
public void OnVideoRecordingExampleButtonClick ()
97+
public void OnVideoRecordingExampleButtonClick()
9398
{
94-
SceneManager.LoadScene ("VideoRecordingExample");
99+
SceneManager.LoadScene("VideoRecordingExample");
95100
}
96101
}
97102
}

Assets/NatCorderWithOpenCVForUnityExample/Scripts/Utils/FpsMonitor.cs

+74-55
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using UnityEngine;
2-
using System.Collections;
3-
using System.Collections.Generic;
1+
using System.Collections.Generic;
2+
using UnityEngine;
43

54
namespace NatCorderWithOpenCVForUnityExample
65
{
@@ -48,12 +47,13 @@ public enum Alignment
4847
int oldScrWidth;
4948
int oldScrHeight;
5049

51-
Dictionary<string, string> outputDict = new Dictionary<string, string> ();
50+
Dictionary<string, string> outputDict = new Dictionary<string, string>();
5251
public string consoleText;
5352

5453
// Use this for initialization
55-
void Start () {
56-
console_labelStyle = new GUIStyle ();
54+
void Start()
55+
{
56+
console_labelStyle = new GUIStyle();
5757
console_labelStyle.fontSize = 32;
5858
console_labelStyle.fontStyle = FontStyle.Normal;
5959
console_labelStyle.wordWrap = true;
@@ -65,104 +65,123 @@ void Start () {
6565
}
6666

6767
// Update is called once per frame
68-
void Update () {
68+
void Update()
69+
{
6970
tick++;
7071
elapsed += Time.deltaTime;
71-
if (elapsed >= 1f) {
72+
if (elapsed >= 1f)
73+
{
7274
fps = tick / elapsed;
7375
tick = 0;
7476
elapsed = 0;
7577
}
7678
}
7779

78-
void OnGUI () {
79-
if (oldScrWidth != Screen.width || oldScrHeight != Screen.height) {
80+
void OnGUI()
81+
{
82+
if (oldScrWidth != Screen.width || oldScrHeight != Screen.height)
83+
{
8084
LocateGUI();
8185
}
8286
oldScrWidth = Screen.width;
8387
oldScrHeight = Screen.height;
8488

85-
if (boxVisible) {
89+
if (boxVisible)
90+
{
8691
GUI.Box(outer, "");
8792
}
8893

8994
GUILayout.BeginArea(inner);
9095
{
9196
GUILayout.BeginVertical();
9297
GUILayout.Label("fps : " + fps.ToString("F1"));
93-
foreach (KeyValuePair<string, string> pair in outputDict) {
98+
foreach (KeyValuePair<string, string> pair in outputDict)
99+
{
94100
GUILayout.Label(pair.Key + " : " + pair.Value);
95101
}
96102
GUILayout.EndVertical();
97103
}
98-
GUILayout.EndArea ();
104+
GUILayout.EndArea();
99105

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, "");
103111
}
104112

105-
GUILayout.BeginArea (console_inner);
113+
GUILayout.BeginArea(console_inner);
106114
{
107-
GUILayout.BeginVertical ();
108-
GUILayout.Label (consoleText, console_labelStyle);
109-
GUILayout.EndVertical ();
115+
GUILayout.BeginVertical();
116+
GUILayout.Label(consoleText, console_labelStyle);
117+
GUILayout.EndVertical();
110118
}
111-
GUILayout.EndArea ();
119+
GUILayout.EndArea();
112120
}
113121
}
114122

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);
120132
}
121133
}
122134

123-
public void Remove (string key) {
124-
outputDict.Remove (key);
135+
public void Remove(string key)
136+
{
137+
outputDict.Remove(key);
125138
}
126139

127-
public void Clear () {
128-
outputDict.Clear ();
140+
public void Clear()
141+
{
142+
outputDict.Clear();
129143
}
130-
131-
public void LocateGUI() {
144+
145+
public void LocateGUI()
146+
{
132147
x = GetAlignedX(alignment, boxWidth);
133148
y = GetAlignedY(alignment, boxHeight);
134149
outer = new Rect(x, y, boxWidth, boxHeight);
135150
inner = new Rect(x + padding.x, y + padding.y, boxWidth, boxHeight);
136151

137152
console_x = GetAlignedX(Alignment.LeftBottom, Screen.width);
138153
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);
141156
}
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;
153170
}
154171
}
155172

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;
166185
}
167186
}
168187
}

Assets/NatCorderWithOpenCVForUnityExample/Scripts/Utils/RuntimePermissionHelper.cs

+12-9
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ public virtual IEnumerator hasUserAuthorizedCameraPermission()
1010
{
1111
#if UNITY_IOS && UNITY_2018_1_OR_NEWER
1212
UserAuthorization mode = UserAuthorization.WebCam;
13-
if (!Application.HasUserAuthorization (mode)) {
14-
yield return RequestUserAuthorization (mode);
15-
}
16-
yield return Application.HasUserAuthorization (mode);
13+
if (!Application.HasUserAuthorization(mode))
14+
{
15+
yield return RequestUserAuthorization(mode);
16+
}
17+
yield return Application.HasUserAuthorization(mode);
1718
#elif UNITY_ANDROID && UNITY_2018_3_OR_NEWER
1819
string permission = UnityEngine.Android.Permission.Camera;
1920
if (!UnityEngine.Android.Permission.HasUserAuthorizedPermission(permission))
@@ -30,10 +31,11 @@ public virtual IEnumerator hasUserAuthorizedMicrophonePermission()
3031
{
3132
#if UNITY_IOS && UNITY_2018_1_OR_NEWER
3233
UserAuthorization mode = UserAuthorization.Microphone;
33-
if (!Application.HasUserAuthorization (mode)) {
34-
yield return RequestUserAuthorization (mode);
35-
}
36-
yield return Application.HasUserAuthorization (mode);
34+
if (!Application.HasUserAuthorization(mode))
35+
{
36+
yield return RequestUserAuthorization(mode);
37+
}
38+
yield return Application.HasUserAuthorization(mode);
3739
#elif UNITY_ANDROID && UNITY_2018_3_OR_NEWER
3840
string permission = UnityEngine.Android.Permission.Microphone;
3941
if (!UnityEngine.Android.Permission.HasUserAuthorizedPermission(permission))
@@ -80,7 +82,8 @@ protected virtual IEnumerator RequestUserAuthorization(UserAuthorization mode)
8082
float timeElapsed = 0;
8183
while (isUserRequestingPermission)
8284
{
83-
if (timeElapsed > 0.25f){
85+
if (timeElapsed > 0.25f)
86+
{
8487
isUserRequestingPermission = false;
8588
yield break;
8689
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
using System.Collections;
2-
using UnityEngine;
1+
using UnityEngine;
32
using UnityEngine.SceneManagement;
43

54
namespace NatCorderWithOpenCVForUnityExample
65
{
76
public class ShowLicense : MonoBehaviour
87
{
98
// Use this for initialization
10-
void Start ()
9+
void Start()
1110
{
1211

1312
}
14-
13+
1514
// Update is called once per frame
16-
void Update ()
15+
void Update()
1716
{
1817

1918
}
2019

21-
public void OnBackButtonClick ()
20+
public void OnBackButtonClick()
2221
{
23-
SceneManager.LoadScene ("NatCorderWithOpenCVForUnityExample");
22+
SceneManager.LoadScene("NatCorderWithOpenCVForUnityExample");
2423
}
2524
}
2625
}

0 commit comments

Comments
 (0)