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

LeanTween Size New Command #1012

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions Assets/Fungus/Scripts/Commands/LeanTween/SizeLean.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// This code is part of the Fungus library (https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Serialization;
using System.Collections;
using System;

namespace Fungus
{
/// <summary>
/// Changes a game object's RectTransform's size to a specified value over time.
/// </summary>
[CommandInfo("LeanTween",
"Size",
"Changes a gameObject's RectTransform size to a specified value over time.")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class SizeLean : BaseLeanTweenCommand
{
[Tooltip("Target transform that the GameObject will scale to")]
[SerializeField]
protected RectTransform _toRectTransform;

[Tooltip("Target scale that the GameObject will scale to, if no To RectTransform is set")]
[SerializeField]
protected Vector2 _toScale = Vector2.one;

public override LTDescr ExecuteTween()
{
RectTransform ui;

if(_targetObject.Value.GetComponent<RectTransform>() != null)
{
ui = _targetObject.Value.GetComponent<RectTransform>();
}
else
{
Debug.LogWarning("Target gameObject is not UI component");
return;
Continue();
}
var sc = _toRectTransform == null ? _toScale : _toRectTransform.sizeDelta;

if (IsInAddativeMode)
{
sc += ui.sizeDelta;
}

if (IsInFromMode)
{
var cur = ui.sizeDelta;
ui.sizeDelta = sc;
sc = cur;
}

return LeanTween.size(ui, sc, _duration);
}

public override bool HasReference(Variable variable)
{
return variable == base.HasReference(variable);
}
}
}