Exemplo n.º 1
0
        private void OnEnable()
        {
#if UNITY_EDITOR
            Vector2[] uv = null;
            foreach (var group in _groups)
            {
                foreach (var feature in group.features)
                {
                    LeapSpriteFeature spriteFeature = feature as LeapSpriteFeature;
                    if (spriteFeature != null)
                    {
                        foreach (var data in spriteFeature.featureData)
                        {
                            uv = data.sprite.uv;
                        }
                    }
                }
            }
#endif

            if (Application.isPlaying)
            {
                if (_space != null)
                {
                    _space.RebuildHierarchy();
                    _space.RecalculateTransformers();
                }

                foreach (var group in _groups)
                {
                    group.OnEnable();
                }
            }
        }
Exemplo n.º 2
0
        private void OnEnable()
        {
#if UNITY_EDITOR
            Vector2[] uv = null;
            foreach (var group in _groups)
            {
                foreach (var feature in group.features)
                {
                    LeapSpriteFeature spriteFeature = feature as LeapSpriteFeature;
                    if (spriteFeature != null)
                    {
                        foreach (var data in spriteFeature.featureData)
                        {
                            uv = data.sprite.uv;
                        }
                    }
                }
            }

            UnityEditor.Undo.undoRedoPerformed -= onUndoRedoPerformed;
            UnityEditor.Undo.undoRedoPerformed += onUndoRedoPerformed;
#endif

            if (Application.isPlaying)
            {
                if (_space != null)
                {
                    _space.RebuildHierarchy();
                    _space.RecalculateTransformers();
                    _lastSpaceWasNull = false;
                }

                foreach (var group in _groups)
                {
                    group.OnEnable();
                }
            }
        }
Exemplo n.º 3
0
    void Update()
    {
        space.RecalculateTransformers();
        var transformer = space.transformer;

        List <int> pressedIds = new List <int>();

        float minDistance  = float.MaxValue;
        float averageDelta = 0;
        int   deltaCount   = 0;

        if (interactionEnabled)
        {
            foreach (var hand in provider.CurrentFrame.Hands)
            {
                Vector3 tip = hand.GetIndex().Bone(Leap.Bone.BoneType.TYPE_DISTAL).NextJoint.ToVector3();

                Vector3 rectTip = transformer.InverseTransformPoint(tip);

                minDistance = Mathf.Min(minDistance, rectTip.z);

                if (rectTip.z > 0)
                {
                    float prevPos;
                    if (_idToPos.TryGetValue(hand.Id, out prevPos))
                    {
                        averageDelta += rectTip.x - prevPos;
                        deltaCount++;
                    }

                    pressedIds.Add(hand.Id);
                    _idToPos[hand.Id] = rectTip.x;
                }
            }
        }

        //If there are two hands and they are both farther than the threshold, do nothing
        if (provider.CurrentFrame.Hands.Count >= 2 && minDistance > -twoHandedZThreshold)
        {
            deltaCount = 0;
        }

        if (cards.Query().Any(c => c.isExpandedOrGrasped))
        {
            deltaCount = 0;
            _resetTween.Play(Direction.Forward);
        }
        else
        {
            _resetTween.Play(Direction.Backward);
        }

        var idsToRemove = _idToPos.Query().Select(t => t.Key).Where(id => !pressedIds.Contains(id)).ToList();

        foreach (var idToRemove in idsToRemove)
        {
            _idToPos.Remove(idToRemove);
        }

        if (deltaCount > 0)
        {
            averageDelta /= deltaCount;

            if (_needsAccum)
            {
                _accumPos += averageDelta;
                if (Mathf.Abs(_accumPos) > positionWarmup)
                {
                    _needsAccum = false;
                }
            }
            else
            {
                _position += averageDelta;
            }

            _smoothedVelocity.Update(averageDelta, Time.deltaTime);
            _velocity = _smoothedVelocity.value;
        }
        else
        {
            _accumPos   = 0;
            _needsAccum = true;

            _position += _velocity;
            _velocity *= damping;
        }

        float totalWidth = cards.Length * spacing;

        for (int i = 0; i < cards.Length; i++)
        {
            float cardOffset = i * spacing;

            float cardPosition = _position + cardOffset;

            while (cardPosition < 0)
            {
                cardPosition += totalWidth;
            }

            float loopedPosition = cardPosition % totalWidth - totalWidth * 0.5f;

            var curvedPos = transformer.TransformPoint(new Vector3(loopedPosition, 0, 0));
            var curvedRot = transformer.TransformRotation(new Vector3(loopedPosition, 0, 0), Quaternion.identity);

            cards[i].transform.localPosition = curvedPos;
            cards[i].transform.localRotation = curvedRot;
        }
    }