本文整理汇总了C#中UISlider.SetLimits方法的典型用法代码示例。如果您正苦于以下问题:C# UISlider.SetLimits方法的具体用法?C# UISlider.SetLimits怎么用?C# UISlider.SetLimits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UISlider
的用法示例。
在下文中一共展示了UISlider.SetLimits方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateUI
void CreateUI()
{
var cache = GetSubsystem<ResourceCache>();
var layout = new UILayout() { Axis = UI_AXIS.UI_AXIS_Y };
layout.Rect = UIView.Rect;
UIView.AddChild(layout);
// Create a scene which will not be actually rendered, but is used to hold SoundSource components while they play sounds
scene = new Scene();
// Create buttons for playing back sounds
foreach (var item in sounds)
{
var button = new UIButton();
layout.AddChild(button);
button.Text = item.Key;
button.SubscribeToEvent<WidgetEvent>(button, e => {
if (e.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
{
// Get the sound resource
Sound sound = cache.Get<Sound>(item.Value);
if (sound != null)
{
// Create a scene node with a SoundSource component for playing the sound. The SoundSource component plays
// non-positional audio, so its 3D position in the scene does not matter. For positional sounds the
// SoundSource3D component would be used instead
Node soundNode = scene.CreateChild("Sound");
SoundSource soundSource = soundNode.CreateComponent<SoundSource>();
soundSource.Play(sound);
// In case we also play music, set the sound volume below maximum so that we don't clip the output
soundSource.Gain = 0.75f;
// Set the sound component to automatically remove its scene node from the scene when the sound is done playing
}
}
});
}
// Create buttons for playing/stopping music
var playMusicButton = new UIButton();
layout.AddChild(playMusicButton);
playMusicButton.Text = "Play Music";
playMusicButton.SubscribeToEvent<WidgetEvent> (playMusicButton, e => {
if (e.Type != UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
return;
if (scene.GetChild ("Music", false) != null)
return;
var music = cache.Get<Sound>("Music/StoryTime.ogg");
music.Looped = true;
Node musicNode = scene.CreateChild ("Music");
SoundSource musicSource = musicNode.CreateComponent<SoundSource> ();
// Set the sound type to music so that master volume control works correctly
musicSource.SetSoundType ("Music");
musicSource.Play (music);
});
var audio = GetSubsystem<Audio>();
// FIXME: Removing the music node is not stopping music
var stopMusicButton = new UIButton();
layout.AddChild(stopMusicButton);
stopMusicButton.Text = "Stop Music";
stopMusicButton.SubscribeToEvent<WidgetEvent>(stopMusicButton, e =>
{
if (e.Type != UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
return;
scene.RemoveChild(scene.GetChild("Music", false));
});
// Effect Volume Slider
var slider = new UISlider();
layout.AddChild(slider);
slider.SetLimits(0, 1);
slider.Text = "Sound Volume";
slider.SubscribeToEvent<WidgetEvent>(slider, e =>
{
if (e.Type != UI_EVENT_TYPE.UI_EVENT_TYPE_CHANGED)
return;
Log.Info($"Setting Effects to {slider.Value}");
audio.SetMasterGain("Effect", slider.Value);
});
// Music Volume Slider
var slider2 = new UISlider();
layout.AddChild(slider2);
slider2.SetLimits(0, 1);
slider2.Text = "Music Volume";
slider2.SubscribeToEvent<WidgetEvent>(slider2, e =>
{
if (e.Type != UI_EVENT_TYPE.UI_EVENT_TYPE_CHANGED)
//.........这里部分代码省略.........