wiki.sine.space | sinespace

Difference between revisions of "Scripting/SClickable"

From wiki.sine.space
Jump to: navigation, search
(Added the Navbox)
Line 2: Line 2:
  
 
==Properties==
 
==Properties==
 +
{{ScriptFunction|bool|Enabled|{get;set;}|Enable or disable the clickable component from a GameObject.|5=
 +
Scene = Space.Scene;<br>
 +
Cube = Scene.Find("Cube");<br>
 +
Clickable=Cube.AddClickable();<br>
 +
Clickable.Enabled = false;<br>
 +
''--Set clickable active.''}}
  
 
{{ScriptFunction|string|Tooltip|{get;set;}|A hint that pops up when the mouse is hovering over the GameObject.|5=
 
{{ScriptFunction|string|Tooltip|{get;set;}|A hint that pops up when the mouse is hovering over the GameObject.|5=

Revision as of 08:06, 16 December 2020

The SClickable class provides tools to work with the Clickable component, which is responsible for interacting with the object through clicking on it.

Properties

Enabled

bool Enabled {get;set;}

Enable or disable the clickable component from a GameObject.

Scene = Space.Scene;

Cube = Scene.Find("Cube");
Clickable=Cube.AddClickable();
Clickable.Enabled = false;

--Set clickable active.


Tooltip

string Tooltip {get;set;}

A hint that pops up when the mouse is hovering over the GameObject.

hostObject = Space.Host.ExecutingObject;

hostObject.AddClickable();

Space.Log(hostObject.Clickable.Tooltip);
-- Prints an empty string to the console - Tooltip is empty upon initializing.
hostObject.Clickable.Tooltip = "I am clickable!";

-- Now, when a mouse is hovered for a few seconds over the object, "I am clickable!" will appear.


Members

AddExtraAction

void AddExtraAction (string name, string tooltip, Action e)

Add a new action for the object to perform when clicked. Can be useful for providing miltuple choice of an action on click.

hostObject = Space.Host.ExecutingObject;

hostObject.AddClickable();

function ClickMe ()

Space.Log("I was clicked!");

end

hostObject.Clickable.AddExtraAction ("Click me", "Prints I was clicked! to the console", ClickMe);


AddExtraAction

void AddExtraAction (string name, string tooltip, Closure e)

Add a new action for the object to perform when clicked. Can be useful for providing miltuple choice of an action on click.

hostObject = Space.Host.ExecutingObject;

hostObject.AddClickable();

function ClickMeAndCount ()

local n = 0;
return function ()
n = n+1;
Space.Log("I was clicked " .. n .. " times!");
end

end

local f = ClickMeAndCount ();
hostObject.Clickable.AddExtraAction ("Click me and count", "Prints to the console how many times I was clicked", f);

-- Hint: try adding the action from the example above to this script - now you can choose from 2 actions when you click!


ClearActions

void ClearActions ()

Removes all actions from the clickable GameObject.

hostObject = Space.Host.ExecutingObject;

hostObject.AddClickable();

function ClickMe ()

Space.Log("I was clicked!");

end
function ClickAndClear ()

Space.Log("No more actions!");
hostObject.Clickable.ClearActions ();

end

hostObject.Clickable.AddExtraAction ("Click me", "Prints I was clicked! to the console", ClickMe);
hostObject.Clickable.AddExtraAction ("Click And Clear", "Clears all actions", ClickAndClear);

-- Now, when the latter option is chosen, the script clears the Clickable component of all actions.


OnClick

void OnClick (Action e)

When clicked, the GameObject performs the required action.

hostObject = Space.Host.ExecutingObject;

hostObject.AddClickable();
local deltaPos = Vector.New(0,0,1);

function MakeMeMove ()

hostObject.WorldPosition = hostObject.WorldPosition + deltaPos;

end

hostObject.Clickable.OnClick (MakeMeMove);

-- Now, every time an object is clicked, it moves by 1 in the positive Z direction.


OnClick

void OnClick (Closure e)

When clicked, the GameObject performs the required action.

hostObject = Space.Host.ExecutingObject;

hostObject.AddClickable();

function ClickAndCount ()

n = 0;
return function ()
n = n+1;
Space.Log("I was clicked " .. n .. " times!");
end

end

local f = ClickAndCount ();

hostObject.Clickable.OnClick (f);