First commit for private source control. Older commits available on Github.

This commit is contained in:
2026-03-26 12:52:52 +00:00
parent a04c602626
commit 2d449c4a17
2176 changed files with 408185 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
#if PRIME_TWEEN_INSTALLED && UNITY_UGUI_INSTALLED
#if UNITY_EDITOR && UNITY_2019_1_OR_NEWER
using UnityEngine.Profiling;
#endif
using PrimeTween;
using UnityEngine;
using UnityEngine.UI;
namespace PrimeTweenDemo {
/// <summary>
/// PrimeTween uses static delegates (lambdas with no external captures) to play animations.
/// The first time a particular animation is played, C# runtime caches the delegate for this animation, and the GC.Alloc is shown in Profiler.
/// Such allocations are not technically 'garbage' because they are not subject to garbage collection.
/// All subsequent calls will use the cached delegate and will never allocate again.
///
/// To replicate '0B' heap allocations shown in the promo video:
/// Disable the 'Project Settings/Editor/Enter Play Mode Settings/Reload Domain' setting.
/// Enable Profiler with Deep Profile.
/// Run the Demo and play all animations at least once. This will cache the aforementioned static delegates.
/// Restart the Demo scene and observe that PrimeTween doesn't allocate heap memory after static delegates warm-up.
/// </summary>
public class DebugInfo : MonoBehaviour {
#pragma warning disable 0414
[SerializeField] MeasureMemoryAllocations measureMemoryAllocations;
[SerializeField] Text tweensCountText;
[SerializeField] Text gcAllocText;
#pragma warning restore 0414
#if UNITY_EDITOR && UNITY_2019_1_OR_NEWER
long curTweensCount = -1;
int? curGCAlloc;
void Start() {
gcAllocText.text = string.Empty;
if (shouldDisable()) {
gameObject.SetActive(false);
}
if (Profiler.enabled && !UnityEditorInternal.ProfilerDriver.deepProfiling) {
Debug.LogWarning("Please enable 'Deep Profile' for more accurate memory allocation measurements.");
}
}
static bool shouldDisable() {
if (!Application.isEditor) {
return true;
}
if (UnityEditor.EditorApplication.isPaused) {
return false; // Profiler.enabled returns false if scene is started paused in Unity 2021.3.26
}
return !Profiler.enabled;
}
void Update() {
var newTweensCount = PrimeTweenManager.Instance.lastId;
if (curTweensCount != newTweensCount) {
curTweensCount = newTweensCount;
tweensCountText.text = $"Animations: {newTweensCount}";
}
var newGCAlloc = measureMemoryAllocations.gcAllocTotal;
if (newGCAlloc.HasValue && curGCAlloc != newGCAlloc.Value) {
curGCAlloc = newGCAlloc.Value;
gcAllocText.text = $"Heap allocations: {UnityEditor.EditorUtility.FormatBytes(newGCAlloc.Value)}";
}
}
#endif
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c0ef97c778caf4b70aea23911ded98ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 252960
packageName: "PrimeTween \xB7 High-Performance Animations and Sequences"
packageVersion: 1.3.7
assetPath: Assets/Plugins/PrimeTween/Demo/Scripts/MeasureAllocations/DebugInfo.cs
uploadId: 860556

View File

@@ -0,0 +1,147 @@
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR && UNITY_2019_1_OR_NEWER
using System.Linq;
using UnityEditor;
using UnityEditor.Profiling;
using UnityEditorInternal;
using UnityEngine.Profiling;
#endif
namespace PrimeTweenDemo {
public class MeasureMemoryAllocations : MonoBehaviour {
#pragma warning disable 0414
[SerializeField] bool logAllocations;
[SerializeField] bool logFiltered;
[SerializeField] bool logIgnored;
[SerializeField] List<string> filterAllocations = new List<string>();
[SerializeField] List<string> ignoreAllocations = new List<string>();
#pragma warning restore 0414
#if UNITY_EDITOR && UNITY_2019_1_OR_NEWER
public int? gcAllocTotal { get; private set; }
readonly Stack<int> stack = new Stack<int>();
readonly List<int> childrenBuffer = new List<int>();
readonly List<int> fullIdPathBuffer = new List<int>();
readonly List<int[]> ignoredPaths = new List<int[]>();
readonly List<int[]> filteredPaths = new List<int[]>();
int lastProcessedFrame = -1;
void OnEnable() {
ProfilerDriver.ClearAllFrames();
}
void Update() {
if (!Profiler.enabled) {
return;
}
var startFrame = Mathf.Max(lastProcessedFrame + 1, ProfilerDriver.firstFrameIndex);
for (int i = startFrame; i <= ProfilerDriver.lastFrameIndex; i++) {
var gcAlloc = calcGCAllocInFrame(i);
if (!gcAlloc.HasValue) {
break;
}
lastProcessedFrame = i;
if (gcAllocTotal.HasValue) {
gcAllocTotal += gcAlloc.Value;
} else {
gcAllocTotal = gcAlloc.Value;
}
}
}
int? calcGCAllocInFrame(int frameIndex) {
int result = 0;
const HierarchyFrameDataView.ViewModes viewMode = HierarchyFrameDataView.ViewModes.MergeSamplesWithTheSameName | HierarchyFrameDataView.ViewModes.HideEditorOnlySamples;
using (var data = ProfilerDriver.GetHierarchyFrameDataView(frameIndex, 0, viewMode, HierarchyFrameDataView.columnGcMemory, false)) {
if (!data.valid) {
return null;
}
stack.Clear();
stack.Push(data.GetRootItemID());
while (stack.Count > 0) {
var current = stack.Pop();
UnityEngine.Assertions.Assert.IsTrue(data.HasItemChildren(current));
data.GetItemChildren(current, childrenBuffer);
foreach (var childId in childrenBuffer) {
var gcAlloc = (int)data.GetItemColumnDataAsSingle(childId, HierarchyFrameDataView.columnGcMemory);
if (gcAlloc == 0) {
continue;
}
if (data.HasItemChildren(childId)) {
stack.Push(childId);
continue;
}
data.GetItemMarkerIDPath(childId, fullIdPathBuffer);
if (ContainsSequence(ignoredPaths, fullIdPathBuffer)) {
continue;
}
if (!ContainsSequence(filteredPaths, fullIdPathBuffer)) {
if (shouldFilter()) {
filteredPaths.Add(fullIdPathBuffer.ToArray());
} else {
ignoredPaths.Add(fullIdPathBuffer.ToArray());
continue;
}
bool shouldFilter() {
if (filterAllocations.Count == 0) {
return true;
}
var itemPath = data.GetItemPath(childId);
foreach (var filter in filterAllocations) {
if (itemPath.Contains(filter) && !ignoreAllocations.Any(itemPath.Contains)) {
if (logFiltered) {
print($"FILTER {itemPath}");
}
return true;
}
}
if (logIgnored) {
print($"IGNORE {itemPath}");
}
return false;
}
}
if (logAllocations) {
print($"GC Alloc in frame {frameIndex}: {EditorUtility.FormatBytes(gcAlloc)}\n" +
$"Path: {data.GetItemPath(childId)}\n");
}
result += gcAlloc;
}
}
}
return result;
}
static bool ContainsSequence(List<int[]> arrays, List<int> list) {
foreach (var arr in arrays) {
if (SequenceEqual(arr, list)) {
return true;
}
}
return false;
// Unity 2019.4.40 doesn't support static local methods
// ReSharper disable once LocalFunctionCanBeMadeStatic
bool SequenceEqual(int[] arr, List<int> _list) {
if (arr.Length != _list.Count) {
return false;
}
for (var i = 0; i < arr.Length; i++) {
if (arr[i] != _list[i]) {
return false;
}
}
return true;
}
}
#else
void Awake() {
if (Application.isEditor) {
Debug.LogWarning($"{nameof(MeasureMemoryAllocations)} is only supported in Unity 2019.1 or newer.", this);
} else {
gameObject.SetActive(false);
}
}
#endif
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6af581ca2a164600b2d47b0f7f7d5570
timeCreated: 1686221280
AssetOrigin:
serializedVersion: 1
productId: 252960
packageName: "PrimeTween \xB7 High-Performance Animations and Sequences"
packageVersion: 1.3.7
assetPath: Assets/Plugins/PrimeTween/Demo/Scripts/MeasureAllocations/MeasureMemoryAllocations.cs
uploadId: 860556

View File

@@ -0,0 +1,27 @@
{
"name": "PrimeTween.Debug",
"rootNamespace": "",
"references": [
"PrimeTween.Runtime"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.kyrylokuzyk.primetween",
"expression": "1.0.0",
"define": "PRIME_TWEEN_INSTALLED"
},
{
"name": "com.unity.ugui",
"expression": "1.0.0",
"define": "UNITY_UGUI_INSTALLED"
}
],
"noEngineReferences": false
}

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: bd26724a735bb4282b7fbdef4681eb5f
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 252960
packageName: "PrimeTween \xB7 High-Performance Animations and Sequences"
packageVersion: 1.3.7
assetPath: Assets/Plugins/PrimeTween/Demo/Scripts/MeasureAllocations/PrimeTween.Debug.asmdef
uploadId: 860556