public bool ShouldUpdateMaterialProperty(MaterialPropertyAsset materialProperty)
        {
            if (materialProperty.propertyType == MaterialPropertyType.ShaderKeywords)
            {
                return(ShaderKeywords == PollingFrequency.UpdateContinuously);
            }
            else if (materialProperty.propertyType == MaterialPropertyType.RenderQueue)
            {
                return(RenderQueue == PollingFrequency.UpdateContinuously);
            }
            else
            {
                MaterialPropertyPollingFrequency pollingFrequency;
                if (PollingFrequencyByMaterialProperty.TryGetValue(new MaterialPropertyKey(materialProperty.ShaderName, materialProperty.propertyName), out pollingFrequency))
                {
                    switch (pollingFrequency.updateFrequency)
                    {
                    case PollingFrequency.UpdateContinuously:
                        return(true);

                    case PollingFrequency.UpdateOnceOnStart:
                        return(false);
                    }
                }

                // If we have a parent, check the parent to see if the parent has an explicit override list
                if (materialProperties == PollingFrequency.InheritFromParent && parentParameters != null)
                {
                    return(parentParameters.ShouldUpdateMaterialProperty(materialProperty));
                }

                return(materialProperties == PollingFrequency.UpdateContinuously);
            }
        }
        public bool ShouldUpdateMaterialProperty(MaterialPropertyAsset materialProperty)
        {
            using (StateSynchronizationPerformanceMonitor.Instance.MeasureEventDuration(performanceComponentName, "ShouldUpdateMaterialProperty"))
            {
                if (materialProperty.propertyType == MaterialPropertyType.ShaderKeywords)
                {
                    return(ShaderKeywords == PollingFrequency.UpdateContinuously);
                }
                else if (materialProperty.propertyType == MaterialPropertyType.RenderQueue)
                {
                    return(RenderQueue == PollingFrequency.UpdateContinuously);
                }
                else
                {
                    MaterialPropertyPollingFrequency pollingFrequency;
                    if (PollingFrequencyByMaterialProperty.TryGetValue(new MaterialPropertyKey(materialProperty.ShaderName, materialProperty.propertyName), out pollingFrequency))
                    {
                        switch (pollingFrequency.updateFrequency)
                        {
                        case PollingFrequency.UpdateContinuously:
                            return(true);

                        case PollingFrequency.UpdateOnceOnStart:
                            return(false);
                        }
                    }

                    // If we have a parent, check the parent to see if the parent has an explicit override list
                    if (materialProperties != PollingFrequency.InheritFromParent || parentParameters == null)
                    {
                        return(materialProperties == PollingFrequency.UpdateContinuously);
                    }
                }
            }

            // Stop the timer before calling parent function
            return(parentParameters.ShouldUpdateMaterialProperty(materialProperty));
        }
        public void SendMaterialPropertyChanges(IEnumerable <SocketEndpoint> endpoints, Renderer renderer, StateSynchronizationPerformanceParameters performanceParameters, Action <BinaryWriter> writeHeader, Func <MaterialPropertyAsset, bool> shouldSynchronizeMaterialProperty)
        {
            Renderer usedRenderer = performanceParameters.MaterialPropertyBlocks == StateSynchronizationPerformanceParameters.FeatureInclusionType.SynchronizeFeature ? renderer : null;

            using (StateSynchronizationPerformanceMonitor.Instance.MeasureScope(StateSynchronizationPerformanceFeature.MaterialPropertyUpdate))
            {
                for (int i = 0; i < cachedMaterials.Length; i++)
                {
                    if (cachedMaterials[i] != null)
                    {
                        foreach (MaterialPropertyAsset propertyAccessor in GetCachedMaterialProperties(i, cachedMaterials))
                        {
                            if (shouldSynchronizeMaterialProperty(propertyAccessor) && performanceParameters.ShouldUpdateMaterialProperty(propertyAccessor))
                            {
                                object newValue = propertyAccessor.GetValue(usedRenderer, cachedMaterials[i]);
                                object oldValue;
                                if (!previousValues[i].TryGetValue(propertyAccessor.propertyName, out oldValue) || !AreMaterialValuesEqual(oldValue, newValue))
                                {
                                    previousValues[i][propertyAccessor.propertyName] = newValue;
                                    SendMaterialPropertyChange(endpoints, usedRenderer, i, propertyAccessor, writeHeader);
                                }
                            }
                        }
                    }
                }
            }
        }