Exemplo n.º 1
0
        /// <summary>
        /// Creates a raycast
        /// </summary>
        /// <param name="origin">the origin of the raycast</param>
        /// <param name="direction">the direction of the raycast</param>
        /// <param name="hit">returns the hit data</param>
        /// <param name="distance">max distance</param>
        /// <param name="mask">layerMask</param>
        /// <returns>did we hit something?</returns>
        public static bool Raycast(Vector3 origin, Vector3 direction, out UCPhysicsHit hit, float distance, int mask)
        {
            UCPhysicsHitsArray hits = RaycastAll(origin, direction, distance, mask, 0);

            hit = new UCPhysicsHit();

            if (hits.Count <= 0)
            {
                return(false);
            }

            hits.Sort();

            hit = hits[0];
            return(true);
        }
Exemplo n.º 2
0
        bool VerifyUnityCollisions(UCPhysicsHit hit, Ray ray)
        {
            BaseBuilding       _tempBuilding;
            BaseSocket         _socket = hit.transform.GetComponent <BaseSocket>();
            IUTCPhysicsIgnored ignoreInterface;

            if (_socket == null)
            {
                return(true);
            }

            RaycastHit[] hits = UnityEngine.Physics.RaycastAll(ray.origin, (_socket.transform.position - ray.origin), hit.distance).OrderBy(x => x.distance).ToArray();
            RaycastHit   _hit;

            for (int i = 0; i < hits.Length; i++)
            {
                _hit            = hits[i];
                ignoreInterface = _hit.transform.GetComponent <IUTCPhysicsIgnored>();

                if (ignoreInterface != null && ignoreInterface.ignore)
                {
                    continue;
                }

                _tempBuilding = _hit.transform.GetComponentInParent <BaseBuilding>();

                if (_tempBuilding == null)
                {
                    return(true);
                }

                if (_tempBuilding == _socket.building)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Raycast the physics object
        /// </summary>
        /// <param name="origin">ray origin</param>
        /// <param name="direction">ray direction</param>
        /// <param name="_hit">hit data</param>
        /// <param name="distance">max distance</param>
        /// <param name="mask">layerMask</param>
        /// <returns>Did we hit something?</returns>
        public bool Raycast(Ray ray, out UCPhysicsHit _hit, LayerMask mask)
        {
            _hit = this.hit;

            if (!usePhysics)
            {
                return(false);
            }

            UpdateBounds(center, size); // update bounds to make sure that if the object moves, the new bounds will be applied.
            if (Bounds.IntersectRay(ray, out _hit.distance))
            {
                _hit.transform = this.transform;
                _hit.point     = ray.GetPoint(_hit.distance);

                return(VerifyUnityCollisions(_hit, ray));
            }

            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        ///  Create a raycast
        /// </summary>
        /// <param name="origin">The origin of the raycast</param>
        /// <param name="direction">The direction of the raycast</param>
        /// <param name="distance">max distance</param>
        /// <param name="mask">mask</param>
        /// <param name="offset">raycast offset</param>
        /// <returns>The hits value</returns>
        public static UCPhysicsHitsArray RaycastAll(Vector3 origin, Vector3 direction, float distance, int mask, float offset)
        {
            UCPhysicsHit hit;

            hits = new UCPhysicsHitsArray();
            ray  = new Ray(origin, direction);

            for (int i = 0; i < physicsObjects.Count; i++)
            {
                currentPObject = physicsObjects[i];

                if (Vector3.Distance(origin, currentPObject.transform.position) <= distance)
                {
                    if (currentPObject.Raycast(ray, out hit, mask))
                    {
                        if (hit.distance <= distance && hit.distance >= offset)
                        {
                            hits.AddToList(hit);
                        }
                    }
                }
            }

            if (UnityEngine.Physics.Raycast(origin, direction, out rayHit, distance))
            {
                if (rayHit.transform.GetComponent <UCPhysicsObject>() != null)
                {
                    hit = new UCPhysicsHit();
                    hit.Convert(rayHit);

                    hits.AddToList(hit);
                }
            }

            return(hits);
        }
Exemplo n.º 5
0
 public void AddToList(UCPhysicsHit hit)
 {
     _data.Add(hit);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a raycast
 /// </summary>
 /// <param name="ray">the ray of the raycast</param>
 /// <param name="hit">returns the hit data</param>
 /// <param name="distance">max distance</param>
 /// <param name="mask">layerMask</param>
 /// <returns>did we hit something?</returns>
 public static bool Raycast(Ray ray, out UCPhysicsHit hit, float distance, int mask)
 {
     return(Raycast(ray.origin, ray.direction, out hit, distance, mask));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a raycast
 /// </summary>
 /// <param name="ray">the ray of the raycast</param>
 /// <param name="hit">the hit data</param>
 /// <param name="distance">max distance</param>
 /// <returns></returns>
 public static bool Raycast(Ray ray, out UCPhysicsHit hit, float distance, bool TakeUnityPhysicsIntoAccount, Transform target)
 {
     return(Raycast(ray.origin, ray.direction, out hit, distance, -1));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a raycast
 /// </summary>
 /// <param name="origin">The origin of the ray</param>
 /// <param name="direction">The direction of the ray</param>
 /// <param name="hit">The hit data of the ray</param>
 /// <param name="distance">max distance</param>
 /// <returns>did we hit something?</returns>
 public static bool Raycast(Vector3 origin, Vector3 direction, out UCPhysicsHit hit, float distance)
 {
     return(Raycast(origin, direction, out hit, distance, -1));
 }