/// <inheritdoc /> public override void SetValue(ThemeStateProperty property, int index, float percentage) { Host.SetActive(property.Values[index].Bool); material = property.Values[index].Material; renderer.material = material; }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { if (renderer == null) { return(null); } renderer.GetPropertyBlock(propertyBlock); startValue.Reset(); int propId = property.GetShaderPropertyId(); switch (property.Type) { case ThemePropertyTypes.Color: startValue.Color = propertyBlock.GetVector(propId); break; case ThemePropertyTypes.Texture: startValue.Texture = propertyBlock.GetTexture(propId); break; case ThemePropertyTypes.ShaderFloat: case ThemePropertyTypes.ShaderRange: startValue.Float = propertyBlock.GetFloat(propId); break; default: break; } return(startValue); }
/// <inheritdoc /> public override void SetValue(ThemeStateProperty property, int index, float percentage) { if (renderer != null) { renderer.GetPropertyBlock(propertyBlock); int propId = property.GetShaderPropertyId(); var propValue = property.Values[index]; switch (property.Type) { case ThemePropertyTypes.Color: Color newColor = Color.Lerp(property.StartValue.Color, propValue.Color, percentage); propertyBlock.SetColor(propId, newColor); break; case ThemePropertyTypes.Texture: propertyBlock.SetTexture(propId, propValue.Texture); break; case ThemePropertyTypes.ShaderFloat: case ThemePropertyTypes.ShaderRange: float floatValue = LerpFloat(property.StartValue.Float, propValue.Float, percentage); propertyBlock.SetFloat(propId, floatValue); break; default: break; } renderer.SetPropertyBlock(propertyBlock); } }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { ThemePropertyValue start = new ThemePropertyValue(); start.Vector3 = IsLocalRotation ? hostTransform.localEulerAngles : hostTransform.eulerAngles; return(start); }
/// <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); } }
/// <inheritdoc /> protected override void SetValue(ThemeStateProperty property, ThemePropertyValue value) { if (spriteIndexer != null) { spriteIndexer.SetIndex(value.Int); } }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { ThemePropertyValue start = new ThemePropertyValue(); start.Bool = Host.activeSelf; return(start); }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { ThemePropertyValue start = new ThemePropertyValue(); start.String = property.Values[lastIndex].String; return(start); }
/// <inheritdoc /> protected override void SetValue(ThemeStateProperty property, ThemePropertyValue value) { if (controller != null && !string.IsNullOrEmpty(value.String)) { controller.SetTrigger(value.String); } }
/// <inheritdoc /> protected override void SetValue(ThemeStateProperty property, ThemePropertyValue value) { if (Host != null) { Host.transform.localScale = value.Vector3; } }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { ThemePropertyValue start = new ThemePropertyValue(); start.Vector3 = hostTransform.localScale; return(start); }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { ThemePropertyValue start = new ThemePropertyValue(); start.Vector3 = hostTransform != null ? hostTransform.localPosition : Vector3.zero; return(start); }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { ThemePropertyValue start = new ThemePropertyValue(); start.String = string.Empty; if (mesh != null) { start.String = mesh.text; } else if (text != null) { start.String = text.text; } else if (meshPro != null) { start.String = meshPro.text; } else if (meshProUGUI != null) { start.String = meshProUGUI.text; } return(start); }
/// <inheritdoc /> protected override void SetValue(ThemeStateProperty property, ThemePropertyValue value) { if (renderer != null) { material = value.Material; renderer.material = material; } }
/// <inheritdoc /> public override void SetValue(ThemeStateProperty property, int index, float percentage) { if (renderer != null) { material = property.Values[index].Material; renderer.material = material; } }
/// <inheritdoc /> public override void SetValue(ThemeStateProperty property, int index, float percentage) { if (lastIndex != index) { SetValue(property, property.Values[index]); lastIndex = index; } }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { ThemePropertyValue start = new ThemePropertyValue(); material = renderer.material; start.Material = material; return(start); }
public override void SetValue(ThemeStateProperty property, int index, float percentage) { if (audioSource == null) { audioSource = Host.AddComponent <AudioSource>(); } audioSource.clip = property.Values[index].AudioClip; audioSource.Play(); }
/// <inheritdoc /> protected override void SetValue(ThemeStateProperty property, ThemePropertyValue value) { if (audioSource == null) { audioSource = Host.AddComponent <AudioSource>(); } audioSource.clip = value.AudioClip; audioSource.Play(); }
public override ThemePropertyValue GetProperty(ThemeStateProperty property) { ThemePropertyValue start = new ThemePropertyValue(); AudioSource audioSource = Host.GetComponentInChildren <AudioSource>(); if (audioSource != null) { start.AudioClip = audioSource.clip; } return(start); }
/// <inheritdoc /> public override void SetValue(ThemeStateProperty property, int index, float percentage) { if (lastIndex != index) { if (controller != null) { controller.SetTrigger(property.Values[index].String); } lastIndex = index; } }
private void SetShaderValue(ThemeStateProperty property, Color color, Texture tex, float floatValue) { int propId = property.GetShaderPropertyId(); if (renderer != null) { renderer.GetPropertyBlock(propertyBlock); switch (property.Type) { case ThemePropertyTypes.Color: propertyBlock.SetColor(propId, color); break; case ThemePropertyTypes.Texture: if (tex != null) { propertyBlock.SetTexture(propId, tex); } break; case ThemePropertyTypes.ShaderFloat: case ThemePropertyTypes.ShaderRange: propertyBlock.SetFloat(propId, floatValue); break; default: break; } renderer.SetPropertyBlock(propertyBlock); } else if (graphic != null) { switch (property.Type) { case ThemePropertyTypes.Color: graphic.material.SetColor(propId, color); break; case ThemePropertyTypes.Texture: graphic.material.SetTexture(propId, tex); break; case ThemePropertyTypes.ShaderFloat: case ThemePropertyTypes.ShaderRange: graphic.material.SetFloat(propId, floatValue); break; default: break; } } }
/// <inheritdoc /> public override void SetValue(ThemeStateProperty property, int index, float percentage) { Vector3 lerpTarget = property.Values[index].Vector3; if (IsRelativeRotation) { lerpTarget = (IsLocalRotation ? originalLocalRotation : originalRotation) + lerpTarget; } SetRotation(Quaternion.Euler(Vector3.Lerp(property.StartValue.Vector3, lerpTarget, percentage))); }
/// <inheritdoc /> public override void SetValue(ThemeStateProperty property, int index, float percentage) { if (!hasGrab && Host != null) { Host.transform.localScale = Vector3.Lerp(property.StartValue.Vector3, Vector3.Scale(startScaleValue.Vector3, property.Values[index].Vector3), percentage); } else { // there is near interaction grab so make sure Ease is not running Ease.Stop(); } }
/// <summary> /// Try to set color on TextMeshProUGUI /// If false, no TextMeshProUGUI was found /// </summary> /// <param name="color">Color to try to set</param> /// <returns>true if succesfully set color on TextMeshProUGUI</returns> protected bool TrySetTextMeshProUGUIColor(Color color, ThemeStateProperty property, int index, float percentage) { TextMeshProUGUI tmp = Host.GetComponent <TextMeshProUGUI>(); if (tmp) { tmp.color = color; return(true); } return(false); }
/// <summary> /// Try to set color on TextMesh /// If false, no TextMesh was found /// </summary> /// <param name="color">Color to try to set</param> /// <returns>true if succesfully set color on TextMesh</returns> protected bool TrySetTextMeshColor(Color color, ThemeStateProperty property, int index, float percentage) { TextMesh mesh = Host.GetComponent <TextMesh>(); if (mesh != null) { mesh.color = color; return(true); } return(false); }
/// <summary> /// Try to set color on UI Text /// If false, no UI Text was found /// </summary> /// <param name="color">Color to try to set</param> /// <returns>true if succesfully set color on Text</returns> protected bool TrySetTextColor(Color color, ThemeStateProperty property, int index, float percentage) { Text text = Host.GetComponent <Text>(); if (text != null) { text.color = color; return(true); } return(false); }
/// <summary> /// Try to get color from TextMeshPro /// If no color is found, TextMeshPro is not on the object /// </summary> /// <param name="color">Color to try to get, returns white if no TextMesh component found</param> /// <returns>true if succesfully get color on TextMeshPro</returns> protected bool TryGetTextMeshProColor(ThemeStateProperty property, out Color color) { color = Color.white; TextMeshPro tmp = Host.GetComponent <TextMeshPro>(); if (tmp) { color = tmp.color; return(true); } return(false); }
private void SetColor(ThemeStateProperty property, Color color) { int propId = property.GetShaderPropertyId(); for (int i = 0; i < propertyBlocks.Count; i++) { BlocksAndRenderer bAndR = propertyBlocks[i]; bAndR.Block.SetColor(propId, color); bAndR.Renderer.SetPropertyBlock(bAndR.Block); propertyBlocks[i] = bAndR; } }
/// <inheritdoc /> public override ThemePropertyValue GetProperty(ThemeStateProperty property) { if (Host == null) { return(startScaleValue); } ThemePropertyValue prop = new ThemePropertyValue(); prop.Vector3 = Host.transform.localScale; return(prop); }