Platform API

PlatformAPI Documentation

The PlatformAPI component provides functionality for defining behavior that occurs only on specific platforms through the Unity inspector. It allows you to check whether the current platform is supported and to take different actions depending on the result, without writing any code. This can be useful for handling platform-specific features or limitations.

Namespace

MetaverseCloudEngine.Unity.Components

Public Methods

  • void PerformCheck(): Manually triggers the platform check and executes the appropriate behavior. This method can be called from Unity Events.

Public Properties

  • Platform Platform: The platforms that are considered supported by this PlatformAPI instance. This property can be set in the Unity inspector.

  • bool Invert: Whether to invert the behavior of the IsCurrentPlatformSupported check. This property can be set in the Unity inspector.

  • UnsupportedBehaviorType UnsupportedBehavior: The behavior to apply when the current platform is not supported. This property can be set in the Unity inspector.

  • PlatformEvents Events: Events that are invoked when the platform is either supported or unsupported. These events can be used to trigger other behaviors in your scene.

  • bool IsCurrentPlatformSupported (read only): Indicates whether the current platform is supported. This property can be used in Unity Events and other inspector-based scripting systems.

Inspector Fields

  • Platform platform: The platforms that are considered supported.

  • bool invert: Whether to invert the behavior of the platform check.

  • UnsupportedBehaviorType unsupportedBehavior: The behavior to apply when the platform is not supported.

  • PlatformEvents events: Events that are invoked based on the platform support.

Behavior

  • Execution Order: This class uses the ExecutionOrder.PreInitialization execution order, meaning it will be initialized before most other components in the scene.

Usage

  1. To use PlatformAPI, start by adding the component to a GameObject in your scene.

  2. In the inspector, select the platforms that you want to consider supported.

  3. Optionally, choose the behavior that should occur when the platform is not supported (e.g., deactivate the GameObject).

  4. You can then use the IsCurrentPlatformSupported property in Unity Events and other inspector-based scripting systems to check whether the current platform is supported and to execute platform-specific logic accordingly.

  5. You can also listen to the onSupported and onUnsupported events to trigger different behaviors when the platform support status changes.

Example:

You can use the PlatformAPI component to deactivate a GameObject if the current platform is not supported. To do this:

  1. Add the PlatformAPI component to the GameObject.

  2. In the inspector, deselect the platforms that you do not want to support.

  3. Set the UnsupportedBehavior property to Deactivate.

This will automatically deactivate the GameObject when the scene is run on an unsupported platform.

Last updated