예제 #1
0
    public bool Raycast(Vector2 screenPos, out ScreenRaycastData hitData)
    {
        for (int i = 0; i < Cameras.Length; ++i)
        {
            Camera cam = Cameras[i];

            // dont raycast from disabled cams
            if (!cam || !cam.enabled)
            {
                continue;
            }

#if UNITY_3_5
            if (!cam.gameObject.active)
            {
                continue;
            }
#else
            if (!cam.gameObject.activeInHierarchy)
            {
                continue;
            }
#endif

            if (Raycast(cam, screenPos, out hitData))
            {
                return(true);
            }
        }

        hitData = new ScreenRaycastData();
        return(false);
    }
예제 #2
0
    public bool Raycast( Vector2 screenPos, out ScreenRaycastData hitData )
    {
        for( int i = 0; i < Cameras.Length; ++i )
        {
            Camera cam = Cameras[i];

            // dont raycast from disabled cams
            if( !cam || !cam.enabled )
                continue;

#if UNITY_3_5
            if( !cam.gameObject.active )
                continue;
#else
            if( !cam.gameObject.activeInHierarchy )
                continue;
#endif

            if( Raycast( cam, screenPos, out hitData ) )
                return true;
        }

        hitData = new ScreenRaycastData();
        return false;
    }
예제 #3
0
    static int get_Raycast(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FingerEvent       obj = (FingerEvent)o;
            ScreenRaycastData ret = obj.Raycast;
            ToLua.PushValue(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index Raycast on a nil value" : e.Message));
        }
    }
예제 #4
0
    bool Raycast(Camera cam, Vector2 screenPos, out ScreenRaycastData hitData)
    {
        hitData = new ScreenRaycastData();

        if (!gameObject.activeInHierarchy)
        {
            return(false);
        }

        //Debug.Log("RAY: "+Time.frameCount);
        Ray  ray    = cam.ScreenPointToRay(screenPos);
        bool didHit = false;



#if !UNITY_3_5
        // try to raycast 2D first - this only makes sense on orthographic cameras (physics2D doesnt work with perspective cameras)
        if (UsePhysics2D && cam.orthographic)
        {
            hitData.Hits2D = Physics2D.RaycastAll(ray.origin, Vector2.zero, Mathf.Infinity, ~IgnoreLayerMask);
            //hitData.Hit2D = Physics2D.Raycast( ray.origin, Vector2.zero, Mathf.Infinity, ~IgnoreLayerMask );

            if (hitData.Hits2D.Length > 0)
            {
                hitData.Hit2D = hitData.Hits2D[0];
            }

            if (hitData.Hit2D.collider)
            {
                hitData.Is2D = true;
                didHit       = true;
            }
        }
#endif

        // regular 3D raycast
        if (!didHit && !disable3DRaycast)
        {
            hitData.Is2D = false;   // ensure this is false

            if (RayThickness > 0)
            {
                didHit = Physics.SphereCast(ray, 0.5f * RayThickness, out hitData.Hit3D, Mathf.Infinity, ~IgnoreLayerMask);
            }
            else
            {
                didHit = Physics.Raycast(ray, out hitData.Hit3D, Mathf.Infinity, ~IgnoreLayerMask);
            }
        }

        // vizualise ray
    #if UNITY_EDITOR
        if (VisualizeRaycasts)
        {
            if (didHit)
            {
                Vector3 hitPos = hitData.Hit3D.point;

#if !UNITY_3_5
                if (hitData.Is2D)
                {
                    hitPos   = hitData.Hit2D.point;
                    hitPos.z = hitData.GameObject.transform.position.z;
                }
#endif

                Debug.DrawLine(ray.origin, hitPos, Color.green, 0.5f);
            }
            else
            {
                Debug.DrawLine(ray.origin, ray.origin + ray.direction * 9999.0f, Color.red, 0.5f);
            }
        }
    #endif

        return(didHit);
    }
예제 #5
0
    bool Raycast( Camera cam, Vector2 screenPos, out ScreenRaycastData hitData )
    {
        Ray ray = cam.ScreenPointToRay( screenPos );
        bool didHit = false;

        hitData = new ScreenRaycastData();

#if !UNITY_3_5
        // try to raycast 2D first - this only makes sense on orthographic cameras (physics2D doesnt work with perspective cameras)
        if( UsePhysics2D && cam.orthographic )
        {
            hitData.Hit2D = Physics2D.Raycast( ray.origin, Vector2.zero, Mathf.Infinity, ~IgnoreLayerMask );

            if( hitData.Hit2D.collider )
            {
                hitData.Is2D = true;
                didHit = true;
            }
        }
#endif

        // regular 3D raycast
        if( !didHit )
        {
            hitData.Is2D = false;   // ensure this is false

            if( RayThickness > 0 )
                didHit = Physics.SphereCast( ray, 0.5f * RayThickness, out hitData.Hit3D, Mathf.Infinity, ~IgnoreLayerMask );
            else
                didHit = Physics.Raycast( ray, out hitData.Hit3D, Mathf.Infinity, ~IgnoreLayerMask );
        }

        // vizualise ray
    #if UNITY_EDITOR
        if( VisualizeRaycasts )
        {
            if( didHit )
            {
                Vector3 hitPos = hitData.Hit3D.point;

#if !UNITY_3_5
                if( hitData.Is2D )
                {
                    hitPos = hitData.Hit2D.point;
                    hitPos.z = hitData.GameObject.transform.position.z;
                }
#endif

                Debug.DrawLine( ray.origin, hitPos, Color.green, 0.5f );
            }
            else
            {
                Debug.DrawLine( ray.origin, ray.origin + ray.direction * 9999.0f, Color.red, 0.5f );
            }
        }
    #endif

        return didHit;
    }