Пример #1
0
        /// <summary>
        /// Gets a random HapticLocation on the configured HardlightSuit.
        /// NOTE: Will remove DisabledRegions
        /// </summary>
        /// <param name="OnlyAreasWithinSet">The AreaFlags you want to randomly select from.</param>
        /// <param name="DisplayInEditor"></param>
        /// <returns>A valid HapticLocation on the body (defaults to null if none are configured or if it is configured incorrectly.</returns>
        public HapticLocation FindRandomLocation(AreaFlag OnlyAreasWithinSet = AreaFlag.All_Areas, bool RemoveDisabledRegions = false, bool DisplayInEditor = false)
        {
            if (RemoveDisabledRegions)
            {
                OnlyAreasWithinSet = OnlyAreasWithinSet.RemoveArea(DisabledRegions.InactiveRegions);
            }

            HapticLocation loc = Definition.GetRandomLocationWithinSet(OnlyAreasWithinSet).GetComponent <HapticLocation>();

            if (loc != null)
            {
                if (!loc.LocationActive)
                {
                    Debug.LogError("FindRandomLocation and GetRandomLocationWithinSet have returned a HapticLocation that is marked as inactive.\n\tThis is an expected bug but should be fixed in the future - try using DeactiveHapticLocation to turn regions off.\n");
                }
                if (DisplayInEditor)
                {
                    ColorHapticLocationInEditor(loc, Color.blue);
                }

                return(loc);
            }
            else
            {
                Debug.LogError("Failed to complete PlayerBody.FindRandomLocation(). The returned object did not have a HapticLocation component\n");
            }
            return(null);
        }
Пример #2
0
        /// <summary>
        /// Finds a Haptic Location near the source point. Only returns a HapticLocation that we have valid line of sight to the object.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="requireLineOfSight"></param>
        /// <param name="hitLayers"></param>
        /// <returns>A single HapticLocation that is close to the point and within line of sight of it. Defaults to null if nothing within MaxDistance is within range.</returns>
        public HapticLocation FindNearbyLocation(Vector3 point, bool requireLineOfSight, LayerMask hitLayers, float maxDistance = 5.0f)
        {
            GameObject[] closest = Definition.GetMultipleNearestLocations(point, 16, maxDistance);

            //Debug.Log("Find Nearby: " + closest.Length + "\n");
            for (int i = 0; i < closest.Length; i++)
            {
                HapticLocation loc = closest[i].GetComponent <HapticLocation>();
                Debug.DrawLine(point, loc.transform.position, Color.green, 15.0f);
                if (closest[i] != null && loc != null && loc.LocationActive)
                {
                    RaycastHit hit;
                    float      dist = Vector3.Distance(point, loc.transform.position);
                    if (Physics.Raycast(point, loc.transform.position - point, out hit, dist, hitLayers))
                    {
                        //Debug.Log("Hit: " + hit.collider.name + "\n" + hit.collider.gameObject.layer + "\n");
                        Debug.DrawLine(point, hit.point, Color.red, 15.0f);
                    }
                    else
                    {
                        Debug.DrawLine(point, loc.transform.position, Color.green, 15.0f);

                        ColorHapticLocationInEditor(loc, Color.green);
                        return(loc);
                    }
                }
            }
            return(null);
        }
Пример #3
0
        void CheckMyLocation()
        {
            if (_myLocation == null)
            {
                HapticLocation loc = GetComponent <HapticLocation>();

                if (loc == null)
                {
                    Debug.LogError("Haptic Location of " + name + " is null despite being a required component.\n\tYou should NEVER hit this. There is only one case I know of which involves recompiling after adding the RequiresComponent attribute.");
                }
                Debug.Assert(loc != null);
                _myLocation = loc;
            }
        }
Пример #4
0
        /// <summary>
        /// This function is a no-op outside of the editor.
        /// Preprocessor defines keep it from impacting your game's performance.
        /// </summary>
        /// <param name="location">The HapticLocation to color (gets the MeshRenderer)</param>
        /// <param name="color">Defaults to red - the color to use. Will return to the default color of all haptic locations afterward.</param>
        public void ColorHapticLocationInEditor(HapticLocation location, Color color = default(Color))
        {
#if UNITY_EDITOR
            if (color == default(Color))
            {
                color = Color.red;
            }
            MeshRenderer rend = location.gameObject.GetComponent <MeshRenderer>();
            if (rend != null)
            {
                StartCoroutine(ColorHapticLocationCoroutine(rend, color));
            }
#endif
        }
