wiki.sine.space | sinespace

Difference between revisions of "Scripting/SRenderer"

From wiki.sine.space
Jump to: navigation, search
Line 4: Line 4:
  
 
=Properties=
 
=Properties=
{{ScriptFunction|bool|IsVisible|{ get; }|Returns true if the renderer is visible on any camera.|5=<pre>
+
{{ScriptFunction|bool|IsVisible|{ get; }|Returns true if the renderer is visible on any camera.
isVisible = Space.Host.ExecutingObject.Renderer.IsVisible</pre>|6=<pre></pre> }}
+
Note that the object is considered visible when it needs to be rendered in the Scene. For example, it might not actually be visible by any camera but still need to be rendered for shadows. When running in the editor, the Scene view cameras will also cause this value to be true.|5=<pre>
 +
isVisible = Space.Host.ExecutingObject.Renderer.IsVisible</pre>|6=<pre>--this object will move forward only if visible on a camera
 +
 
 +
thisObject = Space.Host.ExecutingObject
 +
 
 +
 
 +
function OnUpdateFunction()
 +
 
 +
  if thisObject.Renderer.IsVisible then
 +
thisObject.WorldPosition = thisObject.WorldPosition + (thisObject.Forward * Space.DeltaTime * 0.2)
 +
end
 +
 
 +
end
 +
 
 +
thisObject.OnUpdate(OnUpdateFunction)</pre> }}
  
  

Revision as of 17:33, 24 January 2022

A renderer is what makes an object appear on the screen.

The SRenderer class component interfaces with Unity's Renderer component, exposing its functions to scripting.

Properties

IsVisible

bool IsVisible { get; }

Returns true if the renderer is visible on any camera. Note that the object is considered visible when it needs to be rendered in the Scene. For example, it might not actually be visible by any camera but still need to be rendered for shadows. When running in the editor, the Scene view cameras will also cause this value to be true.

isVisible = Space.Host.ExecutingObject.Renderer.IsVisible


--this object will move forward only if visible on a camera

thisObject = Space.Host.ExecutingObject


function OnUpdateFunction()
  
  if thisObject.Renderer.IsVisible then
thisObject.WorldPosition = thisObject.WorldPosition + (thisObject.Forward * Space.DeltaTime * 0.2)
 end

end

thisObject.OnUpdate(OnUpdateFunction)


Enabled

bool Enabled { get; set; }

Get/Set if the rendered object is visible.

Space.Host.ExecutingObject.Renderer.Enabled = false 


--clicking this object will make it disappear/reappear

thisGameObject = Space.Host.ExecutingObject


OnClick = function()
thisGameObject.Renderer.Enabled = not thisGameObject.Renderer.Enabled
end

thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)


Material

SMaterial Material { get; set; }

Get/Set the material instantiated to the renderer.

Space.Host.ExecutingObject.Renderer.Material.SetColor("_Color", 1.0, 0.5, 0.5, 1.0)


Materials[]

SMaterial Materials[] { get; set; }

Get/Set all materials instantiated to the renderer.

mats = Space.Host.ExecutingObject.Renderer.Materials



SharedMaterial

SMaterial SharedMaterial { get; set; }

Get/Set the shared material used by the renderer.

Refer to member Material.


SharedMaterials[]

SMaterial SharedMaterials[] { get; set; }

Get/Set all shared materials used by the renderer.

Refer to member Materials.