public static void GetUserSettings(GetUserSettingsCallbackDelegate callback) { if (!instanceCreated) { Debug.LogError("ERROR: Cannot get highlights user setting. The SDK has not been initialized."); return; } GetUserSettingsCallbackId cid = new GetUserSettingsCallbackId(); cid.id = GetCallbackId(); cid.callback = callback; cid.intermediateCallback = GetUserSettingsCallbackInternal; IntPtr asyncOp = Marshal.AllocHGlobal(Marshal.SizeOf(cid)); try { Marshal.StructureToPtr(cid, asyncOp, false); Highlights_GetUserSettingsAsync(asyncOp); } finally { Marshal.FreeHGlobal(asyncOp); } }
private static void GetUserSettingsCallbackInternal(ReturnCode ret, IntPtr blob, IntPtr callbackId) { UserSettings uss = new UserSettings(); uss.highlightSettingTable = new List <UserSetting>(); // read from blob when possible if (ret == ReturnCode.SUCCESS) { UserSettingsInternal ussi = new UserSettingsInternal(); ussi = (UserSettingsInternal)Marshal.PtrToStructure(blob, typeof(UserSettingsInternal)); for (int i = 0; i < ussi.highlightSettingTableSize; i++) { // read usi UserSettingInternal usi = new UserSettingInternal(); IntPtr ptrOfOneSetting = new IntPtr(ussi.highlightSettingTable.ToInt64() + i * Marshal.SizeOf(usi)); usi = (UserSettingInternal)Marshal.PtrToStructure(ptrOfOneSetting, typeof(UserSettingInternal)); // copy usi to us UserSetting us = new UserSetting(); us.enabled = usi.enabled; us.id = usi.id; // pack us into uss uss.highlightSettingTable.Add(us); } } // read cid GetUserSettingsCallbackId cid = new GetUserSettingsCallbackId(); cid = (GetUserSettingsCallbackId)Marshal.PtrToStructure(callbackId, typeof(GetUserSettingsCallbackId)); GetUserSettingsCallbackDelegate nextCall = cid.callback; int id = cid.id; // call user provided function nextCall(ret, uss, id); }