Skip to content

Commit

Permalink
Merge pull request #60 from uezo/develop
Browse files Browse the repository at this point in the history
Add CameraRequestProvider and QRCodeRequestProvider
  • Loading branch information
uezo authored Jun 26, 2020
2 parents d85d338 + 2361c82 commit 59e6e54
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ChatdollKit/Scripts/Dialog/CameraRequestProvider.cs
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;
}
}
}
41 changes: 41 additions & 0 deletions ChatdollKit/Scripts/Dialog/QRCodeRequestProvider.cs
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;
}
}
}

0 comments on commit 59e6e54

Please sign in to comment.