IEnumerator StartFade(Callback0 fn)
    {
        SetActive(true);
        float timer = 0;
        Color color = image.color;

        image.color = new Color(color.r, color.g, color.b, 0);
        while (timer <= durationFade)
        {
            timer      += Time.unscaledDeltaTime;
            image.color = new Color(color.r, color.g, color.b, Mathf.Lerp(0, 1, timer / durationFade));
            yield return(null);
        }

        image.color = new Color(color.r, color.g, color.b, 1);

        if (fn != null)
        {
            fn();
        }


        timer = 0;
        while (timer <= durationFade)
        {
            timer      += Time.unscaledDeltaTime;
            image.color = new Color(color.r, color.g, color.b, Mathf.Lerp(1, 0, timer / durationFade));
            yield return(null);
        }

        image.color = new Color(color.r, color.g, color.b, 0);

        SetActive(false);
    }
    public static IEnumerator DeActive(GameObject obj, float duration, Callback0 fn)
    {
        yield return(new WaitForSeconds(duration));

        obj.SetActive(false);

        if (fn != null)
        {
            fn();
        }
    }
    public static IEnumerator Scale(Transform trans, Vector3 to, float duration, Callback0 fn = null)
    {
        float   elapsed = 0;
        Vector3 from    = trans.localScale;

        while (elapsed <= duration)
        {
            elapsed         += Time.deltaTime;
            trans.localScale = Vector3.Lerp(from, to, quartEaseInOut(elapsed / duration));
            yield return(null);
        }

        if (fn != null)
        {
            fn();
        }
    }
    public static IEnumerator FadeOut(Image image, float duration, Callback0 fn)
    {
        float elapsed = 0;

        while (elapsed <= duration)
        {
            elapsed += Time.deltaTime;
            Color currenColor = image.color;
            image.color = new Color(currenColor.r, currenColor.g, currenColor.b, Mathf.Lerp(1, 0, elapsed / duration));
            yield return(null);
        }

        if (fn != null)
        {
            fn();
        }
    }
    public static IEnumerator Move(GameObject obj, Vector3 to, float duration, Callback0 fn)
    {
        float   elapsed = 0;
        Vector3 from    = obj.transform.position;

        while (elapsed <= duration)
        {
            obj.transform.position = Vector3.Lerp(from, to, elapsed / duration);
            elapsed += Time.deltaTime;
            yield return(null);
        }

        obj.transform.position = to;
        if (fn != null)
        {
            fn();
        }
    }
Example #6
0
        //这里用协程关系到node是否绑定,如果不为空,则直接绑定
        void InitView()
        {
            if (node == null)
            {
                node = new GameObject("View");
            }

            if (LinkGOAndEntity(node, entity))
            {
                if (entity.hasEntityData)
                {
                    MoveNode(entity);
                    AddViewController(entity);
                    InitNode(entity);

                    onComplete?.Invoke();
                    onComplete = null;
                }
            }
        }
Example #7
0
 private static extern void register_app(ref AppInfo appInfo, IntPtr ctx, Callback0 o_cb);
    public static IEnumerator MoveAnchor(RectTransform rec, Vector2 to, float duration, Callback0 fn)
    {
        float   elapsed = 0;
        Vector3 from    = rec.anchoredPosition;

        while (elapsed <= duration)
        {
            elapsed += Time.deltaTime;
            rec.anchoredPosition = Vector2.Lerp(from, to, elapsed / duration);
            yield return(null);
        }
        if (fn != null)
        {
            fn();
        }
    }
 public void Fade(Callback0 fn)
 {
     StartCoroutine(StartFade(fn));
 }
Example #10
0
 public void onDisconnected(Callback0 callback)
 {
     disconnectedCallback = callback;
 }