Breakroom is now Sinewave Campus. Book a meeting

SMaterial

العميلالأنواع
في هذا الصنفInstantiate
  1. الدوال
  2. Instantiate
  3. SetFloat
  4. GetFloat
  5. SetColor
  6. GetColor
  7. SetColor32
  8. SetInt
  9. GetInt
  10. SetTexture
  11. GetTexture
  12. SetTextureOffset
  13. SetTextureScale
  14. SetVector
  15. الخصائص
  16. Name
  17. Shader
  18. RenderQueue
الأعضاء 16
دالةInstantiateReturn a new SMaterial from old.
دالةSetFloatSets a shader property to value
دالةGetFloatGets the current value of a shader property.
دالةSetColorSets a shader colour
دالةGetColorGet a named color value.
دالةSetColor32Sets a shader colour to value (32-bit, 0..255 values)
دالةSetIntSets a shader property to value.
دالةGetIntGets the current value of a shader property.
دالةSetTextureSets a object's specified texture map (specified in parameter 1) to the texture provided as a resource in parameter #2.
دالةGetTextureGet a named texture.
دالةSetTextureOffsetSets a texture offset to a value.
دالةSetTextureScaleSets a texture scale to a value.
دالةSetVectorSets a shader property to value
خاصيةNameReturn a new SMaterial from old.
خاصيةShaderReturn the shader name of current SMaterial.
خاصيةRenderQueueRender queue of this material.

الدوال​

Instantiate​

SMaterial Instantiate()

Return a new SMaterial from old.

القيم المرجعة

SMaterial

مثال

Lua
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​

void SetFloat(string key, float value)

Sets a shader property to value

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–
valuefloat–

القيم المرجعة

void

مثال

Lua
-- Let's set the Metallic property to 0.75:
local obj = Space.Host.ExecutingObject;
obj.Renderer.Material.SetFloat("_Metallic", 0.75);

GetFloat​

float GetFloat(string key)

Gets the current value of a shader property.

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–

القيم المرجعة

float

مثال

Lua
-- 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​

void SetColor(string key, SColor color)
void SetColor(string key, float r, float g, float b, float a)

Sets a shader colour

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–
colorSColor–
rfloat–
gfloat–
bfloat–
afloat–

القيم المرجعة

void

مثال

Lua
-- 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);
Lua
-- Let's change the Color to purple:
local obj = Space.Host.ExecutingObject;
obj.Renderer.Material.SetColor("_Color", 0.5,0,0.5,1);

GetColor​

SColor GetColor(string propertyName)

Get a named color value. Many shaders use more than one color. Use GetColor to get the propertyName color.

المعاملات

المعاملالنوعالوصف
propertyNamestring

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).

القيم المرجعة

SColor

مثال

Lua
Space.Host.ExecutingObject.Renderer.Material.GetColor("_Color")

SetColor32​

void SetColor32(string key, byte r, byte g, byte b, byte a)

Sets a shader colour to value (32-bit, 0..255 values)

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–
rbyte–
gbyte–
bbyte–
abyte–

القيم المرجعة

void

مثال

Lua
-- Let's change the Color to light blue:
local obj = Space.Host.ExecutingObject;
obj.Renderer.Material.SetColor32("_Color", 53,172,232,255);

SetInt​

void SetInt(string key, int value)

Sets a shader property to value. This can be a convenient way to work with Boolean values.

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–
valueint–

القيم المرجعة

void

مثال

Lua
-- 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​

int GetInt(string key)

Gets the current value of a shader property. This can be a convenient way to work with Boolean values.

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–

القيم المرجعة

int

مثال

Lua
-- 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​

void SetTexture(string key, SResource value)

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.

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–
valueSResource–

القيم المرجعة

void

مثال

Lua
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​

SResource GetTexture(string propertyName)

Get a named texture. Many shaders use more than one texture. Use GetTexture to get the propertyName texture.

المعاملات

المعاملالنوعالوصف
propertyNamestring

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.

القيم المرجعة

SResource

مثال

Lua
textureResource = Space.Host.ExecutingObject.Renderer.Material.GetTexture("_MainTex")

SetTextureOffset​

void SetTextureOffset(string key, float x, float y)

Sets a texture offset to a value.

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–
xfloat–
yfloat–

القيم المرجعة

void

مثال

Lua
Space.Host.ExecutingObject.Renderer.Material.SetTextureOffset("_MainTex", 0, 1)

SetTextureScale​

void SetTextureScale(string key, float x, float y)

Sets a texture scale to a value.

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–
xfloat–
yfloat–

القيم المرجعة

void

مثال

Lua
Space.Host.ExecutingObject.Renderer.Material.SetTextureScale("_MainTex", 0, 1)

SetVector​

void SetVector(string key, SVector value)

Sets a shader property to value

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–
valueSVector–

القيم المرجعة

void

مثال

Lua
Space.Host.ExecutingObject.Renderer.Material.SetTexture("_APropertyName", Vector.New(0,1,0))

الخصائص​

Name​

string Name {get; set; }

Return a new SMaterial from old.

مثال

Lua
local cube=Space.Host.ExecutingObject
local mat=cube.Renderer.Material
Space.Log(mat.Name)

Shaderللقراءة فقط​

string Shader {get; }

Return the shader name of current SMaterial.

مثال

Lua
local cube=Space.Host.ExecutingObject
local mat=cube.Renderer.Material
Space.Log(mat.Shader)

RenderQueue​

int RenderQueue {get; set; }

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.

مثال

Lua
RenderQueue = Space.Host.ExecutingObject.Renderer.Material.RenderQueue