Пример #1
0
        public void Init(float speed, int amount)
        {
            if (RatioGameManager.GetGuideMgr().IsInGuide)
            {
                InitGuide();
                return;
            }

            this.speed  = speed;
            this.amount = amount;
            int mCount  = RatioHardManager.GetBallMaterial();
            var prefabs = RatioGameManager.Instance.GetBallPrefabs(amount, mCount);
            int cCount  = RatioHardManager.GetBallColor();
            var colors  = RatioGameManager.Instance.GetBallColors(amount, cCount);

            for (int i = 0; i < amount; i++)
            {
                var ball     = Instantiate(prefabs[i]);
                var renderer = ball.GetComponent <Renderer>();
                renderer.material.color   = colors[i];
                ball.gameObject.name      = i.ToString();
                ball.transform.parent     = transform;
                ball.transform.localScale = Vector3.one * (0.8f + offsetScale * i);
                ball.Init(i, this);
                ballList.Add(ball);
            }

            var randomList = RatioGameManager.Instance.RandomSortList <Ball>(ballList);

            int half = Mathf.CeilToInt(amount / 2f);
            int mod  = amount % 2;

            //set position
            float offset = 2.5f - amount * 0.1f;

            if (mod == 0)
            {
                for (int i = 0; i < half; i++)
                {
                    randomList[i].transform.localPosition = new Vector3(-(i * offset + offset / 2f), 0, 0);
                    randomList[amount - 1 - i].transform.localPosition = new Vector3(i * offset + offset / 2f, 0, 0);
                }
            }
            else
            {
                for (int i = 0; i < half; i++)
                {
                    randomList[half + i - 1].transform.localPosition = new Vector3(i * offset, 0, 0);
                    randomList[half - i - 1].transform.localPosition = new Vector3(-i * offset, 0, 0);
                }
            }
        }
Пример #2
0
        public void OnClicked(Ball ball)
        {
            if (RatioGameManager.GetGuideMgr().IsInGuide)
            {
                if (ball.id == curIndex)
                {
                    if (RatioGameManager.GetGuideMgr().CanClick(curIndex))
                    {
                        var exp = Instantiate(RatioGameManager.Instance.explosion);
                        exp.layer = 1;
                        exp.transform.position = ball.transform.position;
                        ballList.Remove(ball);
                        Destroy(ball.gameObject);
                        curIndex++;
                    }
                }
                return;
            }

            if (ball.id == curIndex)
            {
                var exp = Instantiate(RatioGameManager.Instance.explosion);
                exp.transform.position = ball.transform.position;
                ballList.Remove(ball);
                Destroy(ball.gameObject);
                curIndex++;
                if (curIndex == amount)
                {
                    RatioGameManager.Instance.WinOnce();
                }

                RatioGameManager.Instance.ClickRight();
            }
            else
            {
                Hashtable args = new Hashtable();
                args.Add("amount", new Vector3(0.1f, 0.1f, 0.1f));
                args.Add("isLocal", true);
                args.Add("time", 0.5f);
                iTween.ShakePosition(ball.gameObject, args);

                RatioGameManager.Instance.ClickWrong();
            }
        }