Show / Hide Table of Contents

Class TweenStruct

Tween a single member in a struct (value type).

Inheritance
System.Object
TweenStruct
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: Sttz.Tweener
Assembly: cs.temp.dll.dll
Syntax
public static class TweenStruct
Remarks
Note

TweenStruct uses codegen and is therefore not available with AOT/IL2CPP or .Net Standard.

Instead, you can use a virtual property to tween a struct member:

Animate.EnableAccess("field.x",
    (Example t) => t.field.x,
    (t, v) => { var field = t.field; field.x = v; t.field = field; });

Structs or Value Types are special types in .Net that are copied when used and therefore aren't referenced and don't need to be garbage collected. This can speed up some operations but comes with the downside that it's not easily possible to tween a single member of a struct while leaving the other members alone.

E.g. Unity's Vector3 and Quaternion types are value types. Trying to tween a property on Vector3 or Quaternion will produce an error in Animate. If it proceeded, Animate would only update its copy but would never actually update the value on the target object.

Generally, it's faster to tween the whole value type instead of tweening a single of its properties using TweenStruct. E.g. instead of tweening transform.position.x, tween transform.position instead. Sometimes it's necessary to tween only a single property of a value type and allow the other properties to be modified during the tween. In this case, the TweenStruct plugin can be used.

// If possible, tween the whole struct:
Animate.To(transform, 2f, "position", Vector3.zero);

// Explicit usage, only tween the x value:
Animate.To(transform, 2f, "position.x", Vector3.zero)
.Struct();

// Automatic usage, plugin auto-detects when it's needed:
Animate.Options.EnablePlugin(TweenStruct.Loader);
Animate.To(transform, 2f, "position.x", Vector3.zero);

Methods

CustomLoader(String)

Create a custom TweenStruct plugin loader that defines the nested struct property name.

Declaration
public static PluginLoader CustomLoader(string property)
Parameters
Type Name Description
System.String property

Name of the property on the struct

Returns
Type Description
PluginLoader

A custom plugin loader that forces the property type

Remarks

Pass the result of this method to EnablePlugin(PluginLoader, Nullable<Boolean>, Nullable<Boolean>) to enable the plugin for the options scope.

Loader(Tween, Boolean)

TweenStruct plugin loader.

Declaration
public static PluginResult Loader(Tween tween, bool required)
Parameters
Type Name Description
Tween tween
System.Boolean required
Returns
Type Description
PluginResult
Remarks

Pass this method to EnablePlugin(PluginLoader, Nullable<Boolean>, Nullable<Boolean>) to enable the plugin for the options scope.

Struct<TTarget, TValue>(Tween<TTarget, TValue>, String)

Require the TweenStruct plugin for the current tween.

Declaration
public static Tween<TTarget, TValue> Struct<TTarget, TValue>(this Tween<TTarget, TValue> tween, string property = null)
    where TTarget : class where TValue : struct
Parameters
Type Name Description
Tween<TTarget, TValue> tween
System.String property

Name of the property on the struct

Returns
Type Description
Tween<TTarget, TValue>
Type Parameters
Name Description
TTarget
TValue
Remarks

Shorthand for using EnablePlugin(PluginLoader, Nullable<Boolean>, Nullable<Boolean>) with type-checking.

Back to top © 2018 Adrian Stutz