Ejemplo n.º 1
0
        private bool IsHardlightColliderIsInRangeOfLine(HardlightCollider hardlightCollider, float range, Vector3 A, Vector3 B)
        {
            Vector3 checkedObjectPosition;
            Vector3 ClosestPoint = Vector3.one * 10000;

            checkedObjectPosition = hardlightCollider.transform.position;
            Vector3 AB = B - A;
            float   t  = Vector3.Dot(checkedObjectPosition - A, AB) / Vector3.Dot(AB, AB);

            ClosestPoint = A + t * AB;
            //Vector3 directLineToPoint;

            float SpherecastSizeAndLocationSize = hardlightCollider.LocationSize + range;
            bool  hit = CheckPointDistance(SpherecastSizeAndLocationSize, checkedObjectPosition, ClosestPoint, t);

            for (int i = 0; i < hardlightCollider.AdditionalLocalPoints.Count; i++)
            {
                if (!hit)
                {
                    checkedObjectPosition = hardlightCollider.transform.position + hardlightCollider.transform.rotation * hardlightCollider.AdditionalLocalPoints[i];
                    hit = CheckPointDistance(SpherecastSizeAndLocationSize, checkedObjectPosition, ClosestPoint, t);
                }
            }

            if (hit)
            {
                Debug.DrawLine(checkedObjectPosition, ClosestPoint, Color.green);
            }
            //else
            //{
            //	Debug.DrawLine(ClosestPoint, ClosestPoint - (ClosestPoint - checkedObjectPosition).normalized * range, Color.red);
            //	Debug.DrawLine(checkedObjectPosition, checkedObjectPosition + (ClosestPoint - checkedObjectPosition).normalized * hardlightCollider.LocationSize, Color.blue);
            //}

            return(hit);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This function replaces existing elements so we can change the suit definition more easily at runtime (say the player's arm is added or destroyed)
        /// </summary>
        /// <param name="SingleFlagToModify"></param>
        /// <param name="SingleHolder"></param>
        /// <param name="newCollider"></param>
        /// <returns></returns>
        public bool ModifyValidRegions(AreaFlag SingleFlagToModify, GameObject SingleHolder, HardlightCollider newCollider)
        {
            bool Succeeded = false;

            if (!SingleFlagToModify.IsSingleArea())
            {
                Debug.LogError("Attempted to modify the valid regions of the Hardlight Suit by providing a complex AreaFlag.\n\tThis function does not yet support complex area flags. Call it individually for each flag if you need to do this.");

                return(false);
            }

            if (SingleHolder == null || newCollider == null || SingleFlagToModify == AreaFlag.None)
            {
                Debug.LogError("Attempted to modify the valid regions of the Hardlight Suit to provide invalid elements (either the collider or the holder) or to provide an AreaFlag of None (" + SingleFlagToModify.ToString() + ")");
                return(false);
            }

            bool ReplacedExistingElement = false;

            var               indexOfFlag = -1;
            GameObject        oldHolder   = null;
            HardlightCollider oldCollider = null;

            //If we have the area flag already
            if (Definition.DefinedAreas.Contains(SingleFlagToModify))
            {
                ReplacedExistingElement = true;

                //Find which index it is (index is the access key to all three lists)
                indexOfFlag = Definition.DefinedAreas.IndexOf(SingleFlagToModify);

                //Store the old holder and old collider
                oldHolder   = Definition.ZoneHolders[indexOfFlag];
                oldCollider = Definition.SceneReferences[indexOfFlag];

                oldHolder.SetActive(false);

                //No longer have this location as disabled
                DisabledRegions.EnableArea(SingleFlagToModify);

                //Replace the old elements
                Definition.ZoneHolders[indexOfFlag]     = SingleHolder;
                Definition.SceneReferences[indexOfFlag] = newCollider;
                Succeeded = true;
            }
            //Flag does not yet exist in the dictionary (it was empty so it was deleted)
            else
            {
                //Store the index of the new element we're adding.
                indexOfFlag = DefinedAreas.Count;
                Definition.DefinedAreas.Add(SingleFlagToModify);

                //Add the new elements
                Definition.ZoneHolders.Add(SingleHolder);
                Definition.SceneReferences.Add(newCollider);

                //This location is now enabled.
                DisabledRegions.EnableArea(SingleFlagToModify);

                Succeeded = true;
            }

            if (ReplacedExistingElement)
            {
                //Do something about the old elements?
                //What if we want to revert?
            }

            return(Succeeded);
        }