using System;
namespace UnityEngine.XR.Interaction.Toolkit.AffordanceSystem.Rendering
{
///
/// Creates material instance for a material associated with a given renderer material index and provide accessor to it.
///
[AddComponentMenu("Affordance System/Rendering/Material Instance Helper", 12)]
[HelpURL(XRHelpURLConstants.k_MaterialInstanceHelper)]
[Obsolete("The Affordance System namespace and all associated classes have been deprecated. The existing affordance system will be moved, replaced and updated with a new interaction feedback system in a future version of XRI.")]
public class MaterialInstanceHelper : MaterialHelperBase
{
Material m_MaterialInstance;
///
/// See .
///
protected void OnDestroy()
{
if (m_MaterialInstance != null)
{
Destroy(m_MaterialInstance);
m_MaterialInstance = null;
}
}
///
/// Try to get initialized material instance as configured on the component.
///
/// Material instance. Will be if invalid.
/// Returns if material instance is initialized. Otherwise, returns .
public bool TryGetMaterialInstance(out Material materialInstance)
{
if (!isInitialized)
{
materialInstance = null;
return false;
}
materialInstance = m_MaterialInstance;
return true;
}
///
protected override void Initialize()
{
if (m_MaterialInstance == null)
{
var sharedMaterials = rendererTarget.sharedMaterials;
m_MaterialInstance = new Material(sharedMaterials[materialIndex]);
sharedMaterials[materialIndex] = m_MaterialInstance;
rendererTarget.sharedMaterials = sharedMaterials;
base.Initialize();
}
}
}
}