/// <summary>
        /// Initializes a new instance of the <see cref="HeightStrategy"/> class.
        /// </summary>
        /// <param name="mode">The mode.</param>
        /// <param name="sampleGranularity">The sample granularity.</param>
        /// <param name="ledgeThreshold">The ledge threshold.</param>
        /// <param name="useGlobalHeightNavigationSettings">if set to <c>true</c> global height navigation settings will be used.</param>
        /// <param name="unitsHeightNavigationCapability">The global unit height navigation capability.</param>
        /// <param name="heightMapDetail">The height map detail.</param>
        public HeightStrategy(HeightSamplingMode mode, float sampleGranularity, float ledgeThreshold, bool useGlobalHeightNavigationSettings, HeightNavigationCapabilities unitsHeightNavigationCapability, HeightMapDetailLevel heightMapDetail)
        {
            switch (mode)
            {
                case HeightSamplingMode.HeightMap:
                {
                    _sampler = new HeightMapSampler();
                    break;
                }

                case HeightSamplingMode.Raycast:
                {
                    _sampler = new RaycastSampler();
                    break;
                }

                default:
                case HeightSamplingMode.NoHeightSampling:
                {
                    _sampler = new NullSampler();
                    break;
                }
            }

            this.heightMode = mode;
            this.sampleGranularity = sampleGranularity;
            this.ledgeThreshold = ledgeThreshold;
            this.useGlobalHeightNavigationSettings = useGlobalHeightNavigationSettings;
            this.unitsHeightNavigationCapability = unitsHeightNavigationCapability;
            this.heightMapDetail = heightMapDetail;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HeightStrategy"/> class.
        /// </summary>
        /// <param name="mode">The mode.</param>
        /// <param name="sampleGranularity">The sample granularity.</param>
        /// <param name="ledgeThreshold">The ledge threshold.</param>
        /// <param name="useGlobalHeightNavigationSettings">if set to <c>true</c> global height navigation settings will be used.</param>
        /// <param name="unitsHeightNavigationCapability">The global unit height navigation capability.</param>
        /// <param name="heightMapDetail">The height map detail.</param>
        public HeightStrategy(HeightSamplingMode mode, float sampleGranularity, float ledgeThreshold, bool useGlobalHeightNavigationSettings, HeightNavigationCapabilities unitsHeightNavigationCapability, HeightMapDetailLevel heightMapDetail)
        {
            switch (mode)
            {
            case HeightSamplingMode.HeightMap:
            {
                _sampler = new HeightMapSampler();
                break;
            }

            case HeightSamplingMode.Raycast:
            {
                _sampler = new RaycastSampler();
                break;
            }

            default:
            case HeightSamplingMode.NoHeightSampling:
            {
                _sampler = new NullSampler();
                break;
            }
            }

            this.heightMode        = mode;
            this.sampleGranularity = sampleGranularity;
            this.ledgeThreshold    = ledgeThreshold;
            this.useGlobalHeightNavigationSettings = useGlobalHeightNavigationSettings;
            this.unitsHeightNavigationCapability   = unitsHeightNavigationCapability;
            this.heightMapDetail = heightMapDetail;
        }
        /// <summary>
        /// Called on Start
        /// </summary>
        protected override void Start()
        {
            base.Start();

            // cache a few properties
            _heightSampler = GameServices.heightStrategy.heightSampler;

            var unitData = this.GetUnitFacade();
            _heightCaps = unitData.heightNavigationCapability;
            bufferDistance += unitData.radius;
        }
Example #4
0
        /// <summary>
        /// Called on Start and OnEnable, but only one of the two, i.e. at startup it is only called once.
        /// </summary>
        protected override void OnStartAndEnable()
        {
            _heightSampler = GameServices.heightStrategy.heightSampler;

            if (_unit == null)
            {
                _unit = this.GetUnitFacade();
            }

            base.OnStartAndEnable();
        }
        /// <summary>
        /// Called on Start and OnEnable, but only one of the two, i.e. at startup it is only called once.
        /// </summary>
        protected override void OnStartAndEnable()
        {
            _heightSampler = GameServices.heightStrategy.heightSampler;

            if (_unit == null)
            {
                _unit = this.GetUnitFacade();
            }

            base.OnStartAndEnable();
        }
Example #6
0
        /// <summary>
        /// Called on Start
        /// </summary>
        protected override void Start()
        {
            base.Start();

            // cache a few properties
            _heightSampler = GameServices.heightStrategy.heightSampler;

            var unitData = this.GetUnitFacade();

            _heightCaps     = unitData.heightNavigationCapability;
            bufferDistance += unitData.radius;
        }
Example #7
0
        private void Awake()
        {
            this.WarnIfMultipleInstances();

            _transform = this.transform;
            var rb = this.GetComponent <Rigidbody>();

            //Resolve the mover
            _mover = this.As <IMoveUnits>();
            if (_mover == null)
            {
                var fact           = this.As <IMoveUnitsFactory>();
                var charController = this.GetComponent <CharacterController>();

                if (fact != null)
                {
                    _mover = fact.Create();
                }
                else if (charController != null)
                {
                    _mover = new CharacterControllerMover(charController);
                }
                else if (rb != null)
                {
                    _mover = new RigidBodyMover(rb);
                }
                else
                {
                    _mover = new DefaultMover(_transform);
                }
            }

            //Make sure the rigidbody obeys the rules
            if (rb != null)
            {
                rb.constraints |= RigidbodyConstraints.FreezeRotation;
                rb.useGravity   = false;
            }

            //Height resolver
            _heights = GameServices.heightStrategy.heightSampler;

            //Assign unit ref, container for components and steering visitors
            _steeringComponents    = new List <ISteeringBehaviour>();
            _orientationComponents = new List <IOrientationBehaviour>();
            _steering      = new SteeringOutput();
            _orientation   = new OrientationOutput();
            _steeringInput = new SteeringInput();
        }
        private void Awake()
        {
            this.WarnIfMultipleInstances();

            _transform = this.transform;
            var rb = this.GetComponent<Rigidbody>();

            //Resolve the mover
            _mover = this.As<IMoveUnits>();
            if (_mover == null)
            {
                var fact = this.As<IMoveUnitsFactory>();
                var charController = this.GetComponent<CharacterController>();

                if (fact != null)
                {
                    _mover = fact.Create();
                }
                else if (charController != null)
                {
                    _mover = new CharacterControllerMover(charController);
                }
                else if (rb != null)
                {
                    _mover = new RigidBodyMover(rb);
                }
                else
                {
                    _mover = new DefaultMover(_transform);
                }
            }

            //Make sure the rigidbody obeys the rules
            if (rb != null)
            {
                rb.constraints |= RigidbodyConstraints.FreezeRotation;
                rb.useGravity = false;
            }

            //Height resolver
            _heights = GameServices.heightStrategy.heightSampler;

            //Assign unit ref, container for components and steering visitors
            _steeringComponents = new List<ISteeringBehaviour>();
            _orientationComponents = new List<IOrientationBehaviour>();
            _steering = new SteeringOutput();
            _orientation = new OrientationOutput();
            _steeringInput = new SteeringInput();
        }