/// <summary> /// Called when the cursor move on /// the button. /// </summary> public void OnPointerEnter(PointerEventData eventData) { if (hoverEffect == ToggleButtonHoverEffect.ChangeLeverColor) { LeverMaterial.SetColor("_Color1", LeverColorHovered); LeverMaterial.SetColor("_Color2", LeverColorHovered); } mouseIsOver = true; }
/// <summary> /// Called when the cursor moves off /// the button. /// </summary> public void OnPointerExit(PointerEventData eventData) { if (hoverEffect == ToggleButtonHoverEffect.ChangeLeverColor) { if (leverTransitionType == TransitionType.ChangeColor) { LeverMaterial.SetColor("_Color1", LeverColorOff); LeverMaterial.SetColor("_Color2", leverColorOn); } else { LeverMaterial.SetColor("_Color1", Color.white); LeverMaterial.SetColor("_Color2", Color.white); } } mouseIsOver = false; }
/// <summary> /// Updates the visuals of the button /// depending on whether it's currently /// on or off. /// </summary> /// <remarks> /// If animate is false, then /// the transition of the button visual /// stuff is instant. /// </remarks> private void UpdateUI(bool animate) { if (leverTransitionType == TransitionType.ChangeColor) { // Different colors if (!mouseIsOver) { LeverMaterial.SetColor("_Color1", LeverColorOff); LeverMaterial.SetColor("_Color2", LeverColorOn); } // Same textures LeverMaterial.SetTexture("_MainTex1", leverOffSprite ? leverOffSprite.texture : null); LeverMaterial.SetTexture("_MainTex2", leverOffSprite ? leverOffSprite.texture : null); } else if (leverTransitionType == TransitionType.ChangeImage) { // Default colors if (!mouseIsOver) { LeverMaterial.SetColor("_Color1", Color.white); LeverMaterial.SetColor("_Color2", Color.white); } // Different textures LeverMaterial.SetTexture("_MainTex1", leverOffSprite ? leverOffSprite.texture : null); LeverMaterial.SetTexture("_MainTex2", leverOnSprite ? leverOnSprite.texture : null); } else { // Default colors if (!mouseIsOver) { LeverMaterial.SetColor("_Color1", Color.white); LeverMaterial.SetColor("_Color2", Color.white); } // Same textures LeverMaterial.SetTexture("_MainTex1", leverOffSprite ? leverOffSprite.texture : null); LeverMaterial.SetTexture("_MainTex2", leverOffSprite ? leverOffSprite.texture : null); } if (backgroundTransitionType == TransitionType.ChangeColor) { // Different colors BackgroundMaterial.SetColor("_Color1", BackgroundColorOff); BackgroundMaterial.SetColor("_Color2", BackgroundColorOn); // Same textures BackgroundMaterial.SetTexture("_MainTex1", backgroundOffSprite ? backgroundOffSprite.texture : null); BackgroundMaterial.SetTexture("_MainTex2", backgroundOffSprite ? backgroundOffSprite.texture : null); } else if (backgroundTransitionType == TransitionType.ChangeImage) { // Default colors BackgroundMaterial.SetColor("_Color1", Color.white); BackgroundMaterial.SetColor("_Color2", Color.white); // Different textures BackgroundMaterial.SetTexture("_MainTex1", backgroundOffSprite ? backgroundOffSprite.texture : null); BackgroundMaterial.SetTexture("_MainTex2", backgroundOnSprite ? backgroundOnSprite.texture : null); } else { // Default colors BackgroundMaterial.SetColor("_Color1", Color.white); BackgroundMaterial.SetColor("_Color2", Color.white); // Same textures BackgroundMaterial.SetTexture("_MainTex1", backgroundOffSprite ? backgroundOffSprite.texture : null); BackgroundMaterial.SetTexture("_MainTex2", backgroundOffSprite ? backgroundOffSprite.texture : null); } // Deciding lever direction float positionX = size / 2f; if (!isOn) { positionX = -positionX; } Vector2 targetPosition = new Vector2(positionX, 0f); if (animate) { MoveLeverAnimated(targetPosition); } else { MoveLeverInstantly(targetPosition); } }