From 34d01108e9f0c5488e8824f768c43801dd8ed4cc Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 4 Sep 2021 14:02:24 +0800 Subject: *misc --- Assets/Scripts/Unit/Collider/ColliderAttributes.cs | 5 ++- .../Scripts/Unit/Components/UnitState/PCState.cs | 31 ++++++++++---- Assets/Scripts/Unit/Controller/UnitController.cs | 7 +++- Assets/Scripts/Unit/Events/EventEffect.cs | 2 +- Assets/Scripts/Unit/Events/EventProjectile.cs | 27 +++++++++--- Assets/Scripts/Unit/TimelineEventProxy.cs | 48 ++++++++++++---------- 6 files changed, 81 insertions(+), 39 deletions(-) (limited to 'Assets/Scripts/Unit') diff --git a/Assets/Scripts/Unit/Collider/ColliderAttributes.cs b/Assets/Scripts/Unit/Collider/ColliderAttributes.cs index 47998b3c..27889441 100644 --- a/Assets/Scripts/Unit/Collider/ColliderAttributes.cs +++ b/Assets/Scripts/Unit/Collider/ColliderAttributes.cs @@ -98,13 +98,14 @@ public class AndWhenAttribute : Attribute public class WhenNotAttribute : Attribute { - public WhenNotAttribute(string name, float value) + public WhenNotAttribute(string name, object value) { this.conditionName = name; + this.value = (int)value; } public string conditionName; - public float value; + public int value; } public class CommentAttribute : Attribute diff --git a/Assets/Scripts/Unit/Components/UnitState/PCState.cs b/Assets/Scripts/Unit/Components/UnitState/PCState.cs index 54a48cc2..e448b6b2 100644 --- a/Assets/Scripts/Unit/Components/UnitState/PCState.cs +++ b/Assets/Scripts/Unit/Components/UnitState/PCState.cs @@ -44,9 +44,16 @@ public class PCState : UnitState public override void Initialize() { base.Initialize(); - } + owner.onTimelineEvent += OnTimeLineEvent; + } - PCAnimation pcAnimation { get { return m_Owner.pcAnimation; } } + public override void Release() + { + owner.onTimelineEvent -= OnTimeLineEvent; + base.Release(); + } + + PCAnimation pcAnimation { get { return m_Owner.pcAnimation; } } #region state param public struct IdleParam { } @@ -451,9 +458,17 @@ public class PCState : UnitState void OnLandingExit(EUnitState next) { - } - - #endregion - -} - \ No newline at end of file + } + + #endregion + + #region timeline event handle + + void OnTimeLineEvent(AnimationEventBase animEvent) + { + + } + + #endregion + +} \ No newline at end of file diff --git a/Assets/Scripts/Unit/Controller/UnitController.cs b/Assets/Scripts/Unit/Controller/UnitController.cs index 63202f29..2f43b4e4 100644 --- a/Assets/Scripts/Unit/Controller/UnitController.cs +++ b/Assets/Scripts/Unit/Controller/UnitController.cs @@ -41,7 +41,12 @@ public class UnitController : MonoBehaviour/*, Interactable*/ public GameObject unitObj; // 角色模型 - public bool isTowardRight + #region 事件监听 + public delegate void OnTimelineEventHandle(AnimationEventBase animEvent); + public OnTimelineEventHandle onTimelineEvent { get; set; } + #endregion + + public bool isTowardRight { get { diff --git a/Assets/Scripts/Unit/Events/EventEffect.cs b/Assets/Scripts/Unit/Events/EventEffect.cs index 8820aa21..d6a3fa16 100644 --- a/Assets/Scripts/Unit/Events/EventEffect.cs +++ b/Assets/Scripts/Unit/Events/EventEffect.cs @@ -11,7 +11,7 @@ public class EventEffect : AnimationEventBase [Tooltip("Is attached to a bone")] public bool attached; - [Tooltip("Bone path attach to")] + [If("attached"), Tooltip("Bone path attach to")] public string bone; [Tooltip("Position offset")] diff --git a/Assets/Scripts/Unit/Events/EventProjectile.cs b/Assets/Scripts/Unit/Events/EventProjectile.cs index 5f9a22aa..6083179b 100644 --- a/Assets/Scripts/Unit/Events/EventProjectile.cs +++ b/Assets/Scripts/Unit/Events/EventProjectile.cs @@ -6,21 +6,28 @@ public class EventProjectile : AnimationEventBase { public enum EMoveType { - GoStraight, - Curve, - } + Kinematic = 0, + Curve, // 用一个固定曲线运动 + Procedural, // 程序控制 + } public override TimelineEventProxy.EEventType type { get { return TimelineEventProxy.EEventType.EventProjectile; } } public override string shortName { get { return "P"; } } + [Tooltip("名字,可以用来识别这个projectile")] + public string name; + + [Tooltip("标签,可以用来做一些标记,逗号分隔")] + public string tag; + [Tooltip("Projectile path")] public string projectilePath; [Tooltip("Is attached to a bone")] public bool attachedToBone; - [Tooltip("Bone path attach to")] + [If("attachedToBone"), Tooltip("Bone path attach to")] public string bone; [Tooltip("Position offset")] @@ -29,16 +36,24 @@ public class EventProjectile : AnimationEventBase [Tooltip("Rotation in euler")] public Vector3 rotation; - [When("moveType", EMoveType.GoStraight), Tooltip("Scale")] + [Tooltip("Scale")] public Vector3 scale = Vector3.one; + public float lifeTime; + [Comment("[ 运动方式 ]", TextAnchor.MiddleCenter)] public EMoveType moveType; - [When("moveType", EMoveType.GoStraight), Tooltip("初始速度")] + [When("moveType", EMoveType.Kinematic), Tooltip("初始速度")] public Vector3 velocity; + [When("moveType", EMoveType.Kinematic), Tooltip("加速度")] + public Vector3 acceleration; + + [When("moveType", EMoveType.Curve), Tooltip("运动曲线")] + public string curvePath; + [WhenNot("moveType", EMoveType.Procedural)] public bool towardDirection; [Comment("[ 击中反馈 ]", TextAnchor.MiddleCenter)] diff --git a/Assets/Scripts/Unit/TimelineEventProxy.cs b/Assets/Scripts/Unit/TimelineEventProxy.cs index da4185a7..2c5bf608 100644 --- a/Assets/Scripts/Unit/TimelineEventProxy.cs +++ b/Assets/Scripts/Unit/TimelineEventProxy.cs @@ -131,25 +131,28 @@ public partial class TimelineEventProxy m_PrevFrame = frame; } - #region Event Handles + void ExecuteEvents(List 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); - void ExecuteEvents(List 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); - } - } - } - - void EventEffect(AnimationEventBase animEvent) + if(owner != null) + owner.onTimelineEvent(e); + } + } + } + + #region Event Handles + + void EventEffect(AnimationEventBase animEvent) { EventEffect effect = animEvent as EventEffect; if (effect == null) @@ -204,13 +207,16 @@ public partial class TimelineEventProxy GameObject obj = GameObject.Instantiate(prefab); Projectile projectile = obj.GetComponent(); ProjectileInfo info = new ProjectileInfo(); + info.name = e.name; + info.tag = e.tag; + info.moveType = e.moveType; info.owner = owner; info.position = m_Root.transform.position + e.posOffset; info.rotation = e.rotation; info.scale = e.scale; - info.direction = Vector3.right; - info.velocity = Vector3.right * 10f; - info.lifetime = 5; + info.velocity = e.velocity; + info.acceleration = e.acceleration; + info.lifetime = e.lifeTime; info.sparkPath = e.sparkPath; projectile.Initialize(info); -- cgit v1.1-26-g67d0