#if UGX_BRIDGE || UNITY_EDITOR using UnityEngine; namespace Uigenx.Bridge { /// /// Development only connection details for the studio daemon. Keep it out of source control: /// it holds the pairing token. A build that ships this asset leaks the token, which is why the /// bridge is compiled out unless UGX_BRIDGE is defined. /// [CreateAssetMenu(menuName = "UI Creator/Bridge Config", fileName = "UgxBridgeConfig")] public sealed class UgxBridgeConfig : ScriptableObject { public const string ResourcePath = "UgxBridgeConfig"; /// Command line argument a headless player or CI run can pass instead of the asset. public const string TokenArgument = "-ugx-token"; public const string UrlArgument = "-ugx-url"; [SerializeField] string url = UgxSettings.DefaultDaemonUrl; [SerializeField] string token = string.Empty; [SerializeField] string projectId = string.Empty; public string Url => string.IsNullOrEmpty(url) ? UgxSettings.DefaultDaemonUrl : url; public string Token => token; public string ProjectId => projectId; public static UgxBridgeConfig Load() => Resources.Load(ResourcePath); /// Command line wins over the asset, so CI never needs a committed token. public static string ResolveToken(UgxBridgeConfig config) { var fromCommandLine = ReadArgument(TokenArgument); if (!string.IsNullOrEmpty(fromCommandLine)) return fromCommandLine; return config != null ? config.Token : string.Empty; } public static string ResolveUrl(UgxBridgeConfig config) { var fromCommandLine = ReadArgument(UrlArgument); if (!string.IsNullOrEmpty(fromCommandLine)) return fromCommandLine; if (config != null && !string.IsNullOrEmpty(config.Url)) return config.Url; return UgxSettings.Instance.DaemonUrl; } public static string ReadArgument(string name) { var args = System.Environment.GetCommandLineArgs(); for (int i = 0; i < args.Length - 1; i++) if (args[i] == name) return args[i + 1]; return null; } } } #endif