Exemplo n.º 1
0
        public void OnEvent(UIVirusAddLevelCoinEvent eventType)
        {
            var     rt   = transform as RectTransform;
            Vector2 pos  = VirusTool.SceneToUguiPos(rt, eventType.WorldPos);
            var     coin = PropPools.Instance.Spawn("Coin");

            coin.transform.SetParent(coinParent);
            var rectTransform = coin.transform as RectTransform;

            rectTransform.localScale = Vector3.one;
            if (rectTransform != null)
            {
                rectTransform.anchoredPosition = pos;
                Vector2 e   = _coinBg.anchoredPosition;
                Vector2 s   = pos;
                Vector2 dir = Quaternion.Euler(0, 0, -90) * (e - s).normalized;
                float   mul = Random.Range(0, 2) == 1 ? 1f : -1f;
                float   t1  = Random.Range(0.3f, 0.5f);
                Vector2 mid = Vector2.Lerp(s, e, t1) + mul * dir * Random.Range(1.0f, 2.0f) * 100f;
                float   dis = (e - s).magnitude;
                DOVirtual.Float(0, 10, dis / 1000f, (t) =>
                {
                    Vector2 p = VirusTool.GetBesselPoint(s, e, mid, t / 10f);
                    rectTransform.anchoredPosition = p;
                }).OnComplete(() =>
                {
                    PropPools.Instance.DeSpawn(coin);
                    _isLerp = true;
                    VirusSoundMrg.Instance.PlaySound(VirusSoundType.LevelCoin);
                });
            }
        }