Zinnia.Unity icon indicating copy to clipboard operation
Zinnia.Unity copied to clipboard

Add documentation / prefab on how to properly use PlatformDeviceAssociation with object state switcher

Open studentutu opened this issue 3 years ago • 4 comments

It would be nice to have some sort of prefab on how to auto-enable target SDK rig (depending on the currently found HMD). It is even better if you could put a prefab for Oculus in there.

Copy from https://github.com/ExtendRealityLtd/Tilia.Utilities.ObjectStateSwitcher.Unity/issues/34

studentutu avatar Dec 11 '20 00:12 studentutu

PlatformDeviceAssociation Changed to https://github.com/ExtendRealityLtd/Zinnia.Unity/commit/219d1eb52b39f7e0111fae14c0366e9fae1cad1e

studentutu avatar Feb 01 '22 19:02 studentutu

From discord chat: ok so there are 3 new PattermMatchers

  • XRSettingsPatternMatcher
  • XRDevicePatternMatcher
  • SystemInfoPatternMatcher

each one works very simply

you select a source of a string of what you want to match on, and a regular expression to match with so for example

XRDevicePatternMatcher you can select the Property Source as Model which should report the model of the headset so in the Pattern you could put like Oculus

and then when that PatternMatcher has the DoMatch method run on it, if you're using an Oculus headset then the Model will report as Oculus and the PatternMatcher will match as true

so now you can use that with with a PatternMatcherRule

where one or many patterns can belong to that rule. so if all of the given patterns match then the rule will be true

now... you can use that Rule with the new Rule Association component

which is a collection of gameobjects to turn on if the rule is true, or turn off if the rule is false so now you can have a pattern that says if model is oculus -> then my rule will be true if i'm using an oculus -> therefore turn on these gameobjects because i'm on oculus

you can then run this into the GameObjects Association Activator

which will turn them on when the scene is enabled

image

XRDevicePatternMatcher looking for the string Oculus* (anything that starts with Oculus)

then we create a rule based on that matched pattern (in the PatternMatcherRule). this says if the rule we give it is true then the rule is true.

then we add a RuleAssociation, that says if the given rule is true then we're going to assume the list of gameobjects should be active

Then finally we use a GameObjectsAsscciationActivator to say go through the rule associations and toggle on/off their gameobject collections if their rules are true/false this is the pain and joy of v4. its very powerful, but that inherently makes it more complicated making this super easy and dumbed down would make it a complete pain to support other devices or use cases right now with this system you could do things like

if oculus then make the teleport pointer blue, or if htc vice then make the teleport pointer green etc

thestonefox avatar Feb 02 '22 16:02 thestonefox

Let's leave this open as this needs official documentation still

thestonefox avatar Feb 02 '22 16:02 thestonefox

  1. Windows -> Zinnia -> Observable List Component Generator

Choose Game Objects Association Activator then press Generate Component image

  1. Choose Rule Association, type in Oculus Association then press Generate Component image

  2. Drag the desired game objects associated with oculus (e.g. CameraRig.OculusIntegration) into the Game Objects array of rule association image

  3. Choose Pattern Rule Matcher, type in Detect Oculus then press Generate Component image

  4. Add component XRDevicePatternMatcher, set Pattern=Oculus*, PropertySource=Model, DeviceSource=Head Drag the component into the Patterns array of the pattern rule matcher image

  5. Drag this rule into the rule association image

  6. Drag the rule association into the game objects association activator image

When play, if the rule detects oculus, it will activate the CameraRig.OculusIntegration.

Repeat steps 2-7 to detect other things

fight4dream avatar Aug 25 '22 09:08 fight4dream

https://www.youtube.com/watch?v=9hpP5JDPmgo

thestonefox avatar May 01 '23 09:05 thestonefox