Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CameraRequestProvider and QRCodeRequestProvider #60

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}