Grimmy
Topic Author
Posts: 5
Joined: 04 Sep 2013, 12:46

Unity3d -Javascript Examples?

04 Sep 2013, 12:49

Hi all, are there any examples of Noesis integrating with Javascript/Unityscript inside Unity3d?

I'm just trying to register a very simple button click in Unity button I am stumped at the start.

I'm getting the following error :BCE0164: Cannot infer generic arguments for method 'NoesisGUIPanel.GetRoot.<T>()'. Provide stronger type information through arguments, or explicitly state the generic arguments.

I get this error in the GetRoot command. Maybe I'm not using it right? It seems to be declared okay initially. Here's the code....
//--------------------------Javascript---------------
 
var button01 : Noesis.Button;
var button02 : Noesis.Button;
var mainGUI : NoesisGUIPanel;
var grid : Noesis.Grid;
 
function Start () {
 
                mainGUI = this.gameObject.GetComponent(NoesisGUIPanel);
                grid = mainGUI.GetRoot();
}
//---------------------------
Thanks all!
Simon
 
Shorinji
Posts: 24
Joined: 16 Aug 2013, 19:45
Location: Shanghai

Re: Unity3d -Javascript Examples?

04 Sep 2013, 13:02

Hi,
This function takes a generic type. When i modify your code into the following :
var button01 : Noesis.Button;
var button02 : Noesis.Button;
var mainGUI : NoesisGUIPanel;
var grid : Noesis.Grid;

function Start () {
 
                mainGUI = this.gameObject.GetComponent(NoesisGUIPanel);
                grid = mainGUI.GetRoot.<Noesis.Grid>();
}
the error disappears.
I'm not a javascript user though, so i don't know if it's a viable to use javascript with NoesisGUi on the long run.
 
Grimmy
Topic Author
Posts: 5
Joined: 04 Sep 2013, 12:46

Re: Unity3d -Javascript Examples?

04 Sep 2013, 13:32

Cool thanks. Now my next step also gives me an error when I run the game...
InvalidCastException: Cannot cast from source type to destination type. I's clearly something to do with the button click function. I am trying to retrofit from the C# examples on the site.

Any ideas>
function Start () {

	mainGUI = this.gameObject.GetComponent(NoesisGUIPanel);
	grid = mainGUI.GetRoot.<Noesis.Grid>();
	
	 button01 = grid.FindName("Button01");
	 button01.Click+=Button1Clicked;
}
function Button1Clicked()
{
	print("Button01 clicked!!!");
}
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unity3d -Javascript Examples?

04 Sep 2013, 13:41

Using javascript with NoesisGUI is something we haven't yet investigated. Majority of users are using C#. Anyway the following code does what you want and it is working, I just tested it.
#pragma strict
     
import Noesis;
     
var _btn : Button;
     
function Start ()
{
    var gui = GetComponent.<NoesisGUIPanel>();
    var root = gui.GetRoot.<FrameworkElement>();
    _btn = root.FindName.<Button>("btn");
    _btn.Click += OnBtnClick;
}
     
function OnBtnClick()
{
    Debug.Log("Button clicked");
}
 
Grimmy
Topic Author
Posts: 5
Joined: 04 Sep 2013, 12:46

Re: Unity3d -Javascript Examples?

04 Sep 2013, 14:02

Cool, I got a slight variation on your code working fine. Hopefully JS will be supported/encouraged because there's a lot of users out there. Here's the code that works perfectly in Unity3d..
var button01 : Noesis.Button;
var mainGUI : NoesisGUIPanel;
var grid : Noesis.Grid;

function Start () {

	mainGUI = this.gameObject.GetComponent(NoesisGUIPanel);
	grid = mainGUI.GetRoot.<Noesis.Grid>();
	
	 button01 = grid.FindName.<Noesis.Button>("Button01");
	 button01.Click+=Button1Clicked;
}
function Button1Clicked()
{
	print("Button01 clicked!!!");
}

Who is online

Users browsing this forum: Google [Bot] and 1 guest