Hi
Here is my test code below:
button.xaml:
<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>
<StackPanel Background="Ivory" Orientation="Horizontal">
<Canvas Width="10"/>
<Button x:Name="t1" Width="100" Height="30" FocusVisualStyle="{DynamicResource MyFocusVisual}">
Focus 1
</Button>
<Canvas Width="100"/>
<Button x:Name="t2" Width="100" Height="30" FocusVisualStyle="{DynamicResource MyFocusVisual}">
Focus 2
</Button>
</StackPanel>
</Grid>
</Grid>
Dictionary1.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication3">
<Style x:Key="MyFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="-8" StrokeThickness="1" Stroke="Red"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Button.cs:
using UnityEngine;
using System.Collections;
using System;
public class Button : MonoBehaviour {
int count = 0;
int countGUI = 0;
NoesisGUIPanel noesisguipanel;
Noesis.Grid _gridroot;
Noesis.Button _button1;
// Use this for initialization
void Start () {
noesisguipanel = GetComponent<NoesisGUIPanel>();
_gridroot = noesisguipanel.GetRoot<Noesis.Grid>();
_button1 = _gridroot.FindName<Noesis.Button>("t1");
_button1.Focus();
_button1.Click += _button1_click;
}
public void _button1_click(object sender, Noesis.RoutedEventArgs e)
{
for(int i =0; i< Input.GetJoystickNames().Length; i++)
{
Debug.Log("Key:" + i + "Name:" + Input.GetJoystickNames()[i]);
}
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
Debug.Log("the current focus:" + UnityEngine.Event.current.keyCode.ToString());
}
}
When i run this test in Unity,i pressed the keyboard in the order of up,left,down and right,and unity logged this out:
log on Unity Console:
the current focus:None
UnityEngine.Debug:Log(Object)
Button:OnGUI() (at Assets/ButtonTest/Button.cs:45)
the current focus:UpArrow
UnityEngine.Debug:Log(Object)
Button:OnGUI() (at Assets/ButtonTest/Button.cs:45)
the current focus:LeftArrow
UnityEngine.Debug:Log(Object)
Button:OnGUI() (at Assets/ButtonTest/Button.cs:45)
the current focus:DownArrow
UnityEngine.Debug:Log(Object)
Button:OnGUI() (at Assets/ButtonTest/Button.cs:45)
the current focus:RightArrow
UnityEngine.Debug:Log(Object)
Button:OnGUI() (at Assets/ButtonTest/Button.cs:45)
When i compiled this in Android package and installed on TV,with remote control button pressed,the log was printed on eclipse:
log on eclipse:
03-16 17:33:18.220: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.220: I/Unity(20596): The current focus : JoystickButton3
03-16 17:33:18.220: I/Unity(20596):
03-16 17:33:18.220: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.230: E/InputDispatcher(1691): keyCode 96,scanCode 304
03-16 17:33:18.230: D/AliTVASR(2859): AliTVASR(TVSensorDevice)->(1)->TVSensorDevice, received DKeyEvent:mData:mSize=1, mKeyCodes[0]=96, mActions[0]=0
03-16 17:33:18.230: D/WindowManager(1691): keycode is 96 , and POWER is 26
03-16 17:33:18.230: D/PowerManagerService(1691): AliScreenSaver:MSG_USER_ACTIVITY_TIMEOUT is sent.... delta = 863992999
03-16 17:33:18.230: D/PowerManagerService(1691): AliScreenSaver:MSG_ALI_SCREEN_SAVER_TIMEOUT is sent.... delta = 431999999
03-16 17:33:18.240: I/Unity(20596): The current focus : JoystickButton3
03-16 17:33:18.240: I/Unity(20596):
03-16 17:33:18.240: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.240: I/Unity(20596): The current focus : JoystickButton3
03-16 17:33:18.240: I/Unity(20596):
03-16 17:33:18.240: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.250: I/Unity(20596): The current focus : Joystick1Button0
03-16 17:33:18.400: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.410: E/InputDispatcher(1691): keyCode 100,scanCode 308
03-16 17:33:18.410: D/WindowManager(1691): keycode is 100 , and POWER is 26
03-16 17:33:18.410: D/AliTVASR(2859): AliTVASR(TVSensorDevice)->(1)->TVSensorDevice, received DKeyEvent:mData:mSize=1, mKeyCodes[0]=100, mActions[0]=0
03-16 17:33:18.420: E/InputDispatcher(1691): keyCode 96,scanCode 304
03-16 17:33:18.420: D/WindowManager(1691): keycode is 96 , and POWER is 26
03-16 17:33:18.420: D/AliTVASR(2859): AliTVASR(TVSensorDevice)->(1)->TVSensorDevice, received DKeyEvent:mData:mSize=1, mKeyCodes[0]=96, mActions[0]=1
03-16 17:33:18.420: I/Unity(20596): The current focus : JoystickButton0
03-16 17:33:18.420: I/Unity(20596):
03-16 17:33:18.420: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.420: I/Unity(20596): The current focus : JoystickButton0
Can you point out what is going on? am i missing anything? Thanks in advance
