if or for statement, for example) both owns and provides access to the data it contains for example, an int variable declared in a scope will be automatically released when the scope end, but within the scope it can be accessed by its name so too is a Context capable of owning and providing access to data required by the operations it supports/logically "contains." Contexts are a common feature of many libraries, including examples such as System.AppContext from the .NET API itself.
Global
: Instance
[Get] |
This Instance is provided for convenience and can be safely used for end-product development (i.e., for the development of an individual game), but development that must incorporate or scale (i.e., library development) should rely on independently Context Instances instead. See the remarks on Context and Instance for a more detailed exploration of this topic.
Signature
Instance Oculus.Interaction.Context.Global |
WhenDestroyed
: Action |
Event which signals the destruction of a Context, allowing dependent instances an opportunity to react.
Signature
Action Oculus.Interaction.Context.WhenDestroyed |
GetOrCreateSingleton< T >
()
|
Retrieves a Context-local or "safe" singleton instance from this Context.
If an instance of the requested type already exists on this Context, that instance will be returned; otherwise, a new one will be lazily created.
This method implements the "safe singleton" pattern discussed in the remarks on the Context. While the name "GetOrCreate" is used to clarify that the requested instance may be created during this call, this method should really only be thought of as an accessor with any instantiation that may or may not happen being simply an irrelevant implementation detail. Ideally, you should think of Context-local singletons as aspects of the Context itself rather than as separate instances which can be created and destroyed independently. Adhering to this thinking will ensure that order-of-operations and independent lifecycles do not complicate the usage of Context. As long as the Context merely exists, all singletons on it can always be accessed identically using GetOrCreateSingleton; all other considerations are the purview of the singletons themselves.
Signature
T Oculus.Interaction.Context.GetOrCreateSingleton< T >() Returns T
A Context-local singleton of the requested type
|
GetOrCreateSingleton< T >
(
factory
)
|
Retrieves a Context-local or "safe" singleton instance from this Context.
If an instance of the requested type already exists on this Context, that instance will be returned; otherwise, a new one will be lazily created by invoking the provided factory callback.
This method differs from GetOrCreateSingleton<T> in that it accepts a factory callback, which it will invoke to create the singleton if necessary instead of simply calling new(). This is useful for singleton types which can only be constructed with arguments, or for types with private constructors. This method implements the "safe singleton" pattern discussed in the remarks on Context and further explored in the remarks on GetOrCreateSingleton<T>.
Signature
T Oculus.Interaction.Context.GetOrCreateSingleton< T >(Func< T > factory) Parameters factory: Func< T >
A callback which creates a singleton of the requested type
Returns T
A Context-local singleton of the requested type
|
ExecuteOnMainThread
(
work
)
|
Executes the specified work on the main Unity thread.
This function provides an easy way for work triggered from arbitrary threads to be performed specifically on the main thread; for example, FinalAction uses this method to cause a callback invoked during destruction (which can happen on any thread) to be executed on the Unity main thread.
Unity 6+ introduces improved support for asynchronous programming techniques, including a new https://docs.unity3d.com/6000.0/Documentation/Manual/async-await-support.html which can be used for the same purpose as this method.
Signature
static void Oculus.Interaction.Context.ExecuteOnMainThread(Action work) Parameters work: Action
The work to execute on the main thread
Returns void |
Instance
(
name
)
|
Basic constructor.
This sets the name which will be given to the lazily-created GameObject which will host the underlying Context.
Signature
Oculus.Interaction.Context.Instance.Instance(string name) Parameters name: string
The name which will be given to the lazily-created GameObject
|
GetInstance
()
|
Retrieves the Context which underlies this Instance; if a valid one does not currently exist, a new one is lazily created.
Note that destroying the GameObject and/or Context created by an Instanceis supported and will successfully tear down the Context; however, if GetInstance is subsequently queried, it will simply lazily create a new Context. This has particular implications on the use of Instance Contexts during app teardown, where order of destruction is not guaranteed and attempts to access an existing InstanceContext may result in the creation of a new Context instead if the prior Context happens to have been destroyed first. For this reason, if access to a specific Context is needed in teardown logic (or to a lesser degree any other logic), you should locally cache a reference to the underlying Context and only invoke GetInstance if the old instance is destroyed and you specifically need a reference to the new one.
Signature
Context Oculus.Interaction.Context.Instance.GetInstance() |