SMaterial
Dans cette classeInstantiate
| Fonction | Instantiate | Return a new SMaterial from old. |
| Fonction | SetFloat | Sets a shader property to value |
| Fonction | GetFloat | Gets the current value of a shader property. |
| Fonction | SetColor | Sets a shader colour |
| Fonction | GetColor | Get a named color value. |
| Fonction | SetColor32 | Sets a shader colour to value (32-bit, 0..255 values) |
| Fonction | SetInt | Sets a shader property to value. |
| Fonction | GetInt | Gets the current value of a shader property. |
| Fonction | SetTexture | Sets a object's specified texture map (specified in parameter 1) to the texture provided as a resource in parameter #2. |
| Fonction | GetTexture | Get a named texture. |
| Fonction | SetTextureOffset | Sets a texture offset to a value. |
| Fonction | SetTextureScale | Sets a texture scale to a value. |
| Fonction | SetVector | Sets a shader property to value |
| Propriété | Name | Return a new SMaterial from old. |
| Propriété | Shader | Return the shader name of current SMaterial. |
| Propriété | RenderQueue | Render queue of this material. |
Fonctions
Instantiate
Return a new SMaterial from old.
Valeurs de retour
SMaterial
Exemple
local cube=Space.Host.ExecutingObject
local cube2=cube.Children[1]
local mat1=cube.Renderer.Material
local newMat=mat1.Instantiate() newMat.SetColor("_Color",Color.Red) cube2.Renderer.Material=newMat
--at this moment, cube2 will turn to red but cube will keep original color.
SetFloat
Sets a shader property to value
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
| value | float | – |
Valeurs de retour
void
Exemple
-- Let's set the Metallic property to 0.75:
local obj = Space.Host.ExecutingObject;
obj.Renderer.Material.SetFloat("_Metallic", 0.75);
GetFloat
Gets the current value of a shader property.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
Valeurs de retour
float
Exemple
-- Let's find out the current Glosiness level
local obj = Space.Host.ExecutingObject;
Space.Log(obj.Renderer.Material.GetFloat("_Glossiness"));
-- prints "0.5" (by default) to the console.
SetColor
Sets a shader colour
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
| color | SColor | – |
| r | float | – |
| g | float | – |
| b | float | – |
| a | float | – |
Valeurs de retour
void
Exemple
-- Let's change the Color to red:
local obj = Space.Host.ExecutingObject;
local newColor = Color.New(1, 0, 0, 1);
obj.Renderer.Material.SetColor("_Color", newColor);
-- Let's change the Color to purple:
local obj = Space.Host.ExecutingObject;
obj.Renderer.Material.SetColor("_Color", 0.5,0,0.5,1);
GetColor
Get a named color value. Many shaders use more than one color. Use GetColor to get the propertyName color.
Paramètres
| Paramètre | Type | Description |
|---|---|---|
| propertyName | string | Common color names used by Unity's builtin shaders: "_Color" is the main color of a material. "_SpecColor" is the specular color of a material (used in specular/glossy/vertexlit shaders). "_EmissionColor" is the emissive color of a material (used in vertexlit shaders). "_ReflectColor" is the reflection color of the material (used in reflective shaders). |
Valeurs de retour
SColor
Exemple
Space.Host.ExecutingObject.Renderer.Material.GetColor("_Color")
SetColor32
Sets a shader colour to value (32-bit, 0..255 values)
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
| r | byte | – |
| g | byte | – |
| b | byte | – |
| a | byte | – |
Valeurs de retour
void
Exemple
-- Let's change the Color to light blue:
local obj = Space.Host.ExecutingObject;
obj.Renderer.Material.SetColor32("_Color", 53,172,232,255);
SetInt
Sets a shader property to value. This can be a convenient way to work with Boolean values.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
| value | int | – |
Valeurs de retour
void
Exemple
-- For example, let's disable Specular Highlights (enabled by default in the Standard shader):
local obj = Space.Host.ExecutingObject;
obj.Renderer.Material.SetInt("_SpecularHighlights", 0);
GetInt
Gets the current value of a shader property. This can be a convenient way to work with Boolean values.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
Valeurs de retour
int
Exemple
-- Let's find out if the Reflections property is enabled:
local obj = Space.Host.ExecutingObject;
Space.Log(obj.Renderer.Material.GetInt("_GlossyReflections"));
-- prints "1" (by default) to the console, which means that the Reflections property is indeed enabled.
SetTexture
Sets a object's specified texture map (specified in parameter 1) to the texture provided as a resource in parameter #2. The example script must be in a object with a '_MainTex' map, and that object should be set as a resource on the scripting runtime. Additionally, that object should be called 'dispobj'.
note also that this function can be used to set any of the texture maps by varying the value of the first parameter accordingly.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
| value | SResource | – |
Valeurs de retour
void
Exemple
function hithere()
image = "mrlee.jpg"
server = "https://middleware.systems/"
obj = Space.Host.GetReference("dispobj")
resrc = Space.WebServices.GetImage(server .. image)
obj.Renderer.Material.SetTexture("_MainTex", resrc)
end
GetTexture
Get a named texture. Many shaders use more than one texture. Use GetTexture to get the propertyName texture.
Paramètres
| Paramètre | Type | Description |
|---|---|---|
| propertyName | string | Common texture names used by Unity's builtin shaders: "_MainTex" is the main diffuse texture. "_BumpMap" is the normal map. "_Cube" is the reflection cubemap. |
Valeurs de retour
SResource
Exemple
textureResource = Space.Host.ExecutingObject.Renderer.Material.GetTexture("_MainTex")
SetTextureOffset
Sets a texture offset to a value.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
| x | float | – |
| y | float | – |
Valeurs de retour
void
Exemple
Space.Host.ExecutingObject.Renderer.Material.SetTextureOffset("_MainTex", 0, 1)
SetTextureScale
Sets a texture scale to a value.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
| x | float | – |
| y | float | – |
Valeurs de retour
void
Exemple
Space.Host.ExecutingObject.Renderer.Material.SetTextureScale("_MainTex", 0, 1)
SetVector
Sets a shader property to value
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
| value | SVector | – |
Valeurs de retour
void
Exemple
Space.Host.ExecutingObject.Renderer.Material.SetTexture("_APropertyName", Vector.New(0,1,0))
Propriétés
Name
Return a new SMaterial from old.
Exemple
local cube=Space.Host.ExecutingObject
local mat=cube.Renderer.Material
Space.Log(mat.Name)
ShaderLecture seule
Return the shader name of current SMaterial.
Exemple
local cube=Space.Host.ExecutingObject
local mat=cube.Renderer.Material
Space.Log(mat.Shader)
RenderQueue
Render queue of this material.
By default materials use render queue of the shader it uses. You can override the render queue used using this variable. Note that if a shader on the material is changed, the render queue resets to that of the shader itself.
Render queue value should be in [0..5000] range to work properly; or -1 to use the render queue from the shader.
Exemple
RenderQueue = Space.Host.ExecutingObject.Renderer.Material.RenderQueue



