Exemplo n.º 1
0
    /// <summary>
    /// This method evalutes if the button was released and which object was clicked.
    /// A delay is included to avoid false clicks due to movement while perfoming the click.
    /// </summary>
    private void CheckLeftClick()
    {
        if (HandManager.IsRayRelativeUp())
        {
            if (TargetManager.IsAnyObjectAttached())
            {
                TargetManager.DetachTargetFromDepthMarker();
                targetsInFoucsSinceLastClickDown = new List <Target>();
                return;
            }
            targetsInFoucsSinceLastClickDown = targetsInFoucsSinceLastClickDown.Distinct().ToList();

            GameObject clickedObj = currentFocusedObject;

            // If current object in focus is null
            // check if there is some older object in the list of targets since last click down
            // There we also check if the velocity was over a threshold and if so no click is made
            // Afterwards send event OnLeftClick
            if (currentFocusedObject == null &&
                targetsInFoucsSinceLastClickDown.Count == 1 && targetsInFoucsSinceLastClickDown[0] != null)
            {
                Target target = targetsInFoucsSinceLastClickDown[0];
                if (target.LastTimeInFocus > Time.time - VariablesManager.DelayClickTime)
                {
                    if (!velocityHandler.VelocityWasOverThSinceTimeStemp(target.LastTimeInFocus))
                    {
                        clickedObj = target.gameObject;
                        Logger.ClickCorrectionUsed(1);
                    }
                }
            }
            else if (currentFocusedObject == null && targetsInFoucsSinceLastClickDown.Count > 1)
            {
                float timeStempWithMinVel = velocityHandler.FindTimeStepWithMinVel();

                Target targetClosestToTimeStemp = null;
                float  timeDifference           = float.MaxValue;
                foreach (Target target in targetsInFoucsSinceLastClickDown)
                {
                    if (Mathf.Abs(target.LastTimeInFocus - timeStempWithMinVel) < timeDifference && target.LastTimeInFocus > Time.time - VariablesManager.DelayClickTime)
                    {
                        timeDifference           = Mathf.Abs(target.LastTimeInFocus - timeStempWithMinVel);
                        targetClosestToTimeStemp = target;
                    }
                }
                if (targetClosestToTimeStemp != null)
                {
                    clickedObj = targetClosestToTimeStemp.gameObject;
                    Logger.ClickCorrectionUsed(2);
                }
            }

            OnLeftClick(clickedObj);
            //Reset list
            targetsInFoucsSinceLastClickDown = new List <Target>();
        }
    }
Exemplo n.º 2
0
 public void Store(PrimitiveType primitiveType)
 {
     MeasurementManager.OnStoreAction(this);
     if (primitiveType == this.primitiveType)
     {
         //correct stored
         // Time when stored
         // Correct or Incorrect stored
         // Information about the manipulation phase
         Logger.LogStoreTarget(this, true);
         TargetManager.DetachTargetFromDepthMarker(gameObject);
         State = TargetState.Disabled;
         gameObject.SetActive(false);
     }
     else
     {
         //incorrect stored
         Logger.LogStoreTarget(this, false);
         State = TargetState.Disabled;
         TargetManager.DetachTargetFromDepthMarker(gameObject);
         gameObject.SetActive(false);
     }
     gameObject.transform.position = Vector3.zero;
 }