Newer
Older
HoloAnatomy / Assets / HoloToolkit-Examples / Utilities / Scripts / PlaneTargetGroup.cs
SURFACEBOOK2\jackwynne on 25 May 2018 1 KB v1
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;

namespace HoloToolkit.Unity.Tests
{
    public class PlaneTargetGroup : MonoBehaviour
    {
        [Tooltip("Enter in same target consecutively to turn on velocity tracking for that target.")]
        public Transform[] Targets;

        public bool UseVelocity { get; private set; }

        [HideInInspector]
        public Transform CurrentTarget;
        private int currentTargetIndex;

        private void Start()
        {
            currentTargetIndex = 0;
            if (Targets.Length > 0)
            {
                CurrentTarget = Targets[currentTargetIndex];
            }
        }

        // Pick a new target within this group. Targets are cycled through in 
        // the order in which they exist in the Targets property. Velocity can
        // be tracked for targets if they exist in Targets array twice and
        // consecutively
        public void PickNewTarget()
        {
            if (Targets.Length == 0)
            {
                return;
            }

            UseVelocity = false;

            ++currentTargetIndex;
            currentTargetIndex %= Targets.Length;

            // Track velocity for consecutive duplicate entries
            Transform newTarget = Targets[currentTargetIndex];
            if (CurrentTarget == newTarget)
            {
                UseVelocity = true;
            }
            CurrentTarget = newTarget;
        }
    }
}