private void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                var pos = _camera.ScreenPointToRay(Input.mousePosition).origin;
                _selectedIdx = FindOverlappedParticle(pos);
            }

            if (_selectedIdx >= 0)
            {
                var m   = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * Time.deltaTime * _moveFactor;
                var pos = _target.GetParticlePosition(_selectedIdx);
                pos += m;
                _target.SetParticlePosition(_selectedIdx, pos);
            }
        }
Exemple #2
0
        /// <summary>
        /// 指定した座標に最も近いパーティクルの番号を取得する
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        int FindOverlappedParticle(Vector2 position)
        {
            if (!_target && !_target.IsReady())
            {
                return(-1);
            }

            int   minIdx       = -1;
            float minSqrLength = _pickRadius * _pickRadius;

            for (var i = 0; i < _target.GetParticleCount(); ++i)
            {
                var sqrLength = (_target.GetParticlePosition(i) - position).sqrMagnitude;
                if (sqrLength < minSqrLength)
                {
                    minIdx       = i;
                    minSqrLength = sqrLength;
                }
            }
            return(minIdx);
        }