Example #1
0
    // Instantiates and places object at provided position and normal of a surface.
    public bool objPlacement(GameObject objToPlace, Vector3 placementPosition, Vector3 surfaceNormal)
    {
        if (creationLock)
        {
            return(false);
        }
        if (spawnedObjects.Count > spawnLimit)
        {
            return(false);
        }

        GameObject newInstance = Instantiate(objToPlace, LeftCamera.transform.position, LeftCamera.transform.rotation);

        spawnedObjects.Add(newInstance);
        surfacePlacementManager.GetComponent <SurfacePlacementManager>().attachToSomeSurface(newInstance, placementPosition, surfaceNormal);

        // Lock creation of new game objects for a short period
        if (creationLockInterval > 0 && !creationLock)
        {
            StartCoroutine(InstanceCreationLock());
        }

        return(true);
    }
Example #2
0
        // Handle menu spawning and attachment
        // Attach the menu to the position the finger is plus an offset so that it doesnt spawn on the hand itself
        // Make the menu face the normal direction of hand's palm instead of finger
        bool handleMenuGesture(Hand hand)
        {
            Finger  pointer    = leapGestures.getFingerOfType(hand.Fingers, menuSign[0]);
            Vector3 fingerPos  = UnityVectorExtension.ToVector3(pointer.TipPosition);
            Vector3 palmNormal = UnityVectorExtension.ToVector3(hand.PalmNormal);

            float offset;

            if (hand.IsLeft)
            {
                offset = .3f;
            }
            else
            {
                offset = -.3f;
            }

            Vector3 positionOffset = new Vector3(fingerPos.x + offset, fingerPos.y, fingerPos.z);

            surfacePlacementManager.GetComponent <SurfacePlacementManager>().attachToSomeSurface(leapGestures.menuObject, positionOffset, palmNormal);
            return(true);
        }
Example #3
0
 // Start is called before the first frame update
 void Start()
 {
     crosshair = GetComponent <Text>();
     spm       = FindObjectOfType(typeof(SurfacePlacementManager)) as SurfacePlacementManager;
     spm       = spm.GetComponent <SurfacePlacementManager>();
 }
Example #4
0
        // Handle index finger pointing action
        // First clear and draw a new pointer line
        // Check if you're pointing at a portal. If you are pointing at a portal for long enough, handle moving the portal around.
        // Check if you're pointing at a plane. If you are, create a blue/orange marker on that plane, depending on your right/left hand.
        // Markers will timeout if the portal spawn gesture isnt done soon enough.
        // Left hand = orange marker for orange portal, right = blue.
        void handlePointMarker(Hand hand)
        {
            Finger  pointer   = leapGestures.getFingerOfType(hand.Fingers, indexPointingOnly[0]);
            Vector3 fingerPos = UnityVectorExtension.ToVector3(pointer.TipPosition);
            Vector3 fingerDir = UnityVectorExtension.ToVector3(pointer.Direction);

            if (hand.IsLeft)
            {
                drawPointer(fingerPos, fingerDir, ref leftPointer);
            }
            else
            {
                drawPointer(fingerPos, fingerDir, ref rightPointer);
            }

            // Move portal instead of dealing with markers
            if (portalMove)
            {
                movePortal(fingerPos, fingerDir);
                return;
            }

            // Raycast in advance to see what we're pointing at
            RaycastHit hit;
            int        castDistance = 20;

            Physics.Raycast(fingerPos, fingerDir * castDistance, out hit);

            if (hit.collider == null)
            {
                return;
            }

            // If pointing at a portal
            if (hit.collider != null && hit.collider.gameObject.tag == portalTag)
            {
                pointingAtPortalTimeCurrent += Time.deltaTime;
                if (pointingAtPortalTimeCurrent > pointingAtPortalTime)
                {
                    moveablePortal = hit.collider.gameObject;
                    portalMove     = true;
                    portalDistance = hit.distance;
                    pointingAtPortalTimeCurrent = 0f;
                }
                return;
            }

            // If pointing at a ZEDPlane, do marker placing.
            if (!surfacePlacementManager.GetComponent <SurfacePlacementManager>().checkIfHitPlane(hit))
            {
                return;
            }

            if (leapGestures.planeMarkerRight != null && hand.IsRight)
            {
                // Disable any old timers that may be running
                if (markerTimeoutRight != null)
                {
                    StopCoroutine(markerTimeoutRight);
                }
                surfacePlacementManager.GetComponent <SurfacePlacementManager>().attachToPlaneFromWorldSpace(leapGestures.planeMarkerRight, hit);
                markerTimeoutRight = markerTimeout(leapGestures.planeMarkerRight);
                StartCoroutine(markerTimeoutRight);
            }
            else if (leapGestures.planeMarkerLeft != null && hand.IsLeft)
            {
                // Disable any old timers that may be running
                if (markerTimeoutLeft != null)
                {
                    StopCoroutine(markerTimeoutLeft);
                }
                surfacePlacementManager.GetComponent <SurfacePlacementManager>().attachToPlaneFromWorldSpace(leapGestures.planeMarkerLeft, hit);
                markerTimeoutLeft = markerTimeout(leapGestures.planeMarkerLeft);
                StartCoroutine(markerTimeoutLeft);
            }
        }