// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) 2022-2023 Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Magic Leap 2 Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2 // Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein. // %COPYRIGHT_END% // --------------------------------------------------------------------- // %BANNER_END% using UnityEngine; using System.Linq; #if UNITY_EDITOR using UnityEditor; using UnityEditor.Compilation; #endif namespace MagicLeap.Spectator { public class MLSpectatorVersion : ScriptableObject { [SerializeField] private string version; public string Version => version; #if UNITY_EDITOR [InitializeOnLoadMethod] private static void Init() { CompilationPipeline.compilationFinished -= OnCompilationFinished; CompilationPipeline.compilationFinished += OnCompilationFinished; } private static void OnCompilationFinished(object obj) { var assembly = typeof(MLSpectatorVersion).Assembly; var packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(assembly); var version = packageInfo.version; var guid = AssetDatabase.FindAssets($"t:{nameof(MLSpectatorVersion)}", new[] { packageInfo.assetPath }).FirstOrDefault(); MLSpectatorVersion asset; if (!string.IsNullOrWhiteSpace(guid)) { var path = AssetDatabase.GUIDToAssetPath(guid); asset = AssetDatabase.LoadAssetAtPath(path); } else { asset = CreateInstance(); asset.name = nameof(MLSpectatorVersion); asset.hideFlags = HideFlags.NotEditable; AssetDatabase.CreateAsset(asset, $"{packageInfo.assetPath}/Runtime/Resources/Prefabs/{nameof(MLSpectatorVersion)}.asset"); } asset.version = version; EditorUtility.SetDirty(asset); } #endif } }