1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2026-02-04 22:34:56 +08:00

Added SetId overloads to store int and string IDs as int/strings and not objects, so that filtered operations can be much faster

This commit is contained in:
Demigiant 2017-09-11 14:33:46 +02:00
parent 33f3ff3b59
commit 26e2e7f155
54 changed files with 236 additions and 25 deletions

View File

@ -2099,8 +2099,18 @@
<param name="autoKillOnCompletion">If TRUE the tween will be automatically killed when complete</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.Object)">
<summary>Sets an ID for the tween, which can then be used as a filter with DOTween's static methods.</summary>
<param name="id">The ID to assign to this tween. Can be an int, a string, an object or anything else.</param>
<summary>Sets an ID for the tween (<see cref="F:DG.Tweening.Tween.id"/>), which can then be used as a filter with DOTween's static methods.</summary>
<param name="objectId">The ID to assign to this tween. Can be an int, a string, an object or anything else.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.String)">
<summary>Sets a string ID for the tween (<see cref="F:DG.Tweening.Tween.stringId"/>), which can then be used as a filter with DOTween's static methods.<para/>
Filtering via string is 2X faster than using an object as an ID (using the alternate obejct overload)</summary>
<param name="stringId">The string ID to assign to this tween.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.Int32)">
<summary>Sets an int ID for the tween (<see cref="F:DG.Tweening.Tween.intId"/>), which can then be used as a filter with DOTween's static methods.<para/>
Filtering via int is 4X faster than via object, 2X faster than via string (using the alternate object/string overloads)</summary>
<param name="intId">The int ID to assign to this tween.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetTarget``1(``0,System.Object)">
<summary>Sets the target for the tween, which can then be used as a filter with DOTween's static methods.
@ -2436,7 +2446,14 @@
<summary>If TRUE the tween wil go backwards</summary>
</member>
<member name="F:DG.Tweening.Tween.id">
<summary>Id (usable for filtering with DOTween static methods). Can be an int, a string, an object, or anything else</summary>
<summary>Object ID (usable for filtering with DOTween static methods). Can be anything except a string or an int
(use <see cref="F:DG.Tweening.Tween.stringId"/> or <see cref="F:DG.Tweening.Tween.intId"/> for those)</summary>
</member>
<member name="F:DG.Tweening.Tween.stringId">
<summary>String ID (usable for filtering with DOTween static methods). 2X faster than using an object id</summary>
</member>
<member name="F:DG.Tweening.Tween.intId">
<summary>String ID (usable for filtering with DOTween static methods). 4X faster than using an object id, 2X faster than using a string id</summary>
</member>
<member name="F:DG.Tweening.Tween.target">
<summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shorcuts</summary>

View File

@ -2099,8 +2099,18 @@
<param name="autoKillOnCompletion">If TRUE the tween will be automatically killed when complete</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.Object)">
<summary>Sets an ID for the tween, which can then be used as a filter with DOTween's static methods.</summary>
<param name="id">The ID to assign to this tween. Can be an int, a string, an object or anything else.</param>
<summary>Sets an ID for the tween (<see cref="F:DG.Tweening.Tween.id"/>), which can then be used as a filter with DOTween's static methods.</summary>
<param name="objectId">The ID to assign to this tween. Can be an int, a string, an object or anything else.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.String)">
<summary>Sets a string ID for the tween (<see cref="F:DG.Tweening.Tween.stringId"/>), which can then be used as a filter with DOTween's static methods.<para/>
Filtering via string is 2X faster than using an object as an ID (using the alternate obejct overload)</summary>
<param name="stringId">The string ID to assign to this tween.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.Int32)">
<summary>Sets an int ID for the tween (<see cref="F:DG.Tweening.Tween.intId"/>), which can then be used as a filter with DOTween's static methods.<para/>
Filtering via int is 4X faster than via object, 2X faster than via string (using the alternate object/string overloads)</summary>
<param name="intId">The int ID to assign to this tween.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetTarget``1(``0,System.Object)">
<summary>Sets the target for the tween, which can then be used as a filter with DOTween's static methods.
@ -2436,7 +2446,14 @@
<summary>If TRUE the tween wil go backwards</summary>
</member>
<member name="F:DG.Tweening.Tween.id">
<summary>Id (usable for filtering with DOTween static methods). Can be an int, a string, an object, or anything else</summary>
<summary>Object ID (usable for filtering with DOTween static methods). Can be anything except a string or an int
(use <see cref="F:DG.Tweening.Tween.stringId"/> or <see cref="F:DG.Tweening.Tween.intId"/> for those)</summary>
</member>
<member name="F:DG.Tweening.Tween.stringId">
<summary>String ID (usable for filtering with DOTween static methods). 2X faster than using an object id</summary>
</member>
<member name="F:DG.Tweening.Tween.intId">
<summary>String ID (usable for filtering with DOTween static methods). 4X faster than using an object id, 2X faster than using a string id</summary>
</member>
<member name="F:DG.Tweening.Tween.target">
<summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shorcuts</summary>

