Exemple #1
0
        /// <summary>
        /// Approximates the number of crowd members that will be generated ,
        /// based on the current values in this object
        /// </summary>
        /// <returns> The predicted value for the crowd members generated</returns>
        public int GetPrediction()
        {
            int _prediction = 0;

            var _bounds = transform.GetChild(0).transform.localPosition;

            switch (_crowdFormation)
            {
            case CrowdFormation.CIRCLE:
                _prediction = CrowdGen.EstimateCircle(_density, _bounds);
                break;

            case CrowdFormation.RING:
                _prediction = CrowdGen.EstimateRing(_density, _bounds, _innerRadius);

                break;

            case CrowdFormation.SQUARE:
                _prediction = CrowdGen.EstimateSquare(_density, _bounds);
                break;
            }


            return(_prediction);
        }
Exemple #2
0
        /// <summary>
        /// Generates a crowd based on the current values in the controller
        /// </summary>
        public void GenerateCrowd()
        {
            if (!_setUp)
            {
                SetUp();
            }

            var _parent = new GameObject();

            _parent.name = "Crowd Source";

            var _cleaner = _parent.AddComponent <CrowdSourceCleaner>();


            var _bounds = transform.GetChild(0).transform.localPosition;

            _parent.transform.position = transform.position;

            var _posModifier = Vector3.zero;

            if (_bounds.x < 0)
            {
                _posModifier.x += _bounds.x;
                _bounds.x      *= -1;
            }

            if (_bounds.z < 0)
            {
                _posModifier.z += _bounds.z;
                _bounds.z      *= -1;
            }

            _parent.transform.position += _posModifier;


            GameObject[] _newCrowd;

            _cleaner.Controller = this;

            switch (_crowdFormation)
            {
            case CrowdFormation.CIRCLE:

                _parent.transform.position += .5f * _bounds;
                _newCrowd = CrowdGen.GenCrowdCircle(_density, _rotDir, _parent, _bounds, _placeholderPrefab);
                break;


            case CrowdFormation.SQUARE:

                _parent.transform.position += .5f * CrowdGen.GetObjectBounds(_placeholderPrefab);
                _newCrowd = CrowdGen.GenCrowdSquare(_density, _rotDir, _parent, _bounds, _placeholderPrefab);
                break;

            default:     // for ring formation
                _parent.transform.position += .5f * _bounds;

                _newCrowd = CrowdGen.GenCrowdRing(_density, _rotDir, _parent, _bounds, _placeholderPrefab, _innerRadius);
                break;
            }

            if (_newCrowd.Length > 0)
            {
                _groupUnassigned.AddCrowdMember(_newCrowd);
                _crowdSources.Add(_parent);
                RecalculateCount();
            }
            else
            {
                Destroy(_parent);
            }
        }