当前位置: 首页>>代码示例>>C#>>正文


C# UIButton.SubscribeToEvent方法代码示例

本文整理汇总了C#中UIButton.SubscribeToEvent方法的典型用法代码示例。如果您正苦于以下问题:C# UIButton.SubscribeToEvent方法的具体用法?C# UIButton.SubscribeToEvent怎么用?C# UIButton.SubscribeToEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UIButton的用法示例。


在下文中一共展示了UIButton.SubscribeToEvent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SampleSelector

        public SampleSelector()
        {
            sampleRef = null;

            var rootLayout = new UILayout();
            rootLayout.Axis = UI_AXIS.UI_AXIS_Y;
            rootLayout.Rect = UIView.Rect;
            UIView.AddChild(rootLayout);

            SubscribeToEvent<KeyDownEvent>(e =>
            {
                if (e.Key == Constants.KEY_ESCAPE)
                    GetSubsystem<Engine>().Exit();
            });

            #if ATOMIC_DESKTOP || ATOMIC_MOBILE
            var sampleTypes = typeof(Sample).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(Sample)) && t != typeof(Sample) ).ToArray();
            foreach (var sample in sampleTypes)
            {
                var button = new UIButton();
                button.Text = sample.Name;

                button.SubscribeToEvent<WidgetEvent>( button,  e =>
                {
                    // We're only interested in clicks
                    if (e.Type != UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
                        return;

                    // set the event as handled, as the UI is about to go away
                    e.Handled = true;

                    // Goodbye UI
                    UIView.RemoveChild(rootLayout);

                    sampleRef = (Sample) Activator.CreateInstance(sample);
                    sampleRef.Start();

                    UnsubscribeFromEvent<KeyDownEvent>();

                });

                rootLayout.AddChild(button);

            }
            #endif
        }
开发者ID:Type1J,项目名称:AtomicExamples,代码行数:46,代码来源:SampleSelector.cs

示例2: 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)
//.........这里部分代码省略.........
开发者ID:Type1J,项目名称:AtomicExamples,代码行数:101,代码来源:14_SoundEffects.cs


注:本文中的UIButton.SubscribeToEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。