wiki.sine.space | sinespace

Difference between revisions of "Scripting/SRenderer"

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/srenderer")
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
A renderer is what makes an object appear on the screen.
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/srenderer
 
+
The SRenderer class component interfaces with Unity's Renderer component, exposing its functions to scripting.
+
 
+
=Properties=
+
{{ScriptFunction|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.|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> }}
+
 
+
 
+
{{ScriptFunction|bool|Enabled|{ get; set; }|Get/Set if the rendered object is visible.|5=<pre>Space.Host.ExecutingObject.Renderer.Enabled = false </pre>|6=<pre>--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)</pre>}}
+
 
+
 
+
{{ScriptFunction|SMaterial|Material|{ get; set; }|Returns the first instantiated Material assigned to the renderer.
+
 
+
Modifying material will change the material for this object only.
+
 
+
If the material is used by any other renderers, this will clone the shared material and start using it from now on.|
+
5=<pre>Space.Host.ExecutingObject.Renderer.Material.SetColor("_Color", 1.0, 0.5, 0.5, 1.0)</pre>|6=<pre>--clicking this object will toggle between Red and Black color when clicked
+
 
+
 
+
thisObject = Space.Host.ExecutingObject
+
 
+
 
+
function OnClickFunction()
+
if thisObject.Renderer.Material.GetColor("_Color") == Color.Black then
+
  thisObject.Renderer.Material.SetColor("_Color", Color.Red)
+
else
+
  thisObject.Renderer.Material.SetColor("_Color", Color.Black)
+
end
+
 
+
end
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClickFunction)</pre>}}
+
{{ScriptFunction|SMaterial|Materials[]|{ get; set; }|Returns all the instantiated materials of this object.
+
 
+
This is an array of all materials used by the renderer. Unity supports a single object using multiple materials; in this case materials contains all the materials. sharedMaterial and material properties return the first used material if there is more than one.
+
 
+
Modifying any material in materials will change the appearance of only that object.
+
 
+
Note that like all arrays returned by Unity, this returns a copy of materials array. If you want to change some materials in it, get the value, change an entry and set materials back.|5=<pre>mats = Space.Host.ExecutingObject.Renderer.Materials</pre>|6=<pre></pre>}}
+
 
+
 
+
{{ScriptFunction|SMaterial|SharedMaterial|{ get; set; }|The shared material of this object.
+
 
+
Modifying sharedMaterial will change the appearance of all objects using this material, and change material settings that are stored in the project too.
+
 
+
It is not recommended to modify materials returned by sharedMaterial. If you want to modify the material of a renderer use material instead.|5=<pre>Space.Host.ExecutingObject.Renderer.SharedMaterial.SetColor("_Color", 1.0, 0.5, 0.5, 1.0)</pre>}}
+
{{ScriptFunction|SMaterial|SharedMaterials[]|{ get; set; }|All the shared materials of this object.
+
 
+
This is an array of all materials used by the renderer. Unity supports a single object using multiple materials; in this case sharedMaterials contains all the materials. sharedMaterial and material properties return the first used material if there is more than one.
+
 
+
Modifying any material in sharedMaterials will change the appearance of all objects using this material, and change material settings that are stored in the project too.
+
 
+
It is not recommended to modify materials returned by sharedMaterials. If you want to modify the material of a renderer use material instead.
+
 
+
Note that like all arrays returned by Unity, this returns a copy of materials array. If you want to change some materials in it, get the value, change an entry and set materials back.|5=<pre>sharedMats = Space.Host.ExecutingObject.Renderer.SharedMaterials</pre>|6=<pre></pre>}}
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 06:19, 19 September 2022

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