using UnityEngine; using System.Collections; using System; using System.Collections.Generic; namespace MoreMountains.Tools { /// /// A class used to store bindings /// [Serializable] public class PlatformBindings { public enum PlatformActions { DoNothing, Disable } public RuntimePlatform Platform = RuntimePlatform.WindowsPlayer; public PlatformActions PlatformAction = PlatformActions.DoNothing; } /// /// Add this class to a gameobject, and it'll enable/disable it based on platform context, using Application.platform to detect the platform /// [AddComponentMenu("More Mountains/Tools/Activation/MMApplicationPlatformActivation")] public class MMApplicationPlatformActivation : MonoBehaviour { /// the possible times at which this script can run public enum ExecutionTimes { Awake, Start, OnEnable } [Header("Settings")] /// the selected execution time public ExecutionTimes ExecutionTime = ExecutionTimes.Awake; /// whether or not this should output a debug line in the console public bool DebugToTheConsole = false; [Header("Platforms")] public List Platforms; /// /// On Enable, processes the state if needed /// protected virtual void OnEnable() { if (ExecutionTime == ExecutionTimes.OnEnable) { Process(); } } /// /// On Awake, processes the state if needed /// protected virtual void Awake() { if (ExecutionTime == ExecutionTimes.Awake) { Process(); } } /// /// On Start, processes the state if needed /// protected virtual void Start() { if (ExecutionTime == ExecutionTimes.Start) { Process(); } } /// /// Enables or disables the object based on current platform /// protected virtual void Process() { foreach (PlatformBindings platform in Platforms) { if (platform.Platform == Application.platform) { DisableIfNeeded(platform.PlatformAction, platform.Platform.ToString()); } } if (Application.platform == RuntimePlatform.Android) { } } /// /// Disables the object if needed, and outputs a debug log if requested /// /// /// protected virtual void DisableIfNeeded(PlatformBindings.PlatformActions platform, string platformName) { if (this.gameObject.activeInHierarchy && (platform == PlatformBindings.PlatformActions.Disable)) { this.gameObject.SetActive(false); if (DebugToTheConsole) { Debug.LogFormat(this.gameObject.name + " got disabled via MMPlatformActivation, platform : " + platformName + "."); } } } } }