private void UpdateParentParameters()
        {
            StateSynchronizationPerformanceMonitor.Instance.IncrementEventCount(performanceComponentName, "UpdateParentParameters");
            if (GetComponent <DefaultStateSynchronizationPerformanceParameters>() != null)
            {
                parentParameters = null;
            }
            else
            {
                if (transform.parent == null)
                {
                    parentParameters = DefaultStateSynchronizationPerformanceParameters.Instance;
                }
                else
                {
                    parentParameters = transform.parent.GetComponentInParent <StateSynchronizationPerformanceParameters>();
                    if (parentParameters == null)
                    {
                        parentParameters = DefaultStateSynchronizationPerformanceParameters.Instance;
                    }
                }
            }

            cachedCheckForComponentBroadcasters = null;
            cachedShaderKeywords         = null;
            cachedRenderQueue            = null;
            cachedMaterialProperties     = null;
            cachedMaterialPropertyBlocks = null;
        }
Ejemplo n.º 2
0
        private void UpdateComponentBroadcasters()
        {
            StateSynchronizationPerformanceParameters StateSynchronizationPerformanceParameters = PerformanceParameters;

            if ((StateSynchronizationPerformanceParameters.CheckForComponentBroadcasters == StateSynchronizationPerformanceParameters.PollingFrequency.UpdateOnceOnStart && needsComponentCheck) ||
                StateSynchronizationPerformanceParameters.CheckForComponentBroadcasters == StateSynchronizationPerformanceParameters.PollingFrequency.UpdateContinuously)
            {
                using (StateSynchronizationPerformanceMonitor.Instance.MeasureEventDuration(PerformanceComponentName, "GameObjectComponentCheck"))
                {
                    bool anyChangesDetected = false;
                    foreach (ComponentBroadcasterDefinition componentDefinition in StateSynchronizationSceneManager.Instance.ComponentBroadcasterDefinitions)
                    {
                        if (!componentDefinition.IsTransformBroadcasterController)
                        {
                            bool changesDetected;
                            componentDefinition.EnsureComponentBroadcastersCreated(this.CachedGameObject, out changesDetected);
                            anyChangesDetected |= changesDetected;
                        }
                    }

                    if (anyChangesDetected)
                    {
                        needsComponentCheck = true;
                    }
                    else
                    {
                        needsComponentCheck = false;
                    }
                }
            }
        }
        public void UpdateMaterials(Renderer renderer, StateSynchronizationPerformanceParameters performanceParameters, Material[] materials, out bool areMaterialsDifferent)
        {
            UpdateCachedMaterials(materials, out areMaterialsDifferent);

            if (renderer != null && performanceParameters.MaterialPropertyBlocks == StateSynchronizationPerformanceParameters.FeatureInclusionType.SynchronizeFeature)
            {
                using (StateSynchronizationPerformanceMonitor.Instance.MeasureEventDuration(performanceComponentName, "MaterialPropertyBlockUpdate"))
                {
                    renderer.UpdateCachedPropertyBlock();
                }
            }
        }
        private T GetInheritedProperty <T>(Func <StateSynchronizationPerformanceParameters, T> getter, T inhertedValue, T defaultValue)
        {
            StateSynchronizationPerformanceParameters parameters = this;

            while (parameters != null)
            {
                T pollingFrequency = getter(parameters);
                if (!Equals(pollingFrequency, PollingFrequency.InheritFromParent))
                {
                    return(pollingFrequency);
                }

                parameters = parameters.parentParameters;
            }

            return(defaultValue);
        }
        private T GetInheritedProperty <T>(Func <StateSynchronizationPerformanceParameters, T> getter, T defaultValue)
        {
            using (StateSynchronizationPerformanceMonitor.Instance.MeasureEventDuration(performanceComponentName, "GetInheritedProperty"))
            {
                StateSynchronizationPerformanceParameters parameters = this;
                while (parameters != null)
                {
                    T pollingFrequency = getter(parameters);
                    if (!Equals(pollingFrequency, PollingFrequency.InheritFromParent))
                    {
                        return(pollingFrequency);
                    }

                    parameters = parameters.parentParameters;
                }

                return(defaultValue);
            }
        }
 private void UpdateParentParameters()
 {
     if (GetComponent <DefaultStateSynchronizationPerformanceParameters>() != null)
     {
         parentParameters = null;
     }
     else
     {
         if (transform.parent == null)
         {
             parentParameters = DefaultStateSynchronizationPerformanceParameters.Instance;
         }
         else
         {
             parentParameters = transform.parent.GetComponentInParent <StateSynchronizationPerformanceParameters>();
             if (parentParameters == null)
             {
                 parentParameters = DefaultStateSynchronizationPerformanceParameters.Instance;
             }
         }
     }
 }
        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.MeasureEventDuration(performanceComponentName, "SendMaterialPropertyChanges"))
            {
                for (int i = 0; i < cachedMaterials.Length; i++)
                {
                    if (cachedMaterials[i] != null &&
                        ShouldAssessAnyPropertyAccessors(performanceParameters))
                    {
                        foreach (MaterialPropertyAsset propertyAccessor in GetCachedMaterialProperties(i, cachedMaterials))
                        {
                            if (shouldSynchronizeMaterialProperty(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);

                                    StateSynchronizationPerformanceMonitor.Instance.IncrementEventCount(performanceComponentName, $"{cachedMaterials[i].name}.{cachedMaterials[i].shader.name}.{propertyAccessor.propertyName}");
                                }
                            }
                        }
                    }
                }
            }
        }
 private bool ShouldAssessAnyPropertyAccessors(StateSynchronizationPerformanceParameters performanceParameters)
 {
     return(performanceParameters.HasCustomMateriaPropertyPollingFrequencies ||
            performanceParameters.ShaderKeywords != StateSynchronizationPerformanceParameters.PollingFrequency.UpdateOnceOnStart ||
            performanceParameters.MaterialProperties != StateSynchronizationPerformanceParameters.PollingFrequency.UpdateOnceOnStart);
 }