Exemplo n.º 1
0
    // A call SetActive(false) calls this, and stops Update() being called.
    protected virtual void OnDisable()
    {
        // Send a pointer exit event if required.
        if (previousContact)
        {
            ServoUnityPointableSurface sups = previousContact.gameObject.GetComponentInParent(typeof(ServoUnityPointableSurface)) as ServoUnityPointableSurface;
            sups?.PointerExit();

            PointerEventArgs args = new PointerEventArgs();
            args.flags  = 0;
            args.target = previousContact;
            OnPointerOut(args);

            previousContact = null;
            reticle.SetActive(false);
        }
    }
Exemplo n.º 2
0
    // A call SetActive(false) calls this, and stops Update() being called.
    protected virtual void OnDisable()
    {
        // Send a pointer exit event if required.
        if (previousContact)
        {
            ServoUnityPointableSurface sups = previousContact.gameObject.GetComponentInParent(typeof(ServoUnityPointableSurface)) as ServoUnityPointableSurface; // Uses GetComponentInParent rather than GetComponent since the MeshCollider is created on VideoSurface, which is a child object of the PointableSurface.
            if (sups != null)                                                                                                                                    // Might be null if the VideoSurface has already been destroyed.
            {
                sups.PointerExit();
            }

            PointerEventArgs args = new PointerEventArgs();
            args.flags  = 0;
            args.target = previousContact;
            OnPointerOut(args);

            previousContact = null;
            reticle.SetActive(false);
        }
    }
Exemplo n.º 3
0
    protected virtual void Update()
    {
        // ray must be set first in derived class.
        rayLength = maximumPointerDistance;
        RaycastHit hit;
        bool       bHit = Physics.Raycast(ray, out hit);

        if (bHit && hit.distance > maximumPointerDistance)
        {
            bHit = false;
        }

        if (previousContact && (!bHit || previousContact != hit.transform))
        {
            ServoUnityPointableSurface sups = previousContact.gameObject.GetComponentInParent(typeof(ServoUnityPointableSurface)) as ServoUnityPointableSurface;
            sups?.PointerExit();

            PointerEventArgs args = new PointerEventArgs();
            args.flags  = 0;
            args.target = previousContact;
            OnPointerOut(args);
        }

        // Target not found for hit testing, so clear state
        if (!bHit)
        {
            reticle.SetActive(false);
            previousContact = null;
            previousCoord   = resetCoord;

            if (buttonUp[0])
            {
                OnPointerAirClick?.Invoke();
            }
        }
        else
        {
            rayLength = hit.distance;
            reticle.SetActive(true);
            reticle.transform.position = hit.point;
            reticle.transform.rotation = Quaternion.LookRotation(-hit.normal);

            ServoUnityPointableSurface sups = hit.transform.gameObject.GetComponentInParent(typeof(ServoUnityPointableSurface)) as ServoUnityPointableSurface;

            if (previousContact != hit.transform)
            {
                sups?.PointerEnter();

                PointerEventArgs argsIn = new PointerEventArgs();
                argsIn.flags  = 0;
                argsIn.target = hit.transform;
                OnPointerIn(argsIn);

                previousContact = hit.transform;
                previousCoord   = resetCoord;
            }

            if (buttonDown[0])
            {
                sups?.PointerPress(ServoUnityPlugin.ServoUnityPointerEventMouseButtonID.Left, hit.textureCoord);
                previousContactButtonDown[0] = previousContact;

                PointerEventArgs argsClick = new PointerEventArgs();
                argsClick.flags  = 0;
                argsClick.target = previousContact;
                OnPointerDown(argsClick);
            }
            if (buttonDown[1])
            {
                sups?.PointerPress(ServoUnityPlugin.ServoUnityPointerEventMouseButtonID.Right, hit.textureCoord);
                previousContactButtonDown[1] = previousContact;
            }
            if (buttonDown[2])
            {
                sups?.PointerPress(ServoUnityPlugin.ServoUnityPointerEventMouseButtonID.Middle, hit.textureCoord);
                previousContactButtonDown[2] = previousContact;
            }

            if (buttonUp[0])
            {
                sups?.PointerRelease(ServoUnityPlugin.ServoUnityPointerEventMouseButtonID.Left, hit.textureCoord);
                if (previousContactButtonDown[0] == previousContact)
                {
                    sups?.PointerClick(ServoUnityPlugin.ServoUnityPointerEventMouseButtonID.Left, hit.textureCoord);
                }

                PointerEventArgs argsClick = new PointerEventArgs();
                argsClick.flags  = 0;
                argsClick.target = previousContact;
                if (previousContactButtonDown[0] == previousContact)
                {
                    OnPointerClick(argsClick);
                }
                OnPointerUp(argsClick);
            }
            if (buttonUp[1])
            {
                sups?.PointerRelease(ServoUnityPlugin.ServoUnityPointerEventMouseButtonID.Right, hit.textureCoord);
                if (previousContactButtonDown[1] == previousContact)
                {
                    sups?.PointerClick(ServoUnityPlugin.ServoUnityPointerEventMouseButtonID.Right, hit.textureCoord);
                }
            }
            if (buttonUp[2])
            {
                sups?.PointerRelease(ServoUnityPlugin.ServoUnityPointerEventMouseButtonID.Middle, hit.textureCoord);
                if (previousContactButtonDown[2] == previousContact)
                {
                    sups?.PointerClick(ServoUnityPlugin.ServoUnityPointerEventMouseButtonID.Middle, hit.textureCoord);
                }
            }

            if (hit.textureCoord != previousCoord)
            {
                sups?.PointerOver(hit.textureCoord);
                previousCoord = hit.textureCoord;
            }

            if (scrollDelta != Vector2.zero)
            {
                sups?.PointerScrollDiscrete(scrollDelta * discreteScrollStepSize, hit.textureCoord);
            }
        } // bHit
    }