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 AlphaCanvas New Command #1011

Open
wants to merge 5 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
89 changes: 89 additions & 0 deletions Assets/Fungus/Scripts/Commands/LeanTween/AlphaCanvas.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 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;

namespace Fungus
{
/// <summary>
///
/// </summary>
[CommandInfo("LeanTween",
"Alpha Canvas",
"Fade in or out a Canvas Group. 0 is the lowest, 1 is the highest")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class AlphaCanvas : Command
{
[Tooltip("Target game object to Pause or Resume LeanTweens on")]
[SerializeField]
protected GameObjectData _targetObject;
[Tooltip("Target value to fade")]
[SerializeField]
protected float targetValue;
[Tooltip("Fade duration")]
[SerializeField]
protected float duration;
[Tooltip("Wait until finished")]
[SerializeField]
protected bool waitUntilFinished = false;

[Tooltip("Disable On Complete")]
[SerializeField]
protected bool disableOnComplete = false;
protected CanvasGroup canvyG;

public override void OnEnter()
{
if (_targetObject.Value != null)
{
canvyG = _targetObject.Value.GetComponent<CanvasGroup>();

if(canvyG != null)
{
float tmpVal = targetValue > 1f ? 1f : targetValue;

LeanTween.alphaCanvas(canvyG, tmpVal, duration)
.setOnComplete(()=>
{
if(disableOnComplete)
canvyG.gameObject.SetActive(false);
if(waitUntilFinished)
Continue();
});
}
}

if(!waitUntilFinished)
Continue();
}

public override string GetSummary()
{
string canvyGerr = "";
if (_targetObject.Value == null)
{
return "Error: No target object selected";
}

if(canvyG == null)
{
canvyG = _targetObject.Value.GetComponent<CanvasGroup>();
if(canvyG == null)
return canvyGerr = "No Canvas Group available";
}

return "Fade In/Out " + _targetObject.Value.name + " " + canvyGerr;
}

public override Color GetButtonColor()
{
return new Color32(233, 163, 180, 255);
}

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