/// <inheritdoc/> protected override bool Select(SurfaceData data) { SpatialTarget target = GetSpatialTarget(data); if (target == null) { if (DelselectAllOnEmptyTarget) { DeselectOtherTargetsOnSelect(target); } return(false); } if (!SelectedTargets.Contains(target)) { SelectedTargets.Add(target); if (!target.Select(this, data)) { SelectedTargets.Remove(target); return(false); } DeselectOtherTargetsOnSelect(target); } else { SelectedTargets.Remove(target); target.Deselect(); } return(true); }
/// <summary> /// Deselects all other selected targets that are associated with this dispatcher. /// </summary> /// <param name="target">The current <see cref="SpatialTarget"/> which will be ignored in the deselect.</param> protected virtual void DeselectOtherTargetsOnSelect(SpatialTarget target) { if (target == null || target.DeactivateOtherSpatialTargetsOnActivated) { foreach (SpatialTarget other in SelectedTargets) { if (other.Equals(target)) { continue; } other.Deselect(true); } SelectedTargets.RemoveAll(item => !item.Equals(target)); } }
/// <summary> /// Gets the <see cref="SpatialTarget"/> related to the given data. /// </summary> /// <param name="data">The data to look on.</param> /// <returns>The found <see cref="SpatialTarget"/>.</returns> protected virtual SpatialTarget GetSpatialTarget(SurfaceData data) { if (data == null || data.CollisionData.transform == null) { return(null); } SpatialTarget foundTarget = data.CollisionData.transform.gameObject.TryGetComponent <SpatialTarget>(false, true); if (foundTarget == null || !TargetValidity.Accepts(foundTarget.TargetContainer != null ? foundTarget.TargetContainer : foundTarget.gameObject)) { return(null); } return(foundTarget); }
/// <inheritdoc/> protected override bool Exit(SurfaceData data) { SpatialTarget target = GetSpatialTarget(data); return(target != null?target.Exit(data) : false); }
/// <summary> /// Removes the given target from the <see cref="SelectedTargets"/> collection. /// </summary> /// <param name="target">The target to remove.</param> public virtual void DoRemoveFromSelectedTargets(SpatialTarget target) { RemoveFromSelectedTargets(target); }
/// <summary> /// Removes the given target from the <see cref="SelectedTargets"/> collection. /// </summary> /// <param name="target">The target to remove.</param> /// <returns>Whether the remove was successful.</returns> public virtual bool RemoveFromSelectedTargets(SpatialTarget target) { return(SelectedTargets.Remove(target)); }