A game about forced loneliness, made by TACStudios
at master 95 lines 3.6 kB view raw
1using System.Collections.Generic; 2using JetBrains.Annotations; 3using System.Diagnostics.CodeAnalysis; 4using UnityEditor.Build; 5using UnityEditor.Build.Reporting; 6using UnityEngine; 7using UnityEngine.Rendering; 8using UnityEngine.Analytics; 9using System; 10 11namespace UnityEditor.Rendering.Analytics 12{ 13 // schema = com.unity3d.data.schemas.editor.analytics.uVolumeProfileOverridesAnalytic_v2 14 // taxonomy = editor.analytics.uVolumeProfileOverridesAnalytic.v2 15 internal class VolumeProfileOverridesAnalytic : IPostprocessBuildWithReport 16 { 17 public int callbackOrder => int.MaxValue; 18 19 20 [AnalyticInfo(eventName: "uVolumeProfileOverridesAnalytic", version: 2, maxEventsPerHour:1000, vendorKey: "unity.srp")] 21 public class Analytic : IAnalytic 22 { 23 public Analytic(string asset_guid, string type, string[] p) 24 { 25 m_Data = new Data 26 { 27 volume_profile_asset_guid = asset_guid, 28 component_type = type, 29 overrided_parameters = p 30 }; 31 } 32 33 [System.Diagnostics.DebuggerDisplay("{volume_profile_asset_guid} - {component_type} - {overrided_parameters.Length}")] 34 [Serializable] 35 struct Data : IAnalytic.IData 36 { 37 // Naming convention for analytics data 38 public string volume_profile_asset_guid; 39 public string component_type; 40 public string[] overrided_parameters; 41 } 42 public bool TryGatherData(out IAnalytic.IData data, out Exception error) 43 { 44 data = m_Data; 45 error = null; 46 return true; 47 } 48 Data m_Data; 49 } 50 51 void IPostprocessBuildWithReport.OnPostprocessBuild(BuildReport _) 52 { 53 SendAnalytic(); 54 } 55 56 private static readonly string[] k_SearchFolders = new[] { "Assets" }; 57 58 [MustUseReturnValue] 59 static bool TryGatherData([NotNullWhen(true)] out List<IAnalytic> datas, [NotNullWhen(false)] out string warning) 60 { 61 warning = string.Empty; 62 63 datas = new List<IAnalytic>(); 64 65 var volumeProfileGUIDs = AssetDatabase.FindAssets($"t:{nameof(VolumeProfile)} glob:\"**/*.asset\"", k_SearchFolders); 66 foreach (var guid in volumeProfileGUIDs) 67 { 68 var volumeProfile = AssetDatabase.LoadAssetAtPath<VolumeProfile>(AssetDatabase.GUIDToAssetPath(guid)); 69 if (volumeProfile == null) 70 continue; 71 72 foreach (var volumeComponent in volumeProfile.components) 73 { 74 var volumeComponentType = volumeComponent.GetType(); 75 var defaultVolumeComponent = (VolumeComponent) ScriptableObject.CreateInstance(volumeComponentType); 76 var overrideParameters = volumeComponent.ToNestedColumnWithDefault(defaultVolumeComponent, true); 77 if (overrideParameters.Length == 0) 78 continue; 79 datas.Add(new Analytic(guid, volumeComponent.GetType().Name, overrideParameters)); 80 } 81 } 82 return true; 83 } 84 85 [MenuItem("internal:Edit/Rendering/Analytics/Send VolumeProfileOverridesAnalytic ", priority = 1)] 86 static void SendAnalytic() 87 { 88 if (!TryGatherData(out var data, out var warning)) 89 Debug.Log(warning); 90 91 data.ForEach(d => AnalyticsUtils.SendData(d)); 92 } 93 } 94 95}