Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- namespace Assets
- {
- /// <summary>
- /// A wrapper to the serivice provider which provides some basic functionality in the absence of the SimplePlanes ServiceProvider
- /// (to be used in the mod's Unity project while testing).
- /// </summary>
- public static class ServiceProviderWrapper
- {
- #region Static Fields
- /// <summary>
- /// The mock cockpit transform to use when the cockpit isn't available (when testing in the mod's Unity scene).
- /// </summary>
- public static Transform MockCockpit;
- #endregion Static Fields
- #region Constructors
- /// <summary>
- /// Initializes the <see cref="ServiceProviderWrapper"/> class.
- /// </summary>
- static ServiceProviderWrapper()
- {
- try
- {
- // See if the service provider is available...set it to enabled if the next line doesn't throw an exception.
- var test = ServiceProvider.Instance.UserInterface.UIRootObject;
- ServiceProviderWrapper.IsServiceProviderAvailable = true;
- }
- catch
- {
- // Whelp, it threw an exception, so it must not be available.
- ServiceProviderWrapper.IsServiceProviderAvailable = false;
- }
- if(ServiceProviderWrapper.IsServiceProviderAvailable == false)
- {
- // You'll need to change "MyMockCockpit" to your real "dummy" cockpit for testing purposes.
- ServiceProviderWrapper.MockCockpit = MyMockCockpit;
- }
- }
- #endregion Constructors
- #region Public Properties
- /// <summary>
- /// Gets a value indicating whether the SimplePlanes service provider is enabled.
- /// </summary>
- /// <value>
- /// <c>true</c> if this instance is enabled; otherwise, <c>false</c>.
- /// </value>
- public static bool IsServiceProviderAvailable
- {
- get;
- private set;
- }
- /// <summary>
- /// Gets the main cockpit position.
- /// </summary>
- /// <value>
- /// The main cockpit position.
- /// </value>
- public static Vector3 MainCockpitPosition
- {
- get
- {
- if (ServiceProviderWrapper.IsServiceProviderAvailable)
- {
- return ServiceProvider.Instance.PlayerAircraft.MainCockpitPosition;
- }
- else
- {
- return ServiceProviderWrapper.MockCockpit.position;
- }
- }
- }
- /// <summary>
- /// Gets the player aircraft velocity.
- /// </summary>
- /// <value>
- /// The player aircraft velocity.
- /// </value>
- public static Vector3 PlayerAircraftVelocity
- {
- get
- {
- if (ServiceProviderWrapper.IsServiceProviderAvailable)
- {
- return ServiceProvider.Instance.PlayerAircraft.Velocity;
- }
- else
- {
- return ServiceProviderWrapper.MockCockpit.GetComponent<Rigidbody>().velocity;
- }
- }
- }
- #endregion Public Properties
- #region Public Methods
- /// <summary>
- /// Sets the main camera enabled.
- /// </summary>
- /// <param name="enabled">if set to <c>true</c> [enabled].</param>
- public static void SetMainCameraEnabled(bool enabled)
- {
- if (ServiceProviderWrapper.IsServiceProviderAvailable)
- {
- ServiceProvider.Instance.GameCamera.SetMainCameraEnabled(enabled);
- }
- else
- {
- // Do nothing.
- }
- }
- #endregion Public Methods
- #region Internal Methods
- /// <summary>
- /// Shows the status message.
- /// </summary>
- /// <param name="message">The message.</param>
- internal static void ShowStatusMessage(string message)
- {
- if (ServiceProviderWrapper.IsServiceProviderAvailable)
- {
- ServiceProvider.Instance.GameWorld.ShowStatusMessage(message);
- }
- else
- {
- // Service provier isn't enabled, just log a Debug.Log message
- Debug.LogFormat("Status message: {0}", message);
- }
- }
- #endregion Internal Methods
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement