public void ProcessGaze()
    {
        Ray        ray = new Ray(transform.position, transform.forward);
        RaycastHit hitInfo;

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

        if (Physics.Raycast(ray, out hitInfo))
        {
            GameObject    hitObj  = hitInfo.collider.gameObject;
            GazableObject gazeObj = hitObj.GetComponentInParent <GazableObject>();

            if (gazeObj != null)
            {
                if (gazeObj != currentGazeObject)
                {
                    ClearCurrentObject();
                    currentGazeObject = gazeObj;
                    currentGazeObject.OnGazeEnter(hitInfo);
                    SetReticleColor(activeColor);
                }
                else
                {
                    currentGazeObject.OnGaze(hitInfo);
                }
                lastHit = hitInfo;
            }
            else
            {
                ClearCurrentObject();
            }
        }
    }
 private void ClearCurrentObject()
 {
     if (currentGazeObject != null)
     {
         currentGazeObject.OnGazeExit();
         SetReticleColor(inactiveColor);
         currentGazeObject = null;
     }
 }
    // Use this for initialization
    void Start()
    {
        var scene = SceneManager.GetActiveScene();
        var roots = scene.GetRootGameObjects();

        foreach (var root in roots)
        {
            GazableObject.CreateFromColliders(root);
        }
    }
 private void CheckForInput(RaycastHit hitInfo)
 {
     if (Input.GetMouseButtonDown(0) && currentGazeObject != null)
     {
         currentSelectedObject = currentGazeObject;
         currentSelectedObject.OnPress(hitInfo);
     }
     else if (Input.GetMouseButton(0) && currentSelectedObject != null)
     {
         currentSelectedObject.OnHold(hitInfo);
     }
     else if (Input.GetMouseButtonUp(0) && currentSelectedObject != null)
     {
         currentSelectedObject.OnRelease(hitInfo);
         currentSelectedObject = null;
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         var instance = (GameObject)Instantiate(prefab1, new Vector3(0, 0, maxDistance - instances.Count * step), Quaternion.identity);
         GazableObject.CreateFromColliders(instance);
         instances.Add(instance);
     }
     if (Input.GetKeyDown(KeyCode.Alpha2))
     {
         var instance = (GameObject)Instantiate(prefab2, new Vector3(0, 0, maxDistance - instances.Count * step), Quaternion.identity);
         instances.Add(instance);
     }
     if (Input.GetKeyDown(KeyCode.Backspace) && instances.Count > 0)
     {
         Destroy(instances[instances.Count - 1]);
         instances.RemoveAt(instances.Count - 1);
     }
 }
Beispiel #6
0
    // Use this for initialization
    void Start()
    {
        var cubeRoot = Mathf.CeilToInt(Mathf.Pow(countToInstantiate, 0.3333f));
        var isEven   = cubeRoot % 2 == 1;
        var halfRoot = cubeRoot / 2f;

        for (int i = 0; i < cubeRoot; ++i)
        {
            for (int j = 0; j < cubeRoot; ++j)
            {
                for (int k = 0; k < cubeRoot; ++k)
                {
                    if (isEven && i == cubeRoot / 2 && j == cubeRoot / 2 && k == cubeRoot / 2)
                    {
                        continue;
                    }

                    var go = (GameObject)Instantiate(cubePrefab, transform);
                    go.transform.position = amplitude * (new Vector3(i, j, k) - halfRoot * Vector3.one);
                }
            }
        }
        GazableObject.CreateFromColliders(gameObject);
    }