Skip to content

Commit

Permalink
added some properties for RectTransform for Unity5 (w/ demo scene for…
Browse files Browse the repository at this point in the history
… testing)
  • Loading branch information
mrcarriere committed Apr 22, 2015
1 parent bbebbb7 commit 218061d
Show file tree
Hide file tree
Showing 20 changed files with 675 additions and 0 deletions.
Binary file added Assets/Demo/7. Unity UI.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Demo/7. Unity UI.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Assets/Demo/scripts/UnityGUITween.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class UnityGUITween : BaseDemoGUI
{
public RectTransform anchorImage;
public RectTransform sizeOffsetImage;

void Start()
{
// this will run indefinitely.
Go.to( anchorImage, 4, new GoTweenConfig()
.anchorMin(Vector2.one * 0.25f)
.anchorMax(Vector2.one * 0.75f)
.setIterations( -1, GoLoopType.PingPong ) );

// hook this one up so we can play with the easeTypes in the UI.
_tween = Go.to( sizeOffsetImage, 2, new GoTweenConfig()
.offsetMax(Vector2.right * 100)
.sizeDelta(Vector2.one * -50f, true)
.setIterations( -1, GoLoopType.PingPong ) );
}
}
12 changes: 12 additions & 0 deletions Assets/Demo/scripts/UnityGUITween.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Assets/Plugins/GoKit/GoProxyProp.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions Assets/Plugins/GoKit/GoTweenConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,94 @@ public GoTweenConfig localRotation( Quaternion endValue, bool isRelative = false
}


/// <summary>
/// anchoredPosition tween
/// </summary>
public GoTweenConfig anchoredPosition( Vector2 endValue, bool isRelative = false )
{
var prop = new AnchoredPositionTweenProperty( endValue, isRelative );
_tweenProperties.Add( prop );

return this;
}

/// <summary>
/// anchoredPosition3D tween
/// </summary>
public GoTweenConfig anchoredPosition3D( Vector3 endValue, bool isRelative = false )
{
var prop = new AnchoredPosition3DTweenProperty( endValue, isRelative );
_tweenProperties.Add( prop );

return this;
}

/// <summary>
/// anchorMax tween
/// </summary>
public GoTweenConfig anchorMax( Vector2 endValue, bool isRelative = false )
{
var prop = new AnchorMaxTweenProperty( endValue, isRelative );
_tweenProperties.Add( prop );

return this;
}

/// <summary>
/// anchorMin tween
/// </summary>
public GoTweenConfig anchorMin( Vector2 endValue, bool isRelative = false )
{
var prop = new AnchorMinTweenProperty( endValue, isRelative );
_tweenProperties.Add( prop );

return this;
}

/// <summary>
/// offsetMax tween
/// </summary>
public GoTweenConfig offsetMax( Vector2 endValue, bool isRelative = false )
{
var prop = new OffsetTweenProperty( endValue, isRelative, true );
_tweenProperties.Add( prop );

return this;
}

/// <summary>
/// offsetMin tween
/// </summary>
public GoTweenConfig offsetMin( Vector2 endValue, bool isRelative = false )
{
var prop = new OffsetTweenProperty( endValue, isRelative );
_tweenProperties.Add( prop );

return this;
}

/// <summary>
/// pivot tween
/// </summary>
public GoTweenConfig pivot( Vector2 endValue, bool isRelative = false )
{
var prop = new PivotTweenProperty( endValue, isRelative );
_tweenProperties.Add( prop );

return this;
}

/// <summary>
/// sizeDelta tween
/// </summary>
public GoTweenConfig sizeDelta( Vector2 endValue, bool isRelative = false )
{
var prop = new SizeDeltaTweenProperty( endValue, isRelative );
_tweenProperties.Add( prop );

return this;
}

/// <summary>
/// material color tween
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using UnityEngine;
using System.Collections;


public class AnchorMaxTweenProperty : AbstractTweenProperty
{
protected RectTransform _target;

protected Vector2 _originalEndValue;
protected Vector2 _startValue;
protected Vector2 _endValue;
protected Vector2 _diffValue;

public AnchorMaxTweenProperty( Vector2 endValue, bool isRelative = false) : base( isRelative )
{
_originalEndValue = endValue;
}

public override bool validateTarget( object target )
{
return target is RectTransform;
}

public override void prepareForUse()
{
_target = _ownerTween.target as RectTransform;

_endValue = _originalEndValue;

if( _ownerTween.isFrom )
{
_startValue = _isRelative ? _endValue + _target.anchorMax : _endValue;
_endValue = _target.anchorMax;
}
else
{
_startValue = _target.anchorMax;
}

if( _isRelative && !_ownerTween.isFrom )
_diffValue = _endValue;
else
_diffValue = _endValue - _startValue;
}


public override void tick( float totalElapsedTime )
{
var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
var vec = GoTweenUtils.unclampedVector2Lerp( _startValue, _diffValue, easedTime );

_target.anchorMax = vec;
}


public void resetWithNewEndValue( Vector2 endValue )
{
_originalEndValue = endValue;
prepareForUse();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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


public class AnchorMinTweenProperty : AbstractTweenProperty
{
protected RectTransform _target;

protected Vector2 _originalEndValue;
protected Vector2 _startValue;
protected Vector2 _endValue;
protected Vector2 _diffValue;

public AnchorMinTweenProperty( Vector2 endValue, bool isRelative = false) : base( isRelative )
{
_originalEndValue = endValue;
}

public override bool validateTarget( object target )
{
return target is RectTransform;
}

public override void prepareForUse()
{
_target = _ownerTween.target as RectTransform;

_endValue = _originalEndValue;

if( _ownerTween.isFrom )
{
_startValue = _isRelative ? _endValue + _target.anchorMin : _endValue;
_endValue = _target.anchorMin;
}
else
{
_startValue = _target.anchorMin;
}

if( _isRelative && !_ownerTween.isFrom )
_diffValue = _endValue;
else
_diffValue = _endValue - _startValue;
}


public override void tick( float totalElapsedTime )
{
var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
var vec = GoTweenUtils.unclampedVector2Lerp( _startValue, _diffValue, easedTime );

_target.anchorMin = vec;
}


public void resetWithNewEndValue( Vector2 endValue )
{
_originalEndValue = endValue;
prepareForUse();
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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


public class AnchoredPosition3DTweenProperty : AbstractTweenProperty
{
protected RectTransform _target;

protected Vector3 _originalEndValue;
protected Vector3 _startValue;
protected Vector3 _endValue;
protected Vector3 _diffValue;

public AnchoredPosition3DTweenProperty( Vector3 endValue, bool isRelative = false) : base( isRelative )
{
_originalEndValue = endValue;
}

public override bool validateTarget( object target )
{
return target is RectTransform;
}

public override void prepareForUse()
{
_target = _ownerTween.target as RectTransform;

_endValue = _originalEndValue;

if( _ownerTween.isFrom )
{
_startValue = _isRelative ? _endValue + _target.anchoredPosition3D : _endValue;
_endValue = _target.anchoredPosition3D;
}
else
{
_startValue = _target.anchoredPosition3D;
}

if( _isRelative && !_ownerTween.isFrom )
_diffValue = _endValue;
else
_diffValue = _endValue - _startValue;
}


public override void tick( float totalElapsedTime )
{
var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
var vec = GoTweenUtils.unclampedVector3Lerp( _startValue, _diffValue, easedTime );

_target.anchoredPosition3D = vec;
}


public void resetWithNewEndValue( Vector3 endValue )
{
_originalEndValue = endValue;
prepareForUse();
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 218061d

Please sign in to comment.