Example #1
0
 public KeyValue(string key, string value)
 {
     if (key.Length > KeyValueList.KEY_SIZE)
     {
         SDK.Log(LogLevel.Error, "KeyValueList, key is to long! Max size = " + KeyValueList.KEY_SIZE);
         this.Key = "";
     }
     else
     {
         this.Key = key;
     }
     if (value.Length > KeyValueList.VALUE_SIZE)
     {
         SDK.Log(LogLevel.Error, "KeyValueList, value is to long! Max size = " + KeyValueList.VALUE_SIZE);
         this.Value = "";
     }
     else
     {
         this.Value = value;
     }
 }
        public static string GetTrailDirectory()
        {
            string[] asmdefGuids = AssetDatabase.FindAssets("t:asmdef", new string[] { "Assets" });
            string   asmdefGuid  = asmdefGuids.FirstOrDefault((guid) =>
            {
                string path             = AssetDatabase.GUIDToAssetPath(guid);
                System.IO.FileInfo file = new System.IO.FileInfo(path);
                if (!file.Exists)
                {
                    return(false);
                }
                return(file.Name == "Trail.asmdef");
            });

            if (string.IsNullOrEmpty(asmdefGuid))
            {
                SDK.Log(LogLevel.Error, "Trail Editor", "Failed to find Trail directory. Have Trail.asmdef been deleted from the project?");
                return("");
            }
            System.IO.FileInfo asmdefFile = new System.IO.FileInfo(AssetDatabase.GUIDToAssetPath(asmdefGuid));
            return(asmdefFile.DirectoryName.Replace("\\", "/"));
        }
        private void UploadLatestBuild()
        {
            ClearStates();
            var hasBuild = HasBuild();

            if (!hasBuild)
            {
                return;
            }
            if (uploadBuildRequest != null && !uploadBuildRequest.IsComplete)
            {
                SDK.Log(LogLevel.Error, "Trail CLI", "Already uploading build, cancel build before attempting to upload a new build!");
                return;
            }
            uploadBuildRequest = TrailBuild.Upload();
            uploadBuildRequest.AddCallback((success, request) =>
            {
                if (success)
                {
                    EditorApplication.delayCall += () =>
                                                   Application.OpenURL(string.Format(MANAGE_DEV_AREA_URL_GAME, cache.selectedGameId));
                }
            });
        }
Example #4
0
        /// <summary>
        /// Initializes Trail SDK with custom dev host address. Example: 127.0.0.1:23000
        /// </summary>
        /// <param name="devHost">The address Trail SDK should connect to if running from Editor.</param>
        /// <returns>Whether creating the SDK worked. The result of Initialization get's provided in Initialize Callback</returns>
        public static Result Init(string devHost)
        {
            if (instance != null)
            {
                Log(LogLevel.Error, "Trail Init failed due to SDK already created!");
                return(IsInitialized ? Result.SDKAlreadyInitialized : Result.SDKAlreadyCreated);
            }
            IntPtr sdkRaw;

#if UNITY
            var createParams = new CreateParams(Application.unityVersion);
            var result       = trail_sdk_create(ref createParams, out sdkRaw);
#else
            var result = trail_sdk_create(out sdkRaw);
#endif
            if (result != Result.Ok)
            {
                Debug.LogError("Trail failed to create the SDK " + result);
#if UNITY_EDITOR
                if (result == Result.SDKAlreadyCreated || result == Result.SDKAlreadyInitialized)
                {
                    var todo = UnityEditor.EditorUtility.DisplayDialog("SDK Error", result.ToString() + "\nDo you want to restart the SDK?", "Yes", "Cancel");
                    if (todo)
                    {
                        trail_sdk_destroy(sdkRaw);
                        return(Init(devHost));
                    }
                }
#endif
                return(result);
            }

            instance = new SDK(sdkRaw);
            // Creates a new mono behaviour instance to connect Unity APIs to Trail.
            instance.mono = TrailMono.Create();

            // Disables standard output
            trail_sdk_set_log_standard_output_enabled(instance.sdkRaw, false);
            // Setup logging for c/c++
            trail_sdk_set_on_log(instance.sdkRaw, Marshal.GetFunctionPointerForDelegate(new LogCB(SDK.OnLogCB)), IntPtr.Zero);
            LogLevel = TrailConfig.DefaultLogLevel;

            // Setup callback for game focus changed
            trail_sdk_set_on_game_active_status_changed(
                instance.sdkRaw,
                Marshal.GetFunctionPointerForDelegate(
                    new GameActiveStatusChangedCB(SDK.OnGameActiveStatusChangedCB)),
                IntPtr.Zero);

            // Setup Init callback
#if BROWSER
            trail_sdk_init(
                instance.sdkRaw,
                Marshal.GetFunctionPointerForDelegate(new InitCB(SDK.onInitCB)),
                IntPtr.Zero
                );
#elif !CSHARP_7_3_OR_NEWER
            var initParams = new InitParams(devHost);
            trail_sdk_init(
                instance.sdkRaw,
                ref initParams,
                Marshal.GetFunctionPointerForDelegate(new InitCB(SDK.onInitCB)),
                IntPtr.Zero
                );
#elif UNITY_EDITOR
            var initParams = new InitParams(devHost);
            WaitForDevServer(initParams);
#endif
            return(Result.Ok);
        }