ChessBoardController.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Meta.Conduit;
  5. using Meta.WitAi;
  6. using UnityEngine;
  7. namespace Oculus.Voice.Demo.ConduitChessDemo
  8. {
  9. public class ChessBoardController : MonoBehaviour
  10. {
  11. public GameObject letters;
  12. public GameObject numbers;
  13. public GameObject chessPiece;
  14. public UnityEngine.UI.Text errorText;
  15. private Vector3 _targetPosition = new Vector3(0,2,0);
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. chessPiece.transform.position = Vector3.Lerp(chessPiece.transform.position, _targetPosition, Time.deltaTime);
  20. }
  21. public enum ChessBoardLetter
  22. {
  23. A,
  24. B,
  25. C,
  26. D,
  27. E,
  28. F,
  29. G,
  30. H
  31. }
  32. [MatchIntent("MoveChessPiece")]
  33. public void MoveChessPiece(ChessBoardLetter letter, int number)
  34. {
  35. Debug.Log("Move chess piece to " + letter + number);
  36. _targetPosition = new Vector3(letters.transform.GetChild((int)letter).position.x, _targetPosition.y,
  37. numbers.transform.GetChild(number - 1).position.z);
  38. }
  39. [HandleEntityResolutionFailure]
  40. public void OnHandleEntityResolutionFailure(string intent , Exception ex)
  41. {
  42. Debug.Log("Failed to resolve parameter for intent " + intent + " with error " + ex.Message);
  43. errorText.text = ex.Message;
  44. }
  45. }
  46. }