mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-25 14:49:28 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
64 lines
1.6 KiB
C#
64 lines
1.6 KiB
C#
using NativeEngine;
|
|
|
|
namespace Sandbox;
|
|
|
|
/// <summary>
|
|
/// A material. Uses several <see cref="Texture"/>s and a <see cref="Shader"/> with specific settings for more interesting visual effects.
|
|
/// </summary>
|
|
public sealed partial class Material : Resource
|
|
{
|
|
internal IMaterial native;
|
|
|
|
public override bool IsValid => native.IsValid;
|
|
|
|
/// <summary>
|
|
/// Name (or path) of the material.
|
|
/// </summary>
|
|
public string Name { get; internal set; }
|
|
|
|
/// <summary>
|
|
/// Access to all of the attributes of this material.
|
|
/// </summary>
|
|
public RenderAttributes Attributes { get; internal set; }
|
|
|
|
/// <summary>
|
|
/// Private constructor, use <see cref="FromNative(IMaterial, string)"/>
|
|
/// </summary>
|
|
/// <param name="native"></param>
|
|
/// <param name="name"></param>
|
|
/// <exception cref="System.Exception"></exception>
|
|
private Material( IMaterial native, string name )
|
|
{
|
|
if ( native.IsNull ) throw new System.Exception( "Material pointer cannot be null!" );
|
|
|
|
this.native = native;
|
|
this.Name = name;
|
|
|
|
SetIdFromResourcePath( name );
|
|
|
|
CRenderAttributes attributes = this.native.GetRenderAttributes();
|
|
Attributes = new RenderAttributes( attributes );
|
|
}
|
|
|
|
~Material()
|
|
{
|
|
// kill the native pointer - it does with the native material
|
|
// we want to reduce the risk that someone is holding on to it.
|
|
Attributes.Set( default );
|
|
Attributes = null;
|
|
|
|
var n = native;
|
|
native = default;
|
|
|
|
MainThread.Queue( () => n.DestroyStrongHandle() );
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a copy of this material
|
|
/// </summary>
|
|
public Material CreateCopy()
|
|
{
|
|
return FromNative( MaterialSystem2.CreateProceduralMaterialCopy( native, 0, true ) );
|
|
}
|
|
}
|