Started project

This commit is contained in:
Caleb Sandford deQuincey
2025-11-14 17:30:41 +00:00
parent 00b55a5b1e
commit 334021d04e
36526 changed files with 4940113 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
using System;
using UnityEditor;
using Unity.Collections;
using UnityEngine;
class CLILeakDetectionSwitcher
{
[InitializeOnLoadMethod]
static void SetLeakDetectionModeFromEnvironment()
{
var nativeLeakDetectionMode = Environment.GetEnvironmentVariable("UNITY_JOBS_NATIVE_LEAK_DETECTION_MODE");
if (!string.IsNullOrEmpty(nativeLeakDetectionMode))
{
switch (nativeLeakDetectionMode)
{
case "0":
NativeLeakDetection.Mode = NativeLeakDetectionMode.Disabled;
break;
case "1":
NativeLeakDetection.Mode = NativeLeakDetectionMode.Enabled;
break;
case "2":
NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;
break;
default:
Debug.LogWarning("The environment variable UNITY_JOBS_NATIVE_LEAK_DETECTION_MODE has an invalid value. Please use: 0 = Disabled, 1 = Enabled, 2 = EnabledWithStackTrace.");
break;
}
Debug.Log("Native leak detection mode: " + NativeLeakDetection.Mode);
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: a3b018ffc4586a441a093c4d954a8cf1
timeCreated: 1507328300
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,124 @@
using System;
using UnityEditor;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs.LowLevel.Unsafe;
using UnityEngine;
// This menu is available from the editor directly on later versions
#if !UNITY_2022_2_14F1_OR_NEWER
class JobsMenu
{
private static int savedJobWorkerCount = JobsUtility.JobWorkerCount;
[SettingsProvider]
private static SettingsProvider JobsPreferencesItem()
{
var provider = new SettingsProvider("Preferences/Jobs", SettingsScope.User)
{
label = "Jobs",
keywords = new[]{"Jobs"},
guiHandler = (searchContext) =>
{
var originalWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 200f;
EditorGUILayout.BeginVertical();
GUILayout.BeginVertical();
EditorGUILayout.LabelField("For safety, these values are reset on editor restart.");
bool madeChange = false;
bool oldWorkerCount = (JobsUtility.JobWorkerCount > 0);
bool newWorkerCount = EditorGUILayout.Toggle(new GUIContent("Use Job Threads:"), oldWorkerCount);
if (newWorkerCount != oldWorkerCount)
{
madeChange = true;
SwitchUseJobThreads();
}
bool oldUseJobsDebugger = JobsUtility.JobDebuggerEnabled;
var newUseJobsDebugger = EditorGUILayout.Toggle(new GUIContent("Enable Jobs Debugger"), JobsUtility.JobDebuggerEnabled);
if (newUseJobsDebugger != oldUseJobsDebugger)
{
madeChange = true;
SetUseJobsDebugger(newUseJobsDebugger);
}
var oldLeakDetectionMode = NativeLeakDetection.Mode;
var newLeakDetectionMode = (NativeLeakDetectionMode) EditorGUILayout.EnumPopup(new GUIContent("Leak Detection Level"), oldLeakDetectionMode);
if (newLeakDetectionMode != oldLeakDetectionMode)
{
madeChange = true;
SetLeakDetection(newLeakDetectionMode);
}
if (madeChange)
Telemetry.LogMenuPreferences(new Telemetry.MenuPreferencesEvent { useJobsThreads = newUseJobsDebugger, enableJobsDebugger = newUseJobsDebugger, nativeLeakDetectionMode = newLeakDetectionMode });
GUILayout.EndVertical();
EditorGUILayout.EndVertical();
EditorGUIUtility.labelWidth = originalWidth;
}
};
return provider;
}
static void SwitchUseJobThreads()
{
if (JobsUtility.JobWorkerCount > 0)
{
savedJobWorkerCount = JobsUtility.JobWorkerCount;
JobsUtility.JobWorkerCount = 0;
}
else
{
JobsUtility.JobWorkerCount = savedJobWorkerCount;
if (savedJobWorkerCount == 0)
{
JobsUtility.ResetJobWorkerCount();
}
}
}
static void SetUseJobsDebugger(bool value)
{
JobsUtility.JobDebuggerEnabled = value;
}
static void SetLeakDetection(NativeLeakDetectionMode value)
{
switch(value)
{
case NativeLeakDetectionMode.Disabled:
{
// In the case where someone enables, disables, then re-enables leak checking, we might miss some frees
// while disabled. So to avoid spurious leak warnings, just forgive the leaks every time someone disables
// leak checking through the menu.
UnsafeUtility.ForgiveLeaks();
Debug.LogWarning("Leak detection has been disabled. Leak warnings will not be generated, and all leaks up to now are forgotten.");
break;
}
case NativeLeakDetectionMode.Enabled:
{
Debug.Log("Leak detection has been enabled. Leak warnings will be generated upon exiting play mode.");
break;
}
case NativeLeakDetectionMode.EnabledWithStackTrace:
{
Debug.Log("Leak detection with stack traces has been enabled. Leak warnings will be generated upon exiting play mode.");
break;
}
default:
{
throw new Exception($"Unhandled {nameof(NativeLeakDetectionMode)}");
}
}
NativeLeakDetection.Mode = value;
}
}
#endif

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7a96926915a7746789220056d7c409a5
timeCreated: 1507328300
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
{
"name": "Unity.Collections.Editor",
"references": [
"Unity.Collections"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"versionDefines":
[
{
"name": "Unity",
"expression": "2022.2.14f1",
"define": "UNITY_2022_2_14F1_OR_NEWER"
}
]
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c668b7a00ffe56a498ddb1fc9f96f4e6
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: