wiki.sine.space | sinespace

Difference between revisions of "Scripting/SAnimator"

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/sanimator")
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/sanimator
==Members==
+
{{ScriptFunction|void|CrossFade|(string stateName, float transitionDuration);|Creates a dynamic transition between the current state and the destination state.
+
stateName: The name of the destination state.
+
transitionDuration: The duration of the transition. Value is in source state normalized time.|5=<pre>Space.Host.ExecutingObject.Animator.CrossFade("State Name", 3.0)</pre> |6=<pre>--clicking the object will make it's animator crossfade from current state to "Second State"
+
--Crossfade duration will be triple the length of Source state
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.CrossFade("Second State", 3.0) --add a main state and "Second State" in Animator Controller
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|CrossFade|(string stateName, float transitionDuration, int layer);|Creates a dynamic transition between the current state and the destination state.
+
stateName: The name of the destination state.
+
transitionDuration: The duration of the transition. Value is in source state normalized time.
+
layer: Layer index containing the destination state. If no layer is specified or layer is -1, the first state that is found with the given name or hash will be played.|5=<pre>Space.Host.ExecutingObject.Animator.CrossFade("State Name", 3.0, 0)</pre>|6=<pre>--clicking the object will make it's animator crossfade from current state to "Second State" (on a second layer)
+
--Crossfade duration will be triple the length of Source state
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.CrossFade("Second State", 3.0, 1)
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|CrossFade|(string stateName, float transitionDuration, int layer, float normalizedTime);|Creates a dynamic transition between the current state and the destination state.
+
stateName: The name of the destination state.
+
transitionDuration: The duration of the transition. Value is in source state normalized time.
+
layer: Layer index containing the destination state. If no layer is specified or layer is -1, the first state that is found with the given name or hash will be played.
+
normalizedTime: Start time of the current destination state. Value is in source state normalized time, should be between 0 and 1. If no explicit normalizedTime is specified or normalizedTime value is float.NegativeInfinity, the state will either be played from the start if it's not already playing, or will continue playing from its current time and no transition will happen.
+
|5=<pre>Space.Host.ExecutingObject.Animator.CrossFade("State Name", 3.0, 0 , 0.0)</pre>|6=<pre>--clicking the object will make it's animator crossfade from current state to the middle of "Second State" (on the second layer)
+
--Crossfade duration will be triple the length of Source state
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.CrossFade("Second State", 3.0, 1, 0.5)
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|CrossFadeInFixedTime|(string stateName, float transitionDuration);|Creates a dynamic transition between the current state and the destination state. The duration and offset in the target state are in fixed time.
+
stateName: The name of the destination state.
+
transitionDuration: The duration of the transition. Value is in seconds.|5=<pre><pre>Space.Host.ExecutingObject.Animator.CrossFadeInFixedTime("State Name", 15.0)</pre>|6=<pre>--clicking the object will make it's animator crossfade from current state to "Second State" in 3 seconds
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.CrossFadeInFixedTime("Second State", 3.0) --add a main state and "Second State" in Animator Controller
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|CrossFadeInFixedTime|(string stateName, float transitionDuration, int layer);|Creates a dynamic transition between the current state and the destination state. The duration and offset in the target state are in fixed time.
+
stateName: The name of the destination state.
+
transitionDuration: The duration of the transition. Value is in seconds.
+
layer: Layer index containing the destination state. If no layer is specified or layer is -1, the first state that is found with the given name or hash will be played.|5=<pre><pre>Space.Host.ExecutingObject.Animator.CrossFadeInFixedTime("State Name", 15.0, 0)</pre>|6=<pre>--clicking the object will make it's animator crossfade from current state to "Second State" (on a second layer) in 3 seconds
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.CrossFadeInFixedTime("Second State", 3.0, 1)
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|CrossFadeInFixedTime|(string stateName, float transitionDuration, int layer, float fixedTime);|Creates a dynamic transition between the current state and the destination state. The duration and offset in the target state are in fixed time.
+
stateName: The name of the destination state.
+
transitionDuration: The duration of the transition. Value is in seconds.
+
layer: Layer index containing the destination state. If no layer is specified or layer is -1, the first state that is found with the given name or hash will be played.
+
fixedTime: Start time of the current destination state. Value is in seconds. If no explicit fixedTime is specified or fixedTime value is float.NegativeInfinity, the state will either be played from the start if it's not already playing, or will continue playing from its current time and no transition will happen.
+
|5=<pre>Space.Host.ExecutingObject.Animator.CrossFadeInFixedTime("State Name", 15.0, 0 , 0.0)</pre>|6=<pre>--clicking the object will make it's animator crossfade from current state to the middle of "Second State" (on the second layer) in 3 seconds
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.CrossFadeInFixedTime("Second State", 3.0, 1, 0.5)
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|bool|GetBool|(string name);|Returns the value of the given boolean parameter.
+
name: The name of the parameter.|5=<pre>isFlying = Space.Host.ExecutingObject.Animator.GetBool("IsFlying")
+
Space.Log(isFlying)</pre>|6=<pre>--clicking the object will toggle it's "isFlying" bool parameter between true and false
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
if thisObject.Animator.GetBool("isFlying") == true then
+
  thisObject.Animator.SetBool("isFlying", false)
+
else
+
  thisObject.Animator.SetBool("isFlying", true)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|bool|GetBool|(int id);|Returns the value of the given boolean parameter.
+
id: The id of the parameter.|5=<pre>ID = Space.Host.ExecutingObject.Animator.StringToHash("isFlying")
+
Space.Host.ExecutingObject.Animator.GetBool(ID)</pre>|6=<pre>--clicking the object will toggle it's "isFlying" bool parameter between true and false
+
--this script uses parameter ID instead of string (StringToHash function gets the ID)
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
  parameterID = thisObject.Animator.StringToHash("isFlying")
+
 
+
if thisObject.Animator.GetBool(parameterID) == true then
+
  thisObject.Animator.SetBool(parameterID, false)
+
else
+
  thisObject.Animator.SetBool(parameterID, true)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|float|GetFloat|(string name);|Returns the value of the given float parameter.
+
name: The name of the parameter.|5=<pre>getParam = Space.Host.ExecutingObject.Animator.GetFloat("paramName")
+
Space.Log(getParam)</pre>|6=<pre>--clicking the object will toggle it's Animator's "flySpeed" float parameter between 0.0 and 5.0
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
if thisObject.Animator.GetFloat("flySpeed") == 0.0 then
+
  thisObject.Animator.SetFloat("flySpeed", 5.0)
+
else
+
  thisObject.Animator.SetFloat("flySpeed", 0.0)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|float|GetFloat|(int id);|Returns the value of the given float parameter.
+
id: The id of the parameter.|5=<pre> paramID = Space.Host.ExecutingObject.Animator.StringToHash("paramName")
+
getParam = Space.Host.ExecutingObject.Animator.GetFloat(paramID)</pre>|6=<pre>--clicking the object will toggle it's Animator's "flySpeed" float parameter between 0.0 and 5.0
+
--this script uses parameter ID instead of string (StringToHash function gets the ID)
+
 
+
thisObject = Space.Host.ExecutingObject
+
paramID = thisObject.Animator.StringToHash("flySpeed")
+
 
+
OnClick = function()
+
if thisObject.Animator.GetFloat(paramID) == 0.0 then
+
  thisObject.Animator.SetFloat(paramID, 5.0)
+
else
+
  thisObject.Animator.SetFloat(paramID, 0.0)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|int|GetInteger|(string name);|Returns the value of the given integer parameter.
+
name: The name of the parameter.|5=<pre>getParam = Space.Host.ExecutingObject.Animator.GetInteger("paramName")
+
Space.Log(getParam)</pre>|6=<pre>--clicking the object will toggle it's Animator's "jumpHeight" int parameter between 0 and 5
+
 
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
if thisObject.Animator.GetInteger("jumpHeight") == 0 then
+
  thisObject.Animator.SetInteger("jumpHeight", 1)
+
else
+
  thisObject.Animator.SetInteger("jumpHeight", 0)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|int|GetInteger|(int id);|Returns the value of the given integer parameter.
+
id: The id of the parameter.|5=<pre> paramID = Space.Host.ExecutingObject.Animator.StringToHash("paramName")
+
getParam = Space.Host.ExecutingObject.Animator.GetInteger(paramID)
+
 
+
</pre>|6=<pre>--clicking the object will toggle it's Animator's "jumpHeight" int parameter between 0 and 5
+
--this script uses parameter ID instead of string (StringToHash function gets the ID)
+
 
+
thisObject = Space.Host.ExecutingObject
+
paramID = thisObject.Animator.StringToHash("jumpHeight")
+
 
+
OnClick = function()
+
if thisObject.Animator.GetInteger(paramID ) == 0 then
+
  thisObject.Animator.SetInteger(paramID , 1)
+
else
+
  thisObject.Animator.SetInteger(paramID , 0)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|int|GetLayerIndex|(string layerName);|Gets the index of the layer with specified name.|5=<pre>layerIndex = Space.Host.ExecutingObject.Animator.GetLayerIndex("Layer Name")
+
Space.Log(layerIndex)</pre>}}
+
 
+
 
+
{{ScriptFunction|string|GetLayerName|(int layerIndex);|Gets name of the layer.|5=<pre>layerName = Space.Host.ExecutingObject.Animator.GetLayerName(1)
+
  Space.Log(layerName)</pre>}}
+
 
+
 
+
{{ScriptFunction|float|GetLayerWeight|(int layerIndex);|Gets the layer's current weight.|5=<pre>layerWeight = Space.Host.ExecutingObject.Animator.GetLayerWeight(1)
+
Space.Log(layerWeight)</pre>|6=<pre>--clicking the object will toggle the Layer Weight of your second layer (index 1) between 0.0 and 1.0
+
 
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
if thisObject.Animator.GetLayerWeight(1) == 0 then
+
  thisObject.Animator.SetLayerWeight(1, 1.0)
+
else
+
  thisObject.Animator.SetLayerWeight(1, 0.0)
+
end
+
 
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|double|GetLength|(int layer);|Current duration of the state.|5=<pre>layerStateLength = Space.Host.ExecutingObject.Animator.GetLength(1)
+
Space.Log(layerStateLength)</pre>}}
+
 
+
 
+
{{ScriptFunction|bool|GetLoop|(int layer);|Is the state looping.|5=<pre>layerStateLoop = Space.Host.ExecutingObject.Animator.GetLoop(0)
+
Space.Log(layerStateLoop)</pre>}}
+
 
+
 
+
{{ScriptFunction|double|GetNormalizedTime|(int layer);|Normalized time of the State.
+
The integer part is the number of time a state has been looped. The fractional part is the % (0-1) of progress in the current loop.|5=<pre>layerStateNormalizedTime = Space.Host.ExecutingObject.Animator.GetNormalizedTime(0)
+
Space.Log(layerStateNormalizedTime)</pre>}}
+
 
+
 
+
{{ScriptFunction|double|GetTime|();||5=<pre>layerStateTime = Space.Host.ExecutingObject.Animator.GetTime(0)
+
Space.Log(layerStateTime)</pre>}}
+
 
+
 
+
{{ScriptFunction|bool|IsInTransition|(int layer);|Is the specified layer in a transition.|5=<pre>layerTransition = Space.Host.ExecutingObject.Animator.IsInTransition(0)
+
Space.Log(layerTransition)</pre>}}
+
 
+
 
+
{{ScriptFunction|bool|IsParameterControlledByCurve|(int id);|Returns true if a parameter is controlled by an additional curve on an animation.|5=<pre></pre>}}
+
 
+
 
+
{{ScriptFunction|bool|IsParameterControlledByCurve|(string name);|Returns true if a parameter is controlled by an additional curve on an animation.|5=<pre>paramCurve = Space.Host.ExecutingObject.Animator.IsParameterControlledByCurve("parameterName")
+
Space.Log(paramCurve)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|Play|(string stateName);|Plays a state.
+
stateName: The name of the state to play.|5=<pre>Space.Host.ExecutingObject.Animator.Play("State Name")</pre>|6=<pre>--clicking the object will make it's animator play the "Second State" when clicked
+
--Object needs an Animator component linked to an Animator Controller with a state called "Second State"
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.Play("Second State")
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|Play|(string stateName, int layer);|Plays a state.
+
stateName: The name of the state to play.
+
Layer index containing the destination state. If no layer is specified or layer is -1, the first state that is found with the given name or hash will be played.|5=<pre>Space.Host.ExecutingObject.Animator.Play("State Name", 0);</pre>|6=<pre>--clicking the object will make it's animator play the "Second State" on the second Layer when clicked
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.Play("Second State",1) --add "Second State" to the second Layer in Animator Controller
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|Play|(string stateName, int layer, float normalizedTime);|Plays a state.
+
stateName: The name of the state to play.
+
Layer index containing the destination state. If no layer is specified or layer is -1, the first state that is found with the given name or hash will be played.
+
normalizedTime: Start time of the current destination state. Value is in normalized time. If no explicit normalizedTime is specified or value is float.NegativeInfinity, the state will either be played from the start if it's not already playing, or will continue playing from its current time.|5=<pre>Space.Host.ExecutingObject.Animator.Play("State Name", 0, 0.0)</pre>| 6=<pre>--clicking the object will make it's animator play the "Second State", on the second Layer, and starting half-way through when clicked
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.Play("Second State",1,0.5) --add "Second State" to the second Layer in Animator Controller
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|PlayInFixedTime|(string stateName);|Plays a state. The offset in the target state is in fixed time.
+
stateName: The name of the state to play.|5=<pre>Space.Host.ExecutingObject.Animator.PlayInFixedTime("State Name")</pre>|6=<pre>--clicking the object will make it's animator play the "Second State" when clicked
+
--Object needs an Animator component linked to an Animator Controller with a state called "Second State"
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.PlayInFixedTime("Second State")
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|PlayInFixedTime|(string stateName, int layer);|Plays a state. The offset in the target state is in fixed time.
+
stateName: The name of the state to play.
+
Layer index containing the destination state. If no layer is specified or layer is -1, the first state that is found with the given name or hash will be played.|5=<pre>Space.Host.ExecutingObject.Animator.PlayInFixedTime("State Name", 0)</pre>|6=<pre>--clicking the object will make it's animator play the "Second State" on the second Layer when clicked
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.PlayInFixedTime("Second State",1) --add "Second State" to the second Layer in Animator Controller
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|PlayInFixedTime|(string stateName, int layer, float fixedTime);|Plays a state. The offset in the target state is in fixed time.
+
stateName: The name of the state to play.
+
Layer index containing the destination state. If no layer is specified or layer is -1, the first state that is found with the given name or hash will be played.
+
fixedTime: Start time of the current destination state. Value is in seconds. If no explicit fixedTime is specified or fixedTime value is float.NegativeInfinity, the state will either be played from the start if it's not already playing, or will continue playing from its current time.|5=<pre>Space.Host.ExecutingObject.Animator.PlayInFixedTime("State Name", 0, 0.0)</pre>|6=<pre>--clicking the object will make it's animator play the "Second State", on the second Layer, and starting half a second in
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
thisObject.Animator.PlayInFixedTime("Second State",1,0.5) --add "Second State" to the second Layer in Animator Controller
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|Rebind|();|Rebind all the animated properties and mesh data with the Animator.|5=<pre>Space.Host.ExecutingObject.Animator.Rebind()</pre>}}
+
 
