Beispiel #1
0
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition settings)
        {
            base.Init(host, settings);

            hostTransform    = Host.transform;
            originalRotation = IsLocalRotation ? hostTransform.localEulerAngles : hostTransform.eulerAngles;
        }
        /// <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);
            }
        }
        /// <summary>
        /// Helper method to create and initialize a Theme Engine for given configuration and targeted GameObject
        /// </summary>
        /// <param name="definition">Theme configuration with type information and properties to initialize ThemeEngine with</param>
        /// <param name="host">GameObject for Theme Engine to target</param>
        /// <returns>Instance of Theme Engine initialized</returns>
        public static InteractableThemeBase CreateAndInitTheme(ThemeDefinition definition, GameObject host = null)
        {
            var theme = CreateTheme(definition.ThemeType);

            theme.Init(host, definition);
            return(theme);
        }
Beispiel #4
0
 /// <inheritdoc />
 public override void Init(GameObject host, ThemeDefinition settings)
 {
     base.Init(host, settings);
     hostTransform    = Host.transform;
     originalPosition = hostTransform.localPosition;
     originalScale    = hostTransform.localScale;
 }
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition settings)
        {
            mesh        = host.GetComponent <TextMesh>();
            text        = host.GetComponent <Text>();
            meshPro     = host.GetComponent <TextMeshPro>();
            meshProUGUI = host.GetComponent <TextMeshProUGUI>();

            base.Init(host, settings);
        }
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition settings)
        {
            base.Init(host, settings);

            if (host != null)
            {
                startScaleValue         = new ThemePropertyValue();
                startScaleValue.Vector3 = host.transform.localScale;
            }

            timer = Ease.LerpTime;
        }
Beispiel #7
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;
        }
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition settings)
        {
            renderer = host.GetComponent <Renderer>();
            if (renderer != null)
            {
                initMaterial = renderer.material;
            }
            else
            {
                Debug.LogError($"Host GameObject {host} does not have a {typeof(Renderer).Name} component. InteractableMaterialTheme cannot execute.");
            }

            base.Init(host, settings);
        }
Beispiel #9
0
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition settings)
        {
            base.Init(host, settings);

            propertyBlocks = new List <BlocksAndRenderer>();
            Renderer[] list = host.GetComponentsInChildren <Renderer>();
            for (int i = 0; i < list.Length; i++)
            {
                MaterialPropertyBlock block = InteractableThemeShaderUtils.InitMaterialPropertyBlock(list[i].gameObject, shaderProperties);
                BlocksAndRenderer     bAndR = new BlocksAndRenderer();
                bAndR.Renderer = list[i];
                bAndR.Block    = block;

                propertyBlocks.Add(bAndR);
            }
        }
Beispiel #10
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);
        }
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition settings)
        {
            if (host != null)
            {
                originalLocalScale = host.transform.localScale;

#pragma warning disable 0618
                // Keep initializing property to support consumers who have not migrated.
                startScaleValue         = new ThemePropertyValue();
                startScaleValue.Vector3 = host.transform.localScale;
#pragma warning restore 0618
            }

            timer = Ease.LerpTime;

            base.Init(host, settings);
        }
        /// <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;
        }
Beispiel #13
0
        /// <inheritdoc/>
        void ISerializationCallbackReceiver.OnBeforeSerialize()
        {
            // Backward compatibility at runtime in case some custom properties have been added in code after first serialization
            ThemeDefinition defaultDefinition = GetDefaultThemeDefinition(ThemeType).Value;

            if (defaultDefinition.CustomProperties.Count > CustomProperties.Count)
            {
                foreach (ThemeProperty prop in defaultDefinition.CustomProperties)
                {
                    if (!CustomProperties.Exists(p => p.Name == prop.Name))
                    {
                        CustomProperties.Add(new ThemeProperty()
                        {
                            Name    = prop.Name,
                            Tooltip = prop.Tooltip,
                            Type    = prop.Type,
                            Value   = prop.Value,
                        });
                    }
                }
            }
        }
        /// <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);
            }
        }
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition settings)
        {
            base.Init(host, settings);

            hostTransform = Host.transform;
        }
Beispiel #16
0
 public override void Init(GameObject host, ThemeDefinition settings)
 {
     base.Init(host, settings);
     audioSource = Host.GetComponentInChildren <AudioSource>();
 }
Beispiel #17
0
 /// <inheritdoc />
 public override void Init(GameObject host, ThemeDefinition settings)
 {
     base.Init(host, settings);
     controller = Host.GetComponent <Animator>();
 }
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition settings)
        {
            base.Init(host, settings);

            renderer = Host.GetComponent <Renderer>();
        }
 /// <inheritdoc />
 public override void Init(GameObject host, ThemeDefinition settings)
 {
     base.Init(host, settings);
 }
Beispiel #20
0
        /// <inheritdoc />
        public override void Init(GameObject host, ThemeDefinition settings)
        {
            spriteIndexer = host.GetComponent <SpriteIndexer>();

            base.Init(host, settings);
        }