Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AttenuatedTweenProperty] Added a AttenuatedShakeTweenProperty and AttenuatedOscillateTweenProperty #37

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 266 additions & 0 deletions Assets/Plugins/GoKit/GoTweenConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,272 @@ public GoTweenConfig floatProp( string propertyName, float endValue, bool isRela
return this;
}

#endregion

#region attenuated shake generic properties

/// <summary>
/// shake generic vector2 tween
/// </summary>
public GoTweenConfig shakeVector2Prop( string propertyName, Vector2 endValue, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector2TweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedShakeTweenProperty( genericProp, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// shake generic vector3 tween
/// </summary>
public GoTweenConfig shakeVector3Prop( string propertyName, Vector3 endValue, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector3TweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedShakeTweenProperty( genericProp, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// shake generic vector4 tween
/// </summary>
public GoTweenConfig shakeVector4Prop( string propertyName, Vector4 endValue, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector4TweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedShakeTweenProperty( genericProp, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// shake generic vector3 path tween
/// </summary>
public GoTweenConfig shakeVector3PathProp( string propertyName, GoSpline path, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector3PathTweenProperty( propertyName, path, isRelative );
var prop = new AttenuatedShakeTweenProperty( genericProp, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// shake generic vector3.x tween
/// </summary>
public GoTweenConfig shakeVector3XProp( string propertyName, float endValue, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector3XTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedShakeTweenProperty( genericProp, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// shake generic vector3.y tween
/// </summary>
public GoTweenConfig shakeVector3YProp( string propertyName, float endValue, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector3YTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedShakeTweenProperty( genericProp, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// shake generic vector3.z tween
/// </summary>
public GoTweenConfig shakeVector3ZProp( string propertyName, float endValue, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector3ZTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedShakeTweenProperty( genericProp, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// shake generic color tween
/// </summary>
public GoTweenConfig shakeColorProp( string propertyName, Color endValue, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new ColorTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedShakeTweenProperty( genericProp, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// shake generic integer tween
/// </summary>
public GoTweenConfig shakeIntProp( string propertyName, int endValue, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new IntTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedShakeTweenProperty( genericProp, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// shake generic float tween
/// </summary>
public GoTweenConfig shakeFloatProp( string propertyName, float endValue, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new FloatTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedShakeTweenProperty( genericProp, frameMod );
_tweenProperties.Add( prop );

return this;
}

#endregion

#region attenuated oscillate generic properties

/// <summary>
/// oscillate generic vector2 tween
/// </summary>
public GoTweenConfig oscillateVector2Prop( string propertyName, Vector2 endValue, float period, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector2TweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedOscillateTweenProperty( genericProp, period, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// oscillate generic vector3 tween
/// </summary>
public GoTweenConfig oscillateVector3Prop( string propertyName, Vector3 endValue, float period, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector3TweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedOscillateTweenProperty( genericProp, period, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// oscillate generic vector4 tween
/// </summary>
public GoTweenConfig oscillateVector4Prop( string propertyName, Vector4 endValue, float period, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector4TweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedOscillateTweenProperty( genericProp, period, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// oscillate generic vector3 path tween
/// </summary>
public GoTweenConfig oscillateVector3PathProp( string propertyName, GoSpline path, float period, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector3PathTweenProperty( propertyName, path, isRelative );
var prop = new AttenuatedOscillateTweenProperty( genericProp, period, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// oscillate generic vector3.x tween
/// </summary>
public GoTweenConfig oscillateVector3XProp( string propertyName, float endValue, float period, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector3XTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedOscillateTweenProperty( genericProp, period, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// oscillate generic vector3.y tween
/// </summary>
public GoTweenConfig oscillateVector3YProp( string propertyName, float endValue, float period, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector3YTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedOscillateTweenProperty( genericProp, period, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// oscillate generic vector3.z tween
/// </summary>
public GoTweenConfig oscillateVector3ZProp( string propertyName, float endValue, float period, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new Vector3ZTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedOscillateTweenProperty( genericProp, period, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// oscillate generic color tween
/// </summary>
public GoTweenConfig oscillateColorProp( string propertyName, Color endValue, float period, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new ColorTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedOscillateTweenProperty( genericProp, period, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// oscillate generic integer tween
/// </summary>
public GoTweenConfig oscillateIntProp( string propertyName, int endValue, float period, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new IntTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedOscillateTweenProperty( genericProp, period, frameMod );
_tweenProperties.Add( prop );

return this;
}


/// <summary>
/// oscillate generic float tween
/// </summary>
public GoTweenConfig oscillateFloatProp( string propertyName, float endValue, float period, bool isRelative = true, int frameMod = 1 )
{
var genericProp = new FloatTweenProperty( propertyName, endValue, isRelative );
var prop = new AttenuatedOscillateTweenProperty( genericProp, period, frameMod );
_tweenProperties.Add( prop );

return this;
}

#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using UnityEngine;
using System.Collections;


public abstract class AbstractDoubleTweenProperty : AbstractTweenProperty
{
protected AbstractTweenProperty _tweenProperty;

/// <summary>
/// reference another tween property
/// </summary>
public AbstractDoubleTweenProperty( AbstractTweenProperty tweenPorperty ) : base( true )
{
_tweenProperty = tweenPorperty;
}


#region Object overrides

public override int GetHashCode()
{
return base.GetHashCode();
}


public override bool Equals( object obj )
{
if (base.Equals(obj)) {
return _tweenProperty.Equals(((AbstractDoubleTweenProperty)obj)._tweenProperty);
}
return false;
}

#endregion

public override void init( GoTween owner )
{
base.init(owner);
//Init owner of _tweenProperty and force ease type to linear
_tweenProperty.setEaseType(GoEaseType.Linear);
_tweenProperty.init(owner);
}

public override bool validateTarget( object target )
{
return _tweenProperty.validateTarget(target);
}


public override void prepareForUse()
{
_tweenProperty.prepareForUse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using UnityEngine;
using System.Collections;



public class AttenuatedOscillateTweenProperty : AttenuatedTweenProperty
{

/// <summary>
/// you can oscilate any AbstractTweenProperty.
/// frameMod allows you to specify what frame count the shakes should occur on. for example, a frameMod of 3 would mean that only when
/// frameCount % 3 == 0 will the shake occur
/// </summary>
public AttenuatedOscillateTweenProperty( AbstractTweenProperty tweenPorperty, float period, int frameMod = 1 ) : base( tweenPorperty, (t,b,c,d) => b+c*Mathf.Sin(t*2*Mathf.PI/period) ,frameMod )
{
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using UnityEngine;
using System.Collections;



public class AttenuatedShakeTweenProperty : AttenuatedTweenProperty
{

/// <summary>
/// you can shake any AbstractTweenProperty.
/// frameMod allows you to specify what frame count the shakes should occur on. for example, a frameMod of 3 would mean that only when
/// frameCount % 3 == 0 will the shake occur
/// </summary>
public AttenuatedShakeTweenProperty( AbstractTweenProperty tweenPorperty, int frameMod = 1 ) : base( tweenPorperty, (t,b,c,d) => b+Random.Range(-c,c) ,frameMod )
{
}
}

Loading