diff --git a/Assets/Fungus/Scripts/Commands/LeanTween.meta b/Assets/Fungus/Scripts/Commands/LeanTween.meta new file mode 100644 index 00000000..89ab4ee6 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 53bec3476dd0fa945af5703dda0cd24f +folderAsset: yes +timeCreated: 1501401094 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs b/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs new file mode 100644 index 00000000..e617d284 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs @@ -0,0 +1,116 @@ +using UnityEngine; +using UnityEngine.Serialization; + +namespace Fungus +{ + /// + /// Abstract base class for LeanTween commands. + /// + [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 + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs.meta b/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs.meta new file mode 100644 index 00000000..b5346d65 --- /dev/null +++ b/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: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs new file mode 100644 index 00000000..319bb21a --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs @@ -0,0 +1,55 @@ + +using UnityEngine; +using UnityEngine.Serialization; +using System.Collections; +using System; + +namespace Fungus +{ + /// + /// 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). + /// + [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); + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs.meta b/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs.meta new file mode 100644 index 00000000..89e3529a --- /dev/null +++ b/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: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs new file mode 100644 index 00000000..eaa26761 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs @@ -0,0 +1,74 @@ + +using UnityEngine; +using UnityEngine.Serialization; +using System.Collections; +using System; + +namespace Fungus +{ + /// + /// Rotates a game object to the specified angles over time. + /// + [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); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs.meta b/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs.meta new file mode 100644 index 00000000..78458eb0 --- /dev/null +++ b/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: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs new file mode 100644 index 00000000..cc26391f --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs @@ -0,0 +1,46 @@ + +using UnityEngine; +using UnityEngine.Serialization; +using System.Collections; +using System; + +namespace Fungus +{ + /// + /// Changes a game object's scale to a specified value over time. + /// + [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); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs.meta b/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs.meta new file mode 100644 index 00000000..22a144b9 --- /dev/null +++ b/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: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs new file mode 100644 index 00000000..19bf64d7 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs @@ -0,0 +1,47 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +namespace Fungus +{ + /// + /// + /// + [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); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs.meta b/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs.meta new file mode 100644 index 00000000..837cb4ca --- /dev/null +++ b/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: