Changing the layer mask of a pointer in MRTK v2.1 - c#

I need to change the layer mask during runtime in order to select different objects depending on the context.
From my understanding this should be done in the InputSystemProfile by editing the Pointers property:
CoreServices.InputSystem.InputSystemProfile.PointerProfile.PointingRaycastLayerMasks
But the field is read-only, and I can't find another way to edit it, other than manually in the editor.
Btw I'm using an editable profile for the input system.
In HTK this was achieved by assigning a value to:
GazeManager.Instance.RaycastLayerMasks
Any suggestions?

For the returned field PointingRaycastLayerMasks, it is an instance of reference type LayerMask[]. Therefore, although you cannot change the value of the reference itself, it is possible to change the data that belongs to that referenced object.
So, you can change Layer Mask with the following code:
//Uncheck [PostProcessing],[Spatial Awareness]
CoreServices.InputSystem.InputSystemProfile.PointerProfile.PointingRaycastLayerMasks[0].value = 19;
If you have questions about how to use LayerMasks in Unity, please see here: How do I use layermasks?

you could change the pointers layer mask by overriding it
All the pointers can by found here: CoreServices.InputSystem.DetectedInputSources
and in each one you can do:
ptr.PrioritizedLayerMasksOverride
Hope this helps

Related

Check if Geopoint lies within GeoboundingBox

The WinRT API knows both Geopoint and GeoboundingBox classes. Is there an easy way to check if a Geopoint lies within a GeoboundingBox? This seems like an obvious thing to do but it seems this is something the framework does not support out of the box?
For a rectangle it might seem trivial, but its getting harder of the GeoshapeType is a Geocircle for example. Am I missing something here or do I need to start comparing long&lat values myself?
There is no built-in API from GeoboundingBox class that could directly check if a Geopoint lies in it. So yes, if you want to check whether the point is inside the GeoboundingBox, you might need to get the long&lat values from the NorthwestCorner property and SoutheastCorner property of GeoboundingBox first. Then compare them with the long&lat values of the target point.

Extending the sealed Pushpin class to include more fields

I am developing a windows store app that allows a User to place points on a map and load them from a server. I have this working fine but I need to include more properties than the standard Pushpin class allows (rating / description / user).
Because Pushpin is sealed, I cannot add these fields and use my own object in place of Pushpin. I tried over the past couple of hours to compose my own PointOfInterest class with a Pushpin object inside it however, this approach fails in a number of areas (When I place a point on a map, I want to retrieve more details than just name / tag and have no way of getting a reference back to the original object.)
If anybody has an idea of where to go from here I would like to hear from you !
If you need access to the private members of a sealed class then you are out of luck.
Best you can do is proxy (which you already seem to be doing by including it as a member). Also called faking it :)

How to read old version of MongoDb document with new model in code

Lets say my c# model updated while correspondent collection still contains old documents, I want old and new documents to coexist in the collection, while using only new version of c# model to read them. I wish no inheritance is used if possible. So I wonder which of this issues are solvable and how:
there is a new property in c# model which does not present in database. I think it never should be an issue, Mongo knows nothing about it, and it will be initialized with default value. The only issue here is to initialize it with particular value for all old documents, anybody knows how?
one of property has gone from model. I want MongoDb to find out there is no more property in c# class to map the field of old document to, and to ignore it instead of crashing. This scenario probably sounds a bit strange as it would mean some garbage left in database, but anyway, is the behavior possible to implement/configure?
type if changed, new type is convertible to old one, like integer->string. Is there any way to configure mapping for old docs?
I can consider using inheritance for second case if it is not solvable otherwise
Most of the answers to your questions are found here.
BsonDefaultValue("abc") attribute on properties to handle values not present in the database, and to give them a default value upon deserialization
BsonIgnoreExtraElements attribute on the class to ignore extra elements found during deserialization (to avoid the exception)
A custom serializer is required to handle if the type of a member is changed, or you need to write an upgrade script to fix the data. It would probably be easier to leave the int on load, and save to a string as needed. (That will mean that you'll need a new property name for the string version of the property.)

UITypeEditor and readonly reference type properties in .Net, WinForms

I thought I had type editors and converters nailed until I tried to persist a Readonly Reference type property after editing it in a UITypeEditor.
In my UITypeEditor, because I'm working with a read only property, I'm careful to pass back the original value (after updating the relevant sub property).
This change is reflected immediately on the designer but will not be persisted unless I do something like resize the control that the property is attached to.
To fix this I, blindly, include a call to context.OnComponentChanged() before returning the value.
I can see why this is needed. It's a reference type, I've altered it (not replaced it), and the property grid doesn't know this. I have a couple of questions for clarification:
Do I need a call to context.OnComponentChanging as well? A simple call to OnComponentChanged works in the tests I've done so far, but I don't want biting on the arse at some point in the future.
Also, is there any danger that, with my call to OnComponentChanging, I'll be persisting other components, in DesignerTransactions, that I shouldn't be persisting?

Changing fields to property is a breaking change under what scenarios?

While reading Jon Skeet's article on fields vs properties he mentions that changing fields to properties is a breaking change.
I would like to understand the common scenarios in which this change can cause breaks. Along with the scenario, if you can, please provide any details.
For starters, the following points have been mentioned elsewhere:
You can't change fields to properties if you are using reflection on the class. This is obvious even though I don't have details. Serialization is one scenario where reflection is used to iterate over the object and changing fields to properties will break the serializer or change the output
You can't easily bind against fields. (Why is this? I read it here)
???
EDIT: Robert has a comprehensive list of reasons for choosing properties over fields and also explains how switching between them can cause a breaking change.
If you have a public field and another assembly has code that is using it, it will need to be recompiled.
IOW the definition of breaking includes "will need to be recompiled".
Properties can throw any arbitrary exceptions, whereas fields can't (at least when compiler knows about field assignment at compile time).
In Windows Forms at least, you can only databind things like DataGridViewColumns to properties on your business objects, not fields. So if your class was being used as a DataSource for a grid, its properties changing to fields would result in some new bugs for the grid owner.
You can pass a field as a ref or out parameter, or take its address in an unsafe context, whilst you cannot do these with a property.

Categories

Resources