Пример #5
0
        /// <summary>
        /// Finds the nearest HapticLocation.Where on the HardlightSuit to the provided point
        /// </summary>
        /// <param name="point">The world space to compare to the PlayerTorso body.</param>
        /// <param name="maxDistance">Disregard body parts less than the given distance</param>
        /// <returns>Defaults to AreaFlag.None if no areas are within range.</returns>
        public AreaFlag FindNearestFlag(Vector3 point, float maxDistance = 5.0f)
        {
            //Maybe get a list of nearby regions?
            GameObject closest = Definition.GetNearestLocation(point, maxDistance);

            //Debug.Log("closest: " + closest.name + "\n");
            if (closest != null && closest.GetComponent <HapticLocation>() != null)
            {
                HapticLocation loc = closest.GetComponent <HapticLocation>();
                ColorHapticLocationInEditor(loc, Color.cyan);
                return(loc.Where);
            }
            Debug.LogError("Could not find the closest pad. Returning an empty location\n" + closest.name);
            return(AreaFlag.None);
        }
Пример #6
0
        /// <summary>
        /// Finds a Haptic Location near the source point.
        /// </summary>
        /// <param name="point">A point near the player's body</param>
        /// <returns>Returns null if no location is within the max distance</returns>
        public HapticLocation FindNearbyLocation(Vector3 point, float maxDistance = 5.0f)
        {
            //Maybe get a list of nearby regions?
            GameObject[] closest = Definition.GetMultipleNearestLocations(point, 1, maxDistance);

            //Debug.Log("Find Nearby: " + closest.Length + "\n");
            for (int i = 0; i < closest.Length; i++)
            {
                HapticLocation loc = closest[i].GetComponent <HapticLocation>();
                //Debug.DrawLine(source, loc.transform.position, Color.green, 15.0f);
                if (closest[i] != null && loc != null && loc.LocationActive)
                {
                    Debug.DrawLine(point, loc.transform.position, Color.red, 15.0f);

                    ColorHapticLocationInEditor(loc, Color.red);
                    return(loc);
                }
            }
            return(null);
        }
Пример #7
0
        /// <summary>
        /// This function finds all HapticLocations within maxDistance of the provided worldspace Point.
        /// </summary>
        /// <param name="point">A worldspace point to compare</param>
        /// <param name="maxDistance">The max distance to look for HapticLocations from this suit's definition.</param>
        /// <returns>AreaFlag with the flagged areas within range. Tip: Use value.AreaCount() or value.IsSingleArea()</returns>
        public AreaFlag FindAllFlagsWithinRange(Vector3 point, float maxDistance, bool DisplayInEditor = false)
        {
            AreaFlag result = AreaFlag.None;

            GameObject[] closest = Definition.GetMultipleNearestLocations(point, 16, maxDistance);
            for (int i = 0; i < closest.Length; i++)
            {
                HapticLocation loc = closest[i].GetComponent <HapticLocation>();
                if (loc != null)
                {
                    if (DisplayInEditor)
                    {
                        ColorHapticLocationInEditor(loc, Color.cyan);
                    }

                    //Debug.Log("Adding: " + loc.name + "\n");
                    result = result.AddFlag(loc.Where);
                }
            }
            //Debug.Log("Result of find all flags: " + result.AreaCount() + "\n");
            return(result);
        }
Пример #8
0
        private void ExampleRequestRandomLocation()
        {
            //We use the suit's find random location option - this gives us a random pad.
            //Great for if your bad guys
            HapticLocation randomLocation = suit.FindRandomLocation(AreaFlag.All_Areas);

            //Directly away from the randomly requested pad.
            Vector3 away = (randomLocation.transform.position - suit.transform.position);

            //The random pads location.
            Vector3 randLocationPosition = randomLocation.transform.position;

            //A bit of fuzzing so the lines stand apart
            Vector3 fuzzyOffset = Random.insideUnitSphere * .1f;

            //Debug.Log("Requested Random Location : " + randomLocation.Where.ToString() + "\n" + randomLocation.name.ToString() + "\t\t" + away.ToString());

            //Draw a line to show the result
            Debug.DrawLine(randLocationPosition + fuzzyOffset,
                           randLocationPosition + fuzzyOffset + away.normalized * 5,
                           Color.cyan, 8.0f);
        }