diff options
author | chai <chaifix@163.com> | 2021-08-09 08:47:48 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-08-09 08:47:48 +0800 |
commit | 7669c3afcbd71f06233bce12bb521c582c07ee5b (patch) | |
tree | 92a15b1c214385a53362a7e704fef8e67c7102ad /Assets/Scripts/Unit | |
parent | 754ceacd8ab62e7094f1827ae45ea16a502725ad (diff) |
*misc
Diffstat (limited to 'Assets/Scripts/Unit')
-rw-r--r-- | Assets/Scripts/Unit/Action/WaitForActionReachEnd.cs | 3 | ||||
-rw-r--r-- | Assets/Scripts/Unit/AnimationData.cs | 121 | ||||
-rw-r--r-- | Assets/Scripts/Unit/Component/UnitAnimation.cs | 12 | ||||
-rw-r--r-- | Assets/Scripts/Unit/Component/UnitState.cs | 16 | ||||
-rw-r--r-- | Assets/Scripts/Unit/TimelineEventProxy.cs (renamed from Assets/Scripts/Unit/UnitTimeline.cs) | 248 | ||||
-rw-r--r-- | Assets/Scripts/Unit/TimelineEventProxy.cs.meta (renamed from Assets/Scripts/Unit/UnitTimeline.cs.meta) | 2 |
6 files changed, 240 insertions, 162 deletions
diff --git a/Assets/Scripts/Unit/Action/WaitForActionReachEnd.cs b/Assets/Scripts/Unit/Action/WaitForActionReachEnd.cs index ab755b64..47aa639c 100644 --- a/Assets/Scripts/Unit/Action/WaitForActionReachEnd.cs +++ b/Assets/Scripts/Unit/Action/WaitForActionReachEnd.cs @@ -20,8 +20,7 @@ public class WaitForActionReachEnd : IEnumerator { var stateInfo = m_UnitAnimation.layers[(int)m_Layer].stateInfo; float normalTime = stateInfo.normalizedTime; - LogHelper.Log(stateInfo.loop.ToString()); - return normalTime < 1f; + return normalTime < 1f; } public void Reset() diff --git a/Assets/Scripts/Unit/AnimationData.cs b/Assets/Scripts/Unit/AnimationData.cs index 6035978d..465c0806 100644 --- a/Assets/Scripts/Unit/AnimationData.cs +++ b/Assets/Scripts/Unit/AnimationData.cs @@ -15,39 +15,86 @@ public enum EAnimationToogle }
[Serializable]
-public class ToggleTimeDictionary : SerializableDictionary<EAnimationToogle, Vector2> { }
+public struct FromTo
+{
+ [SerializeField] public float from;
+ [SerializeField] public float to;
+ public Vector2 fromTo
+ {
+ get
+ {
+ return new Vector2(from, to);
+ }
+ set
+ {
+ from = value.x;
+ to = value.y;
+ }
+ }
+ public FromTo(float from, float to)
+ {
+ this.from = from;
+ this.to = to;
+ }
+ public FromTo(Vector2 fromTo)
+ {
+ this.from = fromTo.x;
+ this.to = fromTo.y;
+ }
+}
+
+[Serializable]
+public class ToggleTimeDictionary : SerializableDictionary<EAnimationToogle, FromTo> { }
public enum EAnimationCurve
{
TimeScale = 0, //
+ RootMotionScale = 1,
}
[Serializable]
public class CurveDictionary : SerializableDictionary<EAnimationCurve, AnimationCurve> { }
+[Serializable]
+public struct AnimationParameter
+{
+ [Serializable]
+ public struct Setter
+ {
+ [SerializeField] public float normalizedTime;
+ [SerializeField] public float value;
+ }
+ [SerializeField] public List<Setter> setters;
+}
+
+[Serializable]
+public class ParameterDictionary : SerializableDictionary<string, AnimationParameter> { }
+
// 某个动画的数据,包括帧事件、碰撞盒、速度曲线
[CreateAssetMenu(fileName = "Animation Data")]
public class AnimationData : ScriptableObject
{
- public string animationName;
- public string animationPath;
+ public string animationName;
+ public string animationPath;
- public List<AnimationEventBase> animationEvents;
+ public List<AnimationEventBase> animationEvents;
- public List<ColliderData> hurtBoxes;
- public List<ColliderData> hitBoxes;
- public List<ColliderData> throwBoxes;
- public List<ColliderData> blockBoxes;
- public List<ColliderData> defendBoxes;
+ public List<ColliderData> hurtBoxes;
+ public List<ColliderData> hitBoxes;
+ public List<ColliderData> throwBoxes;
+ public List<ColliderData> blockBoxes;
+ public List<ColliderData> defendBoxes;
- // 对应的进度的播放速度,默认是1
+ // 对应的进度的播放速度,默认是1
[UnityEngine.Serialization.FormerlySerializedAs("curve")]
- public AnimationCurve speedCurve;
+ public AnimationCurve speedCurve;
public CurveDictionary curves;
public ToggleTimeDictionary toggles;
+ public ParameterDictionary parameters;
+
public const int FPS = 30;
public AnimationData()
@@ -57,23 +104,39 @@ public class AnimationData : ScriptableObject speedCurve = new AnimationCurve(frame0, frame1);
}
- public List<ColliderData> GetColliderBoxesByType(ColliderBox.EColliderType type)
- {
- switch(type)
- {
- case ColliderBox.EColliderType.HurtBox:
- return hurtBoxes;
- case ColliderBox.EColliderType.HitBox:
- return hitBoxes;
- case ColliderBox.EColliderType.BlockBox:
- return blockBoxes;
- case ColliderBox.EColliderType.ThrowBox:
- return throwBoxes;
- case ColliderBox.EColliderType.DefendBox:
- return defendBoxes;
- }
- return null;
- }
+ public List<ColliderData> GetColliderBoxesByType(ColliderBox.EColliderType type)
+ {
+ switch (type)
+ {
+ case ColliderBox.EColliderType.HurtBox:
+ return hurtBoxes;
+ case ColliderBox.EColliderType.HitBox:
+ return hitBoxes;
+ case ColliderBox.EColliderType.BlockBox:
+ return blockBoxes;
+ case ColliderBox.EColliderType.ThrowBox:
+ return throwBoxes;
+ case ColliderBox.EColliderType.DefendBox:
+ return defendBoxes;
+ }
+ return null;
+ }
+
+ //public bool HasParameter(string parameterName, float normalizedTime)
+ //{
+ // if (!parameters.ContainsKey(parameterName))
+ // return false;
+ // var parameter = parameters[parameterName];
+ // parameter.setters.Sort((AnimationParameter.Setter a, AnimationParameter.Setter b) =>
+ // {
+ // return a.normalizedTime - b.normalizedTime < 0 ? -1 : 1;
+ // });
+ //}
+
+ //public float GetParameter(string parameter, float normalizedTime)
+ //{
+
+ //}
public bool HasCurve(EAnimationCurve curve)
{
@@ -96,7 +159,7 @@ public class AnimationData : ScriptableObject {
if (!HasToggle(toggle))
return false;
- return toggles[toggle].y <= normalizedTime && normalizedTime >= toggles[toggle].x;
+ return toggles[toggle].to <= normalizedTime && normalizedTime >= toggles[toggle].from;
}
public ColliderInfo GetColliderInfo(ColliderBox.EColliderType type, int index, float playbackTime)
diff --git a/Assets/Scripts/Unit/Component/UnitAnimation.cs b/Assets/Scripts/Unit/Component/UnitAnimation.cs index 44cfb08b..bbe4eb22 100644 --- a/Assets/Scripts/Unit/Component/UnitAnimation.cs +++ b/Assets/Scripts/Unit/Component/UnitAnimation.cs @@ -233,6 +233,8 @@ public class UnitAnimation : UnitComponent ToIdle,
ToMove,
ToAttack,
+ ToJump,
+ ToAirAttack,
}
public Animator animator { get { return m_Animator; } }
@@ -325,4 +327,14 @@ public class UnitAnimation : UnitComponent m_Animator.SetTrigger(trigger.ToString());
}
+ public void AnimJump()
+ {
+ SetTrigger(ETrigger.ToJump);
+ }
+
+ public void AnimAirAttack()
+ {
+ SetTrigger(ETrigger.ToAirAttack);
+ }
+
}
diff --git a/Assets/Scripts/Unit/Component/UnitState.cs b/Assets/Scripts/Unit/Component/UnitState.cs index fd9bba00..0ad1ec58 100644 --- a/Assets/Scripts/Unit/Component/UnitState.cs +++ b/Assets/Scripts/Unit/Component/UnitState.cs @@ -45,6 +45,8 @@ public class UnitState : UnitComponent InitState();
}
+ UnitAnimation unitAnimation { get { return m_Owner.unitAnimation; } }
+
#region state param
public struct IdleParam {}
@@ -202,13 +204,16 @@ public class UnitState : UnitComponent IEnumerator Jump(JumpParam param)
{
- while(true)
+ unitAnimation.AnimJump();
+ yield return null;
+ yield return new WaitForTransitionDone(unitAnimation);
+ while (true)
{
- // 空中连击
- if(Input.GetKeyDown("j"))
+ if (unitAnimation.layers[0].playbackNomralizedTime >= 1)
+ ChangeState(EUnitState.Idle, new IdleParam());
+ if (Input.GetKeyDown("j"))
{
- SkillParam skill = new SkillParam();
- ChangeState(EUnitState.Skill, skill);
+ ChangeState(EUnitState.Skill, new SkillParam());
}
yield return null;
}
@@ -216,7 +221,6 @@ public class UnitState : UnitComponent void OnJumpExit(EUnitState next)
{
-
}
#endregion
diff --git a/Assets/Scripts/Unit/UnitTimeline.cs b/Assets/Scripts/Unit/TimelineEventProxy.cs index 99c6bdaf..00b5f1dc 100644 --- a/Assets/Scripts/Unit/UnitTimeline.cs +++ b/Assets/Scripts/Unit/TimelineEventProxy.cs @@ -1,125 +1,125 @@ -using System;
-using System.Collections;
-using System.Reflection;
-using System.Collections.Generic;
-using UnityEngine;
-#if UNITY_EDITOR
-using UnityEditor;
-#endif
-
-// 执行帧事件
-[DisallowMultipleComponent]
-public partial class TimelineEventProxy
-{
- public enum EEventType
- {
- EventCamera_Zoom, // 相机聚焦
- EventCamera_Shake, // 相机晃动
- EventCamera_Blur, // 相机模糊
- EventCamera_WhiteOut, // 相机白屏
-
- EventMesh_AfterImage, // 角色残像
- EventMesh_Fade, // 角色透明度
- EventMesh_Gloss, // 角色泛光
-
- EventEnv_Dark,
- EventEnv_Exposure,
-
- EventUI_Drift, //
- EventUI_Blur, //
-
- EventProjectile, // 发射体
- EventEffect, // 特效
- EventSound, // 音效
-
- EventBulletTime, // 子弹时间
- }
-
- public const int kMaxEventsPerFrame = 10;
- public const int FPS = 30; // timeline 每秒采样30次
-
- private int m_PrevFrame = -1;
-
- private UnitAnimation m_UnitAnimation;
-
- private Transform m_Root;
-
- public TimelineEventProxy(Transform root, UnitAnimation unitAnimation = null)
- {
- m_Root = root;
- }
-
- public static Type GetTypeByName(string name)
- {
- Type type = Type.GetType(name);
- return type;
- }
-
- public void ExecuteAnimationEvents(AnimationData animData, float animFrame)
- {
- if (animData == null)
- return;
- int frame = (int)animFrame;
- if (frame != m_PrevFrame)
- {
- for (int i = m_PrevFrame + 1; i <= frame; i++)
- {
- List<int> framesHasEvent = animData.GetAnimationEventFrameIndices();
- if (framesHasEvent.Contains(i))
- {
- List<AnimationEventBase> events = animData.GetAnimationEventsAtFrame(i);
- ExecuteEvents(events);
- ListPool<AnimationEventBase>.Release(events);
- }
- ListPool<int>.Release(framesHasEvent);
- }
- }
- m_PrevFrame = frame;
- }
-
- void ExecuteEvents(List<AnimationEventBase> events)
- {
- if (events == null || events.Count == 0)
- return;
- foreach (var e in events)
- {
- string name = e.type.ToString();
- MethodInfo method = GetType().GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(AnimationEventBase) }, null);
- if (method != null)
- {
- object[] param = new object[] { e };
- method.Invoke(this, param);
- }
- }
- }
-
- #region Event handle
-
- void EventEffect(AnimationEventBase animEvent)
- {
- EventEffect effect = animEvent as EventEffect;
- if (effect == null)
- return;
- string path = effect.effectPath;
-#if UNITY_EDITOR
- GameObject prefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
- if (prefab != null)
- {
- GameObject root = new GameObject();
-
- GameObject go = GameObject.Instantiate(prefab);
- go.transform.SetParent(root.transform);
- FxClear onClear = root.AddComponent<FxClear>();
- onClear.RunInEditor = true;
- onClear.Initialize(new PlayEffectInfo(path, EffectPlayTypes.Oneshot, m_Root, effect.position, effect.rotation, effect.scale, 0, false));
- }
-#endif
- }
-
- void EventCamera_Shake(AnimationEventBase animEvent)
- {
-
- }
-
- #endregion
+using System; +using System.Collections; +using System.Reflection; +using System.Collections.Generic; +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +// 执行帧事件 +[DisallowMultipleComponent] +public partial class TimelineEventProxy +{ + public enum EEventType + { + EventCamera_Zoom, // 相机聚焦 + EventCamera_Shake, // 相机晃动 + EventCamera_Blur, // 相机模糊 + EventCamera_WhiteOut, // 相机白屏 + + EventMesh_AfterImage, // 角色残像 + EventMesh_Fade, // 角色透明度 + EventMesh_Gloss, // 角色泛光 + + EventEnv_Dark, + EventEnv_Exposure, + + EventUI_Drift, // + EventUI_Blur, // + + EventProjectile, // 发射体 + EventEffect, // 特效 + EventSound, // 音效 + + EventBulletTime, // 子弹时间 + } + + public const int kMaxEventsPerFrame = 10; + public const int FPS = 30; // timeline 每秒采样30次 + + private int m_PrevFrame = -1; + + private UnitAnimation m_UnitAnimation; + + private Transform m_Root; + + public TimelineEventProxy(Transform root, UnitAnimation unitAnimation = null) + { + m_Root = root; + } + + public static Type GetTypeByName(string name) + { + Type type = Type.GetType(name); + return type; + } + + public void ExecuteAnimationEvents(AnimationData animData, float animFrame) + { + if (animData == null) + return; + int frame = (int)animFrame; + if (frame != m_PrevFrame) + { + for (int i = m_PrevFrame + 1; i <= frame; i++) + { + List<int> framesHasEvent = animData.GetAnimationEventFrameIndices(); + if (framesHasEvent.Contains(i)) + { + List<AnimationEventBase> events = animData.GetAnimationEventsAtFrame(i); + ExecuteEvents(events); + ListPool<AnimationEventBase>.Release(events); + } + ListPool<int>.Release(framesHasEvent); + } + } + m_PrevFrame = frame; + } + + void ExecuteEvents(List<AnimationEventBase> events) + { + if (events == null || events.Count == 0) + return; + foreach (var e in events) + { + string name = e.type.ToString(); + MethodInfo method = GetType().GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(AnimationEventBase) }, null); + if (method != null) + { + object[] param = new object[] { e }; + method.Invoke(this, param); + } + } + } + + #region Event handle + + void EventEffect(AnimationEventBase animEvent) + { + EventEffect effect = animEvent as EventEffect; + if (effect == null) + return; + string path = effect.effectPath; +#if UNITY_EDITOR + GameObject prefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject; + if (prefab != null) + { + GameObject root = new GameObject(); + + GameObject go = GameObject.Instantiate(prefab); + go.transform.SetParent(root.transform); + FxClear onClear = root.AddComponent<FxClear>(); + onClear.RunInEditor = true; + onClear.Initialize(new PlayEffectInfo(path, EffectPlayTypes.Oneshot, m_Root, effect.position, effect.rotation, effect.scale, 0, false)); + } +#endif + } + + void EventCamera_Shake(AnimationEventBase animEvent) + { + + } + + #endregion }
\ No newline at end of file diff --git a/Assets/Scripts/Unit/UnitTimeline.cs.meta b/Assets/Scripts/Unit/TimelineEventProxy.cs.meta index eacf2ed1..c311d274 100644 --- a/Assets/Scripts/Unit/UnitTimeline.cs.meta +++ b/Assets/Scripts/Unit/TimelineEventProxy.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7bb2f04adc210b04dad020a77628fe79 +guid: 893827f42c99cd849987e51e6af8820d MonoImporter: externalObjects: {} serializedVersion: 2 |