Ejemplo n.º 1
0
    void Update()
    {
        RaycastHit hitInfo;

        Debug.DrawRay(transform.position, transform.forward, Color.red, 3f);

        //if the rays hits any gameobject
        if (Physics.Raycast(transform.position, transform.forward, out hitInfo, 20f, LayerMask.GetMask("Friendly")))
        {
            //if the ray hits an object with an associated gaze interaction
            if (hitInfo.transform.GetComponentInParent <GazeInteraction> () != null)
            {
                Debug.Log("Is interactable");

                //store the gaze interaction component of this frame
                GazeInteraction currentlyLookedAt = hitInfo.transform.GetComponentInParent <GazeInteraction> ();

                //if the gaze interaction is not the same as the one looked at last frame
                if (savedLookedAt != currentlyLookedAt)
                {
                    //look away form the other gaze interaction if it was not null
                    if (savedLookedAt != null)
                    {
                        savedLookedAt.LookAway();
                    }
                    //look at the current object
                    currentlyLookedAt.LookAt();
                }

                //discard the previous frame's gaze interaction and save this one
                savedLookedAt = currentlyLookedAt;

                return;
            }
        }

        //if we were looking at a gaze interaction in the last frame, but now we are not, we need to look away
        if (savedLookedAt != null)
        {
            savedLookedAt.LookAway();
            //clear the saved gaze interaction, since we only want to call saved look at once
            savedLookedAt = null;
        }
    }
Ejemplo n.º 2
0
    //Helper for start
    void assignFunctions(GazeInteraction gi, IPlaceable place, Transform hand)
    {
        Debug.Log(gi);
        gi.delay = 1f;

        gi.RegisterOnGaze(() => {
            Debug.Log("Gazed at");

            /*
             * statsCanvas = Instantiate(BuildManager.Instance.placeableStatsCanvas, Vector3.zero, Quaternion.identity, hand);
             *
             * statsCanvas.transform.localPosition = new Vector3(0f, 0.2f, 0.1f);
             *
             * statsCanvas.GetComponent<BuiltToolStatsCanvas>().FillStats(place);
             */
        });

        gi.RegisterOnLookAway(() => {
            Debug.Log("Gazed away");
            //Destroy(statsCanvas.gameObject);
        });
    }
Ejemplo n.º 3
0
    private void FixedUpdate()
    {
        RaycastHit hitObject;

        //If the raycast hit into an object
        if (Physics.Raycast(transform.position, transform.forward, out hitObject, 200.0f, 8))
        {
            //Get the interaction being hit
            GazeInteraction hitInteraction = hitObject.transform.GetComponent <GazeInteraction>();

            //If the raycast hit is not the same object as previous object
            if (m_objectBeingGazed != hitInteraction)
            {
                m_objectBeingGazed = hitInteraction;
                m_totalGazeTime    = 0;
            }
            //If the raycast hit the same object, increase the timer countdown
            else
            {
                ++m_totalGazeTime;
            }
        }
        //If the raycast doesn't hit anything
        else
        {
            //Reset all the counter
            m_objectBeingGazed = null;
            m_totalGazeTime    = 0;
        }

        //Check if the required gaze time is fulfilled
        if (m_objectBeingGazed.gazeDuration <= m_totalGazeTime)
        {
            m_objectBeingGazed.TriggerEvent();
            m_totalGazeTime = 0;
        }
    }