Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        // Controller model transform
        if (_controllerConnectionHandler.IsControllerValid(_MLInputController.Id))
        {
            controllerObject.transform.position = _MLInputController.Position;
            controllerObject.transform.rotation = _MLInputController.Orientation;
        }

        // Controller pointer
        RaycastHit hit;

        if (Physics.Raycast(controllerObject.transform.position, controllerObject.transform.forward, out hit, 10))
        {
            DirectorMenuButton button = hit.transform.GetComponent <DirectorMenuButton>();

            if (button != null)
            {
                if (_lastButtonHit == null)
                {
                    if (button.OnRaycastEnter != null)
                    {
                        button.OnRaycastEnter(hit.point, button.transform);
                    }
                    _lastButtonHit = button;
                }
                else if (_lastButtonHit == button)
                {
                    if (_lastButtonHit.OnRaycastContinue != null)
                    {
                        _lastButtonHit.OnRaycastContinue(hit.point, _lastButtonHit.transform.GetChild(0));
                    }
                }
                else
                {
                    if (_lastButtonHit.OnRaycastExit != null)
                    {
                        _lastButtonHit.OnRaycastExit(hit.point, _lastButtonHit.transform);
                    }
                    _lastButtonHit = null;
                }
            }
            else
            {
                if (_lastButtonHit != null)
                {
                    if (_lastButtonHit.OnRaycastExit != null)
                    {
                        _lastButtonHit.OnRaycastExit(hit.point, _lastButtonHit.transform);
                    }
                    _lastButtonHit = null;
                }
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Handles the event for trigger down.
    /// </summary>
    /// <param name="controllerId">The id of the controller.</param>
    /// <param name="triggerValue">The value of the trigger.</param>
    private void HandleTriggerDown(byte controllerId, float triggerValue)
    {
        if (MLImageTracker.IsStarted && _controllerConnectionHandler.IsControllerValid(controllerId))
        {
            RaycastHit hit;

            if (Physics.Raycast(controllerObject.transform.position,
                                controllerObject.transform.forward, out hit, 10))
            {
                DirectorMenuButton button =
                    hit.transform.GetComponent <DirectorMenuButton>();

                if (button != null)
                {
                    if (button.OnControllerTriggerDown != null)
                    {
                        button.OnControllerTriggerDown(1.0f, button.PrefabID);
                    }

                    grabinGameObject = Instantiate(prefabs[button.PrefabID]);
                    grabinGameObject.transform.parent        = controllerObject.transform;
                    grabinGameObject.transform.localPosition = new Vector3(0.0f, 0.0f, 0.75f);
                    grabinGameObject.AddComponent <MoveableObject>();

                    DirectorManager.AddObject(grabinGameObject, button.PrefabID);
                }
                else if (hit.transform.GetComponent <MoveableObject>())
                {
                    grabinGameObject = hit.transform.gameObject;
                    grabinGameObject.transform.parent        = controllerObject.transform;
                    grabinGameObject.transform.localPosition = new Vector3(0.0f, 0.0f, 0.75f);
                }
            }

            _isGrabbing = true;
        }
    }