mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2026-03-26 22:49:03 +08:00
Removed allocations happening when a tween was killed (because C# was erroneously converting a line of code into an Activator.CreateInstance)
This commit is contained in:
parent
1b2b216948
commit
5922a852a4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
67
UnityTests.Unity5/Assets/_Tests/AllocationsTests.cs
Normal file
67
UnityTests.Unity5/Assets/_Tests/AllocationsTests.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
using UnityEditor;
|
||||
using DG.Tweening;
|
||||
|
||||
public class AllocationsTests : BrainBase
|
||||
{
|
||||
public enum AllocationTestType
|
||||
{
|
||||
DOMove,
|
||||
DOPath
|
||||
}
|
||||
|
||||
public AllocationTestType testType;
|
||||
public Transform[] targets;
|
||||
public Vector3[] wps;
|
||||
|
||||
Tween tween0;
|
||||
|
||||
IEnumerator Start()
|
||||
{
|
||||
DOTween.Init();
|
||||
yield return new WaitForSeconds(1);
|
||||
|
||||
switch (testType) {
|
||||
case AllocationTestType.DOMove:
|
||||
Profiler.BeginSample("Create tween");
|
||||
// Regular move tweens test
|
||||
Debug.Log("Create tween");
|
||||
tween0 = targets[0].DOMoveX(2, 1);
|
||||
Profiler.EndSample();
|
||||
yield return null;
|
||||
Profiler.BeginSample("Kill tween");
|
||||
Debug.Log("Kill tween");
|
||||
tween0.Kill();
|
||||
Profiler.EndSample();
|
||||
|
||||
yield return null;
|
||||
|
||||
Profiler.BeginSample("Create tween 2");
|
||||
// Regular move tweens test
|
||||
Debug.Log("Create tween 2");
|
||||
tween0 = targets[0].DOMoveX(2, 1);
|
||||
Profiler.EndSample();
|
||||
yield return null;
|
||||
Profiler.BeginSample("Kill tween 2");
|
||||
Debug.Log("Kill tween 2");
|
||||
tween0.Kill();
|
||||
Profiler.EndSample();
|
||||
break;
|
||||
case AllocationTestType.DOPath:
|
||||
// Regular move tweens test
|
||||
Debug.Log("Create tween");
|
||||
tween0 = targets[0].DOPath(wps, 1);
|
||||
yield return null;
|
||||
Debug.Log("Kill tween");
|
||||
tween0.Kill();
|
||||
break;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
yield return null;
|
||||
EditorApplication.isPaused = true;
|
||||
}
|
||||
}
|
||||
12
UnityTests.Unity5/Assets/_Tests/AllocationsTests.cs.meta
Normal file
12
UnityTests.Unity5/Assets/_Tests/AllocationsTests.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e301133b46f04946be2d21ec1d6d8c8
|
||||
timeCreated: 1481111906
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
UnityTests.Unity5/Assets/_Tests/AllocationsTests.unity
Normal file
BIN
UnityTests.Unity5/Assets/_Tests/AllocationsTests.unity
Normal file
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90b999c7b19ca5945a685d62aa5e1c23
|
||||
timeCreated: 1481111891
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
Binary file not shown.
@ -1,2 +1 @@
|
||||
m_EditorVersion: 5.4.1f1
|
||||
m_StandardAssetsVersion: 0
|
||||
m_EditorVersion: 5.5.0f3
|
||||
|
||||
@ -130,7 +130,8 @@ namespace DG.Tweening.Core
|
||||
base.Reset();
|
||||
|
||||
if (tweenPlugin != null) tweenPlugin.Reset(this);
|
||||
plugOptions = new TPlugOptions();
|
||||
// plugOptions = new TPlugOptions(); // Generates GC because converts to an Activator.CreateInstance
|
||||
plugOptions = Utils.InstanceCreator<TPlugOptions>.Create(); // Fixes GC allocation using workaround
|
||||
getter = null;
|
||||
setter = null;
|
||||
hasManuallySetStartValue = false;
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
// License Copyright (c) Daniele Giardini.
|
||||
// This work is subject to the terms at http://dotween.demigiant.com/license.php
|
||||
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DG.Tweening.Core
|
||||
@ -32,5 +34,17 @@ namespace DG.Tweening.Core
|
||||
ang *= -1f;
|
||||
return ang;
|
||||
}
|
||||
|
||||
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
|
||||
// ███ INTERNAL CLASSES ████████████████████████████████████████████████████████████████████████████████████████████████
|
||||
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
|
||||
|
||||
// Uses code from BK > http://stackoverflow.com/a/1280832
|
||||
public class InstanceCreator<T> where T : new()
|
||||
{
|
||||
static readonly Expression<Func<T>> _TExpression = () => new T();
|
||||
static readonly Func<T> _TBuilder = _TExpression.Compile();
|
||||
public static T Create() { return _TBuilder(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -32,7 +32,7 @@ namespace DG.Tweening
|
||||
public class DOTween
|
||||
{
|
||||
/// <summary>DOTween's version</summary>
|
||||
public static readonly string Version = "1.1.340";
|
||||
public static readonly string Version = "1.1.500";
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Options ////////////////////////////////////
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="UnityEngine">
|
||||
<HintPath>C:\Program Files (x86)\Unity 45\Editor\Data\Managed\UnityEngine.dll</HintPath>
|
||||
<HintPath>C:\Program Files (x86)\Unity 46\Editor\Data\Managed\UnityEngine.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user