From 87399c5b439cd909a978c0ebb6f9c6b1eff49032 Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Mon, 28 Nov 2016 21:26:01 +0900 Subject: [PATCH 01/12] Fix orientation issue with unity 5.5 + Implement Aspect Ratio --- Assets/Samples/Continuous/ContinuousDemo.cs | 8 +++++++ Assets/Samples/Simple/SimpleDemo.cs | 5 +++++ .../Scripts/External/WizUtils/Logger/Log.cs | 2 -- Assets/Scripts/Interfaces/IWebcam.cs | 1 + Assets/Scripts/Scanner/Scanner.cs | 22 +++++++++++++++++++ Assets/Scripts/Webcam/UnityWebcam.cs | 9 ++++++-- 6 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Assets/Samples/Continuous/ContinuousDemo.cs b/Assets/Samples/Continuous/ContinuousDemo.cs index 1284e5f..b98356a 100644 --- a/Assets/Samples/Continuous/ContinuousDemo.cs +++ b/Assets/Samples/Continuous/ContinuousDemo.cs @@ -5,6 +5,7 @@ using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; +using Wizcorp.Utils.Logger; public class ContinuousDemo : MonoBehaviour { @@ -24,6 +25,13 @@ void Start () { Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation()); Image.texture = BarcodeScanner.Camera.Texture; RestartTime = Time.realtimeSinceStartup; + + // Keep Image Aspect Ratio + var rect = Image.GetComponent(); + var newHeight = rect.sizeDelta.x * BarcodeScanner.Camera.Height / BarcodeScanner.Camera.Width; + Log.Info("before", rect.sizeDelta); + rect.sizeDelta = new Vector2(rect.sizeDelta.x, newHeight); + Log.Info("after", rect.sizeDelta); }; } diff --git a/Assets/Samples/Simple/SimpleDemo.cs b/Assets/Samples/Simple/SimpleDemo.cs index caf8229..d64a7f7 100644 --- a/Assets/Samples/Simple/SimpleDemo.cs +++ b/Assets/Samples/Simple/SimpleDemo.cs @@ -23,6 +23,11 @@ void Start () { BarcodeScanner.OnReady += (sender, arg) => { Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation()); Image.texture = BarcodeScanner.Camera.Texture; + + // Keep Image Aspect Ratio + var rect = Image.GetComponent(); + var newHeight = rect.sizeDelta.x * BarcodeScanner.Camera.Height / BarcodeScanner.Camera.Width; + rect.sizeDelta = new Vector2(rect.sizeDelta.x, newHeight); }; // Track status of the scanner diff --git a/Assets/Scripts/External/WizUtils/Logger/Log.cs b/Assets/Scripts/External/WizUtils/Logger/Log.cs index 56b85f9..e137f9a 100644 --- a/Assets/Scripts/External/WizUtils/Logger/Log.cs +++ b/Assets/Scripts/External/WizUtils/Logger/Log.cs @@ -15,10 +15,8 @@ private Log() { services = new List(); - #if UNITY_EDITOR // Console log activate by default in Unity Editor services.Add(new ConsoleService()); - #endif } #region Services diff --git a/Assets/Scripts/Interfaces/IWebcam.cs b/Assets/Scripts/Interfaces/IWebcam.cs index 4686aa4..bcb7890 100644 --- a/Assets/Scripts/Interfaces/IWebcam.cs +++ b/Assets/Scripts/Interfaces/IWebcam.cs @@ -20,5 +20,6 @@ public interface IWebcam // Color32[] GetPixels(); float GetRotation(); + int GetCRC(); } } \ No newline at end of file diff --git a/Assets/Scripts/Scanner/Scanner.cs b/Assets/Scripts/Scanner/Scanner.cs index cd51955..2c47429 100644 --- a/Assets/Scripts/Scanner/Scanner.cs +++ b/Assets/Scripts/Scanner/Scanner.cs @@ -51,6 +51,11 @@ private set private Action Callback; private ParserResult Result; + // + private int delayFrameWebcamMin = 3; + private int delayFrameWebcam = 0; + private int lastCRC = -1; + public Scanner(IParser parser = null, IWebcam webcam = null) { // Check Device Authorization @@ -239,12 +244,29 @@ public void Update() return; } + // Be sure that the camera metadata is stable (thanks Unity) + if (lastCRC != Camera.GetCRC()) + { + lastCRC = Camera.GetCRC(); + delayFrameWebcam = 0; + Log.Info(string.Format("Camera [Resolution:{0}x{1}, Orientation:{2}, IsPlaying:{3}]", Camera.Texture.width, Camera.Texture.height, Camera.GetRotation(), Camera.IsPlaying())); + return; + } + // If the app start for the first time (select size & onReady Event) if (Status == ScannerStatus.Initialize) { + if (delayFrameWebcam < delayFrameWebcamMin) + { + delayFrameWebcam++; + return; + } + Status = ScannerStatus.Paused; Camera.SetSize(); + delayFrameWebcam = 0; + if (OnReady != null) { OnReady.Invoke(this, EventArgs.Empty); diff --git a/Assets/Scripts/Webcam/UnityWebcam.cs b/Assets/Scripts/Webcam/UnityWebcam.cs index 8829f79..7b9317e 100644 --- a/Assets/Scripts/Webcam/UnityWebcam.cs +++ b/Assets/Scripts/Webcam/UnityWebcam.cs @@ -49,12 +49,12 @@ public void SetSize() { Width = Mathf.RoundToInt(Webcam.width); Height = Mathf.RoundToInt(Webcam.height); - Log.Info(string.Format("Camera {2} | Resolution {0}x{1}", Width, Height, Webcam.deviceName)); + Log.Info(string.Format("Camera: {2} | Resolution: {0}x{1} | Orientation: {3}", Width, Height, Webcam.deviceName, Webcam.videoRotationAngle + ":" +Webcam.videoVerticallyMirrored)); } public bool IsReady() { - return Webcam != null && Webcam.width >= 100; + return Webcam != null && Webcam.width >= 100 && Webcam.videoRotationAngle % 90 == 0; } public bool IsPlaying() @@ -94,5 +94,10 @@ public float GetRotation() } return rotation; } + + public int GetCRC() + { + return (Webcam.width + Webcam.height + Webcam.deviceName + Webcam.videoRotationAngle).GetHashCode(); + } } } From 0155b22d5c03c0b07b96f59fd98c075486258b3e Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Mon, 28 Nov 2016 22:30:00 +0900 Subject: [PATCH 02/12] Fix Auto-Orientation + Set the App to Portrait Only --- Assets/Samples/Continuous/ContinuousDemo.cs | 4 +- Assets/Samples/Simple/SimpleDemo.cs | 1 + .../Scripts/External/WizUtils/Logger/Log.cs | 2 + Assets/Scripts/Scanner/Scanner.cs | 53 ++-- ProjectSettings/ProjectSettings.asset | 299 ++++++++++-------- 5 files changed, 196 insertions(+), 163 deletions(-) diff --git a/Assets/Samples/Continuous/ContinuousDemo.cs b/Assets/Samples/Continuous/ContinuousDemo.cs index b98356a..3ae2cf4 100644 --- a/Assets/Samples/Continuous/ContinuousDemo.cs +++ b/Assets/Samples/Continuous/ContinuousDemo.cs @@ -5,7 +5,6 @@ using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; -using Wizcorp.Utils.Logger; public class ContinuousDemo : MonoBehaviour { @@ -22,6 +21,7 @@ void Start () { // Display the camera texture through a RawImage BarcodeScanner.OnReady += (sender, arg) => { + // Set Orientation & Texture Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation()); Image.texture = BarcodeScanner.Camera.Texture; RestartTime = Time.realtimeSinceStartup; @@ -29,9 +29,7 @@ void Start () { // Keep Image Aspect Ratio var rect = Image.GetComponent(); var newHeight = rect.sizeDelta.x * BarcodeScanner.Camera.Height / BarcodeScanner.Camera.Width; - Log.Info("before", rect.sizeDelta); rect.sizeDelta = new Vector2(rect.sizeDelta.x, newHeight); - Log.Info("after", rect.sizeDelta); }; } diff --git a/Assets/Samples/Simple/SimpleDemo.cs b/Assets/Samples/Simple/SimpleDemo.cs index d64a7f7..a29626a 100644 --- a/Assets/Samples/Simple/SimpleDemo.cs +++ b/Assets/Samples/Simple/SimpleDemo.cs @@ -21,6 +21,7 @@ void Start () { // Display the camera texture through a RawImage BarcodeScanner.OnReady += (sender, arg) => { + // Set Orientation & Texture Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation()); Image.texture = BarcodeScanner.Camera.Texture; diff --git a/Assets/Scripts/External/WizUtils/Logger/Log.cs b/Assets/Scripts/External/WizUtils/Logger/Log.cs index e137f9a..56b85f9 100644 --- a/Assets/Scripts/External/WizUtils/Logger/Log.cs +++ b/Assets/Scripts/External/WizUtils/Logger/Log.cs @@ -15,8 +15,10 @@ private Log() { services = new List(); + #if UNITY_EDITOR // Console log activate by default in Unity Editor services.Add(new ConsoleService()); + #endif } #region Services diff --git a/Assets/Scripts/Scanner/Scanner.cs b/Assets/Scripts/Scanner/Scanner.cs index 2c47429..5516404 100644 --- a/Assets/Scripts/Scanner/Scanner.cs +++ b/Assets/Scripts/Scanner/Scanner.cs @@ -225,6 +225,32 @@ public void ThreadDecodeQR() #endregion + /// + /// Be sure that the camera metadata is stable (thanks Unity) and wait until then (increment delayFrameWebcam) + /// + /// + private bool WebcamInitialized() + { + // If webcam information still change, reset delayFrame + if (lastCRC != Camera.GetCRC()) + { + lastCRC = Camera.GetCRC(); + delayFrameWebcam = 0; + return false; + } + + // Increment delayFrame + if (delayFrameWebcam < delayFrameWebcamMin) + { + delayFrameWebcam++; + return false; + } + + Camera.SetSize(); + delayFrameWebcam = 0; + return true; + } + /// /// This Update Loop is used to : /// * Wait the Camera is really ready @@ -244,32 +270,17 @@ public void Update() return; } - // Be sure that the camera metadata is stable (thanks Unity) - if (lastCRC != Camera.GetCRC()) - { - lastCRC = Camera.GetCRC(); - delayFrameWebcam = 0; - Log.Info(string.Format("Camera [Resolution:{0}x{1}, Orientation:{2}, IsPlaying:{3}]", Camera.Texture.width, Camera.Texture.height, Camera.GetRotation(), Camera.IsPlaying())); - return; - } - // If the app start for the first time (select size & onReady Event) if (Status == ScannerStatus.Initialize) { - if (delayFrameWebcam < delayFrameWebcamMin) + if (WebcamInitialized()) { - delayFrameWebcam++; - return; - } - - Status = ScannerStatus.Paused; + Status = ScannerStatus.Paused; - Camera.SetSize(); - delayFrameWebcam = 0; - - if (OnReady != null) - { - OnReady.Invoke(this, EventArgs.Empty); + if (OnReady != null) + { + OnReady.Invoke(this, EventArgs.Empty); + } } } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 5440ec4..406a488 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -3,7 +3,8 @@ --- !u!129 &1 PlayerSettings: m_ObjectHideFlags: 0 - serializedVersion: 8 + serializedVersion: 10 + productGUID: eacfb9c2e7fe8b042ade6c49d68a3908 AndroidProfiler: 0 defaultScreenOrientation: 4 targetDevice: 2 @@ -13,26 +14,52 @@ PlayerSettings: productName: Barcode Scanner defaultCursor: {fileID: 0} cursorHotspot: {x: 0, y: 0} + m_SplashScreenBackgroundColor: {r: 0.13333334, g: 0.17254902, b: 0.21176471, a: 1} m_ShowUnitySplashScreen: 1 + m_ShowUnitySplashLogo: 1 + m_SplashScreenOverlayOpacity: 1 + m_SplashScreenAnimation: 1 + m_SplashScreenLogoStyle: 1 + m_SplashScreenDrawMode: 0 + m_SplashScreenBackgroundAnimationZoom: 1 + m_SplashScreenLogoAnimationZoom: 1 + m_SplashScreenBackgroundLandscapeAspect: 1 + m_SplashScreenBackgroundPortraitAspect: 1 + m_SplashScreenBackgroundLandscapeUvs: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + m_SplashScreenBackgroundPortraitUvs: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + m_SplashScreenLogos: [] + m_SplashScreenBackgroundLandscape: {fileID: 0} + m_SplashScreenBackgroundPortrait: {fileID: 0} m_VirtualRealitySplashScreen: {fileID: 0} + m_HolographicTrackingLossScreen: {fileID: 0} defaultScreenWidth: 1024 defaultScreenHeight: 768 defaultScreenWidthWeb: 960 defaultScreenHeightWeb: 600 - m_RenderingPath: 1 - m_MobileRenderingPath: 1 + m_StereoRenderingPath: 0 m_ActiveColorSpace: 0 m_MTRendering: 1 m_MobileMTRendering: 0 - m_Stereoscopic3D: 0 + m_StackTraceTypes: 010000000100000001000000010000000100000001000000 iosShowActivityIndicatorOnLoading: -1 androidShowActivityIndicatorOnLoading: -1 + tizenShowActivityIndicatorOnLoading: -1 iosAppInBackgroundBehavior: 0 displayResolutionDialog: 1 iosAllowHTTPDownload: 1 allowedAutorotateToPortrait: 1 allowedAutorotateToPortraitUpsideDown: 0 - allowedAutorotateToLandscapeRight: 1 + allowedAutorotateToLandscapeRight: 0 allowedAutorotateToLandscapeLeft: 0 useOSAutorotation: 1 use32BitDisplayBuffer: 1 @@ -41,7 +68,7 @@ PlayerSettings: defaultIsNativeResolution: 1 runInBackground: 0 captureSingleScreen: 0 - Override IPod Music: 0 + muteOtherAudioSources: 0 Prepare IOS For Recording: 0 submitAnalytics: 1 usePlayerLog: 1 @@ -50,6 +77,7 @@ PlayerSettings: resizableWindow: 0 useMacAppStoreValidation: 0 gpuSkinning: 0 + graphicsJobs: 0 xboxPIXTextureCapture: 0 xboxEnableAvatar: 0 xboxEnableKinect: 0 @@ -70,7 +98,8 @@ PlayerSettings: uiUse16BitDepthBuffer: 0 ignoreAlphaClear: 0 xboxOneResolution: 0 - ps3SplashScreen: {fileID: 0} + xboxOneMonoLoggingLevel: 0 + xboxOneLoggingLevel: 1 videoMemoryForVertexBuffers: 0 psp2PowerMode: 0 psp2AcquireBGM: 1 @@ -92,11 +121,10 @@ PlayerSettings: bundleIdentifier: com.ganbaranai.BarcodeScanner bundleVersion: 1.0 preloadedAssets: [] - metroEnableIndependentInputSource: 0 - metroEnableLowLatencyPresentationAPI: 0 + metroInputSource: 0 + m_HolographicPauseOnTrackingLoss: 1 xboxOneDisableKinectGpuReservation: 0 - virtualRealitySupported: 0 - productGUID: eacfb9c2e7fe8b042ade6c49d68a3908 + protectGraphicsMemory: 0 AndroidBundleVersionCode: 1 AndroidMinSdkVersion: 21 AndroidPreferredInstallLocation: 1 @@ -116,9 +144,10 @@ PlayerSettings: serializedVersion: 2 m_Bits: 238 iPhoneSdkVersion: 988 - iPhoneTargetOSVersion: 24 + iOSTargetOSVersionString: 7.0 tvOSSdkVersion: 0 - tvOSTargetOSVersion: 900 + tvOSRequireExtendedGameController: 0 + tvOSTargetOSVersionString: 9.0 uIPrerenderedIcon: 0 uIRequiresPersistentWiFi: 0 uIRequiresFullScreen: 1 @@ -139,6 +168,7 @@ PlayerSettings: tvOSSmallIconLayers: [] tvOSLargeIconLayers: [] tvOSTopShelfImageLayers: [] + tvOSTopShelfImageWideLayers: [] iOSLaunchScreenType: 0 iOSLaunchScreenPortrait: {fileID: 0} iOSLaunchScreenLandscape: {fileID: 0} @@ -157,6 +187,10 @@ PlayerSettings: iOSLaunchScreeniPadSize: 100 iOSLaunchScreeniPadCustomXibPath: iOSDeviceRequirements: [] + iOSURLSchemes: [] + iOSBackgroundModes: 0 + iOSMetalForceHardShadows: 0 + appleDeveloperTeamID: AndroidTargetDevice: 0 AndroidSplashScreenScale: 0 androidSplashScreen: {fileID: 0} @@ -180,6 +214,64 @@ PlayerSettings: m_Height: 128 m_BuildTargetBatching: [] m_BuildTargetGraphicsAPIs: [] + m_BuildTargetVRSettings: + - m_BuildTarget: Android + m_Enabled: 0 + m_Devices: + - Oculus + - m_BuildTarget: Metro + m_Enabled: 0 + m_Devices: + - HoloLens + - m_BuildTarget: N3DS + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: PS3 + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: PS4 + m_Enabled: 0 + m_Devices: + - PlayStationVR + - m_BuildTarget: PSM + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: PSP2 + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: SamsungTV + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: Standalone + m_Enabled: 0 + m_Devices: + - Oculus + - m_BuildTarget: Tizen + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: WebGL + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: WebPlayer + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: WiiU + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: Xbox360 + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: XboxOne + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: iOS + m_Enabled: 0 + m_Devices: [] + - m_BuildTarget: tvOS + m_Enabled: 0 + m_Devices: [] + openGLRequireES31: 0 + openGLRequireES31AEP: 0 webPlayerTemplate: APPLICATION:Default m_TemplateCustomTags: {} wiiUTitleID: 0005000011000000 @@ -204,7 +296,9 @@ PlayerSettings: enableInternalProfiler: 0 logObjCUncaughtExceptions: 1 enableCrashReportAPI: 0 + cameraUsageDescription: locationUsageDescription: + microphoneUsageDescription: XboxTitleId: XboxImageXexPath: XboxSpaPath: @@ -215,24 +309,6 @@ PlayerSettings: xboxAdditionalTitleMemorySize: 0 xboxDeployKinectHeadOrientation: 0 xboxDeployKinectHeadPosition: 0 - ps3TitleConfigPath: - ps3DLCConfigPath: - ps3ThumbnailPath: - ps3BackgroundPath: - ps3SoundPath: - ps3NPAgeRating: 12 - ps3TrophyCommId: - ps3NpCommunicationPassphrase: - ps3TrophyPackagePath: - ps3BootCheckMaxSaveGameSizeKB: 128 - ps3TrophyCommSig: - ps3SaveGameSlots: 1 - ps3TrialMode: 0 - ps3VideoMemoryForAudio: 0 - ps3EnableVerboseMemoryStats: 0 - ps3UseSPUForUmbra: 0 - ps3EnableMoveSupport: 1 - ps3DisableDolbyEncoding: 0 ps4NPAgeRating: 12 ps4NPTitleSecret: ps4NPTrophyPackPath: @@ -244,7 +320,8 @@ PlayerSettings: ps4AppType: 0 ps4ParamSfxPath: ps4VideoOutPixelFormat: 0 - ps4VideoOutResolution: 4 + ps4VideoOutInitialWidth: 1920 + ps4VideoOutReprojectionRate: 120 ps4PronunciationXMLPath: ps4PronunciationSIGPath: ps4BackgroundImagePath: @@ -258,6 +335,7 @@ PlayerSettings: ps4NPtitleDatPath: ps4RemotePlayKeyAssignment: -1 ps4RemotePlayKeyMappingDir: + ps4PlayTogetherPlayerCount: 0 ps4EnterButtonAssignment: 1 ps4ApplicationParam1: 0 ps4ApplicationParam2: 0 @@ -272,18 +350,24 @@ PlayerSettings: ps4pnFriends: 1 ps4pnGameCustomData: 1 playerPrefsSupport: 0 + restrictedAudioUsageRights: 0 + ps4UseResolutionFallback: 0 ps4ReprojectionSupport: 0 ps4UseAudio3dBackend: 0 ps4SocialScreenEnabled: 0 + ps4ScriptOptimizationLevel: 3 ps4Audio3dVirtualSpeakerCount: 14 ps4attribCpuUsage: 0 ps4PatchPkgPath: ps4PatchLatestPkgPath: ps4PatchChangeinfoPath: + ps4PatchDayOne: 0 ps4attribUserManagement: 0 ps4attribMoveSupport: 0 ps4attrib3DSupport: 0 ps4attribShareSupport: 0 + ps4attribExclusiveVR: 0 + ps4disableAutoHideSplash: 0 ps4IncludedModules: [] monoEnv: psp2Splashimage: {fileID: 0} @@ -334,9 +418,35 @@ PlayerSettings: psp2InfoBarColor: 0 psp2UseDebugIl2cppLibs: 0 psmSplashimage: {fileID: 0} + splashScreenBackgroundSourceLandscape: {fileID: 0} + splashScreenBackgroundSourcePortrait: {fileID: 0} spritePackerPolicy: + webGLMemorySize: 256 + webGLExceptionSupport: 1 + webGLDataCaching: 0 + webGLDebugSymbols: 0 + webGLEmscriptenArgs: + webGLModulesDirectory: + webGLTemplate: APPLICATION:Default + webGLAnalyzeBuildSize: 0 + webGLUseEmbeddedResources: 0 + webGLUseWasm: 0 + webGLCompressionFormat: 1 scriptingDefineSymbols: 13: + platformArchitecture: + iOS: 2 + scriptingBackend: + Android: 0 + Standalone: 0 + WebGL: 1 + WebPlayer: 0 + iOS: 1 + incrementalIl2cppBuild: + iOS: 1 + additionalIl2CppArgs: + m_RenderingPath: 1 + m_MobileRenderingPath: 1 metroPackageName: TestUnity metroPackageVersion: metroCertificatePath: @@ -363,29 +473,14 @@ PlayerSettings: metroFTAFileTypes: [] metroProtocolName: metroCompilationOverrides: 1 - blackberryDeviceAddress: - blackberryDevicePassword: - blackberryTokenPath: - blackberryTokenExires: - blackberryTokenAuthor: - blackberryTokenAuthorId: - blackberryCskPassword: - blackberrySaveLogPath: - blackberrySharedPermissions: 0 - blackberryCameraPermissions: 0 - blackberryGPSPermissions: 0 - blackberryDeviceIDPermissions: 0 - blackberryMicrophonePermissions: 0 - blackberryGamepadSupport: 0 - blackberryBuildId: 0 - blackberryLandscapeSplashScreen: {fileID: 0} - blackberryPortraitSplashScreen: {fileID: 0} - blackberrySquareSplashScreen: {fileID: 0} tizenProductDescription: tizenProductURL: tizenSigningProfileName: tizenGPSPermissions: 0 tizenMicrophonePermissions: 0 + tizenDeploymentTarget: + tizenDeploymentTargetType: 0 + tizenMinOSVersion: 0 n3dsUseExtSaveData: 0 n3dsCompressStaticMem: 1 n3dsExtSaveDataNumber: 0x12345 @@ -415,101 +510,27 @@ PlayerSettings: XboxOnePackageEncryption: 0 XboxOnePackageUpdateGranularity: 2 XboxOneDescription: + XboxOneLanguage: + - enus + XboxOneCapability: [] + XboxOneGameRating: {} XboxOneIsContentPackage: 0 XboxOneEnableGPUVariability: 0 XboxOneSockets: {} XboxOneSplashScreen: {fileID: 0} XboxOneAllowedProductIds: [] XboxOnePersistentLocalStorageSize: 0 - intPropertyNames: - - Android::ScriptingBackend - - Standalone::ScriptingBackend - - WebGL::ScriptingBackend - - WebGL::audioCompressionFormat - - WebGL::exceptionSupport - - WebGL::memorySize - - WebPlayer::ScriptingBackend - - iOS::Architecture - - iOS::EnableIncrementalBuildSupportForIl2cpp - - iOS::ScriptingBackend - Android::ScriptingBackend: 0 - Standalone::ScriptingBackend: 0 - WebGL::ScriptingBackend: 1 - WebGL::audioCompressionFormat: 4 - WebGL::exceptionSupport: 1 - WebGL::memorySize: 256 - WebPlayer::ScriptingBackend: 0 - iOS::Architecture: 2 - iOS::EnableIncrementalBuildSupportForIl2cpp: 1 - iOS::ScriptingBackend: 1 - boolPropertyNames: - - Android::VR::enable - - Metro::VR::enable - - N3DS::VR::enable - - PS3::VR::enable - - PS4::VR::enable - - PSM::VR::enable - - PSP2::VR::enable - - SamsungTV::VR::enable - - Standalone::VR::enable - - Tizen::VR::enable - - WebGL::VR::enable - - WebGL::analyzeBuildSize - - WebGL::dataCaching - - WebGL::useEmbeddedResources - - WebPlayer::VR::enable - - WiiU::VR::enable - - Xbox360::VR::enable - - XboxOne::VR::enable - - XboxOne::enus - - iOS::VR::enable - - tvOS::VR::enable - Android::VR::enable: 0 - Metro::VR::enable: 0 - N3DS::VR::enable: 0 - PS3::VR::enable: 0 - PS4::VR::enable: 0 - PSM::VR::enable: 0 - PSP2::VR::enable: 0 - SamsungTV::VR::enable: 0 - Standalone::VR::enable: 0 - Tizen::VR::enable: 0 - WebGL::VR::enable: 0 - WebGL::analyzeBuildSize: 0 - WebGL::dataCaching: 0 - WebGL::useEmbeddedResources: 0 - WebPlayer::VR::enable: 0 - WiiU::VR::enable: 0 - Xbox360::VR::enable: 0 - XboxOne::VR::enable: 0 - XboxOne::enus: 1 - iOS::VR::enable: 0 - tvOS::VR::enable: 0 - stringPropertyNames: - - Analytics_ServiceEnabled::Analytics_ServiceEnabled - - Build_ServiceEnabled::Build_ServiceEnabled - - Collab_ServiceEnabled::Collab_ServiceEnabled - - ErrorHub_ServiceEnabled::ErrorHub_ServiceEnabled - - Game_Performance_ServiceEnabled::Game_Performance_ServiceEnabled - - Hub_ServiceEnabled::Hub_ServiceEnabled - - Purchasing_ServiceEnabled::Purchasing_ServiceEnabled - - UNet_ServiceEnabled::UNet_ServiceEnabled - - Unity_Ads_ServiceEnabled::Unity_Ads_ServiceEnabled - - WebGL::emscriptenArgs - - WebGL::template - - additionalIl2CppArgs::additionalIl2CppArgs - Analytics_ServiceEnabled::Analytics_ServiceEnabled: False - Build_ServiceEnabled::Build_ServiceEnabled: False - Collab_ServiceEnabled::Collab_ServiceEnabled: False - ErrorHub_ServiceEnabled::ErrorHub_ServiceEnabled: False - Game_Performance_ServiceEnabled::Game_Performance_ServiceEnabled: False - Hub_ServiceEnabled::Hub_ServiceEnabled: False - Purchasing_ServiceEnabled::Purchasing_ServiceEnabled: False - UNet_ServiceEnabled::UNet_ServiceEnabled: True - Unity_Ads_ServiceEnabled::Unity_Ads_ServiceEnabled: False - WebGL::emscriptenArgs: - WebGL::template: APPLICATION:Default - additionalIl2CppArgs::additionalIl2CppArgs: + vrEditorSettings: {} + cloudServicesEnabled: + Analytics: 0 + Build: 0 + Collab: 0 + ErrorHub: 0 + Game_Performance: 0 + Hub: 0 + Purchasing: 0 + UNet: 1 + Unity_Ads: 0 cloudProjectId: 8f47c944-78a0-48f6-9144-5e984956ebbd projectName: TestUnity organizationId: kevin-destrem From 8e129ee1322fc4162b3d7129da57991bb8f5f99f Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Tue, 29 Nov 2016 14:29:44 +0900 Subject: [PATCH 03/12] Add ScannerSettings object + Reformat ToString and logs --- Assets/Editor/ParserTest.cs | 3 +- Assets/Editor/ScannerTest.cs | 30 ++ Assets/Editor/ScannerTest.cs.meta | 12 + Assets/Scripts/Interfaces/IScanner.cs | 1 + Assets/Scripts/Interfaces/IWebcam.cs | 2 +- Assets/Scripts/Parser/ZXingParser.cs | 15 +- Assets/Scripts/Scanner/Scanner.cs | 73 +++-- Assets/Scripts/Settings.meta | 9 + Assets/Scripts/Settings/ScannerSettings.cs | 54 ++++ .../Scripts/Settings/ScannerSettings.cs.meta | 12 + Assets/Scripts/Webcam/UnityWebcam.cs | 50 ++- ProjectSettings/ProjectSettings.asset | 299 ++++++++---------- 12 files changed, 325 insertions(+), 235 deletions(-) create mode 100644 Assets/Editor/ScannerTest.cs create mode 100644 Assets/Editor/ScannerTest.cs.meta create mode 100644 Assets/Scripts/Settings.meta create mode 100644 Assets/Scripts/Settings/ScannerSettings.cs create mode 100644 Assets/Scripts/Settings/ScannerSettings.cs.meta diff --git a/Assets/Editor/ParserTest.cs b/Assets/Editor/ParserTest.cs index c04d5dc..0a53bbd 100644 --- a/Assets/Editor/ParserTest.cs +++ b/Assets/Editor/ParserTest.cs @@ -55,8 +55,7 @@ public void TestCodes(string file, string check) #region Test Samples static object[] ImageSamples = { - new object[] {"sample_giant_qr", "september" }, - new object[] {"sample_screen_blurry_qr", "http" } + new object[] {"sample_giant_qr", "september" } }; [Test, TestCaseSource("ImageSamples")] diff --git a/Assets/Editor/ScannerTest.cs b/Assets/Editor/ScannerTest.cs new file mode 100644 index 0000000..704fa33 --- /dev/null +++ b/Assets/Editor/ScannerTest.cs @@ -0,0 +1,30 @@ +using BarcodeScanner; +using BarcodeScanner.Scanner; +using NUnit.Framework; +using UnityEngine; + +[TestFixture] +public class ScannerTest +{ + [Test] + public void TestSettings() + { + var settings = new ScannerSettings() + { + ScannerBackgroundThread = false, + ScannerDelayFrameMin = 2, + + ParserAutoRotate = false, + ParserTryInverted = false, + ParserTryHarder = true, + + WebcamDefaultDeviceName = "Webcam Name", + WebcamRequestedWidth = 256, + WebcamRequestedHeight = 512, + WebcamFilterMode = FilterMode.Bilinear + }; + + var scanner = new Scanner(settings); + Assert.AreSame(scanner.Settings, settings); + } +} diff --git a/Assets/Editor/ScannerTest.cs.meta b/Assets/Editor/ScannerTest.cs.meta new file mode 100644 index 0000000..a54e7a5 --- /dev/null +++ b/Assets/Editor/ScannerTest.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 835f16eecbed5de4faf27345c1e51b18 +timeCreated: 1480396393 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Interfaces/IScanner.cs b/Assets/Scripts/Interfaces/IScanner.cs index 96103b5..bd5c00e 100644 --- a/Assets/Scripts/Interfaces/IScanner.cs +++ b/Assets/Scripts/Interfaces/IScanner.cs @@ -12,6 +12,7 @@ public interface IScanner IParser Parser { get; } IWebcam Camera { get; } + ScannerSettings Settings { get; } void Scan(Action Callback); void Stop(); diff --git a/Assets/Scripts/Interfaces/IWebcam.cs b/Assets/Scripts/Interfaces/IWebcam.cs index bcb7890..9a43d7f 100644 --- a/Assets/Scripts/Interfaces/IWebcam.cs +++ b/Assets/Scripts/Interfaces/IWebcam.cs @@ -20,6 +20,6 @@ public interface IWebcam // Color32[] GetPixels(); float GetRotation(); - int GetCRC(); + int GetChecksum(); } } \ No newline at end of file diff --git a/Assets/Scripts/Parser/ZXingParser.cs b/Assets/Scripts/Parser/ZXingParser.cs index 0aac172..69b1664 100644 --- a/Assets/Scripts/Parser/ZXingParser.cs +++ b/Assets/Scripts/Parser/ZXingParser.cs @@ -9,15 +9,16 @@ public class ZXingParser : IParser { public BarcodeReader Scanner { get; private set; } - public ZXingParser() + public ZXingParser() : this(new ScannerSettings()) { - Scanner = new BarcodeReader(); - Scanner.AutoRotate = true; - Scanner.TryInverted = true; + } - #if UNITY_STANDALONE || UNITY_EDITOR - Scanner.Options.TryHarder = true; - #endif + public ZXingParser(ScannerSettings settings) + { + Scanner = new BarcodeReader(); + Scanner.AutoRotate = settings.ParserAutoRotate; + Scanner.TryInverted = settings.ParserTryInverted; + Scanner.Options.TryHarder = settings.ParserTryHarder; } /// diff --git a/Assets/Scripts/Scanner/Scanner.cs b/Assets/Scripts/Scanner/Scanner.cs index 5516404..d3e5f93 100644 --- a/Assets/Scripts/Scanner/Scanner.cs +++ b/Assets/Scripts/Scanner/Scanner.cs @@ -24,14 +24,12 @@ public class Scanner : IScanner // public IWebcam Camera { get; private set; } public IParser Parser { get; private set; } + public ScannerSettings Settings { get; private set; } // private ScannerStatus status; public ScannerStatus Status { - get - { - return status; - } + get { return status; } private set { status = value; @@ -42,21 +40,22 @@ private set } } - // Allow to switch between decoding method (some platform don't support background thread) - private bool useBackgroundThread = true; - private float mainThreadLastDecode = 0; - // Store information about last image / results (use the update loop to access camera and callback) private Color32[] pixels = new Color32[0]; private Action Callback; private ParserResult Result; // - private int delayFrameWebcamMin = 3; - private int delayFrameWebcam = 0; - private int lastCRC = -1; + private float mainThreadLastDecode = 0; + private int webcamFrameDelayed = 0; + private int webcamLastChecksum = -1; + - public Scanner(IParser parser = null, IWebcam webcam = null) + public Scanner() : this(null, null, null) { } + public Scanner(ScannerSettings settings) : this (settings, null, null) {} + public Scanner(IParser parser, IWebcam webcam) : this(null, parser, webcam) {} + + public Scanner(ScannerSettings settings, IParser parser, IWebcam webcam) { // Check Device Authorization if (!Application.HasUserAuthorization(UserAuthorization.WebCam)) @@ -65,12 +64,11 @@ public Scanner(IParser parser = null, IWebcam webcam = null) } Status = ScannerStatus.Initialize; - Parser = (parser == null) ? new ZXingParser() : parser; - Camera = (webcam == null) ? new UnityWebcam() : webcam; - #if UNITY_WEBGL - useBackgroundThread = false; - #endif + // Default Properties + Settings = (settings == null) ? new ScannerSettings() : settings; + Parser = (parser == null) ? new ZXingParser(Settings) : parser; + Camera = (webcam == null) ? new UnityWebcam(Settings): webcam; } /// @@ -81,16 +79,16 @@ public void Scan(Action callback) { if (Callback != null) { - Log.Warning("Already Scan"); + Log.Warning(this + " Already Scan"); return; } Callback = callback; - Log.Info("SimpleScanner -> Start Scan"); + Log.Info(this + " SimpleScanner -> Start Scan"); Status = ScannerStatus.Running; #if !UNITY_WEBGL - if (useBackgroundThread) + if (Settings.ScannerBackgroundThread) { CodeScannerThread = new Thread(ThreadDecodeQR); CodeScannerThread.Start(); @@ -113,12 +111,12 @@ private void Stop(bool forced) { if (!forced && Callback == null) { - Log.Warning("No Scan running"); + Log.Warning(this + " No Scan running"); return; } // Stop thread / Clean callback - Log.Info("SimpleScanner -> Stop Scan"); + Log.Info(this + " SimpleScanner -> Stop Scan"); #if !UNITY_WEBGL if (CodeScannerThread != null) { @@ -167,7 +165,7 @@ public void DecodeQR() } // Process - Log.Debug("SimpleScanner -> Scan ... " + Camera.Width + " / " + Camera.Height); + Log.Debug(this + " SimpleScanner -> Scan ... " + Camera.Width + " / " + Camera.Height); try { Result = Parser.Decode(pixels, Camera.Width, Camera.Height); @@ -201,19 +199,19 @@ public void ThreadDecodeQR() // Wait if (Status != ScannerStatus.Running || pixels.Length == 00 || Camera.Width == 0) { - Thread.Sleep(100); + Thread.Sleep(Mathf.FloorToInt(Settings.ScannerDecodeInterval * 1000)); continue; } // Process - Log.Debug("SimpleScanner -> Scan ... " + Camera.Width + " / " + Camera.Height); + Log.Debug(this + " SimpleScanner -> Scan ... " + Camera.Width + " / " + Camera.Height); try { Result = Parser.Decode(pixels, Camera.Width, Camera.Height); pixels = null; // Sleep a little bit and set the signal to get the next frame - Thread.Sleep(100); + Thread.Sleep(Mathf.FloorToInt(Settings.ScannerDecodeInterval * 1000)); } catch (Exception e) { @@ -232,22 +230,22 @@ public void ThreadDecodeQR() private bool WebcamInitialized() { // If webcam information still change, reset delayFrame - if (lastCRC != Camera.GetCRC()) + if (webcamLastChecksum != Camera.GetChecksum()) { - lastCRC = Camera.GetCRC(); - delayFrameWebcam = 0; + webcamLastChecksum = Camera.GetChecksum(); + webcamFrameDelayed = 0; return false; } // Increment delayFrame - if (delayFrameWebcam < delayFrameWebcamMin) + if (webcamFrameDelayed < Settings.ScannerDelayFrameMin) { - delayFrameWebcam++; + webcamFrameDelayed++; return false; } Camera.SetSize(); - delayFrameWebcam = 0; + webcamFrameDelayed = 0; return true; } @@ -262,7 +260,7 @@ public void Update() // If not ready, wait if (!Camera.IsReady()) { - Log.Warning("Camera Not Ready Yet ..."); + Log.Warning(this + " Camera Not Ready Yet ..."); if (status != ScannerStatus.Initialize) { Status = ScannerStatus.Initialize; @@ -275,6 +273,8 @@ public void Update() { if (WebcamInitialized()) { + Log.Info(this + " Camera is Ready ", Camera); + Status = ScannerStatus.Paused; if (OnReady != null) @@ -303,12 +303,17 @@ public void Update() pixels = Camera.GetPixels(); // If background thread OFF, do the decode main thread with 500ms of pause for UI - if (!useBackgroundThread && mainThreadLastDecode < Time.realtimeSinceStartup - 0.5f) + if (!Settings.ScannerBackgroundThread && mainThreadLastDecode < Time.realtimeSinceStartup - Settings.ScannerDecodeInterval) { DecodeQR(); mainThreadLastDecode = Time.realtimeSinceStartup; } } } + + public override string ToString() + { + return "[UnityBarcodeScanner]"; + } } } diff --git a/Assets/Scripts/Settings.meta b/Assets/Scripts/Settings.meta new file mode 100644 index 0000000..30a55f4 --- /dev/null +++ b/Assets/Scripts/Settings.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 7516674dbafde4f4dbe61fb9bad97acb +folderAsset: yes +timeCreated: 1480394805 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Settings/ScannerSettings.cs b/Assets/Scripts/Settings/ScannerSettings.cs new file mode 100644 index 0000000..913b8bd --- /dev/null +++ b/Assets/Scripts/Settings/ScannerSettings.cs @@ -0,0 +1,54 @@ +using System; +using System.Linq; +using UnityEngine; + +namespace BarcodeScanner +{ + public class ScannerSettings + { + // Scanner Options + public bool ScannerBackgroundThread { get; set; } + public int ScannerDelayFrameMin { get; set; } + public float ScannerDecodeInterval { get; set; } + + // Parser Options + public bool ParserAutoRotate { get; set; } + public bool ParserTryInverted { get; set; } + public bool ParserTryHarder { get; set; } + + // Webcam Options + public string WebcamDefaultDeviceName { get; set; } + public int WebcamRequestedWidth { get; set; } + public int WebcamRequestedHeight { get; set; } + public FilterMode WebcamFilterMode { get; set; } + + public ScannerSettings() + { + ScannerBackgroundThread = true; + ScannerDelayFrameMin = 3; + ScannerDecodeInterval = 0.2f; + + ParserAutoRotate = true; + ParserTryInverted = true; + ParserTryHarder = false; + + WebcamDefaultDeviceName = (WebCamTexture.devices.Length == 0) ? WebCamTexture.devices.First().name : ""; + WebcamRequestedWidth = 512; + WebcamRequestedHeight = 512; + WebcamFilterMode = FilterMode.Trilinear; + + // Device dependent settings + + // Disable background thread for webgl : Thread not supported + #if UNITY_WEBGL + ScannerDecodeInterval = 0.5f; + ScannerBackgroundThread = false; + #endif + + // Enable only for desktop usage : heavy CPU consumption + #if UNITY_STANDALONE || UNITY_EDITOR + ParserTryHarder = true; + #endif + } + } +} diff --git a/Assets/Scripts/Settings/ScannerSettings.cs.meta b/Assets/Scripts/Settings/ScannerSettings.cs.meta new file mode 100644 index 0000000..4230300 --- /dev/null +++ b/Assets/Scripts/Settings/ScannerSettings.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 306637274299b524ca9df1e5aec8351c +timeCreated: 1480394805 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Webcam/UnityWebcam.cs b/Assets/Scripts/Webcam/UnityWebcam.cs index 7b9317e..7d5be2c 100644 --- a/Assets/Scripts/Webcam/UnityWebcam.cs +++ b/Assets/Scripts/Webcam/UnityWebcam.cs @@ -1,6 +1,4 @@ -using System; -using System.Linq; -using UnityEngine; +using UnityEngine; using Wizcorp.Utils.Logger; namespace BarcodeScanner.Webcam @@ -10,35 +8,21 @@ public class UnityWebcam : IWebcam public Texture Texture { get { return Webcam; } } public WebCamTexture Webcam { get; private set; } - public Vector2 Size { - get - { - return new Vector2(Webcam.width, Webcam.height); - } - } - public int Width {get; private set; } - public int Height {get; private set; } + public Vector2 Size { get { return new Vector2(Webcam.width, Webcam.height); } } + public int Width { get; private set; } + public int Height { get; private set; } - /// - /// - /// - /// - /// - public UnityWebcam() + public UnityWebcam() : this(new ScannerSettings()) { - if (WebCamTexture.devices.Length == 0) - { - throw new Exception("No Camera on this device"); - } - - // Init Camera - WebCamDevice selectCamera = WebCamTexture.devices.First(); + } - // Create Texture (512x512 is the max resolution, the camera will try to get the closer resolution possible) - Webcam = new WebCamTexture(selectCamera.name); - Webcam.requestedWidth = 512; - Webcam.requestedHeight = 512; - Webcam.filterMode = FilterMode.Trilinear; + public UnityWebcam(ScannerSettings settings) + { + // Create Webcam Texture + Webcam = new WebCamTexture(settings.WebcamDefaultDeviceName); + Webcam.requestedWidth = settings.WebcamRequestedWidth; + Webcam.requestedHeight = settings.WebcamRequestedHeight; + Webcam.filterMode = settings.WebcamFilterMode; // Get size Width = 0; @@ -49,7 +33,6 @@ public void SetSize() { Width = Mathf.RoundToInt(Webcam.width); Height = Mathf.RoundToInt(Webcam.height); - Log.Info(string.Format("Camera: {2} | Resolution: {0}x{1} | Orientation: {3}", Width, Height, Webcam.deviceName, Webcam.videoRotationAngle + ":" +Webcam.videoVerticallyMirrored)); } public bool IsReady() @@ -95,9 +78,14 @@ public float GetRotation() return rotation; } - public int GetCRC() + public int GetChecksum() { return (Webcam.width + Webcam.height + Webcam.deviceName + Webcam.videoRotationAngle).GetHashCode(); } + + public override string ToString() + { + return string.Format("[UnityWebcam] Camera: {2} | Resolution: {0}x{1} | Orientation: {3}", Width, Height, Webcam.deviceName, Webcam.videoRotationAngle + ":" + Webcam.videoVerticallyMirrored); + } } } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 406a488..5440ec4 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -3,8 +3,7 @@ --- !u!129 &1 PlayerSettings: m_ObjectHideFlags: 0 - serializedVersion: 10 - productGUID: eacfb9c2e7fe8b042ade6c49d68a3908 + serializedVersion: 8 AndroidProfiler: 0 defaultScreenOrientation: 4 targetDevice: 2 @@ -14,52 +13,26 @@ PlayerSettings: productName: Barcode Scanner defaultCursor: {fileID: 0} cursorHotspot: {x: 0, y: 0} - m_SplashScreenBackgroundColor: {r: 0.13333334, g: 0.17254902, b: 0.21176471, a: 1} m_ShowUnitySplashScreen: 1 - m_ShowUnitySplashLogo: 1 - m_SplashScreenOverlayOpacity: 1 - m_SplashScreenAnimation: 1 - m_SplashScreenLogoStyle: 1 - m_SplashScreenDrawMode: 0 - m_SplashScreenBackgroundAnimationZoom: 1 - m_SplashScreenLogoAnimationZoom: 1 - m_SplashScreenBackgroundLandscapeAspect: 1 - m_SplashScreenBackgroundPortraitAspect: 1 - m_SplashScreenBackgroundLandscapeUvs: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - m_SplashScreenBackgroundPortraitUvs: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - m_SplashScreenLogos: [] - m_SplashScreenBackgroundLandscape: {fileID: 0} - m_SplashScreenBackgroundPortrait: {fileID: 0} m_VirtualRealitySplashScreen: {fileID: 0} - m_HolographicTrackingLossScreen: {fileID: 0} defaultScreenWidth: 1024 defaultScreenHeight: 768 defaultScreenWidthWeb: 960 defaultScreenHeightWeb: 600 - m_StereoRenderingPath: 0 + m_RenderingPath: 1 + m_MobileRenderingPath: 1 m_ActiveColorSpace: 0 m_MTRendering: 1 m_MobileMTRendering: 0 - m_StackTraceTypes: 010000000100000001000000010000000100000001000000 + m_Stereoscopic3D: 0 iosShowActivityIndicatorOnLoading: -1 androidShowActivityIndicatorOnLoading: -1 - tizenShowActivityIndicatorOnLoading: -1 iosAppInBackgroundBehavior: 0 displayResolutionDialog: 1 iosAllowHTTPDownload: 1 allowedAutorotateToPortrait: 1 allowedAutorotateToPortraitUpsideDown: 0 - allowedAutorotateToLandscapeRight: 0 + allowedAutorotateToLandscapeRight: 1 allowedAutorotateToLandscapeLeft: 0 useOSAutorotation: 1 use32BitDisplayBuffer: 1 @@ -68,7 +41,7 @@ PlayerSettings: defaultIsNativeResolution: 1 runInBackground: 0 captureSingleScreen: 0 - muteOtherAudioSources: 0 + Override IPod Music: 0 Prepare IOS For Recording: 0 submitAnalytics: 1 usePlayerLog: 1 @@ -77,7 +50,6 @@ PlayerSettings: resizableWindow: 0 useMacAppStoreValidation: 0 gpuSkinning: 0 - graphicsJobs: 0 xboxPIXTextureCapture: 0 xboxEnableAvatar: 0 xboxEnableKinect: 0 @@ -98,8 +70,7 @@ PlayerSettings: uiUse16BitDepthBuffer: 0 ignoreAlphaClear: 0 xboxOneResolution: 0 - xboxOneMonoLoggingLevel: 0 - xboxOneLoggingLevel: 1 + ps3SplashScreen: {fileID: 0} videoMemoryForVertexBuffers: 0 psp2PowerMode: 0 psp2AcquireBGM: 1 @@ -121,10 +92,11 @@ PlayerSettings: bundleIdentifier: com.ganbaranai.BarcodeScanner bundleVersion: 1.0 preloadedAssets: [] - metroInputSource: 0 - m_HolographicPauseOnTrackingLoss: 1 + metroEnableIndependentInputSource: 0 + metroEnableLowLatencyPresentationAPI: 0 xboxOneDisableKinectGpuReservation: 0 - protectGraphicsMemory: 0 + virtualRealitySupported: 0 + productGUID: eacfb9c2e7fe8b042ade6c49d68a3908 AndroidBundleVersionCode: 1 AndroidMinSdkVersion: 21 AndroidPreferredInstallLocation: 1 @@ -144,10 +116,9 @@ PlayerSettings: serializedVersion: 2 m_Bits: 238 iPhoneSdkVersion: 988 - iOSTargetOSVersionString: 7.0 + iPhoneTargetOSVersion: 24 tvOSSdkVersion: 0 - tvOSRequireExtendedGameController: 0 - tvOSTargetOSVersionString: 9.0 + tvOSTargetOSVersion: 900 uIPrerenderedIcon: 0 uIRequiresPersistentWiFi: 0 uIRequiresFullScreen: 1 @@ -168,7 +139,6 @@ PlayerSettings: tvOSSmallIconLayers: [] tvOSLargeIconLayers: [] tvOSTopShelfImageLayers: [] - tvOSTopShelfImageWideLayers: [] iOSLaunchScreenType: 0 iOSLaunchScreenPortrait: {fileID: 0} iOSLaunchScreenLandscape: {fileID: 0} @@ -187,10 +157,6 @@ PlayerSettings: iOSLaunchScreeniPadSize: 100 iOSLaunchScreeniPadCustomXibPath: iOSDeviceRequirements: [] - iOSURLSchemes: [] - iOSBackgroundModes: 0 - iOSMetalForceHardShadows: 0 - appleDeveloperTeamID: AndroidTargetDevice: 0 AndroidSplashScreenScale: 0 androidSplashScreen: {fileID: 0} @@ -214,64 +180,6 @@ PlayerSettings: m_Height: 128 m_BuildTargetBatching: [] m_BuildTargetGraphicsAPIs: [] - m_BuildTargetVRSettings: - - m_BuildTarget: Android - m_Enabled: 0 - m_Devices: - - Oculus - - m_BuildTarget: Metro - m_Enabled: 0 - m_Devices: - - HoloLens - - m_BuildTarget: N3DS - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: PS3 - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: PS4 - m_Enabled: 0 - m_Devices: - - PlayStationVR - - m_BuildTarget: PSM - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: PSP2 - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: SamsungTV - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: Standalone - m_Enabled: 0 - m_Devices: - - Oculus - - m_BuildTarget: Tizen - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: WebGL - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: WebPlayer - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: WiiU - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: Xbox360 - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: XboxOne - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: iOS - m_Enabled: 0 - m_Devices: [] - - m_BuildTarget: tvOS - m_Enabled: 0 - m_Devices: [] - openGLRequireES31: 0 - openGLRequireES31AEP: 0 webPlayerTemplate: APPLICATION:Default m_TemplateCustomTags: {} wiiUTitleID: 0005000011000000 @@ -296,9 +204,7 @@ PlayerSettings: enableInternalProfiler: 0 logObjCUncaughtExceptions: 1 enableCrashReportAPI: 0 - cameraUsageDescription: locationUsageDescription: - microphoneUsageDescription: XboxTitleId: XboxImageXexPath: XboxSpaPath: @@ -309,6 +215,24 @@ PlayerSettings: xboxAdditionalTitleMemorySize: 0 xboxDeployKinectHeadOrientation: 0 xboxDeployKinectHeadPosition: 0 + ps3TitleConfigPath: + ps3DLCConfigPath: + ps3ThumbnailPath: + ps3BackgroundPath: + ps3SoundPath: + ps3NPAgeRating: 12 + ps3TrophyCommId: + ps3NpCommunicationPassphrase: + ps3TrophyPackagePath: + ps3BootCheckMaxSaveGameSizeKB: 128 + ps3TrophyCommSig: + ps3SaveGameSlots: 1 + ps3TrialMode: 0 + ps3VideoMemoryForAudio: 0 + ps3EnableVerboseMemoryStats: 0 + ps3UseSPUForUmbra: 0 + ps3EnableMoveSupport: 1 + ps3DisableDolbyEncoding: 0 ps4NPAgeRating: 12 ps4NPTitleSecret: ps4NPTrophyPackPath: @@ -320,8 +244,7 @@ PlayerSettings: ps4AppType: 0 ps4ParamSfxPath: ps4VideoOutPixelFormat: 0 - ps4VideoOutInitialWidth: 1920 - ps4VideoOutReprojectionRate: 120 + ps4VideoOutResolution: 4 ps4PronunciationXMLPath: ps4PronunciationSIGPath: ps4BackgroundImagePath: @@ -335,7 +258,6 @@ PlayerSettings: ps4NPtitleDatPath: ps4RemotePlayKeyAssignment: -1 ps4RemotePlayKeyMappingDir: - ps4PlayTogetherPlayerCount: 0 ps4EnterButtonAssignment: 1 ps4ApplicationParam1: 0 ps4ApplicationParam2: 0 @@ -350,24 +272,18 @@ PlayerSettings: ps4pnFriends: 1 ps4pnGameCustomData: 1 playerPrefsSupport: 0 - restrictedAudioUsageRights: 0 - ps4UseResolutionFallback: 0 ps4ReprojectionSupport: 0 ps4UseAudio3dBackend: 0 ps4SocialScreenEnabled: 0 - ps4ScriptOptimizationLevel: 3 ps4Audio3dVirtualSpeakerCount: 14 ps4attribCpuUsage: 0 ps4PatchPkgPath: ps4PatchLatestPkgPath: ps4PatchChangeinfoPath: - ps4PatchDayOne: 0 ps4attribUserManagement: 0 ps4attribMoveSupport: 0 ps4attrib3DSupport: 0 ps4attribShareSupport: 0 - ps4attribExclusiveVR: 0 - ps4disableAutoHideSplash: 0 ps4IncludedModules: [] monoEnv: psp2Splashimage: {fileID: 0} @@ -418,35 +334,9 @@ PlayerSettings: psp2InfoBarColor: 0 psp2UseDebugIl2cppLibs: 0 psmSplashimage: {fileID: 0} - splashScreenBackgroundSourceLandscape: {fileID: 0} - splashScreenBackgroundSourcePortrait: {fileID: 0} spritePackerPolicy: - webGLMemorySize: 256 - webGLExceptionSupport: 1 - webGLDataCaching: 0 - webGLDebugSymbols: 0 - webGLEmscriptenArgs: - webGLModulesDirectory: - webGLTemplate: APPLICATION:Default - webGLAnalyzeBuildSize: 0 - webGLUseEmbeddedResources: 0 - webGLUseWasm: 0 - webGLCompressionFormat: 1 scriptingDefineSymbols: 13: - platformArchitecture: - iOS: 2 - scriptingBackend: - Android: 0 - Standalone: 0 - WebGL: 1 - WebPlayer: 0 - iOS: 1 - incrementalIl2cppBuild: - iOS: 1 - additionalIl2CppArgs: - m_RenderingPath: 1 - m_MobileRenderingPath: 1 metroPackageName: TestUnity metroPackageVersion: metroCertificatePath: @@ -473,14 +363,29 @@ PlayerSettings: metroFTAFileTypes: [] metroProtocolName: metroCompilationOverrides: 1 + blackberryDeviceAddress: + blackberryDevicePassword: + blackberryTokenPath: + blackberryTokenExires: + blackberryTokenAuthor: + blackberryTokenAuthorId: + blackberryCskPassword: + blackberrySaveLogPath: + blackberrySharedPermissions: 0 + blackberryCameraPermissions: 0 + blackberryGPSPermissions: 0 + blackberryDeviceIDPermissions: 0 + blackberryMicrophonePermissions: 0 + blackberryGamepadSupport: 0 + blackberryBuildId: 0 + blackberryLandscapeSplashScreen: {fileID: 0} + blackberryPortraitSplashScreen: {fileID: 0} + blackberrySquareSplashScreen: {fileID: 0} tizenProductDescription: tizenProductURL: tizenSigningProfileName: tizenGPSPermissions: 0 tizenMicrophonePermissions: 0 - tizenDeploymentTarget: - tizenDeploymentTargetType: 0 - tizenMinOSVersion: 0 n3dsUseExtSaveData: 0 n3dsCompressStaticMem: 1 n3dsExtSaveDataNumber: 0x12345 @@ -510,27 +415,101 @@ PlayerSettings: XboxOnePackageEncryption: 0 XboxOnePackageUpdateGranularity: 2 XboxOneDescription: - XboxOneLanguage: - - enus - XboxOneCapability: [] - XboxOneGameRating: {} XboxOneIsContentPackage: 0 XboxOneEnableGPUVariability: 0 XboxOneSockets: {} XboxOneSplashScreen: {fileID: 0} XboxOneAllowedProductIds: [] XboxOnePersistentLocalStorageSize: 0 - vrEditorSettings: {} - cloudServicesEnabled: - Analytics: 0 - Build: 0 - Collab: 0 - ErrorHub: 0 - Game_Performance: 0 - Hub: 0 - Purchasing: 0 - UNet: 1 - Unity_Ads: 0 + intPropertyNames: + - Android::ScriptingBackend + - Standalone::ScriptingBackend + - WebGL::ScriptingBackend + - WebGL::audioCompressionFormat + - WebGL::exceptionSupport + - WebGL::memorySize + - WebPlayer::ScriptingBackend + - iOS::Architecture + - iOS::EnableIncrementalBuildSupportForIl2cpp + - iOS::ScriptingBackend + Android::ScriptingBackend: 0 + Standalone::ScriptingBackend: 0 + WebGL::ScriptingBackend: 1 + WebGL::audioCompressionFormat: 4 + WebGL::exceptionSupport: 1 + WebGL::memorySize: 256 + WebPlayer::ScriptingBackend: 0 + iOS::Architecture: 2 + iOS::EnableIncrementalBuildSupportForIl2cpp: 1 + iOS::ScriptingBackend: 1 + boolPropertyNames: + - Android::VR::enable + - Metro::VR::enable + - N3DS::VR::enable + - PS3::VR::enable + - PS4::VR::enable + - PSM::VR::enable + - PSP2::VR::enable + - SamsungTV::VR::enable + - Standalone::VR::enable + - Tizen::VR::enable + - WebGL::VR::enable + - WebGL::analyzeBuildSize + - WebGL::dataCaching + - WebGL::useEmbeddedResources + - WebPlayer::VR::enable + - WiiU::VR::enable + - Xbox360::VR::enable + - XboxOne::VR::enable + - XboxOne::enus + - iOS::VR::enable + - tvOS::VR::enable + Android::VR::enable: 0 + Metro::VR::enable: 0 + N3DS::VR::enable: 0 + PS3::VR::enable: 0 + PS4::VR::enable: 0 + PSM::VR::enable: 0 + PSP2::VR::enable: 0 + SamsungTV::VR::enable: 0 + Standalone::VR::enable: 0 + Tizen::VR::enable: 0 + WebGL::VR::enable: 0 + WebGL::analyzeBuildSize: 0 + WebGL::dataCaching: 0 + WebGL::useEmbeddedResources: 0 + WebPlayer::VR::enable: 0 + WiiU::VR::enable: 0 + Xbox360::VR::enable: 0 + XboxOne::VR::enable: 0 + XboxOne::enus: 1 + iOS::VR::enable: 0 + tvOS::VR::enable: 0 + stringPropertyNames: + - Analytics_ServiceEnabled::Analytics_ServiceEnabled + - Build_ServiceEnabled::Build_ServiceEnabled + - Collab_ServiceEnabled::Collab_ServiceEnabled + - ErrorHub_ServiceEnabled::ErrorHub_ServiceEnabled + - Game_Performance_ServiceEnabled::Game_Performance_ServiceEnabled + - Hub_ServiceEnabled::Hub_ServiceEnabled + - Purchasing_ServiceEnabled::Purchasing_ServiceEnabled + - UNet_ServiceEnabled::UNet_ServiceEnabled + - Unity_Ads_ServiceEnabled::Unity_Ads_ServiceEnabled + - WebGL::emscriptenArgs + - WebGL::template + - additionalIl2CppArgs::additionalIl2CppArgs + Analytics_ServiceEnabled::Analytics_ServiceEnabled: False + Build_ServiceEnabled::Build_ServiceEnabled: False + Collab_ServiceEnabled::Collab_ServiceEnabled: False + ErrorHub_ServiceEnabled::ErrorHub_ServiceEnabled: False + Game_Performance_ServiceEnabled::Game_Performance_ServiceEnabled: False + Hub_ServiceEnabled::Hub_ServiceEnabled: False + Purchasing_ServiceEnabled::Purchasing_ServiceEnabled: False + UNet_ServiceEnabled::UNet_ServiceEnabled: True + Unity_Ads_ServiceEnabled::Unity_Ads_ServiceEnabled: False + WebGL::emscriptenArgs: + WebGL::template: APPLICATION:Default + additionalIl2CppArgs::additionalIl2CppArgs: cloudProjectId: 8f47c944-78a0-48f6-9144-5e984956ebbd projectName: TestUnity organizationId: kevin-destrem From c329bf01530b3487e29b00534cb4af826fc414eb Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Tue, 29 Nov 2016 16:18:41 +0900 Subject: [PATCH 04/12] Update travis script to be more verbose --- Assets/Editor/ParserTest.cs | 3 ++- Assets/Scripts/Settings/ScannerSettings.cs | 2 +- Scripts/build.sh | 9 ++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Assets/Editor/ParserTest.cs b/Assets/Editor/ParserTest.cs index 0a53bbd..c04d5dc 100644 --- a/Assets/Editor/ParserTest.cs +++ b/Assets/Editor/ParserTest.cs @@ -55,7 +55,8 @@ public void TestCodes(string file, string check) #region Test Samples static object[] ImageSamples = { - new object[] {"sample_giant_qr", "september" } + new object[] {"sample_giant_qr", "september" }, + new object[] {"sample_screen_blurry_qr", "http" } }; [Test, TestCaseSource("ImageSamples")] diff --git a/Assets/Scripts/Settings/ScannerSettings.cs b/Assets/Scripts/Settings/ScannerSettings.cs index 913b8bd..659ed24 100644 --- a/Assets/Scripts/Settings/ScannerSettings.cs +++ b/Assets/Scripts/Settings/ScannerSettings.cs @@ -32,7 +32,7 @@ public ScannerSettings() ParserTryInverted = true; ParserTryHarder = false; - WebcamDefaultDeviceName = (WebCamTexture.devices.Length == 0) ? WebCamTexture.devices.First().name : ""; + WebcamDefaultDeviceName = (WebCamTexture.devices.Length > 0) ? WebCamTexture.devices.First().name : ""; WebcamRequestedWidth = 512; WebcamRequestedHeight = 512; WebcamFilterMode = FilterMode.Trilinear; diff --git a/Scripts/build.sh b/Scripts/build.sh index 3446496..f58c943 100644 --- a/Scripts/build.sh +++ b/Scripts/build.sh @@ -10,4 +10,11 @@ echo "Run Unity Tests" -projectPath $(pwd) \ -quit -exit $? \ No newline at end of file +RESULT=$? +if [ "$RESULT" -ne 0 ]; then + echo "Build Failed" + cat $(pwd)/unity.log + cat $(pwd)/EditorTestResults.xml +fi + +exit $RESULT \ No newline at end of file From 034414d9bf5ac64cdb0132ab615b89c29097448b Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Tue, 29 Nov 2016 20:14:02 +0900 Subject: [PATCH 05/12] Fix Vertically Mirror Flag (misunderstanding) + Disable Auto-Rotate on test screen --- Assets/Samples/Boot.cs | 8 +++++++- Assets/Samples/Continuous/ContinuousDemo.cs | 8 ++++++++ Assets/Samples/Simple/SimpleDemo.cs | 20 ++++++++++++++------ Assets/Scripts/Interfaces/IWebcam.cs | 1 + Assets/Scripts/Webcam/UnityWebcam.cs | 12 ++++++------ 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Assets/Samples/Boot.cs b/Assets/Samples/Boot.cs index 3ef9fdc..67cbaf4 100644 --- a/Assets/Samples/Boot.cs +++ b/Assets/Samples/Boot.cs @@ -8,7 +8,13 @@ /// public class Boot : MonoBehaviour { - public IEnumerator Start() + void Awake() + { + Screen.autorotateToPortrait = true; + Screen.autorotateToPortraitUpsideDown = true; + } + + IEnumerator Start() { // When the app start, ask for the authorization to use the webcam yield return Application.RequestUserAuthorization(UserAuthorization.WebCam); diff --git a/Assets/Samples/Continuous/ContinuousDemo.cs b/Assets/Samples/Continuous/ContinuousDemo.cs index 3ae2cf4..ebed191 100644 --- a/Assets/Samples/Continuous/ContinuousDemo.cs +++ b/Assets/Samples/Continuous/ContinuousDemo.cs @@ -14,6 +14,13 @@ public class ContinuousDemo : MonoBehaviour { public AudioSource Audio; private float RestartTime; + // Disable Screen Rotation on that screen + void Awake() + { + Screen.autorotateToPortrait = false; + Screen.autorotateToPortraitUpsideDown = false; + } + void Start () { // Create a basic scanner BarcodeScanner = new Scanner(); @@ -23,6 +30,7 @@ void Start () { BarcodeScanner.OnReady += (sender, arg) => { // Set Orientation & Texture Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation()); + Image.transform.localScale = new Vector2(BarcodeScanner.Camera.IsVerticalyMirrored() ? -Image.transform.localScale.x : Image.transform.localScale.x, Image.transform.localScale.y); Image.texture = BarcodeScanner.Camera.Texture; RestartTime = Time.realtimeSinceStartup; diff --git a/Assets/Samples/Simple/SimpleDemo.cs b/Assets/Samples/Simple/SimpleDemo.cs index a29626a..1baa61e 100644 --- a/Assets/Samples/Simple/SimpleDemo.cs +++ b/Assets/Samples/Simple/SimpleDemo.cs @@ -1,11 +1,11 @@ -using UnityEngine; -using UnityEngine.UI; -using BarcodeScanner; +using BarcodeScanner; using BarcodeScanner.Scanner; -using Wizcorp.Utils.Logger; -using UnityEngine.SceneManagement; -using System.Collections; using System; +using System.Collections; +using UnityEngine; +using UnityEngine.SceneManagement; +using UnityEngine.UI; +using Wizcorp.Utils.Logger; public class SimpleDemo : MonoBehaviour { @@ -14,6 +14,13 @@ public class SimpleDemo : MonoBehaviour { public RawImage Image; public AudioSource Audio; + // Disable Screen Rotation on that screen + void Awake() + { + Screen.autorotateToPortrait = false; + Screen.autorotateToPortraitUpsideDown = false; + } + void Start () { // Create a basic scanner BarcodeScanner = new Scanner(); @@ -23,6 +30,7 @@ void Start () { BarcodeScanner.OnReady += (sender, arg) => { // Set Orientation & Texture Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation()); + Image.transform.localScale = new Vector2(BarcodeScanner.Camera.IsVerticalyMirrored() ? -Image.transform.localScale.x : Image.transform.localScale.x, Image.transform.localScale.y); Image.texture = BarcodeScanner.Camera.Texture; // Keep Image Aspect Ratio diff --git a/Assets/Scripts/Interfaces/IWebcam.cs b/Assets/Scripts/Interfaces/IWebcam.cs index 9a43d7f..7a4a0b3 100644 --- a/Assets/Scripts/Interfaces/IWebcam.cs +++ b/Assets/Scripts/Interfaces/IWebcam.cs @@ -20,6 +20,7 @@ public interface IWebcam // Color32[] GetPixels(); float GetRotation(); + bool IsVerticalyMirrored(); int GetChecksum(); } } \ No newline at end of file diff --git a/Assets/Scripts/Webcam/UnityWebcam.cs b/Assets/Scripts/Webcam/UnityWebcam.cs index 7d5be2c..2be3ec0 100644 --- a/Assets/Scripts/Webcam/UnityWebcam.cs +++ b/Assets/Scripts/Webcam/UnityWebcam.cs @@ -70,12 +70,12 @@ public Color32[] GetPixels() public float GetRotation() { - int rotation = -Webcam.videoRotationAngle; - if (Webcam.videoVerticallyMirrored) - { - rotation += 180; - } - return rotation; + return -Webcam.videoRotationAngle; + } + + public bool IsVerticalyMirrored() + { + return Webcam.videoVerticallyMirrored; } public int GetChecksum() From fff88622022f27b8ba5aba7e96ee98704303189d Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Tue, 29 Nov 2016 22:02:38 +0900 Subject: [PATCH 06/12] Add a logo --- README.md | 2 +- UnityBarcodeScannerLogo.png | Bin 0 -> 6341 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 UnityBarcodeScannerLogo.png diff --git a/README.md b/README.md index 0264873..ade275b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Unity Barcode Scanner -[![Build Status](https://travis-ci.org/kefniark/UnityBarcodeScanner.svg?branch=master)](https://travis-ci.org/kefniark/UnityBarcodeScanner) +![Unity Barcode Scanner Logo](./UnityBarcodeScannerLogo.png) [![Build Status](https://travis-ci.org/kefniark/UnityBarcodeScanner.svg?branch=master)](https://travis-ci.org/kefniark/UnityBarcodeScanner) Since months, I was looking for a good way to parse QRCodes (and generic barcode) in Unity. On the Asset Store, few libraries are already providing that, but they are expensive, overly complex, not tested and not always maintained. diff --git a/UnityBarcodeScannerLogo.png b/UnityBarcodeScannerLogo.png new file mode 100644 index 0000000000000000000000000000000000000000..96fa63d229f343526e36cb44c6e2409ccb535476 GIT binary patch literal 6341 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 Hu0mjf3jx#Q literal 0 HcmV?d00001 From 99d07c658044bc3a9240a3719e90c4efd569395c Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Wed, 30 Nov 2016 02:11:24 +0900 Subject: [PATCH 07/12] Implement a new version of IWebcam.GetPixels() to reuse an existing Color32[] --- Assets/Scripts/Interfaces/IWebcam.cs | 2 +- Assets/Scripts/Scanner/Scanner.cs | 21 ++++++++++----------- Assets/Scripts/Webcam/UnityWebcam.cs | 8 ++++++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/Interfaces/IWebcam.cs b/Assets/Scripts/Interfaces/IWebcam.cs index 9a43d7f..ee141eb 100644 --- a/Assets/Scripts/Interfaces/IWebcam.cs +++ b/Assets/Scripts/Interfaces/IWebcam.cs @@ -18,7 +18,7 @@ public interface IWebcam void Destroy(); // - Color32[] GetPixels(); + Color32[] GetPixels(Color32[] data); float GetRotation(); int GetChecksum(); } diff --git a/Assets/Scripts/Scanner/Scanner.cs b/Assets/Scripts/Scanner/Scanner.cs index d3e5f93..27f3574 100644 --- a/Assets/Scripts/Scanner/Scanner.cs +++ b/Assets/Scripts/Scanner/Scanner.cs @@ -41,11 +41,12 @@ private set } // Store information about last image / results (use the update loop to access camera and callback) - private Color32[] pixels = new Color32[0]; + private Color32[] pixels = null; private Action Callback; private ParserResult Result; // + private bool parserPixelAvailable = false; private float mainThreadLastDecode = 0; private int webcamFrameDelayed = 0; private int webcamLastChecksum = -1; @@ -143,6 +144,7 @@ public void Destroy() Callback = null; Result = null; pixels = null; + parserPixelAvailable = false; // clean camera Camera.Destroy(); @@ -159,7 +161,7 @@ public void Destroy() public void DecodeQR() { // Wait - if (Status != ScannerStatus.Running || pixels.Length == 00 || Camera.Width == 0) + if (Status != ScannerStatus.Running || !parserPixelAvailable || Camera.Width == 0) { return; } @@ -169,7 +171,7 @@ public void DecodeQR() try { Result = Parser.Decode(pixels, Camera.Width, Camera.Height); - pixels = null; + parserPixelAvailable = false; } catch (Exception e) { @@ -192,12 +194,8 @@ public void ThreadDecodeQR() { while (Result == null) { - if (pixels == null) { - pixels = new Color32[0]; - } - // Wait - if (Status != ScannerStatus.Running || pixels.Length == 00 || Camera.Width == 0) + if (Status != ScannerStatus.Running || !parserPixelAvailable || Camera.Width == 0) { Thread.Sleep(Mathf.FloorToInt(Settings.ScannerDecodeInterval * 1000)); continue; @@ -208,7 +206,7 @@ public void ThreadDecodeQR() try { Result = Parser.Decode(pixels, Camera.Width, Camera.Height); - pixels = null; + parserPixelAvailable = false; // Sleep a little bit and set the signal to get the next frame Thread.Sleep(Mathf.FloorToInt(Settings.ScannerDecodeInterval * 1000)); @@ -295,12 +293,13 @@ public void Update() // clean and return Result = null; - pixels = new Color32[0]; + parserPixelAvailable = false; return; } // Get the image as an array of Color32 - pixels = Camera.GetPixels(); + pixels = Camera.GetPixels(pixels); + parserPixelAvailable = true; // If background thread OFF, do the decode main thread with 500ms of pause for UI if (!Settings.ScannerBackgroundThread && mainThreadLastDecode < Time.realtimeSinceStartup - Settings.ScannerDecodeInterval) diff --git a/Assets/Scripts/Webcam/UnityWebcam.cs b/Assets/Scripts/Webcam/UnityWebcam.cs index 7d5be2c..28179b1 100644 --- a/Assets/Scripts/Webcam/UnityWebcam.cs +++ b/Assets/Scripts/Webcam/UnityWebcam.cs @@ -63,9 +63,13 @@ public void Destroy() } } - public Color32[] GetPixels() + public Color32[] GetPixels(Color32[] data = null) { - return Webcam.GetPixels32(); + if (data == null || data.Length != Webcam.width * Webcam.height) + { + return Webcam.GetPixels32(); + } + return Webcam.GetPixels32(data); } public float GetRotation() From 0fdee79a18fbfaeca70bf34e0528e94a07344a5b Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Wed, 30 Nov 2016 02:34:44 +0900 Subject: [PATCH 08/12] Reduce the default interval --- Assets/Scripts/Scanner/Scanner.cs | 1 + Assets/Scripts/Settings/ScannerSettings.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Scanner/Scanner.cs b/Assets/Scripts/Scanner/Scanner.cs index 27f3574..668c16b 100644 --- a/Assets/Scripts/Scanner/Scanner.cs +++ b/Assets/Scripts/Scanner/Scanner.cs @@ -124,6 +124,7 @@ private void Stop(bool forced) CodeScannerThread.Abort(); } #endif + Callback = null; Status = ScannerStatus.Paused; } diff --git a/Assets/Scripts/Settings/ScannerSettings.cs b/Assets/Scripts/Settings/ScannerSettings.cs index 659ed24..7e7d275 100644 --- a/Assets/Scripts/Settings/ScannerSettings.cs +++ b/Assets/Scripts/Settings/ScannerSettings.cs @@ -26,7 +26,7 @@ public ScannerSettings() { ScannerBackgroundThread = true; ScannerDelayFrameMin = 3; - ScannerDecodeInterval = 0.2f; + ScannerDecodeInterval = 0.1f; ParserAutoRotate = true; ParserTryInverted = true; From 25fa206e5c7c8e3d634169e902a1529232bfa360 Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Wed, 30 Nov 2016 03:03:31 +0900 Subject: [PATCH 09/12] Changed IsVerticalyMirrored, based on the documentation the scale to flip is Y, not X --- Assets/Samples/Continuous/ContinuousDemo.cs | 3 ++- Assets/Samples/Simple/SimpleDemo.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Assets/Samples/Continuous/ContinuousDemo.cs b/Assets/Samples/Continuous/ContinuousDemo.cs index ebed191..cf27e0b 100644 --- a/Assets/Samples/Continuous/ContinuousDemo.cs +++ b/Assets/Samples/Continuous/ContinuousDemo.cs @@ -30,7 +30,8 @@ void Start () { BarcodeScanner.OnReady += (sender, arg) => { // Set Orientation & Texture Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation()); - Image.transform.localScale = new Vector2(BarcodeScanner.Camera.IsVerticalyMirrored() ? -Image.transform.localScale.x : Image.transform.localScale.x, Image.transform.localScale.y); + float scaleY = BarcodeScanner.Camera.IsVerticalyMirrored() ? -1f : 1f; + Image.transform.localScale = new Vector2(Image.transform.localScale.x, scaleY * Image.transform.localScale.y); Image.texture = BarcodeScanner.Camera.Texture; RestartTime = Time.realtimeSinceStartup; diff --git a/Assets/Samples/Simple/SimpleDemo.cs b/Assets/Samples/Simple/SimpleDemo.cs index 1baa61e..7b527a1 100644 --- a/Assets/Samples/Simple/SimpleDemo.cs +++ b/Assets/Samples/Simple/SimpleDemo.cs @@ -30,7 +30,8 @@ void Start () { BarcodeScanner.OnReady += (sender, arg) => { // Set Orientation & Texture Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation()); - Image.transform.localScale = new Vector2(BarcodeScanner.Camera.IsVerticalyMirrored() ? -Image.transform.localScale.x : Image.transform.localScale.x, Image.transform.localScale.y); + float scaleY = BarcodeScanner.Camera.IsVerticalyMirrored() ? -1f : 1f; + Image.transform.localScale = new Vector2(Image.transform.localScale.x, scaleY * Image.transform.localScale.y); Image.texture = BarcodeScanner.Camera.Texture; // Keep Image Aspect Ratio From f44a1fdc24b6336a6b3325e6f4b9677dc68396d6 Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Wed, 30 Nov 2016 03:35:03 +0900 Subject: [PATCH 10/12] Update README --- Assets/Scripts/README.md | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/README.md b/Assets/Scripts/README.md index 85158bb..0d19128 100644 --- a/Assets/Scripts/README.md +++ b/Assets/Scripts/README.md @@ -19,7 +19,7 @@ BarcodeScanner = new Scanner(); // Start playing the camera BarcodeScanner.Camera.Play(); -// When for the camera to be ready +// Event when for the camera is ready to scan BarcodeScanner.OnReady += (sender, arg) => { // Bind the Camera texture to any RawImage in your scene diff --git a/README.md b/README.md index 0264873..2e7400b 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,14 @@ Since months, I was looking for a good way to parse QRCodes (and generic barcode On the Asset Store, few libraries are already providing that, but they are expensive, overly complex, not tested and not always maintained. So, I was just trying to do something simple, readable, cross-platform and open source. -* Tested with Unity `5.3.x`, `5.4.x` -* Tested on `PC`, `Mac`, `Android`, `WebGL` +* Tested with Unity `5.3.x`, `5.4.x`, `5.5.x` +* Tested on `PC`, `Mac`, `Android`, `iOS`, `WebGL` * Tested with the following barcode format: * 1D : `Code 39`, `Code 128`, `ISBN` * 2D : `QR Code`, `Aztec`, `Data Matrix` # How does that work ? -This project is a Unity Project that you can use directly. +This project is a Unity Project you can use directly. Every part is separated and can be replaced or extended if needed * Camera : use directly the API of unity to access the webcam (available on iOS, Android, Windows, Mac, Linux, ...) From 0551d717b4778871d8a73ab4aea5c2696a0390fd Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Wed, 30 Nov 2016 19:14:17 +0900 Subject: [PATCH 11/12] Add accessors on the camera (rotation/scale) + Vsync --- Assets/Samples/Boot.cs | 3 +++ Assets/Samples/Continuous/ContinuousDemo.cs | 8 ++++---- Assets/Samples/Simple/SimpleDemo.cs | 5 ++--- Assets/Scripts/Interfaces/IWebcam.cs | 2 ++ Assets/Scripts/Webcam/UnityWebcam.cs | 10 ++++++++++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Assets/Samples/Boot.cs b/Assets/Samples/Boot.cs index 67cbaf4..8deaae3 100644 --- a/Assets/Samples/Boot.cs +++ b/Assets/Samples/Boot.cs @@ -12,6 +12,9 @@ void Awake() { Screen.autorotateToPortrait = true; Screen.autorotateToPortraitUpsideDown = true; + + // Enable vsync for the samples (avoid running mobile device at 300fps) + QualitySettings.vSyncCount = 1; } IEnumerator Start() diff --git a/Assets/Samples/Continuous/ContinuousDemo.cs b/Assets/Samples/Continuous/ContinuousDemo.cs index cf27e0b..aed1ef2 100644 --- a/Assets/Samples/Continuous/ContinuousDemo.cs +++ b/Assets/Samples/Continuous/ContinuousDemo.cs @@ -29,16 +29,16 @@ void Start () { // Display the camera texture through a RawImage BarcodeScanner.OnReady += (sender, arg) => { // Set Orientation & Texture - Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation()); - float scaleY = BarcodeScanner.Camera.IsVerticalyMirrored() ? -1f : 1f; - Image.transform.localScale = new Vector2(Image.transform.localScale.x, scaleY * Image.transform.localScale.y); + Image.transform.localEulerAngles = BarcodeScanner.Camera.GetEulerAngles(); + Image.transform.localScale = BarcodeScanner.Camera.GetScale(); Image.texture = BarcodeScanner.Camera.Texture; - RestartTime = Time.realtimeSinceStartup; // Keep Image Aspect Ratio var rect = Image.GetComponent(); var newHeight = rect.sizeDelta.x * BarcodeScanner.Camera.Height / BarcodeScanner.Camera.Width; rect.sizeDelta = new Vector2(rect.sizeDelta.x, newHeight); + + RestartTime = Time.realtimeSinceStartup; }; } diff --git a/Assets/Samples/Simple/SimpleDemo.cs b/Assets/Samples/Simple/SimpleDemo.cs index 7b527a1..0ada6d9 100644 --- a/Assets/Samples/Simple/SimpleDemo.cs +++ b/Assets/Samples/Simple/SimpleDemo.cs @@ -29,9 +29,8 @@ void Start () { // Display the camera texture through a RawImage BarcodeScanner.OnReady += (sender, arg) => { // Set Orientation & Texture - Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation()); - float scaleY = BarcodeScanner.Camera.IsVerticalyMirrored() ? -1f : 1f; - Image.transform.localScale = new Vector2(Image.transform.localScale.x, scaleY * Image.transform.localScale.y); + Image.transform.localEulerAngles = BarcodeScanner.Camera.GetEulerAngles(); + Image.transform.localScale = BarcodeScanner.Camera.GetScale(); Image.texture = BarcodeScanner.Camera.Texture; // Keep Image Aspect Ratio diff --git a/Assets/Scripts/Interfaces/IWebcam.cs b/Assets/Scripts/Interfaces/IWebcam.cs index 7a4a0b3..8e8cfbf 100644 --- a/Assets/Scripts/Interfaces/IWebcam.cs +++ b/Assets/Scripts/Interfaces/IWebcam.cs @@ -21,6 +21,8 @@ public interface IWebcam Color32[] GetPixels(); float GetRotation(); bool IsVerticalyMirrored(); + Vector3 GetEulerAngles(); + Vector3 GetScale(); int GetChecksum(); } } \ No newline at end of file diff --git a/Assets/Scripts/Webcam/UnityWebcam.cs b/Assets/Scripts/Webcam/UnityWebcam.cs index 2be3ec0..a3bf16b 100644 --- a/Assets/Scripts/Webcam/UnityWebcam.cs +++ b/Assets/Scripts/Webcam/UnityWebcam.cs @@ -78,6 +78,16 @@ public bool IsVerticalyMirrored() return Webcam.videoVerticallyMirrored; } + public Vector3 GetEulerAngles() + { + return new Vector3(0f, 0f, GetRotation()); + } + + public Vector3 GetScale() + { + return new Vector3(1, IsVerticalyMirrored() ? -1f : 1f, 1); + } + public int GetChecksum() { return (Webcam.width + Webcam.height + Webcam.deviceName + Webcam.videoRotationAngle).GetHashCode(); From 9aafd322f8bbba758175290b97904077106850a8 Mon Sep 17 00:00:00 2001 From: Kevin Destrem Date: Wed, 30 Nov 2016 19:47:27 +0900 Subject: [PATCH 12/12] Update Readme (bump version to 0.3) --- Assets/Scripts/README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/README.md b/Assets/Scripts/README.md index 85158bb..605fa73 100644 --- a/Assets/Scripts/README.md +++ b/Assets/Scripts/README.md @@ -4,7 +4,7 @@ Small Barcode Scanner library for Unity ## Informations **Author**: Kefniark -**Version**: 0.2 +**Version**: 0.3 **Main Repository**: https://github.com/kefniark/UnityBarcodeScanner @@ -44,7 +44,7 @@ void Update() Check the samples to have a better example of how to implement it. ## API -** Events ** +**Events** ```csharp // trigger when the scanner can be used event EventHandler OnReady; @@ -52,7 +52,7 @@ event EventHandler OnReady; event EventHandler StatusChanged; ``` -** Properties ** +**Properties** ```csharp // Status of the scanner (enum with different values: Initialize, Running, Paused) ScannerStatus Status { get; } @@ -62,7 +62,7 @@ IParser Parser { get; } IWebcam Camera { get; } ``` -** Method ** +**Method** ```csharp // Start to scan (the callback provide the type and the value of any barcode found) void Scan(Action Callback); @@ -76,6 +76,14 @@ void Destroy(); ## Changes +### 0.3 (30/11/2016) +* Changed how options are exposed +* Fixed Aspect Ratio, Rotation & Flip of the RawTexture +* Improved Logs +* Improved Performance (lower the amount of GC) +* Update samples (vsync, disabled auto-rotation) +* Tested with iOS (iPhone & iPad) + ### 0.2 (24/09/2016) * Implement Basic Samples * Tested with WebGL & Desktop (pc/mac)