/// <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;
        }
        private static int ResolveOptionsIdx(Collider c, HeightSamplingMode activeHeightMode)
        {
            if (activeHeightMode == HeightSamplingMode.NoHeightSampling)
            {
                return(6);
            }

            if (c is CapsuleCollider)
            {
                var cc = c as CapsuleCollider;
                if (cc.direction == 1)
                {
                    return(activeHeightMode == HeightSamplingMode.HeightMap ? 2 : 3);
                }

                return(activeHeightMode == HeightSamplingMode.HeightMap ? 4 : 5);
            }

            if (c is SphereCollider)
            {
                return(activeHeightMode == HeightSamplingMode.HeightMap ? 2 : 3);
            }

            if (c is BoxCollider || c is MeshCollider)
            {
                return(activeHeightMode == HeightSamplingMode.HeightMap ? 0 : 1);
            }

            return(6);
        }
Exemplo n.º 3
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;
        }
        internal static void EnsureValidProviders(HeightSamplingMode mode)
        {
            var items = Resources.FindObjectsOfTypeAll <DefaultHeightNavigator>();

            for (int i = 0; i < items.Length; i++)
            {
                var dhn = items[i];
                if (dhn == null || dhn.Equals(null) || PrefabUtility.GetPrefabType(dhn) == PrefabType.Prefab)
                {
                    continue;
                }

                var c = dhn.GetComponent <Collider>();
                if (c == null)
                {
                    continue;
                }

                var idx     = ResolveOptionsIdx(c, mode);
                var options = _options[idx];
                if (options.FindIndex(dhn.provider) == -1)
                {
                    dhn.provider = options.providerMapping[0];
                }
            }
        }
        internal static void EnsureValidProvider(DefaultHeightNavigator dhn, HeightSamplingMode mode)
        {
            var c = dhn.GetComponent <Collider>();

            var idx     = ResolveOptionsIdx(c, mode);
            var options = _options[idx];

            if (options.FindIndex(dhn.provider) == -1)
            {
                dhn.provider = options.providerMapping[0];
            }
        }
        internal static void EnsureValidProviders(HeightSamplingMode mode)
        {
            var items = Resources.FindObjectsOfTypeAll<DefaultHeightNavigator>();
            for (int i = 0; i < items.Length; i++)
            {
                var dhn = items[i];
                if (dhn == null || dhn.Equals(null) || PrefabUtility.GetPrefabType(dhn) == PrefabType.Prefab)
                {
                    continue;
                }

                var c = dhn.GetComponent<Collider>();
                if (c == null)
                {
                    continue;
                }

                var idx = ResolveOptionsIdx(c, mode);
                var options = _options[idx];
                if (options.FindIndex(dhn.provider) == -1)
                {
                    dhn.provider = options.providerMapping[0];
                }
            }
        }
        private static int ResolveOptionsIdx(Collider c, HeightSamplingMode activeHeightMode)
        {
            if (activeHeightMode == HeightSamplingMode.NoHeightSampling)
            {
                return 6;
            }

            if (c is CapsuleCollider)
            {
                var cc = c as CapsuleCollider;
                if (cc.direction == 1)
                {
                    return activeHeightMode == HeightSamplingMode.HeightMap ? 2 : 3;
                }

                return activeHeightMode == HeightSamplingMode.HeightMap ? 4 : 5;
            }

            if (c is SphereCollider)
            {
                return activeHeightMode == HeightSamplingMode.HeightMap ? 2 : 3;
            }

            if (c is BoxCollider || c is MeshCollider)
            {
                return activeHeightMode == HeightSamplingMode.HeightMap ? 0 : 1;
            }

            return 6;
        }
        internal static void EnsureValidProvider(DefaultHeightNavigator dhn, HeightSamplingMode mode)
        {
            var c = dhn.GetComponent<Collider>();

            var idx = ResolveOptionsIdx(c, mode);
            var options = _options[idx];
            if (options.FindIndex(dhn.provider) == -1)
            {
                dhn.provider = options.providerMapping[0];
            }
        }