Browse Source

Added Basic LeanTween Commands

master
desktop-maesty/steve 8 years ago
parent
commit
393dc751ba
  1. 9
      Assets/Fungus/Scripts/Commands/LeanTween.meta
  2. 116
      Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs
  3. 12
      Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs.meta
  4. 55
      Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs
  5. 12
      Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs.meta
  6. 74
      Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs
  7. 12
      Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs.meta
  8. 46
      Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs
  9. 12
      Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs.meta
  10. 47
      Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs
  11. 12
      Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs.meta

9
Assets/Fungus/Scripts/Commands/LeanTween.meta

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 53bec3476dd0fa945af5703dda0cd24f
folderAsset: yes
timeCreated: 1501401094
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

116
Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs

@ -0,0 +1,116 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace Fungus
{
/// <summary>
/// Abstract base class for LeanTween commands.
/// </summary>
[ExecuteInEditMode]
public abstract class BaseLeanTweenCommand : Command
{
[Tooltip("Target game object to apply the Tween to")]
[SerializeField]
protected GameObjectData _targetObject;
[Tooltip("The time in seconds the animation will take to complete")]
[SerializeField]
protected FloatData _duration = new FloatData(1f);
public enum ToFrom { To, From }
[Tooltip("Does the tween act from current TO destination or is it reversed and act FROM destination to its current")]
[SerializeField]
protected ToFrom _toFrom;
public bool IsInFromMode { get { return _toFrom == ToFrom.From; } }
public enum AbsAdd { Absolute, Additive }
[Tooltip("Does the tween use the value as a target or as a delta to be added to current.")]
[SerializeField]
protected AbsAdd _absAdd;
public bool IsInAddativeMode { get { return _absAdd == AbsAdd.Additive; } }
[Tooltip("The shape of the easing curve applied to the animation")]
[SerializeField]
protected LeanTweenType easeType = LeanTweenType.easeInOutQuad;
[Tooltip("The type of loop to apply once the animation has completed")]
[SerializeField]
protected LeanTweenType loopType = LeanTweenType.once;
[Tooltip("Number of times to repeat the tween, -1 is infinite.")]
[SerializeField]
protected int repeats = 0;
[Tooltip("Stop any previously LeanTweens on this object before adding this one. Warning; expensive.")]
[SerializeField]
protected bool stopPreviousTweens = false;
[Tooltip("Wait until the tween has finished before executing the next command")]
[SerializeField]
protected bool waitUntilFinished = true;
[HideInInspector] protected LTDescr ourTween;
protected virtual void OnTweenComplete()
{
Continue();
}
#region Public members
public override void OnEnter()
{
if (_targetObject.Value == null)
{
Continue();
return;
}
if (stopPreviousTweens)
{
LeanTween.cancel(_targetObject.Value);
}
ourTween = ExecuteTween();
ourTween.setEase(easeType)
.setRepeat(repeats)
.setLoopType(loopType);
if (waitUntilFinished)
{
if(ourTween != null)
{
ourTween.setOnComplete(OnTweenComplete);
}
}
else
{
Continue();
}
}
public abstract LTDescr ExecuteTween();
public override string GetSummary()
{
if (_targetObject.Value == null)
{
return "Error: No target object selected";
}
return _targetObject.Value.name + " over " + _duration.Value + " seconds";
}
public override Color GetButtonColor()
{
return new Color32(233, 163, 180, 255);
}
#endregion
}
}

12
Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 22379d19093ceb34098232d6f1b848a0
timeCreated: 1499564933
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

55
Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs

@ -0,0 +1,55 @@

