Skip to content

Commit

Permalink
Merge pull request #18 from kefniark/develop
Browse files Browse the repository at this point in the history
Update Master
  • Loading branch information
kefniark committed Nov 30, 2016
2 parents 4c35976 + 73f9961 commit 1a5878b
Show file tree
Hide file tree
Showing 17 changed files with 329 additions and 108 deletions.
30 changes: 30 additions & 0 deletions Assets/Editor/ScannerTest.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
12 changes: 12 additions & 0 deletions Assets/Editor/ScannerTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Assets/Samples/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
/// </summary>
public class Boot : MonoBehaviour
{
public IEnumerator Start()
void Awake()
{
Screen.autorotateToPortrait = true;
Screen.autorotateToPortraitUpsideDown = true;

// Enable vsync for the samples (avoid running mobile device at 300fps)
QualitySettings.vSyncCount = 1;
}

IEnumerator Start()
{
// When the app start, ask for the authorization to use the webcam
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
Expand Down
17 changes: 16 additions & 1 deletion Assets/Samples/Continuous/ContinuousDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,30 @@ 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();
BarcodeScanner.Camera.Play();

// Display the camera texture through a RawImage
BarcodeScanner.OnReady += (sender, arg) => {
Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation());
// Set Orientation & Texture
Image.transform.localEulerAngles = BarcodeScanner.Camera.GetEulerAngles();
Image.transform.localScale = BarcodeScanner.Camera.GetScale();
Image.texture = BarcodeScanner.Camera.Texture;
// Keep Image Aspect Ratio
var rect = Image.GetComponent<RectTransform>();
var newHeight = rect.sizeDelta.x * BarcodeScanner.Camera.Height / BarcodeScanner.Camera.Width;
rect.sizeDelta = new Vector2(rect.sizeDelta.x, newHeight);
RestartTime = Time.realtimeSinceStartup;
};
}
Expand Down
28 changes: 21 additions & 7 deletions Assets/Samples/Simple/SimpleDemo.cs
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -14,15 +14,29 @@ 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();
BarcodeScanner.Camera.Play();

// Display the camera texture through a RawImage
BarcodeScanner.OnReady += (sender, arg) => {
Image.transform.localEulerAngles = new Vector3(0f, 0f, BarcodeScanner.Camera.GetRotation());
// Set Orientation & Texture
Image.transform.localEulerAngles = BarcodeScanner.Camera.GetEulerAngles();
Image.transform.localScale = BarcodeScanner.Camera.GetScale();
Image.texture = BarcodeScanner.Camera.Texture;
// Keep Image Aspect Ratio
var rect = Image.GetComponent<RectTransform>();
var newHeight = rect.sizeDelta.x * BarcodeScanner.Camera.Height / BarcodeScanner.Camera.Width;
rect.sizeDelta = new Vector2(rect.sizeDelta.x, newHeight);
};

// Track status of the scanner
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Interfaces/IScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IScanner

IParser Parser { get; }
IWebcam Camera { get; }
ScannerSettings Settings { get; }

void Scan(Action<string, string> Callback);
void Stop();
Expand Down
6 changes: 5 additions & 1 deletion Assets/Scripts/Interfaces/IWebcam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public interface IWebcam
void Destroy();

//
Color32[] GetPixels();
Color32[] GetPixels(Color32[] data);
float GetRotation();
bool IsVerticalyMirrored();
Vector3 GetEulerAngles();
Vector3 GetScale();
int GetChecksum();
}
}
15 changes: 8 additions & 7 deletions Assets/Scripts/Parser/ZXingParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
Expand Down
18 changes: 13 additions & 5 deletions Assets/Scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -44,15 +44,15 @@ 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;
// trigger when the status of the scanner change
event EventHandler StatusChanged;
```

** Properties **
**Properties**
```csharp
// Status of the scanner (enum with different values: Initialize, Running, Paused)
ScannerStatus Status { get; }
Expand All @@ -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<string, string> Callback);
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 1a5878b

Please sign in to comment.