コード例 #1
0
        /// <summary>
        /// Returns True if the whole object is visible, false if any of it is obscured (as defined by the offsets)
        /// </summary>
        /// <param name="objectBounds"></param>
        /// <param name="_start"></param>
        /// <param name="_target"></param>
        /// <returns></returns>
        public static bool ViewNotObstructed(Vector4 objectBounds, Transform _start, Transform _target)
        {
            //Stores the visibility checks
            Vector4 clearFlags;

            //Adds the offsets provided in the Inspector to reach each side.
            Vector3 leftSide   = BaneMath.SplitAddedVector3(_start.position, +objectBounds.x, 0, 0);
            Vector3 rightSide  = BaneMath.SplitAddedVector3(_start.position, +objectBounds.y, 0, 0);
            Vector3 topSide    = BaneMath.SplitAddedVector3(_start.position, 0, +objectBounds.z, 0);
            Vector3 bottomSide = BaneMath.SplitAddedVector3(_start.position, 0, +objectBounds.w, 0);

            //Getting the direction from the correct side to the target
            Vector3 leftDir   = _target.position - leftSide;
            Vector3 rightDir  = _target.position - rightSide;
            Vector3 topDir    = _target.position - topSide;
            Vector3 bottomDir = _target.position - bottomSide;

            //Defines the raycast hit variables
            RaycastHit leftHit;
            RaycastHit rightHit;
            RaycastHit topHit;
            RaycastHit botHit;

            //Set flag to false if the raycast hits something, else set it to true
            clearFlags.x = Physics.Raycast(leftSide, leftDir.normalized, out leftHit, leftDir.magnitude) ? 0 : 1;
            clearFlags.y = Physics.Raycast(rightSide, rightDir.normalized, out rightHit, rightDir.magnitude) ? 0 : 1;
            clearFlags.z = Physics.Raycast(topSide, topDir.normalized, out topHit, topDir.magnitude) ? 0 : 1;
            clearFlags.w = Physics.Raycast(bottomSide, bottomDir.normalized, out botHit, bottomDir.magnitude) ? 0 : 1;

            //If all four flags are true, return true
            return(clearFlags == new Vector4(1, 1, 1, 1) ? true : false);
        }
コード例 #2
0
        public static bool VewNotObstructed(Vector4 objectBounds, Transform _start, Transform _target, bool _debug)
        {
            //Stores the visibility checks
            Vector4 clearFlags = new Vector4(0, 0, 0, 0);

            //Adds the offsets provided in the Inspector to reach each side.
            Vector3 leftSide   = BaneMath.SplitAddedVector3(_start.position, +objectBounds.x, 0, 0);
            Vector3 rightSide  = BaneMath.SplitAddedVector3(_start.position, +objectBounds.y, 0, 0);
            Vector3 topSide    = BaneMath.SplitAddedVector3(_start.position, 0, +objectBounds.z, 0);
            Vector3 bottomSide = BaneMath.SplitAddedVector3(_start.position, 0, +objectBounds.w, 0);

            //Getting the direction from the correct side to the target
            Vector3 leftDir   = _target.position - leftSide;
            Vector3 rightDir  = _target.position - rightSide;
            Vector3 topDir    = _target.position - topSide;
            Vector3 bottomDir = _target.position - bottomSide;

            //Defines the raycast hit variables
            RaycastHit leftHit;
            RaycastHit rightHit;
            RaycastHit topHit;
            RaycastHit botHit;

            if (_debug)
            {
                //Draw Rays so they can be seen in Scene View
                Debug.DrawRay(leftSide, leftDir, BaneTools.Color255(255, 255, 0), 1, false);
                Debug.DrawRay(rightSide, rightDir, BaneTools.Color255(0, 255, 255), 1, false);
                Debug.DrawRay(topSide, topDir, BaneTools.Color255(255, 0, 255), 1, false);
                Debug.DrawRay(bottomSide, bottomDir, BaneTools.Color255(0, 0, 255), 1, false);

                //if (Physics.Raycast(leftSide, leftDir.normalized, out leftHit, leftDir.magnitude))
                //{
                //  Debug.Log("Left hit " + leftHit.collider.name);
                //}
            }

            //Set flag to false if the raycast hits something, else set it to true
            clearFlags.x = Physics.Raycast(leftSide, leftDir.normalized, out leftHit, leftDir.magnitude) ? 0 : 1;
            clearFlags.y = Physics.Raycast(rightSide, rightDir.normalized, out rightHit, rightDir.magnitude) ? 0 : 1;
            clearFlags.z = Physics.Raycast(topSide, topDir.normalized, out topHit, topDir.magnitude) ? 0 : 1;
            clearFlags.w = Physics.Raycast(bottomSide, bottomDir.normalized, out botHit, bottomDir.magnitude) ? 0 : 1;

            Debug.Log(clearFlags);

            //If all four flags are true, return true
            return(clearFlags == new Vector4(1, 1, 1, 1) ? true : false);
        }
コード例 #3
0
 /// <summary>
 /// Converts 0-1 Colour values to percentage equivalents.
 /// </summary>
 /// <param name="_col"></param>
 /// <returns></returns>
 public static Vector3 ColourToPercentage(Color _col)
 {
     return(BaneMath.MultiplyVector3(ColourToVector3(_col), 100));
 }
コード例 #4
0
 /// <summary>
 /// Multiplies the scale of the object provided in World Space.
 /// </summary>
 /// <param name="_object"></param>
 /// <param name="_parent"></param>
 /// <param name="_scale"></param>
 public static void SetWorldScale(Transform _object, Transform _parent, float _scale)
 {
     _object.SetParent(null);
     _object.localScale = BaneMath.MultiplyVector3(_object.localScale, _scale);
     _object.SetParent(_parent);
 }