User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Gamepad Support?

10 Aug 2014, 23:32

Because I need to get that element from the script code using FindName:
var start = root.FindName<Button>("start");
start.Focus()
That way, the focus starts in the centered button.
 
S0L0
Topic Author
Posts: 18
Joined: 07 Aug 2014, 14:49

Re: Gamepad Support?

11 Aug 2014, 02:32

I am liking XAML the more I learn it. :)

Now I am trying to have the menu slide in by playing an animation on the grid when DPadUp is pressed, however it doesn't seem to be working correctly. Also, is it possible to play the animation in reverse when for example menuOnScreen = true?

using System;
using UnityEngine;
using InControl;
using Noesis;


namespace BasicExample
{
	public class Controller : MonoBehaviour
	{
		NoesisGUIPanel noesisGUI_;
		private Storyboard _ani;
		private Grid _root;
		
		void Start()
		{
			noesisGUI_ = GetComponent<NoesisGUIPanel>();
			var root = noesisGUI_.GetRoot<Grid>();
			_ani = root.FindStringResource<Storyboard> ("animation");
			var start = root.FindName<Button>("start");
			start.Focus();

		}
		
		private void Handle(OneAxisInputControl input, Noesis.Key key)
		{
			if (input.WasPressed)
			{
				noesisGUI_.KeyDown(key);
			}
			
			if (input.WasReleased)
			{
				noesisGUI_.KeyUp(key);
			}
		}
		
		private void Handle(InputControl input, Noesis.Key key)
		{
			if (input.WasPressed)
			{
				noesisGUI_.KeyDown(key);
			}
			
			if (input.WasReleased)
			{
				noesisGUI_.KeyUp(key);
			}
		}
		
		void Update()
		{
			// Use last device which provided input.
			var inputDevice = InputManager.ActiveDevice;

			//Menu Navigation
			Handle(inputDevice.DPadLeft, Key.Left);
			Handle(inputDevice.DPadRight, Key.Right);

			//Menu Toggle
			if (inputDevice.DPadUp.WasPressed)
			{
				_ani.Begin(_root);
			}

			//Button
			Handle(inputDevice.DPadDown, Key.Space);
		}
	}
}

 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Gamepad Support?

12 Aug 2014, 15:43

I am liking XAML the more I learn it. :)
Now I am trying to have the menu slide in by playing an animation on the grid when DPadUp is pressed, however it doesn't seem to be working correctly. Also, is it possible to play the animation in reverse when for example menuOnScreen = true?
Hi!

What is the problem with the animation? Does it behave properly on Blend? The way you are activating it seems to be correct.

You can activate AutoReverse in the animations but I think that is not what you want. I think you will have to create two animations, one forward and another backward.
 
S0L0
Topic Author
Posts: 18
Joined: 07 Aug 2014, 14:49

Re: Gamepad Support?

12 Aug 2014, 23:22

 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Gamepad Support?

12 Aug 2014, 23:30

Have you verified that _root and _ani are not null?

Please, paste us here the entire XAML you are using.
 
S0L0
Topic Author
Posts: 18
Joined: 07 Aug 2014, 14:49

Re: Gamepad Support?

12 Aug 2014, 23:33


<Grid
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   mc:Ignorable="d">
	<Grid.Resources>
		<Storyboard x:Key="animation">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid">
				<EasingDoubleKeyFrame KeyTime="0" Value="-85.5"/>
				<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>
	</Grid.Resources>

    <Grid x:Name="grid" HorizontalAlignment="Center" VerticalAlignment="Top" KeyboardNavigation.DirectionalNavigation="Cycle" RenderTransformOrigin="0.5,0.5">
    	<Grid.RenderTransform>
    		<TransformGroup>
    			<ScaleTransform/>
    			<SkewTransform/>
    			<RotateTransform/>
    			<TranslateTransform/>
    		</TransformGroup>
    	</Grid.RenderTransform>
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
      </Grid.RowDefinitions>

      <Button Content="Button" Padding="20" FontSize="20" Grid.Row="1" Grid.Column="0" />
      <Button Content="Button" x:Name="start" Padding="20" FontSize="20" Grid.Row="1" Grid.Column="1" />
      <Button Content="Button" Padding="20" FontSize="20" Grid.Row="1" Grid.Column="2" />
    </Grid>
  
</Grid>
		
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Gamepad Support?

12 Aug 2014, 23:50

The problem is at this line of your code:
var root = noesisGUI_.GetRoot<Grid>();
it should be:
_root = noesisGUI_.GetRoot<Grid>();
Although I would expect an error in the C# (null object or something like that) instead of a crash error in C land. I will investigate it.
 
S0L0
Topic Author
Posts: 18
Joined: 07 Aug 2014, 14:49

Re: Gamepad Support?

12 Aug 2014, 23:56

 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Gamepad Support?

12 Aug 2014, 23:58

It is the same error. Are you sure you updated the script? It is working fine here:
using System;
using UnityEngine;
using InControl;
using Noesis;


namespace BasicExample
{
    public class Controller : MonoBehaviour
    {
        NoesisGUIPanel noesisGUI_;
        private Storyboard _ani;
        private Grid _root;

        void Start()
        {
            noesisGUI_ = GetComponent<NoesisGUIPanel>();
            _root = noesisGUI_.GetRoot<Grid>();
            _ani = _root.FindStringResource<Storyboard>("animation");
            var start = _root.FindName<Button>("start");
            start.Focus();
        }

        private void Handle(OneAxisInputControl input, Noesis.Key key)
        {
            if (input.WasPressed)
            {
                noesisGUI_.KeyDown(key);
            }

            if (input.WasReleased)
            {
                noesisGUI_.KeyUp(key);
            }
        }

        private void Handle(InputControl input, Noesis.Key key)
        {
            if (input.WasPressed)
            {
                noesisGUI_.KeyDown(key);
            }

            if (input.WasReleased)
            {
                noesisGUI_.KeyUp(key);
            }
        }

        void Update()
        {
             // Use last device which provided input.
             var inputDevice = InputManager.ActiveDevice;

             //Menu Navigation
             Handle(inputDevice.DPadLeft, Key.Left);
             Handle(inputDevice.DPadRight, Key.Right);

             //Menu Toggle
             if (inputDevice.DPadUp.WasPressed)
             {
                _ani.Begin(_root);
             }

             //Button
             Handle(inputDevice.DPadDown, Key.Space);
        }
    }
}


 
S0L0
Topic Author
Posts: 18
Joined: 07 Aug 2014, 14:49

Re: Gamepad Support?

13 Aug 2014, 00:02

Its working now, thanks again.

Who is online

Users browsing this forum: No registered users and 1 guest