wiki.sine.space | sinespace

Difference between revisions of "Scripting/SClickable"

From wiki.sine.space
Jump to: navigation, search
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/sclickable")
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
The SClickable class provides tools to work with the Clickable component, which is responsible for interacting with the object through clicking on it.
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/sclickable
 
+
==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=
+
hostObject = Space.Host.ExecutingObject;<br>
+
hostObject.AddClickable();<br><br>
+
Space.Log(hostObject.Clickable.Tooltip);<br>
+
''-- Prints an empty string to the console - Tooltip is empty upon initializing.''<br>
+
hostObject.Clickable.Tooltip = "I am clickable!";<br>
+
''-- Now, when a mouse is hovered for a few seconds over the object, "I am clickable!" will appear.''|6=<pre>--Clicking the object will toggle between two different tooltips
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
 
+
OnClick = function()
+
  if thisGameObject.Clickable.Tooltip == "Turn On" then
+
    thisGameObject.Clickable.Tooltip = "Turn Off"
+
  else
+
    thisGameObject.Clickable.Tooltip = "Turn On"
+
  end
+
end
+
 
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.Tooltip = "Turn On"
+
thisGameObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
==Members==
+
 
+
{{ScriptFunction|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.|5=
+
hostObject = Space.Host.ExecutingObject;<br>
+
hostObject.AddClickable();<br><br>
+
function ClickMe () <br>
+
:Space.Log("I was clicked!");<br>
+
end<br><br>
+
hostObject.Clickable.AddExtraAction ("Click me", "Prints I was clicked! to the console", ClickMe);}}
+
 
+
{{ScriptFunction|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.|5=
+
hostObject = Space.Host.ExecutingObject;<br>
+
hostObject.AddClickable();<br><br>
+
function ClickMeAndCount ()<br>
+
:local n = 0; <br>
+
:return function ()<br>
+
::n = n+1;<br>
+
::Space.Log("I was clicked " .. n .. " times!");<br>
+
:end<br>
+
end<br><br>
+
local f = ClickMeAndCount ();<br>
+
hostObject.Clickable.AddExtraAction ("Click me and count", "Prints to the console how many times I was clicked", f);<br>
+
''-- Hint: try adding the action from the example above to this script - now you can choose from 2 actions when you click!''}}
+
 
+
{{ScriptFunction|void|ClearActions|()|Removes all actions from the clickable GameObject.|5=
+
hostObject = Space.Host.ExecutingObject;<br>
+
hostObject.AddClickable();<br><br>
+
function ClickMe () <br>
+
:Space.Log("I was clicked!");<br>
+
end<br>
+
function ClickAndClear ()<br>
+
:Space.Log("No more actions!");<br>
+
:hostObject.Clickable.ClearActions ();<br>
+
end<br><br>
+
hostObject.Clickable.AddExtraAction ("Click me", "Prints I was clicked! to the console", ClickMe);<br>
+
hostObject.Clickable.AddExtraAction ("Click And Clear", "Clears all actions", ClickAndClear);<br>
+
''-- Now, when the latter option is chosen, the script clears the Clickable component of all actions.''}}
+
 
+
{{ScriptFunction|void|OnClick|(Action e)|When clicked, the GameObject performs the required action.|5=
+
hostObject = Space.Host.ExecutingObject;<br>
+
hostObject.AddClickable();<br>
+
local deltaPos = Vector.New(0,0,1);<br><br>
+
function MakeMeMove () <br>
+
:hostObject.WorldPosition = hostObject.WorldPosition + deltaPos;<br>
+
end<br><br>
+
hostObject.Clickable.OnClick (MakeMeMove);<br>
+
''-- Now, every time an object is clicked, it moves by 1 in the positive Z direction.''}}
+
 
+
{{ScriptFunction|void|OnClick|(Closure e)|When clicked, the GameObject performs the required action.|5=
+
hostObject = Space.Host.ExecutingObject;<br>
+
hostObject.AddClickable();<br><br>
+
function ClickAndCount () <br>
+
:n = 0;<br>
+
:return function ()<br>
+
::n = n+1;<br>
+
::Space.Log("I was clicked " .. n .. " times!");<br>
+
:end<br>
+
end<br><br>
+
local f = ClickAndCount ();<br>
+
hostObject.Clickable.OnClick (f);}}
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 05:32, 19 September 2022

This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/sclickable