using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.AddressableAssets
{
///
/// Options for the Addressables build platform.
///
public enum AddressablesPlatform
{
///
/// Use to indicate that the build platform is unknown.
///
Unknown,
///
/// Use to indicate that the build platform is Windows.
///
Windows,
///
/// Use to indicate that the build platform is OSX.
///
OSX,
///
/// Use to indicate that the build platform is Linux.
///
Linux,
///
/// Use to indicate that the build platform is PS4.
///
PS4,
///
/// Use to indicate that the build platform is PS4.
///
Switch,
///
/// Use to indicate that the build platform is XboxOne.
///
XboxOne,
///
/// Use to indicate that the build platform is WebGL.
///
WebGL,
///
/// Use to indicate that the build platform is iOS.
///
iOS,
///
/// Use to indicate that the build platform is Android.
///
Android,
///
/// Use to indicate that the build platform is WindowsUniversal.
///
WindowsUniversal
}
///
/// Determines the Addressables build platform that should be used based on the target player build platform.
///
public class PlatformMappingService
{
#if UNITY_EDITOR
internal static readonly Dictionary s_BuildTargetMapping =
new Dictionary()
{
{BuildTarget.XboxOne, AddressablesPlatform.XboxOne},
{BuildTarget.Switch, AddressablesPlatform.Switch},
{BuildTarget.PS4, AddressablesPlatform.PS4},
{BuildTarget.iOS, AddressablesPlatform.iOS},
{BuildTarget.Android, AddressablesPlatform.Android},
{BuildTarget.WebGL, AddressablesPlatform.WebGL},
{BuildTarget.StandaloneWindows, AddressablesPlatform.Windows},
{BuildTarget.StandaloneWindows64, AddressablesPlatform.Windows},
{BuildTarget.StandaloneOSX, AddressablesPlatform.OSX},
{BuildTarget.StandaloneLinux64, AddressablesPlatform.Linux},
{BuildTarget.WSAPlayer, AddressablesPlatform.WindowsUniversal},
};
#endif
internal static readonly Dictionary s_RuntimeTargetMapping =
new Dictionary()
{
{RuntimePlatform.XboxOne, AddressablesPlatform.XboxOne},
{RuntimePlatform.Switch, AddressablesPlatform.Switch},
{RuntimePlatform.PS4, AddressablesPlatform.PS4},
{RuntimePlatform.IPhonePlayer, AddressablesPlatform.iOS},
{RuntimePlatform.Android, AddressablesPlatform.Android},
{RuntimePlatform.WebGLPlayer, AddressablesPlatform.WebGL},
{RuntimePlatform.WindowsPlayer, AddressablesPlatform.Windows},
{RuntimePlatform.OSXPlayer, AddressablesPlatform.OSX},
{RuntimePlatform.LinuxPlayer, AddressablesPlatform.Linux},
{RuntimePlatform.WindowsEditor, AddressablesPlatform.Windows},
{RuntimePlatform.OSXEditor, AddressablesPlatform.OSX},
{RuntimePlatform.LinuxEditor, AddressablesPlatform.Linux},
{RuntimePlatform.WSAPlayerARM, AddressablesPlatform.WindowsUniversal},
{RuntimePlatform.WSAPlayerX64, AddressablesPlatform.WindowsUniversal},
{RuntimePlatform.WSAPlayerX86, AddressablesPlatform.WindowsUniversal},
};
#if UNITY_EDITOR
internal static AddressablesPlatform GetAddressablesPlatformInternal(BuildTarget target)
{
if (s_BuildTargetMapping.ContainsKey(target))
return s_BuildTargetMapping[target];
return AddressablesPlatform.Unknown;
}
internal static string GetAddressablesPlatformPathInternal(BuildTarget target)
{
if (s_BuildTargetMapping.ContainsKey(target))
return s_BuildTargetMapping[target].ToString();
return target.ToString();
}
#endif
internal static AddressablesPlatform GetAddressablesPlatformInternal(RuntimePlatform platform)
{
if (s_RuntimeTargetMapping.ContainsKey(platform))
return s_RuntimeTargetMapping[platform];
return AddressablesPlatform.Unknown;
}
internal static string GetAddressablesPlatformPathInternal(RuntimePlatform platform)
{
if (s_RuntimeTargetMapping.ContainsKey(platform))
return s_RuntimeTargetMapping[platform].ToString();
return platform.ToString();
}
///
/// Retrieves the Addressables build platform that is being used.
///
/// Returns the Addressables build platform that is being used.
[Obsolete("This API doesn't adapt to the addition of new platforms. Use GetPlatformPathSubFolder instead.")]
public static AddressablesPlatform GetPlatform()
{
#if UNITY_EDITOR
return GetAddressablesPlatformInternal(EditorUserBuildSettings.activeBuildTarget);
#else
return GetAddressablesPlatformInternal(Application.platform);
#endif
}
///
/// Retrieves the Addressables platform subfolder of the build platform that is being used.
///
/// Returns the Addressables platform subfolder of the build platform that is being used.
public static string GetPlatformPathSubFolder()
{
#if UNITY_EDITOR
return GetAddressablesPlatformPathInternal(EditorUserBuildSettings.activeBuildTarget);
#else
return GetAddressablesPlatformPathInternal(Application.platform);
#endif
}
}
}