Esempio n. 1
0
    private void CheckSurroundings()
    {
        RaycastHit hit;
        var        ray = Camera.main.ViewportPointToRay(midScreen);

        if (Physics.Raycast(ray, out hit, 50f))
        {
            var hitObject = hit.collider.gameObject;
            var gaze      = hitObject.GetComponent <GazeableObject>();
            if (gaze != null)
            {
                if (gaze != currentGazeObject)
                {
                    ClearCurrentObject();
                    AssignCurrentObject(gaze);
                    gaze.OnGazeEnter(hit);
                    SetReticleColor(gazeColor);
                }
                else
                {
                    currentGazeObject.OnGaze(hit);
                }
            }
            else
            {
                ClearCurrentObject();
            }

            lastHit = hit;
        }
        else
        {
            ClearCurrentObject();
        }
    }
    // Create Gaze System
    public void ProcessGaze()
    {
        Ray raycastRay = new Ray(transform.position, transform.forward);

        RaycastHit hitInfo;

        Debug.DrawRay(raycastRay.origin, raycastRay.direction * 100);

        if (Physics.Raycast(raycastRay, out hitInfo))
        {
            // Do something to the object

            // Check if the object is interactable

            // Get the gameObject from the hitInfo
            GameObject hitObj = hitInfo.collider.gameObject;

            // Get the GazeableObject from the hit object
            GazeableObject gazeObj = hitObj.GetComponentInParent <GazeableObject> ();

            // Object has a GazeableObject component
            if (gazeObj != null)
            {
                // Object we're looking at is different
                if (gazeObj != currentGazeObject)
                {
                    ClearCurrentObject();

                    currentGazeObject = gazeObj;

                    currentGazeObject.OnGazeEnter(hitInfo);

                    SetReticleColor(activeReticleColor);
                }
                else
                {
                    currentGazeObject.OnGaze(hitInfo);
                }
            }
            else
            {
                ClearCurrentObject();
            }

            lastHit = hitInfo;
        }
        else
        {
            ClearCurrentObject();
        }
    }
Esempio n. 3
0
    /**
     * @ProcessGaze() method
     * process the gaze object interactions like when we move and staire somthing, stop stairing
     * and many more
     */
    public void ProcessGaze()
    {
        Ray        raycastRay = new Ray(transform.position, transform.forward);
        RaycastHit hitInfo;

        Debug.DrawRay(raycastRay.origin, raycastRay.direction * 100);

        if (Physics.Raycast(raycastRay, out hitInfo))
        {
            // 1: check if the object is interactable

            // get the GameObject from the hitInfo
            // below code will get the currentObject which we are looking at
            GameObject hitObj = hitInfo.collider.gameObject;

            // get the GazebaleObject from the hit object
            // also @gazeObj would be null if the object we are looking at is not GazeableObject
            GazeableObject gazeObj = hitObj.GetComponentInParent <GazeableObject>();

            // object has a GazeableObject component
            if (gazeObj != null)
            {
                // object we're looking at is different
                if (gazeObj != currentGazeObject)
                {
                    ClearCurrentObject();
                    currentGazeObject = gazeObj;
                    currentGazeObject.OnGazeEnter(hitInfo);

                    // set reticle color
                    SetReticleColor(activeReticleColor);
                }
                else
                {
                    // else means we are looking at the same object as erlier
                    currentGazeObject.OnGaze(hitInfo);
                }
            }
            else
            {
                // else means we are looking at a non GazeableObject
                ClearCurrentObject();
            }

            lastHit = hitInfo;
        }
        else
        {
            ClearCurrentObject();
        }
    }
    public void ProcessGaze()
    {
        Ray        raycastRay = new Ray(transform.position, transform.forward);
        RaycastHit hitInfo;

        //raycastRay.direction * 100 because raycastRay.direction is just a very small unit
        Debug.DrawRay(raycastRay.origin, raycastRay.direction * 100);

        if (Physics.Raycast(raycastRay, out hitInfo))
        {
            // Get the GameObject from the hitInfo
            GameObject hitObj = hitInfo.collider.gameObject;

            // Get the GazeableObject from the hit Object, if the obj is not gazable, gazeObj will be NULL
            GazeableObject gazeObj = hitObj.GetComponentInParent <GazeableObject>();

            // Check if object is gazeable
            if (gazeObj != null)
            {
                // Check if object we're looking at is different from the one we've been looking
                if (gazeObj != currentGazeObject)
                {
                    ClearCurrentObject();
                    currentGazeObject = gazeObj;
                    currentGazeObject.OnGazeEnter(hitInfo);
                }
                else
                {
                    //if we keep looking at the same object, call the OnGaze function
                    currentGazeObject.OnGaze(hitInfo);
                }
            }
            else
            {
                //if we're not looking at a gazeable object
                ClearCurrentObject();
            }
            //the last sucessful hit when we keep pressing on the button but moving our eye sight to a ungazeable object
            lastHit = hitInfo;
        }
        else
        {
            //if we're not looking at anything
            ClearCurrentObject();
        }
    }
Esempio n. 5
0
    public void ProcessGaze()
    {
        var        ray = new Ray(transform.position, transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            var hitObject = hit.collider.gameObject;
            var gaze      = hitObject.GetComponentInParent <GazeableObject>();

            if (gaze != null)
            {
                if (gaze != currentGazeObject)
                {
                    ClearCurrentObject();
                    currentGazeObject = gaze;
                    gaze.OnGazeEnter(hit);
                    SetReticleColor(activeReticleColor);
                }
                else
                {
                    currentGazeObject.OnGaze(hit);
                }
            }
            else
            {
                ClearCurrentObject();
            }

            lastHit = hit;
        }
        else
        {
            ClearCurrentObject();
        }
    }