Example #1
0
        public override void Read(SocketEndpoint sendingEndpoint, BinaryReader message)
        {
            ImageBroadcaster.ChangeType changeType = (ImageBroadcaster.ChangeType)message.ReadByte();

            if (ImageBroadcaster.HasFlag(changeType, ImageBroadcaster.ChangeType.Data))
            {
                attachedComponent.overrideSprite = ImageService.Instance.GetSprite(message.ReadGuid());
                attachedComponent.sprite         = ImageService.Instance.GetSprite(message.ReadGuid());
                attachedComponent.fillAmount     = message.ReadSingle();
                attachedComponent.color          = message.ReadColor();

                attachedComponent.alphaHitTestMinimumThreshold = message.ReadSingle();
                attachedComponent.fillOrigin     = message.ReadInt32();
                attachedComponent.fillClockwise  = message.ReadBoolean();
                attachedComponent.fillMethod     = (Image.FillMethod)message.ReadByte();
                attachedComponent.fillCenter     = message.ReadBoolean();
                attachedComponent.preserveAspect = message.ReadBoolean();
                attachedComponent.type           = (Image.Type)message.ReadByte();
                attachedComponent.enabled        = message.ReadBoolean();
            }
            if (ImageBroadcaster.HasFlag(changeType, ImageBroadcaster.ChangeType.Materials))
            {
                var materials = MaterialPropertyAsset.ReadMaterials(message, null);
                if (materials != null &&
                    materials.Length > 0)
                {
                    attachedComponent.material = materials[0];
                }
            }
            if (ImageBroadcaster.HasFlag(changeType, ImageBroadcaster.ChangeType.MaterialProperty))
            {
                int materialIndex = message.ReadInt32();
                MaterialPropertyAsset.Read(message, new Material[] { attachedComponent.material }, materialIndex);
            }
        }
Example #2
0
        public override void Read(SocketEndpoint sendingEndpoint, BinaryReader message)
        {
            TextBroadcaster.ChangeType changeType = (TextBroadcaster.ChangeType)message.ReadByte();

            if (TextBroadcaster.HasFlag(changeType, TextBroadcaster.ChangeType.Text))
            {
                attachedComponent.text = message.ReadString();
            }
            if (TextBroadcaster.HasFlag(changeType, TextBroadcaster.ChangeType.FontAndPlacement))
            {
                attachedComponent.alignment          = (TextAnchor)message.ReadByte();
                attachedComponent.color              = message.ReadColor();
                attachedComponent.fontSize           = message.ReadInt32();
                attachedComponent.fontStyle          = (FontStyle)message.ReadByte();
                attachedComponent.lineSpacing        = message.ReadSingle();
                attachedComponent.horizontalOverflow = (HorizontalWrapMode)message.ReadByte();
                attachedComponent.verticalOverflow   = (VerticalWrapMode)message.ReadByte();
                attachedComponent.font = TextService.Instance.GetFont(message.ReadGuid());
            }
            if (TextBroadcaster.HasFlag(changeType, TextBroadcaster.ChangeType.Materials))
            {
                var materials = MaterialPropertyAsset.ReadMaterials(message, null);
                if (materials != null &&
                    materials.Length > 0)
                {
                    attachedComponent.material = materials[0];
                }
            }
            if (TextBroadcaster.HasFlag(changeType, TextBroadcaster.ChangeType.MaterialProperty))
            {
                int materialIndex = message.ReadInt32();
                MaterialPropertyAsset.Read(message, new Material[] { attachedComponent.material }, materialIndex);
            }
        }
        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);
            }
        }
