devNotes 11-14-16 Button Script – Load Captcha – Scaling

 


using UnityEngine;
using System.Collections;
using ArgosTweenSpacePuppy;
using UnityEngine.UI;

public class File_Button_Animated : MonoBehaviour
{
    public Argos_File argos_File;

    public  float tween_Duration = 0.2f;
    private float tAccum_CoRout = 0;
    private float scaler = 0;
    private Vector3 base_scale;
    private Image img_Swatch;
    public  Image border_image;
    public  int myIdx;
    private bool bHovering = false;

    // Use this for initialization
    void Awake ()
    {
        base_scale = transform.localScale;
        img_Swatch = GetComponent<Image>();
    }
	
	// Update is called once per frame
	void Update ()
    {

    }

    public void onPointer_Enter()
    {
        if (GetComponent<Button>().interactable)
        {
            bHovering = true;
            argos_File.onFileButtonHover(myIdx);
            StopCoroutine("Tween_Hover");
            StartCoroutine("Tween_Hover", true);
        }
    }

    public void onLoadSave_Pointer_Enter()
    {
        bHovering = true;
        StopCoroutine("Tween_Hover");
        StartCoroutine("Tween_Hover", true);
    }

    public void onPointer_Exit()
    {
        bHovering = false;
        StopCoroutine("Tween_Hover");
        StartCoroutine("Tween_Hover", false);
    }

    public void DeSelect()
    {
        if (bHovering)
        {
            bHovering = false;
            StopCoroutine("Tween_Hover");
            StartCoroutine("Tween_Hover", false);
        }
    }
    int count = 0;
    public void onPointer_Down()
    {
        if (GetComponent<Button>().interactable)
        {
            argos_File.onFileButtonDown();
        }
    }

    public void setColor(Color col)
    {
        //swatch_color = col;
        //img_Swatch.color = col;
    }

    private IEnumerator Tween_Hover(bool hovering)
    {
        float dir = 1;

        if (!hovering)
        {
            dir = -1;
        }

        int i = 0; 

        float linProg = tAccum_CoRout / tween_Duration;

        while (i < 180 && ((hovering && linProg < 1) || (!hovering && linProg > 0)))
        {
            tAccum_CoRout += dir * Time.deltaTime;
            linProg = tAccum_CoRout / tween_Duration;
            Mathf.Clamp(tAccum_CoRout, 0, tween_Duration);

            scaler = EaseMethods.StrongEaseInOut(tAccum_CoRout, 0, 1, tween_Duration);
            Set_Hover_Scale(scaler);

            yield return true;
            i++;
        }

        if (hovering)
        {
            tAccum_CoRout = tween_Duration;
            scaler = 1;
        }
        else
        {
            tAccum_CoRout = 0;
            scaler = 0;
        }
        Set_Hover_Scale(scaler);
        StopCoroutine("Tween_Hover");
    }

    public void Set_Hover_Scale(float scaler)
    {
        transform.localScale = base_scale + 0.1f * base_scale * scaler;

        Color col = border_image.color;

        col.a = scaler;
        border_image.color = col;
    }
}

 

 

CxJme6aXEAQLhjG

AstroLabe

http://argos.vu/wp-content/uploads/2016/04/Vision_Summit_Review_Feb_10-11_2016.pdf