using UnityEngine;
using UnityEngine.Serialization;
using System.Collections;
using System;
namespace Fungus
{
/// <summary>
/// Moves a game object to a specified position over time. The position can be defined by a transform in another object (using To Transform) or by setting an absolute position (using To Position, if To Transform is set to None).
/// </summary>
[CommandInfo("LeanTween",
"Move",
"Moves a game object to a specified position over time. The position can be defined by a transform in another object (using To Transform) or by setting an absolute position (using To Position, if To Transform is set to None).")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class MoveLean : BaseLeanTweenCommand
{
[Tooltip("Target transform that the GameObject will move to")]
[SerializeField]
protected TransformData _toTransform;
[Tooltip("Target world position that the GameObject will move to, if no From Transform is set")]
[SerializeField]
protected Vector3Data _toPosition;
[Tooltip("Whether to animate in world space or relative to the parent. False by default.")]
[SerializeField]
protected bool isLocal;
public override LTDescr ExecuteTween()
{
var loc = _toTransform.Value == null ? _toPosition.Value : _toTransform.Value.position;
if(IsInAddativeMode)
{
loc += _targetObject.Value.transform.position;
}
if(IsInFromMode)
{
var cur = _targetObject.Value.transform.position;
_targetObject.Value.transform.position = loc;
loc = cur;
}
if (isLocal)
return LeanTween.moveLocal(_targetObject.Value, loc, _duration);
else
return LeanTween.move(_targetObject.Value, loc, _duration);
}
}
}

12
Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3ca31fffe1be42a49b96bbb8b7ff5a50
timeCreated: 1499566229
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

74
Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs

@ -0,0 +1,74 @@

using UnityEngine;
using UnityEngine.Serialization;
using System.Collections;
using System;
namespace Fungus
{
/// <summary>
/// Rotates a game object to the specified angles over time.
/// </summary>
[CommandInfo("LeanTween",
"Rotate",
"Rotates a game object to the specified angles over time.")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class RotateLean : BaseLeanTweenCommand
{
[Tooltip("Target transform that the GameObject will rotate to")]
[SerializeField]
protected TransformData _toTransform;
[Tooltip("Target rotation that the GameObject will rotate to, if no To Transform is set")]
[SerializeField]
protected Vector3Data _toRotation;
[Tooltip("Whether to animate in world space or relative to the parent. False by default.")]
[SerializeField]
protected bool isLocal;
public enum RotateMode { PureRotate, LookAt2D, LookAt3D}
[Tooltip("Whether to use the provided Transform or Vector as a target to look at rather than a euler to match.")]
[SerializeField]
protected RotateMode rotateMode = RotateMode.PureRotate;
public override LTDescr ExecuteTween()
{
var rot = _toTransform.Value == null ? _toRotation.Value : _toTransform.Value.rotation.eulerAngles;
if(rotateMode == RotateMode.LookAt3D)
{
var pos = _toTransform.Value == null ? _toRotation.Value : _toTransform.Value.position;
var dif = pos - _targetObject.Value.transform.position;
rot = Quaternion.LookRotation(dif.normalized).eulerAngles;
}
else if(rotateMode == RotateMode.LookAt2D)
{
var pos = _toTransform.Value == null ? _toRotation.Value : _toTransform.Value.position;
var dif = pos - _targetObject.Value.transform.position;
dif.z = 0;
rot = Quaternion.FromToRotation(_targetObject.Value.transform.up, dif.normalized).eulerAngles;
}
if (IsInAddativeMode)
{
rot += _targetObject.Value.transform.rotation.eulerAngles;
}
if (IsInFromMode)
{
var cur = _targetObject.Value.transform.rotation.eulerAngles;
_targetObject.Value.transform.rotation = Quaternion.Euler(rot);
rot = cur;
}
if (isLocal)
return LeanTween.rotateLocal(_targetObject.Value, rot, _duration);
else
return LeanTween.rotate(_targetObject.Value, rot, _duration);
}
}
}

12
Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b8feaa22bae049c43a1c6dfe095c498c
timeCreated: 1499583595
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

46
Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs

@ -0,0 +1,46 @@

using UnityEngine;
using UnityEngine.Serialization;
using System.Collections;
using System;
namespace Fungus
{
/// <summary>
/// Changes a game object's scale to a specified value over time.
/// </summary>
[CommandInfo("LeanTween",
"Scale",
"Changes a game object's scale to a specified value over time.")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class ScaleLean : BaseLeanTweenCommand
{
[Tooltip("Target transform that the GameObject will scale to")]
[SerializeField]
protected TransformData _toTransform;
[Tooltip("Target scale that the GameObject will scale to, if no To Transform is set")]
[SerializeField]
protected Vector3Data _toScale = new Vector3Data(Vector3.one);
public override LTDescr ExecuteTween()
{
var sc = _toTransform.Value == null ? _toScale.Value : _toTransform.Value.localScale;
if (IsInAddativeMode)
{
sc += _targetObject.Value.transform.localScale;
}
if (IsInFromMode)
{
var cur = _targetObject.Value.transform.localScale;
_targetObject.Value.transform.localScale = sc;
sc = cur;
}
return LeanTween.scale(_targetObject.Value, sc, _duration);
}
}
}

12
Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 30cbb61ab588b1a4093d2ef0254045b0
timeCreated: 1499585056
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

47
Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs

@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Fungus
{
/// <summary>
///
/// </summary>
[CommandInfo("LeanTween",
"StopTweens",
"Stops the LeanTweens on a target GameObject")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class StopTweensLean : Command
{
[Tooltip("Target game object stop LeanTweens on")]
[SerializeField]
protected GameObjectData _targetObject;
public override void OnEnter()
{
if (_targetObject.Value != null)
{
LeanTween.cancel(_targetObject.Value);
}
Continue();
}
public override string GetSummary()
{
if (_targetObject.Value == null)
{
return "Error: No target object selected";
}
return "Stop all LeanTweens on " + _targetObject.Value.name;
}
public override Color GetButtonColor()
{
return new Color32(233, 163, 180, 255);
}
}
}

12
Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d998218fa600bac43adbc431e9dd6c0c
timeCreated: 1499761355
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save