/// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition definition)
        {
            renderer = host.GetComponent <Renderer>();
            graphic  = host.GetComponent <Graphic>();

            base.Init(host, definition);

            shaderProperties = new List <ThemeStateProperty>();
            foreach (var prop in StateProperties)
            {
                if (ThemeStateProperty.IsShaderPropertyType(prop.Type))
                {
                    shaderProperties.Add(prop);
                }
            }

            if (renderer != null)
            {
                propertyBlock = InteractableThemeShaderUtils.InitMaterialPropertyBlock(host, shaderProperties);
            }
            else if (graphic != null)
            {
                UIMaterialInstantiator.TryCreateMaterialCopy(graphic);
            }

            // Need to update reset history tracking now that property blocks are populated correctly via above code
            var keys = new List <ThemeStateProperty>(originalStateValues.Keys);

            foreach (var value in keys)
            {
                originalStateValues[value] = GetProperty(value);
            }
        }
Example #2
0
        /// <summary>
        /// Initialize current Theme Engine with given configuration and target the provided GameObject
        /// </summary>
        /// <param name="host">GameObject to target changes against</param>
        /// <param name="definition">Configuration information to initialize Theme Engine</param>
        public virtual void Init(GameObject host, ThemeDefinition definition)
        {
            Host = host;

            StateProperties = new List <ThemeStateProperty>();
            foreach (ThemeStateProperty stateProp in definition.StateProperties)
            {
                // This is a temporary workaround to support backward compatible themes
                // If the current state properties is one we know supports shaders, try to migrate data
                // See ThemeStateProperty class for more details
                if (ThemeStateProperty.IsShaderPropertyType(stateProp.Type))
                {
                    stateProp.MigrateShaderData();
                }

                StateProperties.Add(new ThemeStateProperty()
                {
                    Name               = stateProp.Name,
                    Type               = stateProp.Type,
                    Values             = stateProp.Values,
                    Default            = stateProp.Default,
                    TargetShader       = stateProp.TargetShader,
                    ShaderPropertyName = stateProp.ShaderPropertyName,
                });

                originalStateValues.Add(stateProp, GetProperty(stateProp));
            }

            Properties = new List <ThemeProperty>();
            foreach (ThemeProperty prop in definition.CustomProperties)
            {
                Properties.Add(new ThemeProperty()
                {
                    Name    = prop.Name,
                    Tooltip = prop.Tooltip,
                    Type    = prop.Type,
                    Value   = prop.Value,
                });
            }

            Debug.Assert(GetDefaultThemeDefinition().StateProperties.Count == StateProperties.Count, $"{Name}  state properties inconsistency with default theme definition, consider reserializing.");
            Debug.Assert(GetDefaultThemeDefinition().CustomProperties.Count == Properties.Count, $"{Name}  custom properties inconsistency with default theme definition, consider reserializing.");

            if (definition.Easing != null)
            {
                Ease = definition.Easing.Copy();
                Ease.Stop();
            }

            Loaded = true;
        }
Example #3
0
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition definition)
        {
            base.Init(host, definition);

            renderer = Host.GetComponent <Renderer>();

            shaderProperties = new List <ThemeStateProperty>();
            foreach (var prop in StateProperties)
            {
                if (ThemeStateProperty.IsShaderPropertyType(prop.Type))
                {
                    shaderProperties.Add(prop);
                }
            }

            propertyBlock = InteractableThemeShaderUtils.InitMaterialPropertyBlock(host, shaderProperties);
        }
        /// <summary>
        /// Initialize current Theme Engine with given configuration and target the provided GameObject
        /// </summary>
        /// <param name="host">GameObject to target changes against</param>
        /// <param name="definition">Configuration information to intialize Theme Engine</param>
        public virtual void Init(GameObject host, ThemeDefinition definition)
        {
            Host = host;

            this.StateProperties = new List <ThemeStateProperty>();
            foreach (ThemeStateProperty stateProp in definition.StateProperties)
            {
                // This is a temporary workaround to support backward compatible themes
                // If the current state properties is one we know supports shaders, try to migrate data
                // See ThemeStateProperty class for more details
                if (ThemeStateProperty.IsShaderPropertyType(stateProp.Type))
                {
                    stateProp.MigrateShaderData();
                }

                this.StateProperties.Add(new ThemeStateProperty()
                {
                    Name               = stateProp.Name,
                    Type               = stateProp.Type,
                    Values             = stateProp.Values,
                    Default            = stateProp.Default,
                    TargetShader       = stateProp.TargetShader,
                    ShaderPropertyName = stateProp.ShaderPropertyName,
                });
            }

            this.Properties = new List <ThemeProperty>();
            foreach (ThemeProperty prop in definition.CustomProperties)
            {
                this.Properties.Add(new ThemeProperty()
                {
                    Name  = prop.Name,
                    Type  = prop.Type,
                    Value = prop.Value,
                });
            }

            if (definition.Easing != null)
            {
                Ease = definition.Easing.Copy();
                Ease.Stop();
            }

            Loaded = true;
        }
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition definition)
        {
            base.Init(host, definition);

            shaderProperties = new List <ThemeStateProperty>();
            foreach (var prop in StateProperties)
            {
                if (ThemeStateProperty.IsShaderPropertyType(prop.Type))
                {
                    shaderProperties.Add(prop);
                }
            }
            renderer = Host.GetComponent <Renderer>();
            graphic  = Host.GetComponent <Graphic>();
            if (renderer != null)
            {
                propertyBlock = InteractableThemeShaderUtils.InitMaterialPropertyBlock(host, shaderProperties);
            }
            else if (graphic != null)
            {
                UIMaterialInstantiator.TryCreateMaterialCopy(graphic);
            }
        }