Skip to content

Commit 916398a

Browse files
author
Unity Technologies
committed
Unity 2023.2.0a18 C# reference source code
1 parent ddda763 commit 916398a

File tree

490 files changed

+26608
-6570
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

490 files changed

+26608
-6570
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System;
6+
using UnityEngine;
7+
using UnityEngine.Analytics;
8+
9+
namespace UnityEditor.Audio.Analytics;
10+
11+
static class AudioAnalytics
12+
{
13+
const string k_VendorKey = "unity.audio";
14+
15+
internal static bool RegisterEvent(string eventName, int maxEventsPerHour, int maxNumberOfElements)
16+
{
17+
var result = EditorAnalytics.RegisterEventWithLimit(eventName, maxEventsPerHour, maxNumberOfElements, k_VendorKey);
18+
19+
if (result == AnalyticsResult.Ok)
20+
{
21+
return true;
22+
}
23+
24+
Console.WriteLine($"Event '{eventName}' could not be registered.");
25+
return false;
26+
}
27+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System;
6+
using UnityEditor.Build;
7+
using UnityEditor.Build.Reporting;
8+
using UnityEngine;
9+
using UnityEngine.Audio;
10+
11+
namespace UnityEditor.Audio.Analytics;
12+
13+
class AudioRandomContainerBuildAnalyticsEvent : IPostprocessBuildWithReport
14+
{
15+
const string k_EventName = "audioRandomContainerBuild";
16+
const int k_MaxEventsPerHour = 60;
17+
const int k_MaxNumberOfElements = 2;
18+
19+
static bool s_Initialized;
20+
21+
static bool Initialized
22+
{
23+
get
24+
{
25+
if (!s_Initialized)
26+
{
27+
s_Initialized = AudioAnalytics.RegisterEvent(k_EventName, k_MaxEventsPerHour, k_MaxNumberOfElements);
28+
}
29+
30+
return s_Initialized;
31+
}
32+
}
33+
34+
public int callbackOrder { get; }
35+
36+
public void OnPostprocessBuild(BuildReport report)
37+
{
38+
SendEvent(report);
39+
}
40+
41+
static void SendEvent(BuildReport report)
42+
{
43+
if (!EditorAnalytics.enabled
44+
|| AudioSettings.unityAudioDisabled
45+
|| !Initialized
46+
|| report == null
47+
|| report.packedAssets.Length == 0)
48+
{
49+
return;
50+
}
51+
52+
var count = 0;
53+
54+
for (var i = 0; i < report.packedAssets.Length; ++i)
55+
{
56+
var infos = report.packedAssets[i].GetContents();
57+
58+
for (var j = 0; j < infos.Length; ++j)
59+
{
60+
if (infos[j].type == typeof(AudioRandomContainer))
61+
{
62+
++count;
63+
}
64+
}
65+
}
66+
67+
var payload = new Payload
68+
{
69+
build_guid = report.summary.guid.ToString(),
70+
count = count
71+
};
72+
73+
EditorAnalytics.SendEventWithLimit(k_EventName, payload);
74+
}
75+
76+
struct Payload
77+
{
78+
public string build_guid;
79+
public int count;
80+
}
81+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System;
6+
using UnityEngine;
7+
8+
namespace UnityEditor.Audio.Analytics;
9+
10+
[InitializeOnLoad]
11+
class AudioRandomContainerQuitAnalyticsEvent
12+
{
13+
const string k_EventName = "audioRandomContainerQuit";
14+
const int k_MaxEventsPerHour = 60;
15+
const int k_MaxNumberOfElements = 1;
16+
17+
static bool s_Initialized;
18+
19+
static bool Initialized
20+
{
21+
get
22+
{
23+
if (!s_Initialized)
24+
{
25+
s_Initialized = AudioAnalytics.RegisterEvent(k_EventName, k_MaxEventsPerHour, k_MaxNumberOfElements);
26+
}
27+
28+
return s_Initialized;
29+
}
30+
}
31+
32+
static AudioRandomContainerQuitAnalyticsEvent()
33+
{
34+
EditorApplication.wantsToQuit += OnEditorApplicationWantsToQuit;
35+
}
36+
37+
static bool OnEditorApplicationWantsToQuit()
38+
{
39+
SendEvent();
40+
return true;
41+
}
42+
43+
static void SendEvent()
44+
{
45+
if (!EditorAnalytics.enabled || AudioSettings.unityAudioDisabled || !Initialized)
46+
{
47+
return;
48+
}
49+
50+
var assetPaths = AssetDatabase.FindAssets("t:AudioRandomContainer");
51+
var payload = new Payload { count = assetPaths.Length };
52+
EditorAnalytics.SendEventWithLimit(k_EventName, payload);
53+
}
54+
55+
struct Payload
56+
{
57+
public int count;
58+
}
59+
}

0 commit comments

Comments
 (0)