+
 
+
{{ScriptFunction|void|ResetTrigger|(int id);|Resets the trigger parameter to false.|5=<pre>paramID = Space.Host.ExecutingObject.Animator.StringToHash("parameterName")
+
Space.Host.ExecutingObject.Animator.ResetTrigger(paramID)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|ResetTrigger|(string name);|Resets the trigger parameter to false.|5=<pre> Space.Host.ExecutingObject.Animator.ResetTrigger("parameterName")</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetBool|(int id, bool value);|Sets the value of a boolean parameter.|5=<pre> paramID = Space.Host.ExecutingObject.Animator.StringToHash("IsFlying")
+
Space.Host.ExecutingObject.Animator.SetBool(paramID, true)</pre>|6=<pre>--clicking the object will toggle it's "isFlying" bool parameter between true and false
+
--this script uses parameter ID instead of string (StringToHash function gets the ID)
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
  parameterID = thisObject.Animator.StringToHash("isFlying")
+
 
+
if thisObject.Animator.GetBool(parameterID) == true then
+
  thisObject.Animator.SetBool(parameterID, false)
+
else
+
  thisObject.Animator.SetBool(parameterID, true)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetBool|(string name, bool value);|Sets the value of a boolean parameter.|5=<pre>Space.Host.ExecutingObject.Animator.SetBool("IsFlying", true)</pre>|6=<pre>--clicking the object will toggle it's "isFlying" bool parameter between true and false
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
if thisObject.Animator.GetBool("isFlying") == true then
+
  thisObject.Animator.SetBool("isFlying", false)
+
else
+
  thisObject.Animator.SetBool("isFlying", true)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetFloat|(int id, float value);|Sets the value of a float parameter.|5=<pre> paramID = Space.Host.ExecutingObject.Animator.StringToHash("parameterName")
+
Space.Host.ExecutingObject.Animator.SetFloat(paramID, 2.2)
+
</pre>|6=<pre>--clicking the object will toggle it's Animator's "flySpeed" float parameter between 0.0 and 5.0
+
--this script uses parameter ID instead of string (StringToHash function gets the ID)
+
 
+
thisObject = Space.Host.ExecutingObject
+
paramID = thisObject.Animator.StringToHash("flySpeed")
+
 
+
OnClick = function()
+
if thisObject.Animator.GetFloat(paramID) == 0.0 then
+
  thisObject.Animator.SetFloat(paramID, 5.0)
+
else
+
  thisObject.Animator.SetFloat(paramID, 0.0)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetFloat|(int id, float value, float dampTime, float deltaTime);|Send float values to the Animator to affect transitions.
+
dampTime: The damper total time.
+
deltaTime: The delta time to give to the damper.|5=<pre> paramID = Space.Host.ExecutingObject.Animator.StringToHash("parameterName")
+
Space.Host.ExecutingObject.Animator.SetFloat(paramID, 2.2,2.0,Space.DeltaTime)</pre>|6=<pre>--clicking the object will make it's Animator damp transition it's "danceSpeed" property from 0.0 to 5.0
+
--this script uses parameter ID instead of string (StringToHash function gets the ID)
+
 
+
thisObject = Space.Host.ExecutingObject
+
paramID = thisObject.Animator.StringToHash("danceSpeed")
+
 
+
OnClick = function()
+
  Space.Host.StartCoroutine(function()
+
      while thisObject.Animator.GetFloat(paramID ) < 5.0 do
+
thisObject.Animator.SetFloat(paramID , 5.0, 1.0, Space.DeltaTime)
+
coroutine.yield(0)
+
      end
+
 
+
end)
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetFloat|(string name, float value);|Sets the value of a float parameter.|5=<pre>Space.Host.ExecutingObject.Animator.SetFloat("parameterName", 2.2)</pre>|6=<pre>--clicking the object will toggle it's Animator's "flySpeed" float parameter between 0.0 and 5.0
+
 
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
if thisObject.Animator.GetFloat("flySpeed") == 0.0 then
+
  thisObject.Animator.SetFloat("flySpeed", 5.0)
+
else
+
  thisObject.Animator.SetFloat("flySpeed", 0.0)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetFloat|(string name, float value, float dampTime, float deltaTime);|Send float values to the Animator to affect transitions.
+
dampTime: The damper total time.
+
deltaTime: The delta time to give to the damper.|5=<pre>Space.Host.ExecutingObject.Animator.SetFloat("parameterName", 2.2,2.0,Space.DeltaTime)</pre>|6=<pre>--clicking the object will make it's Animator damp transition it's "danceSpeed" property from 0.0 to 5.0
+
 
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
  Space.Host.StartCoroutine(function()
+
      while thisObject.Animator.GetFloat("danceSpeed") < 5.0 do
+
thisObject.Animator.SetFloat("danceSpeed", 5.0, 1.0, Space.DeltaTime)
+
coroutine.yield(0)
+
      end
+
 
+
end)
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetInteger|(int id, int value);|Sets the value of the given integer parameter.|5=<pre> paramID = Space.Host.ExecutingObject.Animator.StringToHash("iParam")
+
Space.Host.ExecutingObject.Animator.SetInteger(paramID, 2)</pre>|6=<pre>--clicking the object will toggle it's Animator's "jumpHeight" int parameter between 0 and 5
+
--this script uses parameter ID instead of string (StringToHash function gets the ID)
+
 
+
thisObject = Space.Host.ExecutingObject
+
paramID = thisObject.Animator.StringToHash("jumpHeight")
+
 
+
OnClick = function()
+
if thisObject.Animator.GetInteger(paramID ) == 0 then
+
  thisObject.Animator.SetInteger(paramID , 1)
+
else
+
  thisObject.Animator.SetInteger(paramID , 0)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
{{ScriptFunction|int|StringToHash|(string name);|Generates an parameter id from a string.
+
Ids are used for optimized setters and getters on parameters.|5=<pre>ID = Space.Host.ExecutingObject.Animator.StringToHash("isFlying")</pre>|6=<pre>--clicking the object will toggle it's "isFlying" bool parameter between true and false
+
--this script uses parameter ID instead of string (StringToHash function gets the ID)
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
  parameterID = thisObject.Animator.StringToHash("isFlying")
+
 
+
if thisObject.Animator.GetBool(parameterID) == true then
+
  thisObject.Animator.SetBool(parameterID, false)
+
else
+
  thisObject.Animator.SetBool(parameterID, true)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetInteger|(string name, int value);|Sets the value of the given integer parameter.|5=<pre>Space.Host.ExecutingObject.Animator.SetInteger("iParam", 2)</pre>|6=<pre>--clicking the object will toggle it's Animator's "jumpHeight" int parameter between 0 and 5
+
 
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
if thisObject.Animator.GetInteger("jumpHeight") == 0 then
+
  thisObject.Animator.SetInteger("jumpHeight", 1)
+
else
+
  thisObject.Animator.SetInteger("jumpHeight", 0)
+
end
+
 
+
end
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetLayerWeight|(int layerIndex, float weight);|Sets the weight of the layer at the given index.|5=<pre>Space.Host.ExecutingObject.Animator.SetLayerWeight(0,2.0)</pre>|6=<pre>--clicking the object will toggle the Layer Weight of your second layer (index 1) between 0.0 and 1.0
+
 
+
thisObject = Space.Host.ExecutingObject
+
 
+
OnClick = function()
+
if thisObject.Animator.GetLayerWeight(1) == 0 then
+
  thisObject.Animator.SetLayerWeight(1, 1.0)
+
else
+
  thisObject.Animator.SetLayerWeight(1, 0.0)
+
end
+
 
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetTime|(double time);||5=<pre>Space.Host.ExecutingObject.Animator.SetTime(1.0)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetTrigger|(int id);|Sets a trigger parameter to active. A trigger parameter is a bool parameter that gets reset to false when it has been used in a transition. For state machines with multiple layers, the trigger will only get reset once all layers have been evaluated, so that the layers can synchronize their transitions on the same parameter.|5=<pre>paramID = thisObject.Animator.StringToHash("parameterName")
+
Space.Host.ExecutingObject.Animator.SetTrigger(paramID)</pre>|6=<pre>-- when object is clicked, "clickedTrigger" trigger parameter will be set
+
thisObject = Space.Host.ExecutingObject
+
paramID = thisObject.Animator.StringToHash("clickedTrigger")
+
 
+
OnClick = function()
+
 
+
thisObject.Animator.SetTrigger(paramID)
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|SetTrigger|(string trigger);|Sets a trigger parameter to active. A trigger parameter is a bool parameter that gets reset to false when it has been used in a transition. For state machines with multiple layers, the trigger will only get reset once all layers have been evaluated, so that the layers can synchronize their transitions on the same parameter.|5=<pre>Space.Host.ExecutingObject.Animator.SetTrigger("parameterName")</pre>|6=<pre>-- when object is clicked, "clickedTrigger" trigger parameter will be set
+
thisObject = Space.Host.ExecutingObject
+
 
+
 
+
OnClick = function()
+
thisObject.Animator.SetTrigger("clickedTrigger")
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|void|StartPlayback|();|Sets the animator in playback mode.|5=<pre>Space.Host.ExecutingObject.Animator.StartPlayback()</pre>}}
+
 
+
 
+
{{ScriptFunction|void|Stop|();|Stop the Animator.|5=<pre>Space.Host.ExecutingObject.Animator.Stop()</pre>}}
+
 
+
 
+
{{ScriptFunction|void|StopPlayback|();|Stops the animator playback mode. When playback stops, the avatar resumes getting control from game logic.|5=<pre>Space.Host.ExecutingObject.Animator.StopPlayback()</pre>}}
+
 
+
 
+
{{ScriptFunction|void|StartRecording|();|Sets the animator in recording mode. The recording will continue until the user calls StopRecording. Maximum 10,000 frames. Note it is not possible to start playback until a call to StopRecording is made|5=<pre>Space.Host.ExecutingObject.Animator.StartRecording()</pre>}}
+
 
+
 
+
{{ScriptFunction|void|StopRecording|();|Stops animator record mode.|5=<pre>Space.Host.ExecutingObject.Animator.StopRecording()</pre>}}
+
 
+
 
+
{{ScriptFunction|void|Update|(float deltaTime);|Evaluates the animator based on deltaTime.|5=<pre>Space.Host.ExecutingObject.Animator.Update(Space.DeltaTime)</pre>}}
+
 
+
{{ScriptFunction|SAnimatorStateInfo|GetCurrentAnimationStateInfo|(int Layerindex);|Returns an SAnimatorStateInfo with the information on the current state..|5=<pre>Space.Host.ExecutingObject.Animator.GetCurrentAnimationStateInfo(0)</pre>}}
+
 
+
 
+
==Properties==
+
{{ScriptFunction|bool|ApplyRootMotion|{ get;set; }|Should root motion be applied?
+
Root motion is the effect where an object's entire mesh moves away from its starting point but that motion is created by the animation itself rather than by changing the Transform position.|5=<pre>Space.Host.ExecutingObject.Animator.ApplyRootMotion = true</pre>|6=<pre>--clicking this object will Enable/Disable it's Root Motion
+
thisGameObject = Space.Host.ExecutingObject
+
animator = thisGameObject.Animator
+
 
+
 
+
OnClick = function()
+
animator.ApplyRootMotion =  not animator.ApplyRootMotion
+
end
+
 
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|SResource|Controller|{ get;set; }|The Animator Controller resource of this Animator|5=<pre>Space.Host.ExecutingObject.Animator.Controller = Space.GetResource("newController")</pre>|6=<pre>--this script will make a button toggle an object between two different Animator Controllers
+
--[UIButton object needs to be added to the Scripting Runtime references with name "Button"]
+
--[You need to add an Animator Controller to the Scripting Runtime's resources with name "newController"]
+
--[GameObject needs to have Animator Component]
+
 
+
thisObject = Space.Host.ExecutingObject
+
button = Space.Host.GetReference("Button").UIButton
+
 
+
defaultController = thisObject.Animator.Controller
+
newController = Space.GetResource("newController")
+
 
+
isNewController = false
+
 
+
OnClick = function()
+
    if isNewController then
+
      thisObject.Animator.Controller = defaultController
+
      isNewController = false
+
    else
+
      thisObject.Animator.Controller = newController
+
      isNewController = true
+
    end
+
end
+
 
+
button.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|bool|Enabled|{ get;set; }|Wether the Animator component is enabled or not|5=<pre>Space.Host.ExecutingObject.Animator.Enabled = true</pre>|6=<pre>--clicking this object will Enable/Disable it's Animator component
+
thisGameObject = Space.Host.ExecutingObject
+
animator = thisGameObject.Animator
+
 
+
 
+
OnClick = function()
+
animator.Enabled =  not animator.Enabled
+
end
+
 
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
 
+
{{ScriptFunction|string[]|Parameters|{ get;set; }|The AnimatorControllerParameter list used by the animator.|5=<pre>parameters = Space.Host.ExecutingObject.Animator.Parameters
+
for i=1,#parameters do Space.Log(parameters[i]) end --prints all parameters</pre>}}
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 05:05, 19 September 2022

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