using System; namespace UnityEngine.XR.Interaction.Toolkit.AffordanceSystem.Rendering { /// /// Bridge between components needing to write to a renderer's material property block. /// Allows multiple components to handle their own material properties and write them to a central space and update it only as needed. /// [AddComponentMenu("Affordance System/Rendering/Material Property Block Helper", 12)] [HelpURL(XRHelpURLConstants.k_MaterialPropertyBlockHelper)] [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 MaterialPropertyBlockHelper : MaterialHelperBase { MaterialPropertyBlock m_PropertyBlock; bool m_IsDirty; /// /// See . /// protected void OnDestroy() { m_PropertyBlock = null; } /// /// See . /// protected void LateUpdate() { if (!m_IsDirty || !isInitialized) return; rendererTarget.SetPropertyBlock(m_PropertyBlock, materialIndex); m_IsDirty = false; } /// /// Get material property block associated the the material index set in the inspector. /// /// If true, marks property block as dirty to be updated at the end of the frame. /// Material property block for associated material index. public MaterialPropertyBlock GetMaterialPropertyBlock(bool markPropertyBlockAsDirty = true) { if (markPropertyBlockAsDirty) m_IsDirty = true; return m_PropertyBlock; } /// protected override void Initialize() { base.Initialize(); m_PropertyBlock = new MaterialPropertyBlock(); rendererTarget.GetPropertyBlock(m_PropertyBlock, materialIndex); } } }