Example #4
0
        protected override bool ShouldSynchronizeMaterialProperty(MaterialPropertyAsset materialProperty)
        {
            if (materialProperty.propertyType == MaterialPropertyType.Texture && (textMesh.font == null || textMesh.font.dynamic))
            {
                // Font generate textures on each end and we shouldn't attempt to sync that texture over the network
                return(false);
            }

            return(true);
        }
        public static Material[] ReadMaterials(BinaryReader message, Material[] existingMaterials)
        {
            int materialCount = message.ReadInt32();

            Material[] materials = new Material[materialCount];
            for (int i = 0; i < materialCount; i++)
            {
                string shaderName = message.ReadString();
                if (shaderName != string.Empty)
                {
                    Material material;
                    if (existingMaterials != null && i < existingMaterials.Length)
                    {
                        material      = existingMaterials[i];
                        material.name = message.ReadString();

                        if (material.shader.name != shaderName)
                        {
                            Shader shader = Shader.Find(shaderName);
                            if (shader == null)
                            {
                                Debug.Log("Couldn't find shader with name " + shaderName);
                                shader = Shader.Find("Standard");
                            }
                            material.shader = shader;
                        }
                    }
                    else
                    {
                        Shader shader = Shader.Find(shaderName);
                        if (shader == null)
                        {
                            Debug.Log("Couldn't find shader with name " + shaderName);
                            shader = Shader.Find("Standard");
                        }

                        material      = new Material(shader);
                        material.name = message.ReadString();
                    }

                    materials[i] = material;

                    int materialPropertyCount = message.ReadInt32();
                    for (int j = 0; j < materialPropertyCount; j++)
                    {
                        MaterialPropertyAsset.Read(message, materials, i);
                    }
                }
            }
            return(materials);
        }
Example #6
0
 protected virtual void Read(SocketEndpoint sendingEndpoint, BinaryReader message, byte changeType)
 {
     if (RendererBroadcaster <TRenderer, TComponentService> .HasFlag(changeType, RendererBroadcaster <TRenderer, TComponentService> .ChangeType.Enabled) && Renderer)
     {
         Renderer.enabled = message.ReadBoolean();
     }
     if (RendererBroadcaster <TRenderer, TComponentService> .HasFlag(changeType, RendererBroadcaster <TRenderer, TComponentService> .ChangeType.Materials) && Renderer)
     {
         Renderer.materials = MaterialPropertyAsset.ReadMaterials(message, Renderer.materials);
     }
     if (RendererBroadcaster <TRenderer, TComponentService> .HasFlag(changeType, RendererBroadcaster <TRenderer, TComponentService> .ChangeType.MaterialProperty) && Renderer)
     {
         int materialIndex = message.ReadInt32();
         MaterialPropertyAsset.Read(message, Renderer.materials, materialIndex);
     }
 }
        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));
        }
        protected void SendMaterialPropertyChange(IEnumerable <SocketEndpoint> endpoints, Renderer renderer, int materialIndex, MaterialPropertyAsset propertyAccessor, Action <BinaryWriter> writeHeader)
        {
            using (MemoryStream memoryStream = new MemoryStream())
                using (BinaryWriter message = new BinaryWriter(memoryStream))
                {
                    writeHeader(message);
                    message.Write(materialIndex);
                    propertyAccessor.Write(message, renderer, cachedMaterials[materialIndex]);

                    message.Flush();
                    StateSynchronizationSceneManager.Instance.Send(endpoints, memoryStream.ToArray());
                }
        }
Example #9
0
 protected virtual bool ShouldSynchronizeMaterialProperty(MaterialPropertyAsset materialProperty)
 {
     return(true);
 }
 private bool ShouldSynchronizeMaterialProperty(MaterialPropertyAsset materialProperty)
 {
     return(true);
 }
        protected void SendMaterialPropertyChange(IEnumerable <INetworkConnection> connections, Renderer renderer, int materialIndex, MaterialPropertyAsset propertyAccessor, Action <BinaryWriter> writeHeader)
        {
            using (MemoryStream memoryStream = new MemoryStream())
                using (BinaryWriter message = new BinaryWriter(memoryStream))
                {
                    writeHeader(message);
                    message.Write(materialIndex);
                    propertyAccessor.Write(message, renderer, cachedMaterials[materialIndex]);

                    message.Flush();
                    StateSynchronizationSceneManager.Instance.Send(connections, memoryStream.GetBuffer(), 0, memoryStream.Position);
                }
        }