我有一个增强现实移动应用程序,其中声音会自动为特定的图像目标播放,当目标丢失时声音会停止。我需要的是如何在仍然聚焦于该图像目标的同时,通过使用按钮来重复声音。
示例:
Image target - Apple
Sound - Letter A sound
Image target- Banana
Sound - Letter B sound
当我专注于苹果的图像目标时,会发出字母A的声音。我该如何使用按钮来重复这种声音,这样我就不必再次专注于图像目标了。
答案 0 :(得分:0)
有多种方法可以做到这一点
通常,您将拥有一个带有公共方法的组件,例如
<?php
$first = ( $per_page * $paged ) - $per_page;
$last = min( $total, $per_page * $paged );
$current = isset( $paged ) ? $paged : wc_get_loop_prop( 'current_page' );
$base = isset( $base ) ? '' : esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) );
$format = isset( $format ) ? '?page=%#%' : '%#%';
echo paginate_links( apply_filters( 'woocommerce_pagination_args', array( // WPCS: XSS ok.
'base' => $base,
'format' => $format,
'add_args' => false,
'current' => max( 1, $current ),
'total' => ceil($total / $per_page),
'prev_text' => '←',
'next_text' => '→',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3,
) ) );
?>
将其放在public class SoundController : MonoBehaviour
{
// here you reference your Scene's AudioSource in the inspector
// e.g. via drag and drop
[SerializeField] private AudioSource _audioSource;
// Here you reference the according AudioClips
[SerializeField] private AudioClip _letterASound;
[SerializeField] private AudioClip _letterBSound;
// an enum makes it esier to find the correct letter later
public enum Letter
{
A,
B
// etc
}
// store the current Sound to be played
public Letter CurrentLetter;
private Button _button;
// a dictionary makes it easy to find the according sound for a specific letter
private Dictionary<Letter, AudioClip> _sounds;
private void Awake()
{
// initialize the dictionary
_sounds = new Dictionary<Letter, AudioClip>()
{
{A, _lettarASound},
{B, _letterBSound}
}
// get the Button component
_button = GetComponent<Button>();
// add an onclick callback for the button
// (it is save to allways first remove the callback to avoid double calls)
_button.onClick.RemoveListener(PlayCurrentSound);
_button.onClick.AddListener(PlayCurrentSound);
}
// make it public so you could even call it from somewhere else if needed
public void PlayCurrentSound()
{
AudioSource.PlayOneShot(_sounds[CurrentLetter]);
}
}
组件旁边的按钮上,并引用Button
和AudioSource
(当然,可以根据需要添加更多内容)。
现在,剩下的就是每次将鼠标悬停在新的字母上时都更改AudioClip
。我不知道您的代码看起来如何,但是您会添加类似的内容
CurrentLetter
因此,下次您按下按钮时,它将播放A的声音。