clean project
This commit is contained in:
244
Assets/Oculus/Voice/Demo/Scripts/BuiltinDemo/TimerController.cs
Normal file
244
Assets/Oculus/Voice/Demo/Scripts/BuiltinDemo/TimerController.cs
Normal file
@@ -0,0 +1,244 @@
|
||||
/**************************************************************************************************
|
||||
* Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
*
|
||||
* Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
* ANY KIND, either express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
**************************************************************************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Oculus.Voice.Demo.BuiltInDemo
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a countdown timer.
|
||||
/// </summary>
|
||||
public class TimerController : MonoBehaviour
|
||||
{
|
||||
private float _time = 0; // [sec] current time of the countdown timer.
|
||||
private bool _timerExist = false;
|
||||
private bool _timerRunning = false;
|
||||
|
||||
[Tooltip("The UI text element to show app messages.")]
|
||||
public Text logText;
|
||||
|
||||
[Tooltip("The timer ring sound.")] public AudioClip buzzSound;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (_timerExist && _timerRunning)
|
||||
{
|
||||
_time -= Time.deltaTime;
|
||||
if (_time < 0)
|
||||
{
|
||||
// Raise a ring.
|
||||
OnElapsedTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Log(string msg)
|
||||
{
|
||||
Debug.Log(msg);
|
||||
logText.text = msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Buzzes and resets the timer.
|
||||
/// </summary>
|
||||
private void OnElapsedTime()
|
||||
{
|
||||
_time = 0;
|
||||
_timerRunning = false;
|
||||
_timerExist = false;
|
||||
Log("Buzz!");
|
||||
AudioSource.PlayClipAtPoint(buzzSound, Vector3.zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the timer. It corresponds to the wit intent "wit$delete_timer"
|
||||
/// </summary>
|
||||
public void DeleteTimer()
|
||||
{
|
||||
if (!_timerExist)
|
||||
{
|
||||
Log("Error: There is no timer to delete.");
|
||||
return;
|
||||
}
|
||||
|
||||
_timerExist = false;
|
||||
_time = 0;
|
||||
_timerRunning = false;
|
||||
Log("Timer deleted.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a timer. It corresponds to the wit intent "wit$create_timer"
|
||||
/// </summary>
|
||||
/// <param name="entityValues">countdown in minutes.</param>
|
||||
public void CreateTimer(string[] entityValues)
|
||||
{
|
||||
if (_timerExist)
|
||||
{
|
||||
Log("A timer already exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ParseTime(entityValues, out _time))
|
||||
{
|
||||
_timerExist = true;
|
||||
_timerRunning = true;
|
||||
Log($"Countdown Timer is set for {entityValues[0]} {entityValues[1]}(s).");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Error in CreateTimer(): Could not parse wit reply.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays current timer value. It corresponds to "wit$get_timer".
|
||||
/// </summary>
|
||||
public void GetTimerIntent()
|
||||
{
|
||||
// Show the remaining time of the countdown timer.
|
||||
var msg = GetFormattedTimeFromSeconds();
|
||||
Log(msg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pauses the timer. It corresponds to the wit intent "wit$pause_timer"
|
||||
/// </summary>
|
||||
public void PauseTimer()
|
||||
{
|
||||
_timerRunning = false;
|
||||
Log("Timer paused.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// It corresponds to the wit intent "wit$resume_timer"
|
||||
/// </summary>
|
||||
public void ResumeTimer()
|
||||
{
|
||||
_timerRunning = true;
|
||||
Log("Timer resumed.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts time from the timer. It corresponds to the wit intent "wit$subtract_time_timer".
|
||||
/// </summary>
|
||||
/// <param name="entityValues"></param>
|
||||
public void SubtractTimeTimer(string[] entityValues)
|
||||
{
|
||||
if (!_timerExist)
|
||||
{
|
||||
Log("Error: No Timer is created.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ParseTime(entityValues, out var time))
|
||||
{
|
||||
var msg = $"{entityValues[0]} {entityValues[1]}(s) were subtracted from the timer.";
|
||||
_time -= time;
|
||||
if (_time < 0)
|
||||
{
|
||||
_time = 0;
|
||||
Log(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
Log(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Error in Subtract_time_timer(): Could not parse the wit reply.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds time to the timer. It corresponds to the wit intent "wit$add_time_timer".
|
||||
/// </summary>
|
||||
/// <param name="entityValues"></param>
|
||||
public void AddTimeToTimer(string[] entityValues)
|
||||
{
|
||||
if (!_timerExist)
|
||||
{
|
||||
Log("Error: No Timer is created.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ParseTime(entityValues, out var time))
|
||||
{
|
||||
_time += time;
|
||||
var msg = $"{entityValues[0]} {entityValues[1]}(s) were added to the timer.";
|
||||
Log(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Error in AddTimeToTimer(): Could not parse with reply.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the remaining time (in sec) of the countdown timer.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public float GetRemainingTime()
|
||||
{
|
||||
return _time;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns time in the format of min:sec.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetFormattedTimeFromSeconds()
|
||||
{
|
||||
return TimeSpan.FromSeconds(_time).ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses entity values to get a resulting time value in seconds
|
||||
/// </summary>
|
||||
/// <param name="entityValues">The entity value results from a Response Handler</param>
|
||||
/// <param name="time">The parsed time</param>
|
||||
/// <returns>The parsed time in seconds or the current value of _time</returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private bool ParseTime(string[] entityValues, out float time)
|
||||
{
|
||||
time = _time;
|
||||
if (entityValues.Length > 0 && float.TryParse(entityValues[0], out time))
|
||||
{
|
||||
if (entityValues.Length < 2)
|
||||
{
|
||||
throw new ArgumentException("Entities being parsed must include time value and unit.");
|
||||
}
|
||||
|
||||
// If entity was not included in the result it will be empty, but the array will still be size 2
|
||||
if (!string.IsNullOrEmpty(entityValues[1]))
|
||||
{
|
||||
switch (entityValues[1])
|
||||
{
|
||||
case "minute":
|
||||
time *= 60;
|
||||
break;
|
||||
case "hour":
|
||||
time *= 60 * 60;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb4fe076c92383b438b557433015250e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
37
Assets/Oculus/Voice/Demo/Scripts/BuiltinDemo/TimerDisplay.cs
Normal file
37
Assets/Oculus/Voice/Demo/Scripts/BuiltinDemo/TimerDisplay.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
/**************************************************************************************************
|
||||
* Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
*
|
||||
* Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
* ANY KIND, either express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
**************************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Oculus.Voice.Demo.BuiltInDemo
|
||||
{
|
||||
public class TimerDisplay : MonoBehaviour
|
||||
{
|
||||
public TimerController timer;
|
||||
|
||||
private Text _uiText;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_uiText = GetComponent<Text>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// Note: This is not optimized and you should avoid updating time each frame.
|
||||
_uiText.text = timer.GetFormattedTimeFromSeconds();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dacc4d06eebcecb4a846759a3ac9f6e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
/**************************************************************************************************
|
||||
* Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
*
|
||||
* Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
* ANY KIND, either express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
**************************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Demo.BuiltInDemo
|
||||
{
|
||||
public class WitActivation : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private AppVoiceExperience voiceExperience;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if (!voiceExperience) voiceExperience = GetComponent<AppVoiceExperience>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
voiceExperience = GetComponent<AppVoiceExperience>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Make it possible to activate wit in the Unity Editor without the need to deploy to the headset.
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
print("*** Pressed Space bar ***");
|
||||
ActivateWit();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates Wit i.e. start listening to the user.
|
||||
/// </summary>
|
||||
public void ActivateWit()
|
||||
{
|
||||
voiceExperience.Activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3699a21444dc7164289344371a620e0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user