//////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2007-2020 , Inc. All Rights Reserved. // //////////////////////////////////////////////////////////////////////////////// using System; using GCSeries.Core.Interop; namespace GCSeries.Core.Sdk { public class ZTargetManager : ZNativeResourceCache { public ZTargetManager(ZContext context) { this._context = context; } //////////////////////////////////////////////////////////////////////// // Public Properties //////////////////////////////////////////////////////////////////////// /// /// The default head target ( glasses). /// public ZTarget HeadTarget => this.GetTarget(ZTargetType.Head); /// /// The default stylus target. /// public ZTarget StylusTarget => this.GetTarget(ZTargetType.Primary); //////////////////////////////////////////////////////////////////////// // Public Methods //////////////////////////////////////////////////////////////////////// /// /// Gets the number of trackable targets of a specified type that /// are currently supported. /// /// /// /// The target type. /// /// /// /// The number of supported trackable targets of a specified type. /// public int GetNumTargets(ZTargetType targetType) { int numTargets = 0; ZPlugin.LogOnError(ZPlugin.GetNumTargetsByType( this._context.NativePtr, targetType, out numTargets), "GetNumTargetsByType"); return numTargets; } /// /// Gets a reference to a trackable target of a specified type at a /// specified index. /// /// /// /// The target type. /// /// /// The index to retrieve the target at. /// /// /// /// A reference to the trackable target if found. Null otherwise. /// public ZTarget GetTarget(ZTargetType targetType, int index = 0) { IntPtr targetNativePtr = IntPtr.Zero; ZPlugin.LogOnError(ZPlugin.GetTargetByType( this._context.NativePtr, targetType, index, out targetNativePtr), "GetTargetByType"); return this.GetOrCreateCachedResource(targetNativePtr); } //////////////////////////////////////////////////////////////////////// // Private Methods //////////////////////////////////////////////////////////////////////// private ZTarget GetOrCreateCachedResource(IntPtr targetNativePtr) { return this.GetOrCreateCachedResource( targetNativePtr, t => new ZTarget(t)); } //////////////////////////////////////////////////////////////////////// // Private Members //////////////////////////////////////////////////////////////////////// private ZContext _context = null; } }