// Copyright HTC Corporation All Rights Reserved. using System; using System.Runtime.InteropServices; namespace VIVE.OpenXR.Feature { public interface IViveFeatureWrapper { public bool OnInstanceCreate(XrInstance xrInstance, IntPtr xrGetInstanceProcAddr); public void OnInstanceDestroy(); } public class ViveFeatureWrapperBase where T : ViveFeatureWrapperBase, new() { private static readonly Lazy lazyInstance = new Lazy(() => new T()); public static T Instance => lazyInstance.Value; // Set true in yourfeature's OnInstanceCreate public bool IsInited { get; protected set; } = false; public OpenXRHelper.xrGetInstanceProcAddrDelegate xrGetInstanceProcAddr; /// /// Complete the xrGetInstanceProcAddr by set the pointer received in OnInstanceCreate /// /// public void SetGetInstanceProcAddrPtr(IntPtr intPtr) { if (intPtr == null || intPtr == IntPtr.Zero) throw new Exception("xrGetInstanceProcAddr is null"); xrGetInstanceProcAddr = Marshal.GetDelegateForFunctionPointer(intPtr); } } }