summaryrefslogtreecommitdiff
path: root/Assets/UI_Extension/Scripts/Animation
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-05-30 11:05:38 +0800
committerchai <chaifix@163.com>2021-05-30 11:05:38 +0800
commit3bd21c73384906267a2a4c48acdb96df77bd1f67 (patch)
tree5f55740506d64f4bcc6fe0bc32b9a26c5e6da8b6 /Assets/UI_Extension/Scripts/Animation
parent26e4dc3a35d9c778684388de1af8b3f288fe627d (diff)
*tween
Diffstat (limited to 'Assets/UI_Extension/Scripts/Animation')
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween.meta2
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Demo/TweenDemo.unity273
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs70
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs.meta11
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs125
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Alpha.cs2
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Color.cs2
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Drag.cs58
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Drag.cs.meta11
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs63
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_RectSize.cs2
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/TweenAnimation.cs64
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/TweenController.cs3
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/TweenModule.cs18
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/TweenModule_Alpha.cs8
-rw-r--r--Assets/UI_Extension/Scripts/Animation/Tween/TweenModule_RectSize.cs1
16 files changed, 603 insertions, 110 deletions
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween.meta b/Assets/UI_Extension/Scripts/Animation/Tween.meta
index 85f2fd1..89ea32f 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween.meta
+++ b/Assets/UI_Extension/Scripts/Animation/Tween.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 6c9d4f729e1ee6344be85d61910dcd7e
+guid: 7958968c294ebdc43baadd2ca13cc3d5
folderAsset: yes
DefaultImporter:
externalObjects: {}
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Demo/TweenDemo.unity b/Assets/UI_Extension/Scripts/Animation/Tween/Demo/TweenDemo.unity
index 504a1ac..bf6c3a1 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/Demo/TweenDemo.unity
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Demo/TweenDemo.unity
@@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
- m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
+ m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@@ -225,7 +225,6 @@ ParticleSystemRenderer:
m_RendererPriority: 0
m_Materials:
- {fileID: 10301, guid: 0000000000000000f000000000000000, type: 0}
- - {fileID: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@@ -5012,6 +5011,148 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 419127640}
m_CullTransparentMesh: 0
+--- !u!1 &638242413
+GameObject:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ serializedVersion: 6
+ m_Component:
+ - component: {fileID: 638242414}
+ - component: {fileID: 638242416}
+ - component: {fileID: 638242415}
+ m_Layer: 5
+ m_Name: Image (1)
+ m_TagString: Untagged
+ m_Icon: {fileID: 0}
+ m_NavMeshLayer: 0
+ m_StaticEditorFlags: 0
+ m_IsActive: 1
+--- !u!224 &638242414
+RectTransform:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 638242413}
+ m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+ m_LocalPosition: {x: 0, y: 0, z: 0}
+ m_LocalScale: {x: 1, y: 1, z: 1}
+ m_Children: []
+ m_Father: {fileID: 2122384177}
+ m_RootOrder: 2
+ m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+ m_AnchorMin: {x: 0.5, y: 0.5}
+ m_AnchorMax: {x: 0.5, y: 0.5}
+ m_AnchoredPosition: {x: 0, y: 0}
+ m_SizeDelta: {x: 100, y: 100}
+ m_Pivot: {x: 0.5, y: 0.5}
+--- !u!114 &638242415
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 638242413}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
+ m_Material: {fileID: 0}
+ m_Color: {r: 1, g: 1, b: 1, a: 0.9256807}
+ m_RaycastTarget: 1
+ m_OnCullStateChanged:
+ m_PersistentCalls:
+ m_Calls: []
+ m_Sprite: {fileID: 0}
+ m_Type: 0
+ m_PreserveAspect: 0
+ m_FillCenter: 1
+ m_FillMethod: 4
+ m_FillAmount: 1
+ m_FillClockwise: 1
+ m_FillOrigin: 0
+--- !u!222 &638242416
+CanvasRenderer:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 638242413}
+ m_CullTransparentMesh: 0
+--- !u!1 &1853917338
+GameObject:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ serializedVersion: 6
+ m_Component:
+ - component: {fileID: 1853917339}
+ - component: {fileID: 1853917341}
+ - component: {fileID: 1853917340}
+ m_Layer: 5
+ m_Name: Image
+ m_TagString: Untagged
+ m_Icon: {fileID: 0}
+ m_NavMeshLayer: 0
+ m_StaticEditorFlags: 0
+ m_IsActive: 1
+--- !u!224 &1853917339
+RectTransform:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1853917338}
+ m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+ m_LocalPosition: {x: 0, y: 0, z: 0}
+ m_LocalScale: {x: 1, y: 1, z: 1}
+ m_Children: []
+ m_Father: {fileID: 2122384177}
+ m_RootOrder: 1
+ m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+ m_AnchorMin: {x: 0.5, y: 0.5}
+ m_AnchorMax: {x: 0.5, y: 0.5}
+ m_AnchoredPosition: {x: 121.1, y: 0.7}
+ m_SizeDelta: {x: 100, y: 100}
+ m_Pivot: {x: 0.5, y: 0.5}
+--- !u!114 &1853917340
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1853917338}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
+ m_Material: {fileID: 0}
+ m_Color: {r: 1, g: 1, b: 1, a: 0}
+ m_RaycastTarget: 1
+ m_OnCullStateChanged:
+ m_PersistentCalls:
+ m_Calls: []
+ m_Sprite: {fileID: 0}
+ m_Type: 0
+ m_PreserveAspect: 0
+ m_FillCenter: 1
+ m_FillMethod: 4
+ m_FillAmount: 1
+ m_FillClockwise: 1
+ m_FillOrigin: 0
+--- !u!222 &1853917341
+CanvasRenderer:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1853917338}
+ m_CullTransparentMesh: 0
--- !u!1 &2060442856
GameObject:
m_ObjectHideFlags: 0
@@ -5195,6 +5336,8 @@ RectTransform:
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 224828143557382810}
+ - {fileID: 1853917339}
+ - {fileID: 638242414}
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -5310,114 +5453,129 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_LocalPosition.x
- value: 0
+ propertyPath: m_Pivot.x
+ value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_LocalPosition.y
- value: 0
+ propertyPath: m_Pivot.y
+ value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_LocalPosition.z
- value: -11.932719
+ propertyPath: m_RootOrder
+ value: 0
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_LocalRotation.x
- value: -0
+ propertyPath: m_AnchorMax.x
+ value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_LocalRotation.y
- value: -0
+ propertyPath: m_AnchorMax.y
+ value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_LocalRotation.z
- value: -0
+ propertyPath: m_AnchorMin.x
+ value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_LocalRotation.w
- value: 1
+ propertyPath: m_AnchorMin.y
+ value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_RootOrder
- value: 0
+ propertyPath: m_SizeDelta.x
+ value: 100
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_LocalEulerAnglesHint.x
- value: 0
+ propertyPath: m_SizeDelta.y
+ value: 100
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_LocalEulerAnglesHint.y
+ propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_LocalEulerAnglesHint.z
+ propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_AnchoredPosition.x
- value: -97.91989
+ propertyPath: m_LocalPosition.z
+ value: -11.932719
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_AnchoredPosition.y
- value: -209.7435
+ propertyPath: m_LocalRotation.w
+ value: 1
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_SizeDelta.x
- value: 100
+ propertyPath: m_LocalRotation.x
+ value: -0
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_SizeDelta.y
- value: 100
+ propertyPath: m_LocalRotation.y
+ value: -0
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_AnchorMin.x
- value: 0.5
+ propertyPath: m_LocalRotation.z
+ value: -0
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_AnchorMin.y
- value: 0.5
+ propertyPath: m_AnchoredPosition.x
+ value: -97.91989
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_AnchorMax.x
- value: 0.5
+ propertyPath: m_AnchoredPosition.y
+ value: -209.7435
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_AnchorMax.y
- value: 0.5
+ propertyPath: m_LocalEulerAnglesHint.x
+ value: 0
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_Pivot.x
- value: 0.5
+ propertyPath: m_LocalEulerAnglesHint.y
+ value: 0
objectReference: {fileID: 0}
- target: {fileID: 2160533344743970981, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
- propertyPath: m_Pivot.y
- value: 0.5
+ propertyPath: m_LocalEulerAnglesHint.z
+ value: 0
objectReference: {fileID: 0}
- target: {fileID: 2225253819299306041, guid: 1821abac54ca6014d8fff06cff6aff5d,
type: 3}
propertyPath: m_Name
value: Panel
objectReference: {fileID: 0}
+ - target: {fileID: 2269033645537954357, guid: 1821abac54ca6014d8fff06cff6aff5d,
+ type: 3}
+ propertyPath: animations.Array.size
+ value: 1
+ objectReference: {fileID: 0}
+ - target: {fileID: 2269033645537954357, guid: 1821abac54ca6014d8fff06cff6aff5d,
+ type: 3}
+ propertyPath: animations.Array.data[0].name
+ value: Normal
+ objectReference: {fileID: 0}
+ - target: {fileID: 2269033645537954357, guid: 1821abac54ca6014d8fff06cff6aff5d,
+ type: 3}
+ propertyPath: animations.Array.data[0].animation
+ value:
+ objectReference: {fileID: 2226187378230708801}
m_RemovedComponents:
- {fileID: 2226187378230708801, guid: 1821abac54ca6014d8fff06cff6aff5d, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 1821abac54ca6014d8fff06cff6aff5d, type: 3}
@@ -5442,13 +5600,24 @@ MonoBehaviour:
description: No Description
modules:
- id: 0
- duration: 5
- playbackStyle: 1
+ - id: 1
+ duration: 2
+ playbackStyle: 2
eventTriggeredDirection: -1
playbackLimit: 0
triggerOnce: 0
scriptHandler: 0
- eventList: []
+ eventList:
+ - name: New Event
+ time: 0
+ eventHandler:
+ m_PersistentCalls:
+ m_Calls: []
+ - name: New Event
+ time: 1
+ eventHandler:
+ m_PersistentCalls:
+ m_Calls: []
references:
version: 1
00000000:
@@ -5456,8 +5625,18 @@ MonoBehaviour:
data:
enabled: 1
timeOffset: 0
- duration: 5
+ duration: 1
description:
- target: {fileID: 0}
from: 1
to: 0
+ graphic: {fileID: 1853917340}
+ 00000001:
+ type: {class: TweenAlpha, ns: TweenAnimation, asm: Assembly-CSharp}
+ data:
+ enabled: 1
+ timeOffset: 1.07
+ duration: 0.69
+ description:
+ from: 0
+ to: 1
+ graphic: {fileID: 638242415}
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs
new file mode 100644
index 0000000..4890f2b
--- /dev/null
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs
@@ -0,0 +1,70 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+namespace TweenAnimation
+{
+ public class PlaybackTimer
+ {
+ // 考虑了Pause的playback时间
+ public float time
+ {
+ get
+ {
+ if (m_PauseRealTime != -1)
+ return m_PauseRealTime - m_StartRealTime;
+ return realTime;
+ }
+ }
+
+ // 从调用Resume开始后的时间
+ private float realTime
+ {
+ get
+ {
+ return (float)EditorApplication.timeSinceStartup - m_StartRealTime;
+ }
+ }
+
+ private float m_StartRealTime;
+
+ private float m_PauseRealTime;
+
+ public PlaybackTimer()
+ {
+ Reset();
+ }
+
+ //Start & Resume
+ public void Resume()
+ {
+ if (m_PauseRealTime != -1)
+ m_StartRealTime = (float)EditorApplication.timeSinceStartup - time;
+ else
+ m_StartRealTime = (float)EditorApplication.timeSinceStartup;
+ m_PauseRealTime = -1;
+ }
+
+ public void Pause()
+ {
+ m_PauseRealTime = (float)EditorApplication.timeSinceStartup;
+ }
+
+ public void Stop()
+ {
+ Reset();
+ }
+
+ public void Reset()
+ {
+ m_StartRealTime = -1;
+ m_PauseRealTime = -1;
+ }
+
+ public void SetPauseTimeOffset(float dt)
+ {
+ m_PauseRealTime += dt;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs.meta b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs.meta
new file mode 100644
index 0000000..367e685
--- /dev/null
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 609e015dff09c2c47ae8469c7574e88e
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs
index cc57055..bd98aa8 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector.cs
@@ -11,6 +11,13 @@ namespace TweenAnimation
[CustomEditor(typeof(TweenAnimation), false)]
public partial class TweenAnimationInspector : Editor
{
+ static Dictionary<string, Type> s_TweenModuleClasses;
+ static string[] s_TweenModuleClassNames;
+ static Dictionary<string, MethodInfo> s_TweenModuleGUI;
+
+ static int s_ModuleTabHash = "TweenModuleTab".GetHashCode();
+ static int s_ModuleEnabledHash = "TweenModuleEnabled".GetHashCode();
+
TweenModuleGUIStyles styles
{
get
@@ -27,17 +34,8 @@ namespace TweenAnimation
}
}
- float value = 20;
-
TweenAnimation animation;
- bool m_ShowAnimationTab = true;
-
- static Dictionary<string, Type> s_TweenModuleClasses;
- static string[] s_TweenModuleClassNames;
- static Dictionary<string, MethodInfo> s_TweenModuleGUI;
-
- static int s_ModuleTabHash = "TweenModuleTab".GetHashCode();
- static int s_ModuleEnabledHash = "TweenModuleEnabled".GetHashCode();
+ bool m_ShowAnimationTab = false;
// 是否在时间轴上显示
bool m_ShowEvents;
@@ -65,8 +63,24 @@ namespace TweenAnimation
m_EventTimeSet.Clear();
m_SelectedEventTime = -1;
+
+ m_Play = false;
+ EditorStop();
+
+ m_DragState = DragState.Release;
+
+ if (m_PlaybackTimer == null)
+ m_PlaybackTimer = new PlaybackTimer();
}
-
+
+ public void OnDisable()
+ {
+ m_Play = false;
+ if (m_Play)
+ EditorStop();
+ m_PlaybackTimer.Reset();
+ }
+
public override void OnInspectorGUI()
{
animation = target as TweenAnimation;
@@ -124,6 +138,9 @@ namespace TweenAnimation
// 事件触发方向
animation.eventTriggeredDirection = (TweenAnimation.EventTriggeredDirection)ui.GUIEnumMask("Event Direction", animation.eventTriggeredDirection);
+ // 是否触发事件
+ animation.triggerEvents = ui.GUIToggle("Trigger Events", animation.triggerEvents);
+
// 是否只触发一次
animation.triggerOnce = ui.GUIToggle("Trigger Once", animation.triggerOnce);
@@ -134,7 +151,7 @@ namespace TweenAnimation
// 时间轴
DrawRuler(1f, true);
-
+
EventList();
}
@@ -211,6 +228,8 @@ namespace TweenAnimation
{
if (module == null)
return;
+ Event e = Event.current;
+
string name = module.name;
string description = module.description;
bool enabled = module.enabled;
@@ -228,20 +247,32 @@ namespace TweenAnimation
deleteRect.x = rect.x + rect.width - 18;
deleteRect.width = 20;
deleteRect.height = 20;
- if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseUp || Event.current.type == EventType.Layout)
- {
- module.enabled = GUI.Toggle(checkRect, module.enabled, "", styles.checkmark);
- if (GUI.Button(deleteRect, "-", styles.textBoldBig))
- animation.RemoveModule(module);
- if (GUI.Button(headerRect, "", styles.headerBg))
- module.unfold = !module.unfold;
- }
- else if (Event.current.type == EventType.Repaint /*|| Event.current.type == EventType.Layout*/)
- {
- GUI.Button(headerRect, "", styles.headerBg);
- GUI.Toggle(checkRect, enabled, "", styles.checkmark);
- GUI.Button(deleteRect, "-", styles.textBoldBig);
- }
+ //if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseUp || Event.current.type == EventType.Layout)
+ //{
+ // module.enabled = GUI.Toggle(checkRect, module.enabled, "", styles.checkmark);
+ // if (GUI.Button(deleteRect, "-", styles.textBoldBig))
+ // animation.RemoveModule(module);
+ // if (GUI.Button(headerRect, "", styles.headerBg))
+ // module.unfold = !module.unfold;
+ //}
+ //else if (Event.current.type == EventType.Repaint /*|| Event.current.type == EventType.Layout*/)
+ //{
+ // GUI.Button(headerRect, "", styles.headerBg);
+ // GUI.Toggle(checkRect, enabled, "", styles.checkmark);
+ // GUI.Button(deleteRect, "-", styles.textBoldBig);
+ //}
+
+ //https://answers.unity.com/questions/1562998/how-to-draw-two-button-overlap-in-editor-window-an.html
+ Rect headerRegion = headerRect;
+ headerRegion.x += 20;
+ headerRegion.width -= 50;
+ GUI.enabled = !(e.isMouse && !headerRegion.Contains(e.mousePosition));
+ if (GUI.Button(headerRect, "", styles.headerBg))
+ module.unfold = !module.unfold;
+ GUI.enabled = true;
+ module.enabled = GUI.Toggle(checkRect, module.enabled, "", styles.checkmark);
+ if (GUI.Button(deleteRect, "-", styles.textBoldBig))
+ animation.RemoveModule(module);
Vector2 size = styles.text.CalcSize(new GUIContent(name));
GUI.Label(new Rect(rect.x + 15, rect.y + 2, size.x, 20), name, styles.text);
@@ -398,7 +429,7 @@ namespace TweenAnimation
for(int i = 0; i < animation.modules.Count; ++i)
{
TweenModule module = animation.modules[i];
- if(module.unfold)
+ if(/*module.unfold*/module.enabled)
{
float left = module.timeOffset / duration * rulerRect.width;
float right = (module.timeOffset + module.duration) / duration * rulerRect.width;
@@ -409,6 +440,14 @@ namespace TweenAnimation
}
}
+ // 绘制playback竖线
+ if(bRepaint && (m_Play || m_Pause))
+ {
+ float time = animation.HandleTime(m_PlaybackTimer.time);
+ float x = (time / animation.duration) * rulerRect.width + 5;
+ ui.DrawVerticalLineFast(x, yOffBase, yOffBase - (rulerRect.height), Color.red);
+ }
+
GL.PopMatrix();
GL.End();
@@ -420,8 +459,9 @@ namespace TweenAnimation
if (i % stepSlice == 0 || stepSlice == 10 && i % (stepSlice / 2) == 0)
{
float time = i * timePerStep; // sec
- Vector2 size = styles.text.CalcSize(new GUIContent(time.ToString("f2")));
- GUI.Label(new Rect(rulerRect.x + i * stepPixelWidth - size.x / 2, yOffBase + 2, 50, 15), time.ToString("f2"), styles.text );
+ string timeStr = time == 0 ? "0" : time.ToString("f1");
+ Vector2 size = styles.text.CalcSize(new GUIContent(timeStr));
+ GUI.Label(new Rect(rulerRect.x + i * stepPixelWidth - size.x / 2, yOffBase + 2, 50, 15), timeStr, styles.text );
}
}
}
@@ -499,6 +539,7 @@ namespace TweenAnimation
{
m_Pause = m_Stop = false;
EditorPlay();
+ m_PlaybackTimer.Resume();
}
}
GUI.color = col;
@@ -512,7 +553,13 @@ namespace TweenAnimation
{
m_Pause = !m_Pause;
if (m_Pause)
+ {
+ EditorPlay();
+ if(!m_Play)
+ m_PlaybackTimer.Resume();
+ m_PlaybackTimer.Pause();
m_Play = m_Stop = false;
+ }
}
GUI.color = col;
@@ -521,10 +568,23 @@ namespace TweenAnimation
if (GUI.Button(stopRect, "Stop", styles.miniRight))
{
EditorStop();
+ m_PlaybackTimer.Stop();
m_Pause = m_Play = false;
}
}
+ // playback time
+ {
+ if (m_Play || m_Pause)
+ {
+ Rect playbackTimeRect = new Rect(100, yOffBase + 23, 90, 20); ;
+ GUI.Label(playbackTimeRect, "Playback Time: " + m_PlaybackTimer.time.ToString("f1") + "s", styles.text);
+ }
+ }
+
+ // 拖拽进度
+ DragPlay(rulerRect);
+
GUI.EndGroup();
}
@@ -594,6 +654,7 @@ namespace TweenAnimation
unfoldRect.x = rect.x + rect.width - 19;
unfoldRect.width = 13;
unfoldRect.height = 13;
+ unfoldRect.y += 3;
e.unfold = GUI.Button(unfoldRect, (e.unfold ? "▲" : "▼"), styles.textSmall) ? !e.unfold : e.unfold;
if(e.unfold)
{
@@ -626,5 +687,11 @@ namespace TweenAnimation
}
}
+ static EditorWindow s_SceneView;
+
+ private void OnSceneGUI()
+ {
+ }
+
}
} \ No newline at end of file
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Alpha.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Alpha.cs
index 1f7c0cd..c13e312 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Alpha.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Alpha.cs
@@ -21,7 +21,7 @@ namespace TweenAnimation
alpha = Mathf.Clamp(alpha, 0, 1);
tween.to = alpha;
- tween.target = ui.GUIObject("Target", tween.target, typeof(Graphic)) as Graphic;
+ tween.graphic = ui.GUIObject("Graphic", tween.graphic, typeof(Graphic)) as Graphic;
}
}
} \ No newline at end of file
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Color.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Color.cs
index 2aee642..b2155d3 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Color.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Color.cs
@@ -11,8 +11,6 @@ namespace TweenAnimation
{
OnInspector_Base(module);
- value = ui.GUIFloat("Float value", value, "f2");
-
}
}
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Drag.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Drag.cs
new file mode 100644
index 0000000..b6d9e89
--- /dev/null
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Drag.cs
@@ -0,0 +1,58 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+using UnityEditor;
+namespace TweenAnimation
+{
+
+ public partial class TweenAnimationInspector : Editor
+ {
+ bool m_MouseDown;
+
+ DragState m_DragState;
+
+ enum DragState
+ {
+ Release,
+ Drag,
+
+ }
+
+ void DragPlay(Rect rulerRect)
+ {
+ if (!m_Pause)
+ return;
+
+ Event e = Event.current;
+
+ Vector2 mousePos = e.mousePosition;
+
+ bool bIn = rulerRect.Contains(mousePos);
+
+ switch (m_DragState)
+ {
+ case DragState.Release:
+ if (e.type == EventType.MouseDown && bIn)
+ m_DragState = DragState.Drag;
+ break;
+ case DragState.Drag:
+ if (e.type == EventType.MouseUp)
+ m_DragState = DragState.Release;
+ break;
+ }
+ if (m_DragState == DragState.Drag && bIn)
+ {
+ float x = mousePos.x - rulerRect.x;
+ float t = x / rulerRect.width * animation.duration;
+ float t0 = animation.GetIdentifiedTime(m_PlaybackTimer.time);
+ float dt = 0;
+ if (t0 >= 0)
+ dt = t - t0;
+ else // pingpong
+ dt = -t0 - t;
+ m_PlaybackTimer.SetPauseTimeOffset(dt);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Drag.cs.meta b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Drag.cs.meta
new file mode 100644
index 0000000..6535e03
--- /dev/null
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Drag.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 18a4e19a94101554eb76b88fbe6c4cc6
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs
index a4f4c3b..0aedd02 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs
@@ -10,12 +10,11 @@ namespace TweenAnimation
{
public partial class TweenAnimationInspector : Editor
{
- float m_Time;
+ PlaybackTimer m_PlaybackTimer;
// 编辑器下播放动画
void EditorPlay()
{
- m_Time = 0;
EditorApplication.update -= Update;
EditorApplication.update += Update;
}
@@ -25,10 +24,66 @@ namespace TweenAnimation
EditorApplication.update -= Update;
}
+ //https://answers.unity.com/questions/1187622/how-to-manually-refresh-inspector-from-editor-code.html
+ void RepaintInspector(System.Type t)
+ {
+ Editor[] ed = (Editor[])Resources.FindObjectsOfTypeAll<Editor>();
+ for (int i = 0; i < ed.Length; i++)
+ {
+ if (ed[i].GetType() == t)
+ {
+ ed[i].Repaint();
+ return;
+ }
+ }
+ }
+
+ //https://gamedev.stackexchange.com/questions/125698/how-to-edit-and-persist-serializable-assets-in-the-editor-window
+ //https://support.unity.com/hc/en-us/articles/115002294603-How-do-I-make-a-scene-dirty-when-modifying-a-property-via-script-
+ //https://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html
+ //void MarkTargetsDirty()
+ //{
+ // if (animation == null)
+ // return;
+ // for (int i = 0; i < animation.modules.Count; ++i)
+ // {
+ // var module = animation.modules[i];
+ // if (module.target)
+ // EditorUtility.SetDirty(module.target);
+ // if (module.targets != null)
+ // {
+ // for (int j = 0; j < module.targets.Length; ++j)
+ // {
+ // EditorUtility.SetDirty(module.targets[j]);
+ // }
+ // }
+ // }
+ //}
+
+ //https://forum.unity.com/threads/editor-script-mark-scene-dirty-changed.100340/
+ void MarkSceneDirty()
+ {
+ if(animation)
+ EditorUtility.SetDirty(animation);
+ }
+
void Update()
{
- m_Time += Time.deltaTime;
- animation.UpdateEditor(m_Time);
+ animation.UpdateEditor(m_PlaybackTimer.time);
+
+ // repaint
+ MarkSceneDirty();
+ RepaintInspector(typeof(TweenAnimationInspector));
+
+ //MarkSceneDirty();
+ //MarkTargetsDirty();
+ //UnityEngine.SceneManagement.Scene scene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene();
+ //UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
+ //UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(scene);
+ //EditorWindow.GetWindow<SceneView>().Repaint();
+ //SceneView.RepaintAll();
+ //UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
+ //SceneView.lastActiveSceneView.Repaint();
}
}
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_RectSize.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_RectSize.cs
index be6bf44..b963e85 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_RectSize.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_RectSize.cs
@@ -11,8 +11,6 @@ namespace TweenAnimation
{
OnInspector_Base(module);
- value = ui.GUIFloat("Float value", value, "f2");
-
}
}
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/TweenAnimation.cs b/Assets/UI_Extension/Scripts/Animation/Tween/TweenAnimation.cs
index e722a08..6441552 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/TweenAnimation.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/TweenAnimation.cs
@@ -1,4 +1,5 @@
-using System;
+// by chai
+using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -15,11 +16,10 @@ namespace TweenAnimation
public UnityEvent eventHandler; // 回调函数
#if UNITY_EDITOR
[NonSerialized]
- public bool unfold;
+ public bool unfold = false;
#endif
public TweenEvent()
{
- unfold = false;
name = "New Event";
time = 0;
eventHandler = null;
@@ -56,6 +56,9 @@ namespace TweenAnimation
// 回放次数,0是不限制,默认是0
public int playbackLimit;
+ // 是否触发事件
+ public bool triggerEvents;
+
// 只触发一次事件
public bool triggerOnce;
@@ -111,14 +114,8 @@ namespace TweenAnimation
if (modules == null)
return;
- float logicTime = time;
-
- if (this.playbackStyle == PlaybackStyle.Once)
- logicTime = HandleOnce(time);
- else if (this.playbackStyle == PlaybackStyle.Loop)
- logicTime = HandleLoop(time);
- else if (this.playbackStyle == PlaybackStyle.PingPong)
- logicTime = HandlePingpong(time);
+ time = ApplyLimit(time);
+ float logicTime = HandleTime(time);
for (int i = 0; i < modules.Count; i ++)
{
@@ -129,19 +126,19 @@ namespace TweenAnimation
}
}
- private float HandleOnce(float time)
+ float HandleOnce(float time)
{
time = Mathf.Clamp(time, 0, duration);
return time;
}
- private float HandleLoop(float time)
+ float HandleLoop(float time)
{
time = time % duration;
return time;
}
- private float HandlePingpong(float time)
+ float HandlePingpong(float time)
{
if (time <= duration)
return time;
@@ -156,11 +153,50 @@ namespace TweenAnimation
return time;
}
+ // 返回[0,duration]范围内的逻辑时间
+ public float HandleTime(float time)
+ {
+ float logicTime = time;
+ if (this.playbackStyle == PlaybackStyle.Once)
+ logicTime = HandleOnce(time);
+ else if (this.playbackStyle == PlaybackStyle.Loop)
+ logicTime = HandleLoop(time);
+ else if (this.playbackStyle == PlaybackStyle.PingPong)
+ logicTime = HandlePingpong(time);
+ return logicTime;
+ }
+
+ public float ApplyLimit(float time)
+ {
+ if (playbackLimit <= 0)
+ return time;
+ if (playbackStyle == PlaybackStyle.Loop)
+ time = Mathf.Clamp(time, 0, playbackLimit * duration);
+ else if(playbackStyle == PlaybackStyle.PingPong)
+ time = Mathf.Clamp(time, 0, playbackLimit * duration);
+ return time;
+ }
+
#if UNITY_EDITOR
public void UpdateEditor(float time)
{
Process(time);
}
+
+ // 返回0-duration内的时间,用负数代表从右往左
+ public float GetIdentifiedTime(float t)
+ {
+ int round = (int)(t / duration);
+ float time = HandleTime(t);
+ if(playbackStyle == PlaybackStyle.PingPong)
+ {
+ bool bOdd = (round & 1) == 1;
+ if(bOdd)
+ time = -time;
+ }
+ return time;
+ }
+
#endif
}
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/TweenController.cs b/Assets/UI_Extension/Scripts/Animation/Tween/TweenController.cs
index 20d2876..561eff6 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/TweenController.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/TweenController.cs
@@ -1,4 +1,5 @@
-using System;
+// by chai
+using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule.cs b/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule.cs
index e42236b..2fd3742 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule.cs
@@ -1,7 +1,9 @@
-using System;
+// by chai
+using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
+using UnityEngine.UI;
namespace TweenAnimation
{
@@ -14,8 +16,10 @@ namespace TweenAnimation
public float duration;
+ private float m_LastTime;
+
#if UNITY_EDITOR
- public new virtual string name { get { return ""; } }
+ public virtual string name { get { return ""; } }
public string description;
@@ -25,13 +29,19 @@ namespace TweenAnimation
public bool unfold;
#endif
+ private bool IsValidTime0(float time0)
+ {
+ return time0 >= 0 && time0 <= duration;
+ }
+
// 根据当前时间更新值, time的范围是tween animation的duration
public void OnUpdate(float time)
{
float time0 = time - timeOffset;
- if (time0 < 0 || time0 > duration)
+ if (!IsValidTime0(time0) && !IsValidTime0(duration))
return;
- SetValue(time0);
+ m_LastTime = time0;
+ SetValue(Mathf.Clamp(time0, 0, duration));
}
// time是去掉了offset后的时间
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule_Alpha.cs b/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule_Alpha.cs
index 55ff647..34d6abb 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule_Alpha.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule_Alpha.cs
@@ -9,19 +9,19 @@ namespace TweenAnimation
[Serializable]
public class TweenAlpha : TweenModule
{
- public Graphic target;
public float from;
public float to;
+ public Graphic graphic;
protected override void SetValue(float time)
{
float t = time / duration;
float alpha = Mathf.Lerp(from, to, t);
- if (target != null)
+ if (graphic != null)
{
- Color c = target.color;
+ Color c = graphic.color;
c.a = alpha;
- target.color = c;
+ graphic.color = c;
}
}
diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule_RectSize.cs b/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule_RectSize.cs
index 03aa454..c3c4839 100644
--- a/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule_RectSize.cs
+++ b/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule_RectSize.cs
@@ -16,7 +16,6 @@ namespace TweenAnimation
protected override void SetValue(float time)
{
- throw new System.NotImplementedException();
}
}
} \ No newline at end of file