View File

@ -2099,8 +2099,18 @@
<param name="autoKillOnCompletion">If TRUE the tween will be automatically killed when complete</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.Object)">
<summary>Sets an ID for the tween, which can then be used as a filter with DOTween's static methods.</summary>
<param name="id">The ID to assign to this tween. Can be an int, a string, an object or anything else.</param>
<summary>Sets an ID for the tween (<see cref="F:DG.Tweening.Tween.id"/>), which can then be used as a filter with DOTween's static methods.</summary>
<param name="objectId">The ID to assign to this tween. Can be an int, a string, an object or anything else.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.String)">
<summary>Sets a string ID for the tween (<see cref="F:DG.Tweening.Tween.stringId"/>), which can then be used as a filter with DOTween's static methods.<para/>
Filtering via string is 2X faster than using an object as an ID (using the alternate obejct overload)</summary>
<param name="stringId">The string ID to assign to this tween.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.Int32)">
<summary>Sets an int ID for the tween (<see cref="F:DG.Tweening.Tween.intId"/>), which can then be used as a filter with DOTween's static methods.<para/>
Filtering via int is 4X faster than via object, 2X faster than via string (using the alternate object/string overloads)</summary>
<param name="intId">The int ID to assign to this tween.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetTarget``1(``0,System.Object)">
<summary>Sets the target for the tween, which can then be used as a filter with DOTween's static methods.
@ -2436,7 +2446,14 @@
<summary>If TRUE the tween wil go backwards</summary>
</member>
<member name="F:DG.Tweening.Tween.id">
<summary>Id (usable for filtering with DOTween static methods). Can be an int, a string, an object, or anything else</summary>
<summary>Object ID (usable for filtering with DOTween static methods). Can be anything except a string or an int
(use <see cref="F:DG.Tweening.Tween.stringId"/> or <see cref="F:DG.Tweening.Tween.intId"/> for those)</summary>
</member>
<member name="F:DG.Tweening.Tween.stringId">
<summary>String ID (usable for filtering with DOTween static methods). 2X faster than using an object id</summary>
</member>
<member name="F:DG.Tweening.Tween.intId">
<summary>String ID (usable for filtering with DOTween static methods). 4X faster than using an object id, 2X faster than using a string id</summary>
</member>
<member name="F:DG.Tweening.Tween.target">
<summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shorcuts</summary>

View File

@ -36,9 +36,9 @@ public class Ids : BrainBase
GUILayout.Space(50);
GUILayout.BeginHorizontal();
if (GUILayout.Button("TogglePause by Id")) DOTween.TogglePause(0);
if (GUILayout.Button("TogglePause by StringId")) DOTween.TogglePause("string");
if (GUILayout.Button("TogglePause by ObjId")) DOTween.TogglePause(this);
if (GUILayout.Button("TogglePause by Int Id")) DOTween.TogglePause(0);
if (GUILayout.Button("TogglePause by String Id")) DOTween.TogglePause("string");
if (GUILayout.Button("TogglePause by Object Id")) DOTween.TogglePause(this);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();

View File

@ -0,0 +1,71 @@
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
public class Ids_MassFiltering : MonoBehaviour
{
public int totItemsPerId = 200;
public Transform objectId;
int[] intsToTween = new[] {1, 2, 3};
int int0, int1, int2;
void Start()
{
for (int i = 0; i < 3; ++i) {
for (int c = 0; c < totItemsPerId; ++c) {
int index = i;
Tween t = DOTween.To(() => intsToTween[index], x => intsToTween[index] = x, UnityEngine.Random.Range(1, 10), 2)
.Pause().SetAutoKill(false).SetLoops(-1, LoopType.Yoyo);
switch (i) {
case 0: // Int (uses id)
t.SetId(15);
break;
case 1: // String (uses stringId)
t.SetId("aString");
break;
case 2: // Object (uses id)
t.SetId(objectId);
break;
}
}
}
}
void OnGUI()
{
DGUtils.BeginGUI();
GUILayout.Space(50);
float elapsed;
GUILayout.BeginHorizontal();
if (GUILayout.Button("TogglePause by Int Id")) {
elapsed = Time.realtimeSinceStartup;
DOTween.TogglePause(15);
Debug.Log("elapsed: " + (decimal)(Time.realtimeSinceStartup - elapsed));
}
if (GUILayout.Button("TogglePause by String Id")) {
elapsed = Time.realtimeSinceStartup;
DOTween.TogglePause("aString");
Debug.Log("elapsed: " + (decimal)(Time.realtimeSinceStartup - elapsed));
}
if (GUILayout.Button("TogglePause by Object Id")) {
elapsed = Time.realtimeSinceStartup;
DOTween.TogglePause(objectId);
Debug.Log("elapsed: " + (decimal)(Time.realtimeSinceStartup - elapsed));
}
GUILayout.EndHorizontal();
DGUtils.EndGUI();
}
Vector3 RndVector3()
{
return new Vector3(
UnityEngine.Random.Range(3, 10),
UnityEngine.Random.Range(3, 10),
UnityEngine.Random.Range(3, 10)
);
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 942e3b19e5823e04392b6f6327325fa3
timeCreated: 1505127073
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 02e78af34d93f2240b63ca8aeafb3418
timeCreated: 1505127063
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1 +1 @@
m_EditorVersion: 5.6.1f1
m_EditorVersion: 5.6.3p1

View File

@ -457,6 +457,23 @@ namespace DG.Tweening.Core
int totInvolved = 0;
bool hasDespawned = false;
int optionalArrayLen = optionalArray == null ? 0 : optionalArray.Length;
// Determine if ID is required, and if it's stringId
bool useStringId = false;
string stringId = null;
bool useIntId = false;
int intId = 0;
switch (filterType) {
case FilterType.TargetOrId:
case FilterType.TargetAndId:
if (id is string) {
useStringId = true;
stringId = (string)id;
} else if (id is int) {
useIntId = true;
intId = (int)id;
}
break;
}
for (int i = _maxActiveLookupId; i > -1; --i) {
Tween t = _activeTweens[i];
if (t == null || !t.active) continue;
@ -467,16 +484,26 @@ namespace DG.Tweening.Core
isFilterCompliant = true;
break;
case FilterType.TargetOrId:
isFilterCompliant = t.id != null && id.Equals(t.id) || t.target != null && id.Equals(t.target);
if (useStringId) isFilterCompliant = t.stringId != null && t.stringId == stringId;
else if (useIntId) isFilterCompliant = t.intId == intId;
else isFilterCompliant = t.id != null && id.Equals(t.id) || t.target != null && id.Equals(t.target);
break;
case FilterType.TargetAndId:
isFilterCompliant = t.id != null && t.target != null && optionalObj != null && id.Equals(t.id) && optionalObj.Equals(t.target);
if (useStringId) isFilterCompliant = t.target != null && t.stringId == stringId && optionalObj != null && optionalObj.Equals(t.target);
else if (useIntId) isFilterCompliant = t.target != null && t.intId == intId && optionalObj != null && optionalObj.Equals(t.target);
else isFilterCompliant = t.id != null && t.target != null && optionalObj != null && id.Equals(t.id) && optionalObj.Equals(t.target);
break;
case FilterType.AllExceptTargetsOrIds:
isFilterCompliant = true;
for (int c = 0; c < optionalArrayLen; ++c) {
object objId = optionalArray[c];
if (t.id != null && objId.Equals(t.id) || t.target != null && objId.Equals(t.target)) {
if (useStringId && t.stringId == stringId) {
isFilterCompliant = false;
break;
} else if (useIntId && t.intId == intId) {
isFilterCompliant = false;
break;
} else if (t.id != null && objId.Equals(t.id) || t.target != null && objId.Equals(t.target)) {
isFilterCompliant = false;
break;
}

View File

@ -32,7 +32,7 @@ namespace DG.Tweening
public class DOTween
{
/// <summary>DOTween's version</summary>
public static readonly string Version = "1.1.640";
public static readonly string Version = "1.1.650";
///////////////////////////////////////////////
// Options ////////////////////////////////////

View File

@ -23,8 +23,13 @@ namespace DG.Tweening
public float timeScale;
/// <summary>If TRUE the tween wil go backwards</summary>
public bool isBackwards;
/// <summary>Id (usable for filtering with DOTween static methods). Can be an int, a string, an object, or anything else</summary>
/// <summary>Object ID (usable for filtering with DOTween static methods). Can be anything except a string or an int
/// (use <see cref="stringId"/> or <see cref="intId"/> for those)</summary>
public object id;
/// <summary>String ID (usable for filtering with DOTween static methods). 2X faster than using an object id</summary>
public string stringId;
/// <summary>String ID (usable for filtering with DOTween static methods). 4X faster than using an object id, 2X faster than using a string id</summary>
public int intId;
/// <summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shorcuts</summary>
public object target; // Automatically set by DO shortcuts using SetTarget extension. Also used during Tweener.DoStartup in some special cases
// Update type and eventual independence (changed via TweenManager.SetUpdateType)

View File

@ -54,13 +54,33 @@ namespace DG.Tweening
return t;
}
/// <summary>Sets an ID for the tween, which can then be used as a filter with DOTween's static methods.</summary>
/// <param name="id">The ID to assign to this tween. Can be an int, a string, an object or anything else.</param>
public static T SetId<T>(this T t, object id) where T : Tween
/// <summary>Sets an ID for the tween (<see cref="Tween.id"/>), which can then be used as a filter with DOTween's static methods.</summary>
/// <param name="objectId">The ID to assign to this tween. Can be an int, a string, an object or anything else.</param>
public static T SetId<T>(this T t, object objectId) where T : Tween
{
if (t == null || !t.active) return t;
t.id = id;
t.id = objectId;
return t;
}
/// <summary>Sets a string ID for the tween (<see cref="Tween.stringId"/>), which can then be used as a filter with DOTween's static methods.<para/>
/// Filtering via string is 2X faster than using an object as an ID (using the alternate obejct overload)</summary>
/// <param name="stringId">The string ID to assign to this tween.</param>
public static T SetId<T>(this T t, string stringId) where T : Tween
{
if (t == null || !t.active) return t;
t.stringId = stringId;
return t;
}
/// <summary>Sets an int ID for the tween (<see cref="Tween.intId"/>), which can then be used as a filter with DOTween's static methods.<para/>
/// Filtering via int is 4X faster than via object, 2X faster than via string (using the alternate object/string overloads)</summary>
/// <param name="intId">The int ID to assign to this tween.</param>
public static T SetId<T>(this T t, int intId) where T : Tween
{
if (t == null || !t.active) return t;
t.intId = intId;
return t;
}

View File

@ -2099,8 +2099,18 @@
<param name="autoKillOnCompletion">If TRUE the tween will be automatically killed when complete</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.Object)">
<summary>Sets an ID for the tween, which can then be used as a filter with DOTween's static methods.</summary>
<param name="id">The ID to assign to this tween. Can be an int, a string, an object or anything else.</param>
<summary>Sets an ID for the tween (<see cref="F:DG.Tweening.Tween.id"/>), which can then be used as a filter with DOTween's static methods.</summary>
<param name="objectId">The ID to assign to this tween. Can be an int, a string, an object or anything else.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.String)">
<summary>Sets a string ID for the tween (<see cref="F:DG.Tweening.Tween.stringId"/>), which can then be used as a filter with DOTween's static methods.<para/>
Filtering via string is 2X faster than using an object as an ID (using the alternate obejct overload)</summary>
<param name="stringId">The string ID to assign to this tween.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetId``1(``0,System.Int32)">
<summary>Sets an int ID for the tween (<see cref="F:DG.Tweening.Tween.intId"/>), which can then be used as a filter with DOTween's static methods.<para/>
Filtering via int is 4X faster than via object, 2X faster than via string (using the alternate object/string overloads)</summary>
<param name="intId">The int ID to assign to this tween.</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetTarget``1(``0,System.Object)">
<summary>Sets the target for the tween, which can then be used as a filter with DOTween's static methods.
@ -2436,7 +2446,14 @@
<summary>If TRUE the tween wil go backwards</summary>
</member>
<member name="F:DG.Tweening.Tween.id">
<summary>Id (usable for filtering with DOTween static methods). Can be an int, a string, an object, or anything else</summary>
<summary>Object ID (usable for filtering with DOTween static methods). Can be anything except a string or an int
(use <see cref="F:DG.Tweening.Tween.stringId"/> or <see cref="F:DG.Tweening.Tween.intId"/> for those)</summary>
</member>
<member name="F:DG.Tweening.Tween.stringId">
<summary>String ID (usable for filtering with DOTween static methods). 2X faster than using an object id</summary>
</member>
<member name="F:DG.Tweening.Tween.intId">
<summary>String ID (usable for filtering with DOTween static methods). 4X faster than using an object id, 2X faster than using a string id</summary>
</member>
<member name="F:DG.Tweening.Tween.target">
<summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shorcuts</summary>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.