From 38fcfe64f453d855a5a1a3e3df4d22565c7c56cb Mon Sep 17 00:00:00 2001 From: Chris Cunningham Date: Sat, 30 Jan 2016 16:17:33 -0400 Subject: [PATCH] added UITweening Methods --- Assets/UITweening.meta | 9 + Assets/UITweening/Editor.meta | 7 + .../UITweening/Editor/TweenCGAlphaEditor.cs | 59 ++++ .../Editor/TweenCGAlphaEditor.cs.meta | 10 + Assets/UITweening/Editor/TweenColorEditor.cs | 53 ++++ .../Editor/TweenColorEditor.cs.meta | 10 + Assets/UITweening/Editor/TweenMainEditor.cs | 73 +++++ .../UITweening/Editor/TweenMainEditor.cs.meta | 10 + Assets/UITweening/Editor/TweenPosEditor.cs | 62 ++++ .../UITweening/Editor/TweenPosEditor.cs.meta | 10 + Assets/UITweening/Editor/TweenRotEditor.cs | 59 ++++ .../UITweening/Editor/TweenRotEditor.cs.meta | 10 + Assets/UITweening/Editor/TweenScaleEditor.cs | 59 ++++ .../Editor/TweenScaleEditor.cs.meta | 10 + Assets/UITweening/Editor/TweenSliderEditor.cs | 59 ++++ .../Editor/TweenSliderEditor.cs.meta | 10 + Assets/UITweening/README.md | 13 + Assets/UITweening/README.md.meta | 6 + Assets/UITweening/SliderColors.cs | 38 +++ Assets/UITweening/SliderColors.cs.meta | 10 + Assets/UITweening/TweenAlpha.cs | 101 +++++++ Assets/UITweening/TweenAlpha.cs.meta | 19 ++ Assets/UITweening/TweenBtnAlpha.cs | 87 ++++++ Assets/UITweening/TweenBtnAlpha.cs.meta | 19 ++ Assets/UITweening/TweenBtnColor.cs | 86 ++++++ Assets/UITweening/TweenBtnColor.cs.meta | 19 ++ Assets/UITweening/TweenBtnOffset.cs | 88 ++++++ Assets/UITweening/TweenBtnOffset.cs.meta | 19 ++ Assets/UITweening/TweenBtnRotation.cs | 87 ++++++ Assets/UITweening/TweenBtnRotation.cs.meta | 19 ++ Assets/UITweening/TweenBtnScale.cs | 88 ++++++ Assets/UITweening/TweenBtnScale.cs.meta | 19 ++ Assets/UITweening/TweenCGAlpha.cs | 103 +++++++ Assets/UITweening/TweenCGAlpha.cs.meta | 19 ++ Assets/UITweening/TweenColor.cs | 87 ++++++ Assets/UITweening/TweenColor.cs.meta | 19 ++ Assets/UITweening/TweenMain.cs | 285 ++++++++++++++++++ Assets/UITweening/TweenMain.cs.meta | 19 ++ Assets/UITweening/TweenPos.cs | 107 +++++++ Assets/UITweening/TweenPos.cs.meta | 19 ++ Assets/UITweening/TweenRot.cs | 101 +++++++ Assets/UITweening/TweenRot.cs.meta | 19 ++ Assets/UITweening/TweenScale.cs | 102 +++++++ Assets/UITweening/TweenScale.cs.meta | 19 ++ Assets/UITweening/TweenSlider.cs | 98 ++++++ Assets/UITweening/TweenSlider.cs.meta | 10 + Assets/UITweening/UnScaledTime.cs | 45 +++ Assets/UITweening/UnScaledTime.cs.meta | 19 ++ 48 files changed, 2299 insertions(+) create mode 100644 Assets/UITweening.meta create mode 100644 Assets/UITweening/Editor.meta create mode 100644 Assets/UITweening/Editor/TweenCGAlphaEditor.cs create mode 100644 Assets/UITweening/Editor/TweenCGAlphaEditor.cs.meta create mode 100644 Assets/UITweening/Editor/TweenColorEditor.cs create mode 100644 Assets/UITweening/Editor/TweenColorEditor.cs.meta create mode 100644 Assets/UITweening/Editor/TweenMainEditor.cs create mode 100644 Assets/UITweening/Editor/TweenMainEditor.cs.meta create mode 100644 Assets/UITweening/Editor/TweenPosEditor.cs create mode 100644 Assets/UITweening/Editor/TweenPosEditor.cs.meta create mode 100644 Assets/UITweening/Editor/TweenRotEditor.cs create mode 100644 Assets/UITweening/Editor/TweenRotEditor.cs.meta create mode 100644 Assets/UITweening/Editor/TweenScaleEditor.cs create mode 100644 Assets/UITweening/Editor/TweenScaleEditor.cs.meta create mode 100644 Assets/UITweening/Editor/TweenSliderEditor.cs create mode 100644 Assets/UITweening/Editor/TweenSliderEditor.cs.meta create mode 100644 Assets/UITweening/README.md create mode 100644 Assets/UITweening/README.md.meta create mode 100644 Assets/UITweening/SliderColors.cs create mode 100644 Assets/UITweening/SliderColors.cs.meta create mode 100644 Assets/UITweening/TweenAlpha.cs create mode 100644 Assets/UITweening/TweenAlpha.cs.meta create mode 100644 Assets/UITweening/TweenBtnAlpha.cs create mode 100644 Assets/UITweening/TweenBtnAlpha.cs.meta create mode 100644 Assets/UITweening/TweenBtnColor.cs create mode 100644 Assets/UITweening/TweenBtnColor.cs.meta create mode 100644 Assets/UITweening/TweenBtnOffset.cs create mode 100644 Assets/UITweening/TweenBtnOffset.cs.meta create mode 100644 Assets/UITweening/TweenBtnRotation.cs create mode 100644 Assets/UITweening/TweenBtnRotation.cs.meta create mode 100644 Assets/UITweening/TweenBtnScale.cs create mode 100644 Assets/UITweening/TweenBtnScale.cs.meta create mode 100644 Assets/UITweening/TweenCGAlpha.cs create mode 100644 Assets/UITweening/TweenCGAlpha.cs.meta create mode 100644 Assets/UITweening/TweenColor.cs create mode 100644 Assets/UITweening/TweenColor.cs.meta create mode 100644 Assets/UITweening/TweenMain.cs create mode 100644 Assets/UITweening/TweenMain.cs.meta create mode 100644 Assets/UITweening/TweenPos.cs create mode 100644 Assets/UITweening/TweenPos.cs.meta create mode 100644 Assets/UITweening/TweenRot.cs create mode 100644 Assets/UITweening/TweenRot.cs.meta create mode 100644 Assets/UITweening/TweenScale.cs create mode 100644 Assets/UITweening/TweenScale.cs.meta create mode 100644 Assets/UITweening/TweenSlider.cs create mode 100644 Assets/UITweening/TweenSlider.cs.meta create mode 100644 Assets/UITweening/UnScaledTime.cs create mode 100644 Assets/UITweening/UnScaledTime.cs.meta diff --git a/Assets/UITweening.meta b/Assets/UITweening.meta new file mode 100644 index 0000000..4a4c018 --- /dev/null +++ b/Assets/UITweening.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 7ea28b86718e2413f8fae7f8f9ad5ff6 +folderAsset: yes +timeCreated: 1454184941 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/Editor.meta b/Assets/UITweening/Editor.meta new file mode 100644 index 0000000..019341e --- /dev/null +++ b/Assets/UITweening/Editor.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: bae4a7ab355790e40a9eb3ba200c03c5 +folderAsset: yes +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/Editor/TweenCGAlphaEditor.cs b/Assets/UITweening/Editor/TweenCGAlphaEditor.cs new file mode 100644 index 0000000..ad1d266 --- /dev/null +++ b/Assets/UITweening/Editor/TweenCGAlphaEditor.cs @@ -0,0 +1,59 @@ +using UnityEditor; + +namespace UnityEngine.UI +{ + [CustomEditor(typeof(TweenCGAlpha))] + [CanEditMultipleObjects] + public class TweenCGAlphaEditor : TweenMainEditor + { + private SerializedProperty + _fromProperty, + _fromOffsetProperty, + _toProperty, + _toOffsetProperty; + + protected override void OnEnable() + { + base.OnEnable(); + _fromProperty = serializedObject.FindProperty("from"); + _fromOffsetProperty = serializedObject.FindProperty("fromOffset"); + _toProperty = serializedObject.FindProperty("to"); + _toOffsetProperty = serializedObject.FindProperty("toOffset"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.Slider(_fromProperty, 0f, 1f); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenCGAlpha) i; + self.FromCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(_fromOffsetProperty); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.Slider(_toProperty, 0f, 1f); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenCGAlpha) i; + self.ToCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(_toOffsetProperty); + serializedObject.ApplyModifiedProperties(); + + EditorGUILayout.Separator(); + BaseTweenerProperties(); + } + } +} diff --git a/Assets/UITweening/Editor/TweenCGAlphaEditor.cs.meta b/Assets/UITweening/Editor/TweenCGAlphaEditor.cs.meta new file mode 100644 index 0000000..911a736 --- /dev/null +++ b/Assets/UITweening/Editor/TweenCGAlphaEditor.cs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 19a2ab5b70c99ac48b0833e55fd19158 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/Editor/TweenColorEditor.cs b/Assets/UITweening/Editor/TweenColorEditor.cs new file mode 100644 index 0000000..0bb6c52 --- /dev/null +++ b/Assets/UITweening/Editor/TweenColorEditor.cs @@ -0,0 +1,53 @@ +using UnityEditor; + +namespace UnityEngine.UI +{ + [CustomEditor(typeof(TweenColor))] + [CanEditMultipleObjects] + public class TweenColorEditor : TweenMainEditor + { + private SerializedProperty + _fromProperty, + _toProperty; + + protected override void OnEnable() + { + base.OnEnable(); + _fromProperty = serializedObject.FindProperty("from"); + _toProperty = serializedObject.FindProperty("to"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(_fromProperty); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenColor) i; + self.FromCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(_toProperty); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenColor) i; + self.ToCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + serializedObject.ApplyModifiedProperties(); + + EditorGUILayout.Separator(); + BaseTweenerProperties(); + } + } +} diff --git a/Assets/UITweening/Editor/TweenColorEditor.cs.meta b/Assets/UITweening/Editor/TweenColorEditor.cs.meta new file mode 100644 index 0000000..e07c3cc --- /dev/null +++ b/Assets/UITweening/Editor/TweenColorEditor.cs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 001f2da1137827e41878943939f3e7c5 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/Editor/TweenMainEditor.cs b/Assets/UITweening/Editor/TweenMainEditor.cs new file mode 100644 index 0000000..b8e20ad --- /dev/null +++ b/Assets/UITweening/Editor/TweenMainEditor.cs @@ -0,0 +1,73 @@ +using UnityEditor; + +namespace UnityEngine.UI +{ + [CustomEditor(typeof(TweenMain), true)] + [CanEditMultipleObjects] + public class TweenMainEditor : Editor + { + protected SerializedProperty + style, + method, + functionCurve, + delay, + duration, + ignoreTimeScale, + onFinished; + + private bool tweenerFoldOut = true; + + protected virtual void OnEnable() + { + style = serializedObject.FindProperty("style"); + method = serializedObject.FindProperty("method"); + functionCurve = serializedObject.FindProperty("functionCurve"); + ignoreTimeScale = serializedObject.FindProperty("ignoreTimeScale"); + delay = serializedObject.FindProperty("delay"); + duration = serializedObject.FindProperty("duration"); + onFinished = serializedObject.FindProperty("OnFinished"); + } + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + BaseTweenerProperties(); + } + + protected void BaseTweenerProperties() + { + serializedObject.Update(); + + tweenerFoldOut = EditorGUILayout.Foldout(tweenerFoldOut, "TweenSettings:"); + if (tweenerFoldOut) + { + BeginContents(); + EditorGUILayout.PropertyField(style, new GUIContent("Tween Style")); + EditorGUILayout.PropertyField(method); + EditorGUILayout.PropertyField(functionCurve, new GUIContent("Curve"), GUILayout.Height(52f)); + EditorGUILayout.PropertyField(ignoreTimeScale, new GUIContent("Ignore TimeScale")); + EditorGUILayout.PropertyField(delay); + EditorGUILayout.PropertyField(duration); + EndContents(); + } + + EditorGUILayout.PropertyField(onFinished, new GUIContent("OnFinished")); + serializedObject.ApplyModifiedProperties(); + } + + protected void BeginContents() + { + EditorGUILayout.BeginHorizontal(GUILayout.MinHeight(10f)); + GUILayout.Space(10f); + GUILayout.BeginVertical(); + GUILayout.Space(2f); + } + + protected void EndContents() + { + GUILayout.Space(3f); + GUILayout.EndVertical(); + EditorGUILayout.EndHorizontal(); + } + } +} diff --git a/Assets/UITweening/Editor/TweenMainEditor.cs.meta b/Assets/UITweening/Editor/TweenMainEditor.cs.meta new file mode 100644 index 0000000..d9bc5d5 --- /dev/null +++ b/Assets/UITweening/Editor/TweenMainEditor.cs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: fcc7e4fcbe0b6a54cbce5367233c793c +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/Editor/TweenPosEditor.cs b/Assets/UITweening/Editor/TweenPosEditor.cs new file mode 100644 index 0000000..dc4491a --- /dev/null +++ b/Assets/UITweening/Editor/TweenPosEditor.cs @@ -0,0 +1,62 @@ +using UnityEditor; + +namespace UnityEngine.UI +{ + [CustomEditor(typeof(TweenPos))] + [CanEditMultipleObjects] + public class TweenPosEditor : TweenMainEditor + { + private SerializedProperty + _fromProperty, + _fromOffsetProperty, + _toProperty, + _toOffsetProperty, + _cSpaceProperty; + + protected override void OnEnable() + { + base.OnEnable(); + _fromProperty = serializedObject.FindProperty("from"); + _fromOffsetProperty = serializedObject.FindProperty("fromOffset"); + _toProperty = serializedObject.FindProperty("to"); + _toOffsetProperty = serializedObject.FindProperty("toOffset"); + _cSpaceProperty = serializedObject.FindProperty("CSpace"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(_fromProperty); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenPos) i; + self.FromCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(_fromOffsetProperty, new GUIContent("Offset")); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(_toProperty); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenPos) i; + self.ToCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(_toOffsetProperty, new GUIContent("Offset")); + EditorGUILayout.PropertyField(_cSpaceProperty, new GUIContent("Coordinate Space")); + serializedObject.ApplyModifiedProperties(); + + EditorGUILayout.Separator(); + BaseTweenerProperties(); + } + } +} diff --git a/Assets/UITweening/Editor/TweenPosEditor.cs.meta b/Assets/UITweening/Editor/TweenPosEditor.cs.meta new file mode 100644 index 0000000..570deed --- /dev/null +++ b/Assets/UITweening/Editor/TweenPosEditor.cs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: c330b99dce960fb40a7beacb1ab72e79 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/Editor/TweenRotEditor.cs b/Assets/UITweening/Editor/TweenRotEditor.cs new file mode 100644 index 0000000..b275e36 --- /dev/null +++ b/Assets/UITweening/Editor/TweenRotEditor.cs @@ -0,0 +1,59 @@ +using UnityEditor; + +namespace UnityEngine.UI +{ + [CustomEditor(typeof(TweenRot))] + [CanEditMultipleObjects] + public class TweenRotEditor : TweenMainEditor + { + private SerializedProperty + _fromProperty, + _fromOffetProperty, + _toProperty, + _toOffetProperty; + + protected override void OnEnable() + { + base.OnEnable(); + _fromProperty = serializedObject.FindProperty("from"); + _fromOffetProperty = serializedObject.FindProperty("fromOffset"); + _toProperty = serializedObject.FindProperty("to"); + _toOffetProperty = serializedObject.FindProperty("toOffset"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(_fromProperty); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenRot) i; + self.FromCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(_fromOffetProperty); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(_toProperty); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenRot) i; + self.ToCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(_toOffetProperty); + serializedObject.ApplyModifiedProperties(); + + EditorGUILayout.Separator(); + BaseTweenerProperties(); + } + } +} diff --git a/Assets/UITweening/Editor/TweenRotEditor.cs.meta b/Assets/UITweening/Editor/TweenRotEditor.cs.meta new file mode 100644 index 0000000..428e81c --- /dev/null +++ b/Assets/UITweening/Editor/TweenRotEditor.cs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: f506f6665714107409f6352fd148516a +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/Editor/TweenScaleEditor.cs b/Assets/UITweening/Editor/TweenScaleEditor.cs new file mode 100644 index 0000000..270b98b --- /dev/null +++ b/Assets/UITweening/Editor/TweenScaleEditor.cs @@ -0,0 +1,59 @@ +using UnityEditor; + +namespace UnityEngine.UI +{ + [CustomEditor(typeof(TweenScale))] + [CanEditMultipleObjects] + public class TweenScaleEditor : TweenMainEditor + { + private SerializedProperty + _fromProperty, + _fromOffsetProperty, + _toProperty, + _toOffsetProperty; + + protected override void OnEnable() + { + base.OnEnable(); + _fromProperty = serializedObject.FindProperty("to"); + _fromOffsetProperty = serializedObject.FindProperty("toOffset"); + _toProperty = serializedObject.FindProperty("to"); + _toOffsetProperty = serializedObject.FindProperty("toOffset"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(_fromProperty); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenScale) i; + self.FromCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(_fromOffsetProperty); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(_toProperty); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenScale) i; + self.ToCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(_toOffsetProperty); + serializedObject.ApplyModifiedProperties(); + + EditorGUILayout.Separator(); + BaseTweenerProperties(); + } + } +} diff --git a/Assets/UITweening/Editor/TweenScaleEditor.cs.meta b/Assets/UITweening/Editor/TweenScaleEditor.cs.meta new file mode 100644 index 0000000..277bca9 --- /dev/null +++ b/Assets/UITweening/Editor/TweenScaleEditor.cs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: ec6bc62f29782b04392ff5aef411aeeb +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/Editor/TweenSliderEditor.cs b/Assets/UITweening/Editor/TweenSliderEditor.cs new file mode 100644 index 0000000..b0af3df --- /dev/null +++ b/Assets/UITweening/Editor/TweenSliderEditor.cs @@ -0,0 +1,59 @@ +using UnityEditor; + +namespace UnityEngine.UI +{ + [CustomEditor(typeof(TweenSlider))] + [CanEditMultipleObjects] + public class TweenSliderEditor : TweenMainEditor + { + private SerializedProperty + _fromProperty, + _fromOffsetProperty, + _toProperty, + _toOffsetProperty; + + protected override void OnEnable() + { + base.OnEnable(); + _fromProperty = serializedObject.FindProperty("from"); + _fromOffsetProperty = serializedObject.FindProperty("fromOffset"); + _toProperty = serializedObject.FindProperty("to"); + _toOffsetProperty = serializedObject.FindProperty("toOffset"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(_fromProperty); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenSlider) i; + self.FromCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(_fromOffsetProperty); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PropertyField(_toProperty); + if (GUILayout.Button("\u25C0", GUILayout.Width(24f))) + { + foreach (var i in targets) + { + var self = (TweenSlider) i; + self.ToCurrentValue(); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(_toOffsetProperty); + serializedObject.ApplyModifiedProperties(); + + EditorGUILayout.Separator(); + BaseTweenerProperties(); + } + } +} diff --git a/Assets/UITweening/Editor/TweenSliderEditor.cs.meta b/Assets/UITweening/Editor/TweenSliderEditor.cs.meta new file mode 100644 index 0000000..0062a87 --- /dev/null +++ b/Assets/UITweening/Editor/TweenSliderEditor.cs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 14c58647eb6fed24ea61c7a463ec4c5d +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/README.md b/Assets/UITweening/README.md new file mode 100644 index 0000000..b5a14e0 --- /dev/null +++ b/Assets/UITweening/README.md @@ -0,0 +1,13 @@ +UGUITWeen +========= + +All of the tween components can be found in UI/Tweening of the compinents menui or can be accessed +vai the static method Tween on the TweenAlpha, TweenCGAlpha, +TweenPos, TweenRot, TweenScale classes. + +[Class Documation] (http://cmcproductions.co.uk/Docs/UGuiTween/annotated.html) + +Usage: +``` +TweenPos.Tween(gameObject, 1f, vector3.zero); +``` diff --git a/Assets/UITweening/README.md.meta b/Assets/UITweening/README.md.meta new file mode 100644 index 0000000..d045f8a --- /dev/null +++ b/Assets/UITweening/README.md.meta @@ -0,0 +1,6 @@ +fileFormatVersion: 2 +guid: 5c7a6ab480fbd334d93a793c60488318 +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/SliderColors.cs b/Assets/UITweening/SliderColors.cs new file mode 100644 index 0000000..e90cdfc --- /dev/null +++ b/Assets/UITweening/SliderColors.cs @@ -0,0 +1,38 @@ +using UnityEngine; +using System.Collections; +using UnityEngine.Events; + +namespace UnityEngine.UI +{ + [AddComponentMenu("UI/Tweening/Slider Colors")] + [RequireComponent(typeof(Slider))] + public class SliderColors : MonoBehaviour + { + public Image target; + public Color[] Colors = {Color.red, Color.yellow, Color.green}; + + private Slider slider; + + private void Start() + { + slider = GetComponent(); + if (target == null) + target = slider.GetComponentInChildren(); + + slider.onValueChanged.AddListener(OnValueChanged); + OnValueChanged(slider.value); + } + + private void OnValueChanged(float value) + { + float val = value * (Colors.Length - 1); + int startIndex = Mathf.FloorToInt(val); + Color c = Colors[0]; + if ((startIndex + 1) < Colors.Length) + c = Color.Lerp(Colors[startIndex], Colors[startIndex + 1], val - startIndex); + else if (startIndex < Colors.Length) + c = Colors[startIndex]; + target.color = c; + } + } +} diff --git a/Assets/UITweening/SliderColors.cs.meta b/Assets/UITweening/SliderColors.cs.meta new file mode 100644 index 0000000..d89b314 --- /dev/null +++ b/Assets/UITweening/SliderColors.cs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: b2b94c4c67dcce640af9e407c1c022e1 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenAlpha.cs b/Assets/UITweening/TweenAlpha.cs new file mode 100644 index 0000000..08b8ae7 --- /dev/null +++ b/Assets/UITweening/TweenAlpha.cs @@ -0,0 +1,101 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Events; +using System.Collections; + +namespace UnityEngine.UI +{ + [RequireComponent(typeof(Graphic))] + [AddComponentMenu("UI/Tweening/Alpha")] + public class TweenAlpha : TweenMain + { + [Range(0f, 1f)] + public float + from, + to; + + private float + _from, + _to; + + private Graphic _gfx; + private Graphic Gfx + { + get { return _gfx ?? (_gfx = GetComponent()); } + } + + public float value + { + get { return Gfx.color.a; } + set { Gfx.color = new Color(Gfx.color.r, Gfx.color.g, Gfx.color.b, value); } + } + + protected override void Start() + { + if (fromOffset) _from = value + from; + else _from = from; + if (toOffset) _to = value + to; + else _to = to; + } + + protected override void OnUpdate(float factor, bool isFinished) + { + value = Mathf.Lerp(_from, _to, factor); + } + + public override void ToCurrentValue() { to = value; } + public override void FromCurrentValue() { from = value; } + + /// + /// Create a TweenAlpha Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenAlpha component + public static TweenAlpha Tween(GameObject go, float duration, float alpha, UnityAction finished = null) + { + TweenAlpha cls = TweenMain.Tween(go, duration, finished); + cls.from = cls.value; + cls.to = alpha; + cls.Start(); + return cls; + } + + /// + /// Create a TweenAlpha Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenAlpha component + public static TweenAlpha Tween(GameObject go, float duration, float fromVal, float toVal, UnityAction finished = null) + { + return Tween(go, duration, fromVal, toVal, Style.Once, Method.Linear, finished); + } + + /// + /// Create a TweenAlpha Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// The style of tween (Once, Looped, PingPong) + /// The Interpolation method of the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenAlpha component + public static TweenAlpha Tween(GameObject go, float duration, float fromVal, float toVal, + Style style, Method method, UnityAction finished = null) + { + TweenAlpha cls = TweenMain.Tween(go, duration, style, method, finished); + cls.from = fromVal; + cls.to = toVal; + cls.Start(); + return cls; + } + } +} diff --git a/Assets/UITweening/TweenAlpha.cs.meta b/Assets/UITweening/TweenAlpha.cs.meta new file mode 100644 index 0000000..4c8e19a --- /dev/null +++ b/Assets/UITweening/TweenAlpha.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: a1a86ec76a7a4014a85faf236c3b267e +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenBtnAlpha.cs b/Assets/UITweening/TweenBtnAlpha.cs new file mode 100644 index 0000000..55a7fd8 --- /dev/null +++ b/Assets/UITweening/TweenBtnAlpha.cs @@ -0,0 +1,87 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using System.Collections; + +namespace UnityEngine.UI +{ + [AddComponentMenu("UI/Tweening/Interaction/Button Alpha")] + public class TweenBtnAlpha : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler + { + public Transform target; + public TweenMain.Method method = TweenMain.Method.Linear; + public TweenMain.Style style = TweenMain.Style.Once; + [Range(0f, 1f)] + public float + hover = 1f, + pressed = 1f; + public float duration = 0.2f; + + private Graphic gfx; + private float _Alpha; + private bool _Started = false; + private bool hovered = false; + + void Start() + { + if (!_Started) + { + _Started = true; + if (target == null) target = transform; + gfx = target.GetComponent(); + _Alpha = gfx.color.a; + } + } + + void OnDisable() + { + if (_Started && target != null) + { + TweenAlpha tc = target.GetComponent(); + if (tc != null) + tc.value = _Alpha; + tc.enabled = false; + } + } + void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + if (enabled) + { + if (!_Started) Start(); + TweenAlpha.Tween(target.gameObject, duration, gfx.color.a, pressed, style, method); + } + } + + void IPointerUpHandler.OnPointerUp(PointerEventData eventData) + { + if (enabled) + { + if (!_Started) Start(); + if (hovered) + TweenAlpha.Tween(target.gameObject, duration, gfx.color.a, hover, style, method); + else + TweenAlpha.Tween(target.gameObject, gfx.color.a, duration, _Alpha, TweenMain.Style.Once, method); + } + } + + void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) + { + hovered = true; + if (enabled) + { + if (!_Started) Start(); + TweenAlpha.Tween(target.gameObject, duration, gfx.color.a, hover, style, method); + } + } + + void IPointerExitHandler.OnPointerExit(PointerEventData eventData) + { + hovered = false; + if (enabled) + { + if (!_Started) Start(); + TweenAlpha.Tween(target.gameObject, duration, gfx.color.a, _Alpha, TweenMain.Style.Once, method); + } + } + } +} diff --git a/Assets/UITweening/TweenBtnAlpha.cs.meta b/Assets/UITweening/TweenBtnAlpha.cs.meta new file mode 100644 index 0000000..a7f15dc --- /dev/null +++ b/Assets/UITweening/TweenBtnAlpha.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: c1750da843bed95439dd20a36565f4fc +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenBtnColor.cs b/Assets/UITweening/TweenBtnColor.cs new file mode 100644 index 0000000..03e924d --- /dev/null +++ b/Assets/UITweening/TweenBtnColor.cs @@ -0,0 +1,86 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using System.Collections; + +namespace UnityEngine.UI +{ + [AddComponentMenu("UI/Tweening/Interaction/Button Color")] + public class TweenBtnColor : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler + { + public Transform target; + public TweenMain.Method method = TweenMain.Method.Linear; + public TweenMain.Style style = TweenMain.Style.Once; + public Color hover = Color.black; + public Color pressed = Color.black; + public float duration = 0.2f; + + private Graphic gfx; + private Color _Col; + private bool _Started = false; + private bool hovered = false; + + void Start() + { + if (!_Started) + { + _Started = true; + if (target == null) target = transform; + gfx = target.GetComponent(); + _Col = gfx.color; + } + } + + void OnDisable() + { + if (_Started && target != null) + { + TweenColor tc = target.GetComponent(); + if (tc != null) + tc.value = _Col; + tc.enabled = false; + } + } + + void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + if (enabled) + { + if (!_Started) Start(); + TweenColor.Tween(target.gameObject, duration, gfx.color, pressed, style, method); + } + } + + void IPointerUpHandler.OnPointerUp(PointerEventData eventData) + { + if (enabled) + { + if (!_Started) Start(); + if (hovered) + TweenColor.Tween(target.gameObject, duration, gfx.color, hover, style, method); + else + TweenColor.Tween(target.gameObject, duration, gfx.color, _Col, TweenMain.Style.Once, method); + } + } + + void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) + { + hovered = true; + if (enabled) + { + if (!_Started) Start(); + TweenColor.Tween(target.gameObject, duration, gfx.color, hover, style, method); + } + } + + void IPointerExitHandler.OnPointerExit(PointerEventData eventData) + { + hovered = false; + if (enabled) + { + if (!_Started) Start(); + TweenColor.Tween(target.gameObject, duration, gfx.color, _Col, TweenMain.Style.Once, method); + } + } + } +} diff --git a/Assets/UITweening/TweenBtnColor.cs.meta b/Assets/UITweening/TweenBtnColor.cs.meta new file mode 100644 index 0000000..054f84d --- /dev/null +++ b/Assets/UITweening/TweenBtnColor.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: 6603eac9d0b9acc4d99c093f4e8ea8dd +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenBtnOffset.cs b/Assets/UITweening/TweenBtnOffset.cs new file mode 100644 index 0000000..4738665 --- /dev/null +++ b/Assets/UITweening/TweenBtnOffset.cs @@ -0,0 +1,88 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using System.Collections; + +namespace UnityEngine.UI +{ + [AddComponentMenu("UI/Tweening/Interaction/Button Offset")] + public class TweenBtnOffset : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler + { + public Transform target; + public TweenMain.Method method = TweenMain.Method.Linear; + public TweenMain.Style style = TweenMain.Style.Once; + public Vector3 hover = Vector3.zero; + public Vector3 pressed = new Vector3(2f, -2f); + public float duration = 0.2f; + + private RectTransform rect; + private Vector3 _Pos; + private bool _Started = false; + private bool hovered = false; + + void Start() + { + if (!_Started) + { + _Started = true; + if (target == null) target = transform; + rect = target.GetComponent(); + _Pos = rect.anchoredPosition3D; + } + } + + void OnDisable() + { + if (_Started && target != null) + { + TweenPos tc = target.GetComponent(); + + if (tc != null) { + tc.value = _Pos; + tc.enabled = false; + } + } + } + + void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + if (enabled) + { + if (!_Started) Start(); + TweenPos.Tween(target.gameObject, duration, rect.anchoredPosition3D, _Pos + pressed, style, method); + } + } + + void IPointerUpHandler.OnPointerUp(PointerEventData eventData) + { + if (enabled) + { + if (!_Started) Start(); + if (hovered) + TweenPos.Tween(target.gameObject, duration, rect.anchoredPosition3D, _Pos + hover, style, method); + else + TweenPos.Tween(target.gameObject, duration, rect.anchoredPosition3D, _Pos, TweenMain.Style.Once, method); + } + } + + void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) + { + hovered = true; + if (enabled) + { + if (!_Started) Start(); + TweenPos.Tween(target.gameObject, duration, rect.anchoredPosition3D, _Pos + hover, style, method); + } + } + + void IPointerExitHandler.OnPointerExit(PointerEventData eventData) + { + hovered = false; + if (enabled) + { + if (!_Started) Start(); + TweenPos.Tween(target.gameObject, duration, rect.anchoredPosition3D, _Pos, TweenMain.Style.Once, method); + } + } + } +} diff --git a/Assets/UITweening/TweenBtnOffset.cs.meta b/Assets/UITweening/TweenBtnOffset.cs.meta new file mode 100644 index 0000000..5c8a8bd --- /dev/null +++ b/Assets/UITweening/TweenBtnOffset.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: 2ff592cd616f4f6458b24ec7d1a6c097 +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenBtnRotation.cs b/Assets/UITweening/TweenBtnRotation.cs new file mode 100644 index 0000000..a7d8046 --- /dev/null +++ b/Assets/UITweening/TweenBtnRotation.cs @@ -0,0 +1,87 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using System.Collections; + +namespace UnityEngine.UI +{ + [AddComponentMenu("UI/Tweening/Interaction/Button Rotation")] + public class TweenBtnRotation : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler + { + public Transform target; + public TweenMain.Method method = TweenMain.Method.Linear; + public TweenMain.Style style = TweenMain.Style.Once; + public Vector3 hover = Vector3.zero; + public Vector3 pressed = new Vector3(0f, 0f, 180f); + public float duration = 0.2f; + + private RectTransform rect; + private Quaternion _Rot; + private bool _Started = false; + private bool hovered = false; + + void Start() + { + if (!_Started) + { + _Started = true; + if (target == null) target = transform; + rect = target.GetComponent(); + _Rot = rect.rotation; + } + } + + void OnDisable() + { + if (_Started && target != null) + { + TweenRot tc = target.GetComponent(); + + if (tc != null) + tc.value = _Rot; + tc.enabled = false; + } + } + + void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + if (enabled) + { + if (!_Started) Start(); + TweenRot.Tween(target.gameObject, duration, rect.rotation, _Rot * Quaternion.Euler(pressed), style, method); + } + } + + void IPointerUpHandler.OnPointerUp(PointerEventData eventData) + { + if (enabled) + { + if (!_Started) Start(); + if (hovered) + TweenRot.Tween(target.gameObject, duration, rect.rotation, _Rot * Quaternion.Euler(hover), style, method); + else + TweenRot.Tween(target.gameObject, duration, rect.rotation, _Rot, TweenMain.Style.Once, method); + } + } + + void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) + { + hovered = true; + if (enabled) + { + if (!_Started) Start(); + TweenRot.Tween(target.gameObject, duration, rect.rotation, _Rot * Quaternion.Euler(hover), style, method); + } + } + + void IPointerExitHandler.OnPointerExit(PointerEventData eventData) + { + hovered = false; + if (enabled) + { + if (!_Started) Start(); + TweenRot.Tween(target.gameObject, duration, rect.rotation, _Rot, TweenMain.Style.Once, method); + } + } + } +} diff --git a/Assets/UITweening/TweenBtnRotation.cs.meta b/Assets/UITweening/TweenBtnRotation.cs.meta new file mode 100644 index 0000000..e5a3a78 --- /dev/null +++ b/Assets/UITweening/TweenBtnRotation.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: 741d513dd0b04e348b7f456b46eb7011 +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenBtnScale.cs b/Assets/UITweening/TweenBtnScale.cs new file mode 100644 index 0000000..b131ccb --- /dev/null +++ b/Assets/UITweening/TweenBtnScale.cs @@ -0,0 +1,88 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using System.Collections; + +namespace UnityEngine.UI +{ + [AddComponentMenu("UI/Tweening/Interaction/Button Scale")] + public class TweenBtnScale : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler + { + public Transform target; + public TweenMain.Method method = TweenMain.Method.Linear; + public TweenMain.Style style = TweenMain.Style.Once; + public Vector3 hover = new Vector3(1.1f, 1.1f, 1.1f); + public Vector3 pressed = new Vector3(1.05f, 1.05f, 1.05f); + public float duration = 0.2f; + + private Vector3 _Scale; + private bool _Started = false; + + private bool hovered = false; + + void Start() + { + if (!_Started) + { + _Started = true; + if (target == null) target = transform; + _Scale = target.localScale; + } + } + + void OnDisable() + { + if (_Started && target != null) + { + TweenScale tc = target.GetComponent(); + + if (tc != null) + { + tc.value = _Scale; + tc.enabled = false; + } + } + } + + void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + if (enabled) + { + if (!_Started) Start(); + TweenScale.Tween(target.gameObject, duration, target.localScale, pressed, style, method); + } + } + + void IPointerUpHandler.OnPointerUp(PointerEventData eventData) + { + if (enabled) + { + if (!_Started) Start(); + if (hovered) + TweenScale.Tween(target.gameObject, duration, target.localScale, hover, style, method); + else + TweenScale.Tween(target.gameObject, duration, target.localScale, _Scale, TweenMain.Style.Once, method); + } + } + + void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) + { + hovered = true; + if (enabled) + { + if (!_Started) Start(); + TweenScale.Tween(target.gameObject, duration, target.localScale, hover, style, method); + } + } + + void IPointerExitHandler.OnPointerExit(PointerEventData eventData) + { + hovered = false; + if (enabled) + { + if (!_Started) Start(); + TweenScale.Tween(target.gameObject, duration, target.localScale, _Scale, TweenMain.Style.Once, method); + } + } + } +} diff --git a/Assets/UITweening/TweenBtnScale.cs.meta b/Assets/UITweening/TweenBtnScale.cs.meta new file mode 100644 index 0000000..54db86c --- /dev/null +++ b/Assets/UITweening/TweenBtnScale.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: 90076c4dda59c29449d3ec774b50e63f +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenCGAlpha.cs b/Assets/UITweening/TweenCGAlpha.cs new file mode 100644 index 0000000..2ad2428 --- /dev/null +++ b/Assets/UITweening/TweenCGAlpha.cs @@ -0,0 +1,103 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Events; +using System.Collections; + +namespace UnityEngine.UI +{ + [RequireComponent(typeof(CanvasGroup))] + [AddComponentMenu("UI/Tweening/Canvas Group Alpha")] + public class TweenCGAlpha : TweenMain + { + + [Range(0f, 1f)] + public float + from, + to; + + private float + _from, + _to; + + private CanvasGroup _mcg; + private CanvasGroup _cg + { + get { return _mcg ?? (_mcg = GetComponent()); } + } + + public float value + { + get { return _cg.alpha; } + set { _cg.alpha = value; } + } + + protected override void Start() + { + if (fromOffset) _from = value + from; + else _from = from; + if (toOffset) _to = value + to; + else _to = to; + } + + protected override void OnUpdate(float factor, bool isFinished) + { + value = Mathf.Lerp(_from, _to, factor); + } + + public override void ToCurrentValue() { to = value; } + public override void FromCurrentValue() { from = value; } + + /// + /// Create a TweenCGAlpha Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenCGAlpha component + public static TweenCGAlpha Tween(GameObject go, float duration, float alpha, UnityAction finished = null) + { + TweenCGAlpha cls = TweenMain.Tween(go, duration, finished); + cls.from = cls.value; + cls.to = alpha; + cls.Start(); + return cls; + } + + /// + /// Create a TweenCGAlpha Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenCGAlpha component + public static TweenCGAlpha Tween(GameObject go, float duration, float fromVal, float toVal, + UnityAction finished = null) + { + return Tween(go, duration, fromVal, toVal, Style.Once, Method.Linear, finished); + } + + /// + /// Create a TweenCGAlpha Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// The style of tween (Once, Looped, PingPong) + /// The Interpolation method of the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenCGAlpha component + public static TweenCGAlpha Tween(GameObject go, float duration, float fromVal, float toVal, + Style style, Method method, UnityAction finished = null) + { + TweenCGAlpha cls = TweenMain.Tween(go, duration, style, method, finished); + cls.from = fromVal; + cls.to = toVal; + cls.Start(); + return cls; + } + } +} diff --git a/Assets/UITweening/TweenCGAlpha.cs.meta b/Assets/UITweening/TweenCGAlpha.cs.meta new file mode 100644 index 0000000..52c95e3 --- /dev/null +++ b/Assets/UITweening/TweenCGAlpha.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: ff7302b1728012f438e3a5839bb0e646 +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenColor.cs b/Assets/UITweening/TweenColor.cs new file mode 100644 index 0000000..4b6e37b --- /dev/null +++ b/Assets/UITweening/TweenColor.cs @@ -0,0 +1,87 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Events; +using System.Collections; + +namespace UnityEngine.UI +{ + [RequireComponent(typeof(Graphic))] + [AddComponentMenu("UI/Tweening/Color")] + public class TweenColor : TweenMain + { + public Color from = Color.black; + public Color to = Color.black; + + private Graphic _gfx; + private Graphic Gfx + { + get { return _gfx ?? (_gfx = GetComponent()); } + } + + public Color value + { + get { return Gfx.color; } + set { Gfx.color = value; } + } + + protected override void OnUpdate(float factor, bool isFinished) + { + value = Color.Lerp(from, to, factor); + } + + public override void ToCurrentValue() { to = value; } + public override void FromCurrentValue() { from = value; } + + /// + /// Create a TweenColor Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenColor component + public static TweenColor Tween(GameObject go, float duration, Color color, UnityAction finished = null) + { + TweenColor cls = TweenMain.Tween(go, duration, finished); + cls.from = cls.value; + cls.to = color; + cls.Start(); + return cls; + } + + /// + /// Create a TweenColor Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenColor component + public static TweenColor Tween(GameObject go, float duration, Color fromVal, Color toVal, UnityAction finished = null) + { + return Tween(go, duration, fromVal, toVal, Style.Once, Method.Linear, finished); + } + + /// + /// Create a TweenColor Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// The style of tween (Once, Looped, PingPong) + /// The Interpolation method of the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenColor component + public static TweenColor Tween(GameObject go, float duration, Color fromVal, Color toVal, + Style style, Method method, UnityAction finished = null) + { + TweenColor cls = TweenMain.Tween(go, duration, style, method, finished); + cls.from = fromVal; + cls.to = toVal; + cls.Start(); + return cls; + } + } +} diff --git a/Assets/UITweening/TweenColor.cs.meta b/Assets/UITweening/TweenColor.cs.meta new file mode 100644 index 0000000..3f4180a --- /dev/null +++ b/Assets/UITweening/TweenColor.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: 925a2df448897c9478d5778048459f33 +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenMain.cs b/Assets/UITweening/TweenMain.cs new file mode 100644 index 0000000..b9204b2 --- /dev/null +++ b/Assets/UITweening/TweenMain.cs @@ -0,0 +1,285 @@ +using UnityEngine; +using UnityEngine.Events; +using System.Collections; +using System.Collections.Generic; + +namespace UnityEngine.UI +{ + public abstract class TweenMain : MonoBehaviour + { + static public TweenMain self; + + #region Enums + public enum Method + { + Linear, + EaseIn, + EaseOut, + EaseInOut, + BounceIn, + BounceOut, + BounceInOut + } + + public enum Style + { + Once, + Loop, + PingPong + } + #endregion + + #region publicVars + public UnityEvent OnFinished = new UnityEvent(); + + public bool fromOffset = false; + public bool toOffset = false; + + public Method method = Method.Linear; + public AnimationCurve functionCurve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f)); + public Style style = Style.Once; + public bool ignoreTimeScale = true; + public float delay = 0f; + public float duration = 1f; + + public float amountPerDelta + { + get + { + if (_Duration != duration) + { + _Duration = duration; + _AmountPerDelta = Mathf.Abs((duration > 0f) ? 1f / duration : 1000f); + } + return _AmountPerDelta; + } + } + + public float tweenFactor { get { return _Factor; } set { _Factor = Mathf.Clamp01(value); } } + #endregion + + #region privateVars + private bool _Started = false; + private float + _StartTime = 0f, + _Duration = 0f, + _AmountPerDelta = 1000f, + _Factor = 0f; + #endregion + + void Reset() + { + if (!_Started) + { + ToCurrentValue(); + FromCurrentValue(); + } + Start(); + } + + void Awake() + { + if (OnFinished == null) + OnFinished = new UnityEvent(); + } + + protected virtual void Start() { Update(); } + void Update() + { + float delta = ignoreTimeScale ? UnScaledTime.deltaTime : Time.deltaTime; + float time = ignoreTimeScale ? UnScaledTime.time : Time.time; + if (!_Started) + { + _Started = true; + _StartTime = time + delay; + } + + if (time < _StartTime) + return; + + _Factor += amountPerDelta * delta; + + if (style == Style.Loop) + { + if (_Factor > 1f) + _Factor -= Mathf.Floor(_Factor); + } + else if (style == Style.PingPong) + { + if (_Factor > 1f) + { + _Factor = 1f - (_Factor - Mathf.Floor(_Factor)); + _AmountPerDelta = -_AmountPerDelta; + } + else if (_Factor < 0f) + { + _Factor = -_Factor; + _Factor -= Mathf.Floor(_Factor); + _AmountPerDelta = -_AmountPerDelta; + } + } + + if ((style == Style.Once) && (duration == 0f || _Factor > 1f || _Factor < 0f)) + { + _Factor = Mathf.Clamp01(_Factor); + Sample(_Factor, true); + + if (duration == 0f || (_Factor == 1f && _AmountPerDelta > 0f || _Factor == 0f && amountPerDelta < 0f)) + enabled = false; + + //Event Callback stuff + if (self == null) + { + self = this; + if (OnFinished != null) + OnFinished.Invoke(); + } + self = null; + } + else + Sample(_Factor, false); + } + + void OnDisable() { _Started = false; } + + protected void Sample(float factor, bool isFinished) + { + float val = Mathf.Clamp01(factor); + + switch (method) + { + case Method.Linear: + val = Easing.Linear(val); + break; + + case Method.EaseIn: + val = Easing.Sinusoidal.In(val); + break; + + case Method.EaseOut: + val = Easing.Sinusoidal.Out(val); + break; + + case Method.EaseInOut: + val = Easing.Sinusoidal.InOut(val); + break; + + case Method.BounceIn: + val = Easing.Bounce.In(val); + break; + + case Method.BounceOut: + val = Easing.Bounce.Out(val); + break; + + case Method.BounceInOut: + val = Easing.Bounce.InOut(val); + break; + } + OnUpdate((functionCurve != null) ? functionCurve.Evaluate(val) : val, isFinished); + } + + #region PlayMethods + /// + /// Reset Tween to begining. + /// + public void ResetToBeginning() + { + _Started = false; + _Factor = (_AmountPerDelta < 0f) ? 1f : 0f; + Sample(_Factor, false); + Start(); + } + + /// + /// Plays Tween. + /// + public void Play() { PlayForward(); } + + /// + /// Plays Tween. + /// + public void PlayForward() + { + _AmountPerDelta = Mathf.Abs(_AmountPerDelta); + enabled = true; + Start(); + Update(); + } + + /// + /// Plays Tween in reverse. + /// + public void PlayReverse() + { + _AmountPerDelta = -Mathf.Abs(_AmountPerDelta); + enabled = true; + Start(); + Update(); + } + + /// + /// Toogle play direction and play tween. + /// + public void Toggle() + { + if (_Factor > 0f) + _AmountPerDelta = -amountPerDelta; + else + _AmountPerDelta = Mathf.Abs(amountPerDelta); + enabled = true; + } + #endregion + + /// + /// Interface for new tweeners to implemeant. + /// + /// + /// + abstract protected void OnUpdate(float factor, bool isFinished); + + /// + /// Set "To" the current Value. + /// + public virtual void ToCurrentValue() { } + /// + /// Set "From" the current Value. + /// + public virtual void FromCurrentValue() { } + + protected static T Tween(GameObject go, float duration, + Style style, Method method, UnityAction finished = null) where T :TweenMain + { + T cls = Tween(go, duration, finished); + cls.style = style; + cls.method = method; + return cls; + } + + protected static T Tween(GameObject go, float duration, + UnityAction finished = null) where T : TweenMain + { + T cls = go.GetComponent(); + if (cls == null) + cls = go.AddComponent(); + + cls.OnFinished.RemoveAllListeners(); + if (finished != null) + cls.OnFinished.AddListener(finished); + + cls._Started = false; + cls.duration = duration; + cls._Factor = 0f; + cls._AmountPerDelta = Mathf.Abs(cls._AmountPerDelta); + cls.functionCurve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 0f), new Keyframe(1f, 1f, 1f, 1f)); + cls.enabled = true; + + if (duration <= 0f) + { + cls.Sample(1f, true); + cls.enabled = false; + } + return cls; + } + } +} diff --git a/Assets/UITweening/TweenMain.cs.meta b/Assets/UITweening/TweenMain.cs.meta new file mode 100644 index 0000000..a664021 --- /dev/null +++ b/Assets/UITweening/TweenMain.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: 7a4688ec51f7aaa4fb4ed73730b35deb +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenPos.cs b/Assets/UITweening/TweenPos.cs new file mode 100644 index 0000000..8f0b1b7 --- /dev/null +++ b/Assets/UITweening/TweenPos.cs @@ -0,0 +1,107 @@ +using UnityEngine.Events; + +namespace UnityEngine.UI +{ + public enum CSpace { Anchored, World, Local } + + [RequireComponent(typeof(RectTransform))] + [AddComponentMenu("UI/Tweening/Position")] + public class TweenPos : TweenMain + { + public CSpace CSpace = CSpace.Anchored; + + public Vector3 + from, + to; + + private Vector3 + _from, + _to; + + private RectTransform _rect; + private RectTransform Rect + { + get { return _rect ?? (_rect = GetComponent()); } + } + + public Vector3 value + { + get { return Rect.anchoredPosition3D; } + set { Rect.anchoredPosition3D = value; } + } + + protected override void Start() + { + if (fromOffset) _from = value + from; + else _from = from; + if (toOffset) _to = value + to; + else _to = to; + } + + protected override void OnUpdate(float factor, bool isFinished) + { + value = Vector3.Lerp(_from, _to, factor); + } + + public override void ToCurrentValue() { to = value; } + public override void FromCurrentValue() { from = value; } + + /// + /// Create a TweenPos Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// A optional Arugmeant to define the coordnaite space to work in + /// Return reference to the new TweenPos component + public static TweenPos Tween(GameObject go, float duration, Vector3 pos, UnityAction finished = null, CSpace cSpace = CSpace.Anchored) + { + TweenPos cls = TweenMain.Tween(go, duration, finished); + cls.CSpace = cSpace; + cls.from = cls.value; + cls.to = pos; + cls.Start(); + return cls; + } + + /// + /// Create a TweenPos Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// A optional Arugmeant to define the coordnaite space to work in + /// Return reference to the new TweenPos component + public static TweenPos Tween(GameObject go, float duration, Vector3 fromVal, Vector3 toVal, + UnityAction finished = null, CSpace cSpace = CSpace.Anchored) + { + return Tween(go, duration, fromVal, toVal, Style.Once, Method.Linear, finished, cSpace); + } + + /// + /// Create a TweenPos Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// The style of tween (Once, Looped, PingPong) + /// The Interpolation method of the tween + /// A optional Callback to fire when the tween is done + /// A optional Arugmeant to define the coordnaite space to work in + /// Return reference to the new TweenPos component + public static TweenPos Tween(GameObject go, float duration, Vector3 fromVal, Vector3 toVal, + Style style, Method method, UnityAction finished = null, CSpace cSpace = CSpace.Anchored) + { + TweenPos cls = TweenMain.Tween(go, duration, style, method, finished); + cls.CSpace = cSpace; + cls.from = fromVal; + cls.to = toVal; + cls.Start(); + return cls; + } + } +} diff --git a/Assets/UITweening/TweenPos.cs.meta b/Assets/UITweening/TweenPos.cs.meta new file mode 100644 index 0000000..cb463e9 --- /dev/null +++ b/Assets/UITweening/TweenPos.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: e6a1f13a675d4a8428b5599d06aeda3b +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenRot.cs b/Assets/UITweening/TweenRot.cs new file mode 100644 index 0000000..059b08a --- /dev/null +++ b/Assets/UITweening/TweenRot.cs @@ -0,0 +1,101 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Events; +using System.Collections; + +namespace UnityEngine.UI +{ + [RequireComponent(typeof(RectTransform))] + [AddComponentMenu("UI/Tweening/Rotation")] + public class TweenRot : TweenMain + { + public Vector3 + from, + to; + + private Vector3 + _from, + _to; + + private RectTransform _rect; + private RectTransform Rect + { + get { return _rect ?? (_rect = GetComponent()); } + } + + public Quaternion value + { + get { return Rect.localRotation; } + set { Rect.localRotation = value; } + } + + protected override void Start() + { + if (fromOffset) _from = value.eulerAngles + from; + else _from = from; + if (toOffset) _to = value.eulerAngles + to; + else _to = to; + } + + protected override void OnUpdate(float factor, bool isFinished) + { + value = Quaternion.Euler(Vector3.Lerp(_from, _to, factor)); + } + + public override void ToCurrentValue() { to = value.eulerAngles; } + public override void FromCurrentValue() { from = value.eulerAngles; } + + /// + /// Create a TweenRot Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenRot component + public static TweenRot Tween(GameObject go, float duration, Quaternion rot, UnityAction finished = null) + { + TweenRot cls = TweenMain.Tween(go, duration, finished); + cls.from = cls.value.eulerAngles; + cls.to = rot.eulerAngles; + cls.Start(); + return cls; + } + + /// + /// Create a TweenRot Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenRot component + public static TweenRot Tween(GameObject go, float duration, Quaternion fromVal, Quaternion toVal, + UnityAction finished = null) + { + return Tween(go, duration, fromVal, toVal, Style.Once, Method.Linear, finished); + } + + /// + /// Create a TweenRot Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// The style of tween (Once, Looped, PingPong) + /// The Interpolation method of the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenRot component + public static TweenRot Tween(GameObject go, float duration, Quaternion fromVal, Quaternion toVal, + Style style, Method method, UnityAction finished = null) + { + TweenRot cls = TweenMain.Tween(go, duration, style, method, finished); + cls.from = fromVal.eulerAngles; + cls.to = toVal.eulerAngles; + cls.Start(); + return cls; + } + } +} diff --git a/Assets/UITweening/TweenRot.cs.meta b/Assets/UITweening/TweenRot.cs.meta new file mode 100644 index 0000000..3244dbb --- /dev/null +++ b/Assets/UITweening/TweenRot.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: 5cdd94751faa6514b83b311b9eaab6e5 +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenScale.cs b/Assets/UITweening/TweenScale.cs new file mode 100644 index 0000000..6d870f8 --- /dev/null +++ b/Assets/UITweening/TweenScale.cs @@ -0,0 +1,102 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Events; +using System.Collections; + +namespace UnityEngine.UI +{ + [RequireComponent(typeof(RectTransform))] + [AddComponentMenu("UI/Tweening/Scale")] + public class TweenScale : TweenMain + { + public Vector3 + from = Vector3.one, + to = Vector3.one; + + private Vector3 + _from = Vector3.one, + _to = Vector3.one; + + private RectTransform _rect; + private RectTransform Rect + { + get { return _rect ?? (_rect = GetComponent()); } + } + + public Vector3 value + { + get { return Rect.localScale; } + set { Rect.localScale = value; } + } + + protected override void Start() + { + if (fromOffset) _from = value + from; + else _from = from; + if (toOffset) _to = value + to; + else _to = to; + base.Start(); + } + + protected override void OnUpdate(float factor, bool isFinished) + { + value = Vector3.Lerp(_from, _to, factor); + } + + public override void FromCurrentValue() { from = value; } + public override void ToCurrentValue() { to = value; } + + /// + /// Create a TweenScale Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenScale component + public static TweenScale Tween(GameObject go, float duration, Vector3 scale, UnityAction finished = null) + { + TweenScale cls = TweenMain.Tween(go, duration, finished); + cls.from = cls.value; + cls.to = scale; + cls.Start(); + return cls; + } + + /// + /// Create a TweenScale Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenScale component + public static TweenScale Tween(GameObject go, float duration, Vector3 fromVal, Vector3 toVal, + UnityAction finished = null) + { + return Tween(go, duration, fromVal, toVal, Style.Once, Method.Linear, finished); + } + + /// + /// Create a TweenScale Component and start a tween + /// + /// GameObject to apply tween too + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// The style of tween (Once, Looped, PingPong) + /// The Interpolation method of the tween + /// A optional Callback to fire when the tween is done + /// Return reference to the new TweenScale component + public static TweenScale Tween(GameObject go, float duration, Vector3 fromVal, Vector3 toVal, + Style style, Method method, UnityAction finished = null) + { + TweenScale cls = TweenMain.Tween(go, duration, style, method, finished); + cls.from = fromVal; + cls.to = toVal; + cls.Start(); + return cls; + } + } +} diff --git a/Assets/UITweening/TweenScale.cs.meta b/Assets/UITweening/TweenScale.cs.meta new file mode 100644 index 0000000..7632cbf --- /dev/null +++ b/Assets/UITweening/TweenScale.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: fc504a6421cdffa4c90ab901aa4632d7 +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/TweenSlider.cs b/Assets/UITweening/TweenSlider.cs new file mode 100644 index 0000000..5465c48 --- /dev/null +++ b/Assets/UITweening/TweenSlider.cs @@ -0,0 +1,98 @@ +using UnityEngine.Events; + +namespace UnityEngine.UI +{ + [RequireComponent(typeof(Slider))] + [AddComponentMenu("UI/Tweening/Slider")] + public class TweenSlider : TweenMain + { + public float + from, + to; + + private float + _from, + _to; + + private Slider _sld; + public Slider Sld + { + get { return _sld ?? (_sld = GetComponent()); } + } + + public float value + { + get { return Sld.value; } + set { Sld.value = value; } + } + + protected override void Start() + { + if (fromOffset) _from = value + from; + else _from = from; + if (toOffset) _to = value + to; + else _to = to; + } + + protected override void OnUpdate(float factor, bool isFinished) + { + value = Mathf.Lerp(_from, _to, factor); + } + + public override void ToCurrentValue() { to = value; } + public override void FromCurrentValue() { from = value; } + + /// + /// Create a TweenSlider Component and start a tween + /// + /// GameObject to apply tween to + /// Duration of tween + /// The ending value for the tween + /// A optional callback to fire when the tween is done + /// Returns a reference to the new TweenAlpha component + public static TweenSlider Tween(GameObject go, float duration, float value, UnityAction finished = null) + { + TweenSlider cls = TweenMain.Tween(go, duration, finished); + cls.from = cls.value; + cls.to = value; + cls.Start(); + return cls; + } + + /// + /// Create a TweenSlider Component and start a tween + /// + /// GameObject to apply tween to + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// A optional callback to fire when the tween is done + /// Returns a reference to the new TweenAlpha component + public static TweenSlider Tween(GameObject go, float duration, float fromVal, float toVal, + UnityAction finished = null) + { + return Tween(go, duration, fromVal, toVal, Style.Once, Method.Linear, finished); + } + + /// + /// Create a TweenSlider Component and start a tween + /// + /// GameObject to apply tween to + /// Duration of tween + /// The starting value for the tween + /// The ending value for the tween + /// The style of tween (Once, Looped, PingPong) + /// The Interpolation method of the tween + /// A optional callback to fire when the tween is done + /// Returns a reference to the new TweenAlpha component + public static TweenSlider Tween(GameObject go, float duration, float fromVal, float toVal, + Style style, Method method, UnityAction finished = null) + { + TweenSlider cls = TweenMain.Tween(go, duration, style, method, finished); + cls.from = fromVal; + cls.to = toVal; + cls.Start(); + return cls; + } + } +} diff --git a/Assets/UITweening/TweenSlider.cs.meta b/Assets/UITweening/TweenSlider.cs.meta new file mode 100644 index 0000000..e855fc2 --- /dev/null +++ b/Assets/UITweening/TweenSlider.cs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 80ea04a82bf0ddd4086efca39f365aaa +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UITweening/UnScaledTime.cs b/Assets/UITweening/UnScaledTime.cs new file mode 100644 index 0000000..396e25c --- /dev/null +++ b/Assets/UITweening/UnScaledTime.cs @@ -0,0 +1,45 @@ +using UnityEngine; +using System.Collections; + +public class UnScaledTime : MonoBehaviour +{ + static UnScaledTime Instance; + + float RealTime = 0f; + float RealDeltaTime = 0f; + + static public float time + { + get + { + if (!Application.isPlaying) return Time.realtimeSinceStartup; + if (Instance == null) Spawn(); + return Instance.RealTime; + } + } + + static public float deltaTime + { + get + { + if (!Application.isPlaying) return 0f; + if (Instance == null) Spawn(); + return Instance.RealDeltaTime; + } + } + + static void Spawn() + { + GameObject go = new GameObject("_UnScaledTime"); + DontDestroyOnLoad(go); + Instance = go.AddComponent(); + Instance.RealTime = Time.realtimeSinceStartup; + } + + void Update() + { + float rt = Time.realtimeSinceStartup; + RealDeltaTime = Mathf.Clamp01(rt - RealTime); + RealTime = rt; + } +} diff --git a/Assets/UITweening/UnScaledTime.cs.meta b/Assets/UITweening/UnScaledTime.cs.meta new file mode 100644 index 0000000..dc9b882 --- /dev/null +++ b/Assets/UITweening/UnScaledTime.cs.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: e8f45c883eba386458ddb4a49a70df1f +labels: +- UGUI +- Tween +- Tweening +- UserInterface +- UI +- Animation +- GUI +- Effect +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: