コード例 #1
0
ファイル: GameRoot.cs プロジェクト: ijotus/TestKraft
        void CreateField()
        {
            int count         = 3;
            var templProgress = _resourcesManager.Load <GameObject>("prefabs/UIProgress");
            var templSource   = _resourcesManager.Load <GameObject>("prefabs/Source");
            var templReceiver = _resourcesManager.Load <GameObject>("prefabs/Receiver");

            var     offsetX         = 1;
            var     receiverOffsetX = 2;
            var     offsetY         = 1;
            var     halfScreen      = new Vector2(Screen.width, Screen.height) * (0.5f / PIXELS_PER_UNIT);
            Vector3 sourcePos       = new Vector3(-halfScreen.x + offsetX, 0, 0);
            Vector3 receiverPos     = new Vector3(halfScreen.x - receiverOffsetX, 0, 0);
            float   step            = Screen.height / (3f * PIXELS_PER_UNIT);

            int i = 0;

            while (count-- > 0)
            {
                var source = GameObject.Instantiate(templSource).GetComponent <ISource>();

                _sources.Add(source.GetHashCode(), source);

                var posY = halfScreen.y - (i++ *step) - offsetY;
                sourcePos.y     = posY;
                source.Position = sourcePos;
                _sourceInitialPosition.Add(source.GetHashCode(), sourcePos);


                var goProgress = GameObject.Instantiate(templProgress);
                var uiProgress = goProgress.GetComponent <IUIProgress>();
                _uiRoot.AddChild(goProgress.transform);



                var receiver = GameObject.Instantiate(templReceiver).GetComponent <IReceiver>();
                receiver.CollisionEnter += OnCollisionEnter;
                receiver.CollisionExit  += OnCollisionExit;
                _receivers.Add(receiver.GetHashCode(), receiver);

                receiverPos.y     = posY;
                receiver.Position = receiverPos;

                var progress = new ProgressHandler(_coroutine);
                progress.ProgressChanged += (a, b) => { uiProgress.SetProgress(b.Object1); };
                progress.ProgressDone    += (a, b) =>
                {
                    _circleColors.Remove(HexUtil.ColorToUint(receiver.Color));
                    receiver.Color = GetColor(true, receiver.Color);
                };
                _receiverProgresses.Add(receiver.GetHashCode(), progress);
                var screenPos = _cameraManager.WorldToScreenPoint(receiver.Position + new Vector3(1, 0, 0));
                goProgress.transform.position = new Vector3(screenPos.x, screenPos.y, screenPos.z / 10f);
            }
        }
コード例 #2
0
ファイル: GameRoot.cs プロジェクト: ijotus/TestKraft
        Color GetColor(Dictionary <uint, int> dic, Color lastColor)
        {
            var avaible = _config.Colors.Where((color) =>
            {
                var test = HexUtil.ColorToUint(color);
                return(!dic.ContainsKey(test) && lastColor != color);
            });

            var index  = UnityEngine.Random.Range(0, avaible.Count());
            var result = avaible.ElementAt(index);
            var cl     = HexUtil.ColorToUint(result);

            dic.Add(cl, 0);
            return(result);
        }
コード例 #3
0
ファイル: GameRoot.cs プロジェクト: ijotus/TestKraft
        void OnDrop(object sender, EventArgs e)
        {
            if (_currentSource != null && _currentReceiver != null)
            {
                if (_currentSource.Color == _currentReceiver.Color)
                {
                    Scores += 1;
                    _squareColors.Remove(HexUtil.ColorToUint(_currentSource.Color));
                    _currentSource.Color = GetColor(false, _currentSource.Color);
                }
            }

            var pos = _sourceInitialPosition[_currentSource.GetHashCode()];

            _currentSource.Position = pos;
            _currentSource          = null;
        }