-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from uezo/develop
Add CameraRequestProvider and QRCodeRequestProvider
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using UnityEngine; | ||
using ChatdollKit.IO; | ||
|
||
|
||
namespace ChatdollKit.Dialog | ||
{ | ||
public class CameraRequestProvider : MonoBehaviour, IRequestProvider | ||
{ | ||
// This provides photo taken by camera | ||
public RequestType RequestType { get; } = RequestType.Camera; | ||
|
||
public string CameraCaption; | ||
public int SelfTimerSeconds = 3; | ||
|
||
private ChatdollCamera chatdollCamera; | ||
|
||
private void Start() | ||
{ | ||
chatdollCamera = GameObject.Find("ChatdollCamera").GetComponent<ChatdollCamera>(); | ||
} | ||
|
||
// Create request using voice recognition | ||
public async Task<Request> GetRequestAsync(User user, Context context, CancellationToken token) | ||
{ | ||
var request = new Request(RequestType, user); | ||
var payloads = new List<Texture2D>(); | ||
|
||
if (chatdollCamera != null) | ||
{ | ||
payloads.Add(await chatdollCamera.CaptureTextureWithTimerAsync(CameraCaption, SelfTimerSeconds)); | ||
} | ||
else | ||
{ | ||
Debug.LogWarning("ChatdollCamera is not found"); | ||
} | ||
|
||
request.Payloads = payloads; | ||
return request; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using UnityEngine; | ||
using ChatdollKit.IO; | ||
|
||
|
||
namespace ChatdollKit.Dialog | ||
{ | ||
public class QRCodeRequestProvider : MonoBehaviour, IRequestProvider | ||
{ | ||
// This provides decoded QRCode data | ||
public RequestType RequestType { get; } = RequestType.QRCode; | ||
|
||
private ChatdollCamera chatdollCamera; | ||
|
||
private void Start() | ||
{ | ||
chatdollCamera = GameObject.Find("ChatdollCamera").GetComponent<ChatdollCamera>(); | ||
} | ||
|
||
// Create request using voice recognition | ||
public async Task<Request> GetRequestAsync(User user, Context context, CancellationToken token) | ||
{ | ||
var request = new Request(RequestType, user); | ||
var payloads = new List<string>(); | ||
|
||
if (chatdollCamera != null) | ||
{ | ||
payloads.Add(await chatdollCamera.ReadCodeAsync()); | ||
} | ||
else | ||
{ | ||
Debug.LogWarning("ChatdollCamera is not found"); | ||
} | ||
|
||
request.Payloads = payloads; | ||
return request; | ||
} | ||
} | ||
} |