diff options
Diffstat (limited to 'Assets/Scripts')
17 files changed, 255 insertions, 28 deletions
diff --git a/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs b/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs index 5dbe6d6c..9798d7a2 100644 --- a/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs +++ b/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs @@ -74,7 +74,7 @@ public class AttackAbility : AbilityBase }
foreach (var abilityTrigger in m_Triggers)
{
- if (abilityTrigger.Update())
+ if (abilityTrigger.Update() && abilityTrigger.Swallow)
break;
}
}
diff --git a/Assets/Scripts/AbilitySystem/Abilities/IdleAbility.cs b/Assets/Scripts/AbilitySystem/Abilities/IdleAbility.cs index 0a59419f..d42308db 100644 --- a/Assets/Scripts/AbilitySystem/Abilities/IdleAbility.cs +++ b/Assets/Scripts/AbilitySystem/Abilities/IdleAbility.cs @@ -35,7 +35,7 @@ public class IdleAbility : AbilityBase {
foreach(var trigger in m_Triggers)
{
- if (trigger.Update())
+ if (trigger.Update() && trigger.Swallow)
break;
}
diff --git a/Assets/Scripts/AbilitySystem/Abilities/MoveAbility.cs b/Assets/Scripts/AbilitySystem/Abilities/MoveAbility.cs index 139325b6..757cd2d1 100644 --- a/Assets/Scripts/AbilitySystem/Abilities/MoveAbility.cs +++ b/Assets/Scripts/AbilitySystem/Abilities/MoveAbility.cs @@ -53,7 +53,7 @@ public class MoveAbility : AbilityBase {
foreach (var abilityTrigger in m_Triggers)
{
- if (abilityTrigger.Update())
+ if (abilityTrigger.Update() && abilityTrigger.Swallow)
break;
}
}
diff --git a/Assets/Scripts/AbilitySystem/Actions/ActionEffects/ActionDisableGhost.cs b/Assets/Scripts/AbilitySystem/Actions/ActionEffects/ActionDisableGhost.cs new file mode 100644 index 00000000..2da01daf --- /dev/null +++ b/Assets/Scripts/AbilitySystem/Actions/ActionEffects/ActionDisableGhost.cs @@ -0,0 +1,19 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// 残影特效 +public class ActionDisableGhost : ActionBase +{ + CharacterGhostEffect m_GhostEffect; + + public ActionDisableGhost(CharacterGhostEffect effect) + { + m_GhostEffect = effect; + } + + public override void Execute() + { + m_GhostEffect.IsEnable = false; + } +} diff --git a/Assets/Scripts/Effects/IEffectHandler.cs.meta b/Assets/Scripts/AbilitySystem/Actions/ActionEffects/ActionDisableGhost.cs.meta index 142a3f23..185da50b 100644 --- a/Assets/Scripts/Effects/IEffectHandler.cs.meta +++ b/Assets/Scripts/AbilitySystem/Actions/ActionEffects/ActionDisableGhost.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: cb3081a24820b3e438133b2ca6eb5549 +guid: 8548d7836b8033643954ca68cc3a5948 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/AbilitySystem/Actions/ActionEffects/ActionEffectGhost.cs b/Assets/Scripts/AbilitySystem/Actions/ActionEffects/ActionEffectGhost.cs index 0bff3df3..05d3a1a5 100644 --- a/Assets/Scripts/AbilitySystem/Actions/ActionEffects/ActionEffectGhost.cs +++ b/Assets/Scripts/AbilitySystem/Actions/ActionEffects/ActionEffectGhost.cs @@ -5,10 +5,15 @@ using UnityEngine; // 残影特效
public class ActionEffectGhost : ActionBase
{
+ CharacterGhostEffect m_GhostEffect;
+ public ActionEffectGhost(CharacterGhostEffect effect)
+ {
+ m_GhostEffect = effect;
+ }
public override void Execute()
{
-
- }
+ m_GhostEffect.IsEnable = true;
+ }
}
diff --git a/Assets/Scripts/AbilitySystem/Bahaviours.meta b/Assets/Scripts/AbilitySystem/Bahaviours.meta new file mode 100644 index 00000000..982222bf --- /dev/null +++ b/Assets/Scripts/AbilitySystem/Bahaviours.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d10a8e3e46f321146b54b9f74ca76db6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/AbilitySystem/Bahaviours/GhostEffectSpwan.cs b/Assets/Scripts/AbilitySystem/Bahaviours/GhostEffectSpwan.cs new file mode 100644 index 00000000..cbc9c632 --- /dev/null +++ b/Assets/Scripts/AbilitySystem/Bahaviours/GhostEffectSpwan.cs @@ -0,0 +1,14 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class GhostEffectSpwan : MonoBehaviour +{ + public CharacterGhostEffect GhostEffect; + + public void SpawnGhost() + { + GhostEffect.CreateGhost(); + } + +} diff --git a/Assets/Scripts/AbilitySystem/Bahaviours/GhostEffectSpwan.cs.meta b/Assets/Scripts/AbilitySystem/Bahaviours/GhostEffectSpwan.cs.meta new file mode 100644 index 00000000..4acfc78c --- /dev/null +++ b/Assets/Scripts/AbilitySystem/Bahaviours/GhostEffectSpwan.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 12bdc2613cfcd9043ad58b1bcc15c8ce +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/AbilitySystem/Trigger.cs b/Assets/Scripts/AbilitySystem/Trigger.cs index 416655ee..dc173a6d 100644 --- a/Assets/Scripts/AbilitySystem/Trigger.cs +++ b/Assets/Scripts/AbilitySystem/Trigger.cs @@ -8,20 +8,30 @@ using UnityEngine; public sealed class Trigger { + public bool Swallow; + private ConditionBase m_Condition; private List<ActionBase> m_ActionChain = new List<ActionBase>(); - - public Trigger(ConditionBase condition, List<ActionBase> actions) + + public Trigger(ConditionBase condition, List<ActionBase> actions, bool onlyOnce = false, bool swallow = true) { + Swallow = swallow; m_Condition = condition; m_ActionChain.AddRange(actions); } - public Trigger(ConditionBase condition, ActionBase action) + public Trigger(ConditionBase condition, ActionBase action, bool onlyOnce = false, bool swallow = true) { + Swallow = swallow; m_Condition = condition; m_ActionChain.Add(action); } + //重置触发器的参数 + public void Reset() + { + + } + /// <summary> /// 如果触发执行了,返回true,否则返回false /// </summary> diff --git a/Assets/Scripts/Effects/AfterImageEffects.cs b/Assets/Scripts/Effects/AfterImageEffects.cs index a19be897..ba269279 100644 --- a/Assets/Scripts/Effects/AfterImageEffects.cs +++ b/Assets/Scripts/Effects/AfterImageEffects.cs @@ -1,4 +1,4 @@ -using UnityEngine;
+ using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
diff --git a/Assets/Scripts/Effects/CharacterGhostEffect.cs b/Assets/Scripts/Effects/CharacterGhostEffect.cs new file mode 100644 index 00000000..d40adc17 --- /dev/null +++ b/Assets/Scripts/Effects/CharacterGhostEffect.cs @@ -0,0 +1,127 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CharacterGhostEffect : EffectHandler +{ + [Tooltip("目标skinMeshRenderer")] + public SkinnedMeshRenderer m_Renderer; + + [Tooltip("如果mesh包含多个submesh,需要每个submesh单独设置一个材质")] + public Material[] Materials; + + [Tooltip("Submesh是否使用同一个材质")] + public bool SubmeshShareMaterial; + + [Tooltip("使用范围内的submesh")] + public bool UseRangedSubmesh; + + [Tooltip("Submesh索引范围")] + public Vector2Int SubmeshRange; + + [Tooltip("是否开启残影效果")] + public bool IsEnable; + + [Tooltip("残影生成的时间间隔")] + public float Interval = 0.1f; + + [Tooltip("残影的生存时间")] + public float LifeTime = 0.5f; + + private float m_Time = 0; + private List<GhostSnapshot> m_Ghosts = new List<GhostSnapshot>(); + + void Update() + { + //if (!IsEnable) + //{ + // if (m_Ghosts.Count > 0) + // UpdateGhost(); // destroy ghosts + // return; + //} + + if (m_Ghosts == null || m_Renderer == null || Materials == null || Materials.Length == 0) + { + IsEnable = false; + return; + } + + m_Time += Time.deltaTime; + + //if(IsEnable) + // CreateGhost(); + + UpdateGhost(); + DrawGhost(); + } + + public void CreateGhost() + { + if(m_Time >= Interval) + { + m_Time -= Interval; + + Mesh mesh = new Mesh(); + m_Renderer.BakeMesh(mesh); + + Matrix4x4 mat = m_Renderer.localToWorldMatrix; + + m_Ghosts.Add(new GhostSnapshot(mesh, mat, Time.realtimeSinceStartup, LifeTime)); + } + } + + void UpdateGhost() + { + for(int i = m_Ghosts.Count - 1; i >= 0 ; --i) + { + GhostSnapshot ghost = m_Ghosts[i]; + float passTime = Time.realtimeSinceStartup - ghost.startTime; + + if (passTime > ghost.lifeTime) + { + m_Ghosts.Remove(ghost); + Destroy(ghost); + continue; + } + } + } + + void DrawGhost() + { + for(int i = 0; i < m_Ghosts.Count; ++ i) + { + GhostSnapshot ghost = m_Ghosts[i]; + int start = 0, end = ghost.mesh.subMeshCount - 1; + if(UseRangedSubmesh) + { + start = SubmeshRange.x; + end = SubmeshRange.y; + } + for (int j = start; j <= end; ++j) + { + Material material; + if (SubmeshShareMaterial) + material = Materials[0]; + else + material = Materials[j]; + Graphics.DrawMesh(ghost.mesh, ghost.matrix, material, gameObject.layer, null, j); + } + } + } +} + +class GhostSnapshot : Object +{ + public Mesh mesh; + public Matrix4x4 matrix; + public float startTime; + public float lifeTime; + + public GhostSnapshot(Mesh mesh, Matrix4x4 mat, float startTime, float lifeTime) + { + this.mesh = mesh; + this.matrix = mat; + this.startTime = startTime; + this.lifeTime = lifeTime; + } +} diff --git a/Assets/Scripts/Effects/CharacterGhostEffect.cs.meta b/Assets/Scripts/Effects/CharacterGhostEffect.cs.meta new file mode 100644 index 00000000..9a1f3a3a --- /dev/null +++ b/Assets/Scripts/Effects/CharacterGhostEffect.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 76b355b49906df24cac5ccfb0de69331 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Effects/IEffectHandler.cs b/Assets/Scripts/Effects/EffectHandler.cs index bdc4c6a0..265a1001 100644 --- a/Assets/Scripts/Effects/IEffectHandler.cs +++ b/Assets/Scripts/Effects/EffectHandler.cs @@ -1,18 +1,18 @@ -using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class IEffectHandler : MonoBehaviour
-{
- // Start is called before the first frame update
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
-
- }
-}
+using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EffectHandler : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Effects/EffectHandler.cs.meta b/Assets/Scripts/Effects/EffectHandler.cs.meta new file mode 100644 index 00000000..81ee0c34 --- /dev/null +++ b/Assets/Scripts/Effects/EffectHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 83576b34fc8f74048a5c050c30ab463f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Test/SaionjiScript.cs b/Assets/Scripts/Test/SaionjiScript.cs index 6b3f983e..bba87e17 100644 --- a/Assets/Scripts/Test/SaionjiScript.cs +++ b/Assets/Scripts/Test/SaionjiScript.cs @@ -16,6 +16,8 @@ public partial class SaionjiScript : MonoBehaviour public bool EnableAbilitySystem;
+ public EffectHandler[] Effects;
+
// Start is called before the first frame update
void Start()
{
diff --git a/Assets/Scripts/Test/SaionjiScript_Ability.cs b/Assets/Scripts/Test/SaionjiScript_Ability.cs index e01514b5..785b93b0 100644 --- a/Assets/Scripts/Test/SaionjiScript_Ability.cs +++ b/Assets/Scripts/Test/SaionjiScript_Ability.cs @@ -75,6 +75,9 @@ public partial class SaionjiScript : MonoBehaviour ActionWipeCmdRecord wipeCmdRecord = new ActionWipeCmdRecord();
+ ActionEffectGhost enableGhost = new ActionEffectGhost(Effects[0] as CharacterGhostEffect);
+ ActionDisableGhost disableGhost = new ActionDisableGhost(Effects[0] as CharacterGhostEffect);
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// conditions
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -168,6 +171,12 @@ public partial class SaionjiScript : MonoBehaviour attk1.AddTrigger(triggerTurnRight);
attk1.AddTrigger(triggerTurnLeft);
+ //ConditionAnimRange condAttkRushGhostRange = new ConditionAnimRange(animator, 0f, 0.8f);
+ //trigger = new Trigger(condAttkRushGhostRange, enableGhost, false);
+ //attkRush.AddTrigger(trigger);
+ //ConditionAnimRange condAttkRushGhostDisableRange = new ConditionAnimRange(animator, 0.8f, 10f);
+ //trigger = new Trigger(condAttkRushGhostDisableRange, disableGhost, false);
+ //attkRush.AddTrigger(trigger);
ConditionAnimRange condAttkRushAtRange = new ConditionAnimRange(animator, 0.5f, 1f);
trigger = new Trigger(And(condAttkRushAtRange, condCircleCmd), switchToAttk2);
attkRush.AddTrigger(trigger);
|