From 34d01108e9f0c5488e8824f768c43801dd8ed4cc Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 4 Sep 2021 14:02:24 +0800 Subject: *misc --- Assets/Scripts/Curve3D.meta | 8 --- Assets/Scripts/Drone.meta | 8 --- Assets/Scripts/Projectile/Projectile.cs | 59 +++++++++++++++------- Assets/Scripts/Props.meta | 8 --- Assets/Scripts/Robot.meta | 8 --- Assets/Scripts/Scene.meta | 8 --- 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 ++++++++++-------- 12 files changed, 122 insertions(+), 97 deletions(-) delete mode 100644 Assets/Scripts/Curve3D.meta delete mode 100644 Assets/Scripts/Drone.meta delete mode 100644 Assets/Scripts/Props.meta delete mode 100644 Assets/Scripts/Robot.meta delete mode 100644 Assets/Scripts/Scene.meta (limited to 'Assets/Scripts') diff --git a/Assets/Scripts/Curve3D.meta b/Assets/Scripts/Curve3D.meta deleted file mode 100644 index fef1c5e7..00000000 --- a/Assets/Scripts/Curve3D.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ad8b718b6b700d8419838dad07158567 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Drone.meta b/Assets/Scripts/Drone.meta deleted file mode 100644 index 694cff70..00000000 --- a/Assets/Scripts/Drone.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ec3412151f8a72a41b2ed21316763399 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Projectile/Projectile.cs b/Assets/Scripts/Projectile/Projectile.cs index a6411f5f..ba325302 100644 --- a/Assets/Scripts/Projectile/Projectile.cs +++ b/Assets/Scripts/Projectile/Projectile.cs @@ -4,16 +4,18 @@ using UnityEngine; public struct ProjectileInfo { - public UnitController owner; + public string name; + public string tag; + public EventProjectile.EMoveType moveType; + public UnitController owner; public Vector3 position; public Vector3 rotation; public Vector3 scale; - public Vector3 direction; public Vector3 velocity; - public bool towardDirection; + public Vector3 acceleration; + public bool towardDirection; public float lifetime; public bool useGravity; - public float gravity; public string sparkPath; } @@ -35,9 +37,17 @@ public class Projectile : MonoBehaviour public Box colliderGrid; public Vector3 slice; - #endregion + #endregion - [HideInInspector] + //名字,可以用来识别这个projectile + public new string name; + + //标签,可以用来做一些标记 + public new string tag; + + public EventProjectile.EMoveType moveType; + + [HideInInspector] public UnitController owner; [HideInInspector] @@ -46,10 +56,10 @@ public class Projectile : MonoBehaviour [HideInInspector] public Vector3 velocity; // 初始速度 - [HideInInspector] - public float gravity; + [HideInInspector] + public Vector3 acceleration; // 加速度 - [HideInInspector] + [HideInInspector] public bool towardDirection; // foward朝向运动的方向 [HideInInspector] @@ -65,12 +75,16 @@ public class Projectile : MonoBehaviour public void Initialize(ProjectileInfo info) { + this.name = info.name; + this.tag = info.tag; + this.moveType = info.moveType; this.owner = info.owner; this.transform.rotation = Quaternion.Euler(info.rotation); this.transform.position = info.position; this.transform.localScale.Scale(info.scale); this.velocity = info.velocity; - this.lifetime = info.lifetime; + this.acceleration = info.acceleration; + this.lifetime = info.lifetime; this.sparkPath = info.sparkPath; markDestroy = false; @@ -92,15 +106,19 @@ public class Projectile : MonoBehaviour public void Update(float deltaTime) { - this.transform.position += this.velocity * deltaTime; - time += deltaTime; - if (time > this.lifetime || markDestroy) - { - DestroyImmediate(this.gameObject); - } - } + if(moveType == EventProjectile.EMoveType.Kinematic) + { + this.velocity += this.acceleration * deltaTime; + this.transform.position += this.velocity * deltaTime; + } + time += deltaTime; + if (time > this.lifetime || markDestroy) + { + DestroyImmediate(this.gameObject); + } + } - void OnDestroy() + void OnDestroy() { ColliderRegistry.Instance.RemoveProjectile(this); } @@ -179,4 +197,9 @@ public class Projectile : MonoBehaviour } } + public bool HasTag(string tag) + { + return this.tag != null && this.tag.Contains(tag); + } + } \ No newline at end of file diff --git a/Assets/Scripts/Props.meta b/Assets/Scripts/Props.meta deleted file mode 100644 index bb96602e..00000000 --- a/Assets/Scripts/Props.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f299520ed9fcf4a45858ad4ef5a8d5d1 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Robot.meta b/Assets/Scripts/Robot.meta deleted file mode 100644 index 0b5a087e..00000000 --- a/Assets/Scripts/Robot.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 7c09ca1609552d24bbe697d1516f8aa9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Scene.meta b/Assets/Scripts/Scene.meta deleted file mode 100644 index eb7a8716..00000000 --- a/Assets/Scripts/Scene.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: eaee2d0f48cff9b40baf0686a8105600 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: 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