浏览代码

Reworked all Actions and Conditions to take advantage of the refactor

/main
Ciro Continisio 4 年前
当前提交
c81112b1
共有 37 个文件被更改,包括 159 次插入238 次删除
  1. 12
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsAirborne_False_OnExit.asset
  2. 12
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsAirborne_True_OnEnter.asset
  3. 12
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsTalking_False_OnExit.asset
  4. 12
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsTalking_True_OnEnter.asset
  5. 12
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsWalking_False_OnEnter.asset
  6. 12
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsWalking_True_OnEnter.asset
  7. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/MoveInTheAir.asset
  8. 7
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/PlayJumpSound.asset
  9. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/RotateFast.asset
  10. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/Slide.asset
  11. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/Timer_JumpHoldButton.asset
  12. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/Timer_Talking.asset
  13. 49
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/AnimatorParameterActionSO.cs
  14. 15
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/AscendActionSO.cs
  15. 7
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/DescendActionSO.cs
  16. 12
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/Editor/AnimatorParameterActionSOEditor.cs
  17. 15
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/GroundGravityActionSO.cs
  18. 21
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/HorizontalMoveActionSO.cs
  19. 23
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/PlayAudioCueActionSO.cs
  20. 15
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/RotateActionSO.cs
  21. 18
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/SlideActionSO.cs
  22. 2
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/HasHitHeadConditionSO.cs
  23. 2
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsCharacterControllerGroundedConditionSO.cs
  24. 2
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsHoldingExtraActionConditionSO.cs
  25. 2
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsHoldingJumpConditionSO.cs
  26. 17
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsMovingConditionSO.cs
  27. 16
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/TimeElapsedConditionSO.cs
  28. 2
      UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/InitOnlyAttributeDrawer.cs
  29. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravityGround.asset
  30. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravitySliding.asset
  31. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/MoveOnTheGround.asset
  32. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GroundGravity.asset
  33. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/SlidingGravity.asset
  34. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/Walk.asset
  35. 0
      /UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravityGround.asset.meta
  36. 0
      /UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravitySliding.asset.meta
  37. 0
      /UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/MoveOnTheGround.asset.meta

12
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsAirborne_False_OnExit.asset


m_Script: {fileID: 11500000, guid: 4c70afd7f911db7449d578cc18700875, type: 3}
m_Name: IsAirborne_False_OnExit
m_EditorClassIdentifier:
_parameterType: 0
_parameterName: IsAirborne
_boolValue: 0
_intValue: 0
_floatValue: 0
_whenToRun: 1
parameterType: 0
parameterName: IsAirborne
boolValue: 0
intValue: 0
floatValue: 0
whenToRun: 1

12
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsAirborne_True_OnEnter.asset


m_Script: {fileID: 11500000, guid: 4c70afd7f911db7449d578cc18700875, type: 3}
m_Name: IsAirborne_True_OnEnter
m_EditorClassIdentifier:
_parameterType: 0
_parameterName: IsAirborne
_boolValue: 1
_intValue: 0
_floatValue: 0
_whenToRun: 0
parameterType: 0
parameterName: IsAirborne
boolValue: 1
intValue: 0
floatValue: 0
whenToRun: 0

12
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsTalking_False_OnExit.asset


m_Script: {fileID: 11500000, guid: 4c70afd7f911db7449d578cc18700875, type: 3}
m_Name: IsTalking_False_OnExit
m_EditorClassIdentifier:
_parameterType: 0
_parameterName: IsTalking
_boolValue: 0
_intValue: 0
_floatValue: 0
_whenToRun: 1
parameterType: 0
parameterName: IsTalking
boolValue: 0
intValue: 0
floatValue: 0
whenToRun: 1

12
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsTalking_True_OnEnter.asset


m_Script: {fileID: 11500000, guid: 4c70afd7f911db7449d578cc18700875, type: 3}
m_Name: IsTalking_True_OnEnter
m_EditorClassIdentifier:
_parameterType: 0
_parameterName: IsTalking
_boolValue: 1
_intValue: 0
_floatValue: 0
_whenToRun: 0
parameterType: 0
parameterName: IsTalking
boolValue: 1
intValue: 0
floatValue: 0
whenToRun: 0

12
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsWalking_False_OnEnter.asset


m_Script: {fileID: 11500000, guid: 4c70afd7f911db7449d578cc18700875, type: 3}
m_Name: IsWalking_False_OnEnter
m_EditorClassIdentifier:
_parameterType: 0
_parameterName: IsWalking
_boolValue: 0
_intValue: 0
_floatValue: 0
_whenToRun: 0
parameterType: 0
parameterName: IsWalking
boolValue: 0
intValue: 0
floatValue: 0
whenToRun: 0

12
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/IsWalking_True_OnEnter.asset


m_Script: {fileID: 11500000, guid: 4c70afd7f911db7449d578cc18700875, type: 3}
m_Name: IsWalking_True_OnEnter
m_EditorClassIdentifier:
_parameterType: 0
_parameterName: IsWalking
_boolValue: 1
_intValue: 0
_floatValue: 0
_whenToRun: 0
parameterType: 0
parameterName: IsWalking
boolValue: 1
intValue: 0
floatValue: 0
whenToRun: 0

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/MoveInTheAir.asset


m_Script: {fileID: 11500000, guid: 09fcb347b6cb3524c9f59fbde36ec7c7, type: 3}
m_Name: MoveInTheAir
m_EditorClassIdentifier:
_speed: 3.5
speed: 3.5

7
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/PlayJumpSound.asset


m_Script: {fileID: 11500000, guid: 7fe1333f4a744134ebafe667cc9f1e1a, type: 3}
m_Name: PlayJumpSound
m_EditorClassIdentifier:
_audioCue: {fileID: 11400000, guid: 5977d168e99dd5443a497ed77990980f, type: 2}
_audioCueEventChannel: {fileID: 11400000, guid: c3c796b7c31ad3647a3fbae42e74764e,
audioCue: {fileID: 11400000, guid: 5977d168e99dd5443a497ed77990980f, type: 2}
audioCueEventChannel: {fileID: 11400000, guid: c3c796b7c31ad3647a3fbae42e74764e,
_audioConfiguration: {fileID: 11400000, guid: 8d4217c8fabf9824490196f34baf326a,
type: 2}
audioConfiguration: {fileID: 11400000, guid: 8d4217c8fabf9824490196f34baf326a, type: 2}

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/RotateFast.asset


m_Script: {fileID: 11500000, guid: 8c2b40ff7519a5e41a2dc48c2aca516c, type: 3}
m_Name: RotateFast
m_EditorClassIdentifier:
_turnSmoothTime: 0.1
turnSmoothTime: 0.1

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/Slide.asset


m_Script: {fileID: 11500000, guid: 3d6639e9199e4ec44852fe925b2dc470, type: 3}
m_Name: Slide
m_EditorClassIdentifier:
_slideSpeed: 10
slideSpeed: 10

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/Timer_JumpHoldButton.asset


m_Name: Timer_JumpHoldButton
m_EditorClassIdentifier:
cacheResult: 1
_timerLength: 0.4
timerLength: 0.4

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/Timer_Talking.asset


m_Name: Timer_Talking
m_EditorClassIdentifier:
cacheResult: 1
_timerLength: 3
timerLength: 3

49
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/AnimatorParameterActionSO.cs


[CreateAssetMenu(fileName = "AnimatorParameterAction", menuName = "State Machines/Actions/Set Animator Parameter")]
public class AnimatorParameterActionSO : StateActionSO
{
[SerializeField] private ParameterType _parameterType = default;
[SerializeField] private string _parameterName = default;
public ParameterType parameterType = default;
public string parameterName = default;
[SerializeField] private bool _boolValue = default;
[SerializeField] private int _intValue = default;
[SerializeField] private float _floatValue = default;
public bool boolValue = default;
public int intValue = default;
public float floatValue = default;
[SerializeField] private Moment _whenToRun = default; // Allows this StateActionSO type to be reused for all 3 state moments.
public Moment whenToRun = default; // Allows this StateActionSO type to be reused for all 3 state moments
// Bit of a waste to send all three parameters to the StateAction, but it's a small price to pay for a lot of convenience
protected override StateAction CreateAction() => new AnimatorParameterAction(_whenToRun, _parameterName, _parameterType,
_boolValue, _intValue, _floatValue);
protected override StateAction CreateAction() => new AnimatorParameterAction(Animator.StringToHash(parameterName));
public enum ParameterType
{

{
//Component references
private Animator _animator;
private AnimatorParameterActionSO _originSO => (AnimatorParameterActionSO)base.OriginSO; // The SO this StateAction spawned from
private AnimatorParameterActionSO.ParameterType _parameterType;
private bool _boolValue;
private int _intValue;
private float _floatValue;
private SpecificMoment _whenToRun;
public AnimatorParameterAction(SpecificMoment whenToRun, string parameterName,
AnimatorParameterActionSO.ParameterType parameterType,
bool newBoolValue, int newIntValue, float newFloatValue)
public AnimatorParameterAction(int parameterHash)
_whenToRun = whenToRun;
_parameterHash = Animator.StringToHash(parameterName);
_parameterType = parameterType;
_boolValue = newBoolValue;
_intValue = newIntValue;
_floatValue = newFloatValue;
_parameterHash = parameterHash;
}
public override void Awake(StateMachine stateMachine)

public override void OnStateEnter()
{
if (_whenToRun == SpecificMoment.OnStateEnter)
if (_originSO.whenToRun == SpecificMoment.OnStateEnter)
if (_whenToRun == SpecificMoment.OnStateExit)
if (_originSO.whenToRun == SpecificMoment.OnStateExit)
switch (_parameterType)
switch (_originSO.parameterType)
_animator.SetBool(_parameterHash, _boolValue);
_animator.SetBool(_parameterHash, _originSO.boolValue);
_animator.SetInteger(_parameterHash, _intValue);
_animator.SetInteger(_parameterHash, _originSO.intValue);
_animator.SetFloat(_parameterHash, _floatValue);
_animator.SetFloat(_parameterHash, _originSO.floatValue);
break;
case AnimatorParameterActionSO.ParameterType.Trigger:
_animator.SetTrigger(_parameterHash);

15
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/AscendActionSO.cs


using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "Ascend", menuName = "State Machines/Actions/Ascend")]
public class AscendActionSO : StateActionSO
public class AscendActionSO : StateActionSO<AscendAction>
[SerializeField] private float _initialJumpForce = 10f;
protected override StateAction CreateAction() => new AscendAction(_initialJumpForce);
public float initialJumpForce = 6f;
}
public class AscendAction : StateAction

private float _verticalMovement;
private float _gravityContributionMultiplier;
private float _initialJumpForce;
private AscendActionSO _originSO => (AscendActionSO)base.OriginSO; // The SO this StateAction spawned from
public override void Awake(StateMachine stateMachine)
{

public AscendAction(float initialJumpForce)
{
_initialJumpForce = initialJumpForce;
}
_verticalMovement = _initialJumpForce;
_verticalMovement = _originSO.initialJumpForce;
}
public override void OnUpdate()

7
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/DescendActionSO.cs


using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "Descend", menuName = "State Machines/Actions/Descend")]
public class DescendActionSO : StateActionSO
{
protected override StateAction CreateAction() => new DescendAction();
}
[CreateAssetMenu(menuName = "State Machines/Actions/Descend")]
public class DescendActionSO : StateActionSO<DescendAction> { }
public class DescendAction : StateAction
{

12
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/Editor/AnimatorParameterActionSOEditor.cs


{
serializedObject.Update();
EditorGUILayout.PropertyField(serializedObject.FindProperty("_whenToRun"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("whenToRun"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("_parameterName"), new GUIContent("Name"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("parameterName"), new GUIContent("Name"));
SerializedProperty animParamValue = serializedObject.FindProperty("_parameterType");
SerializedProperty animParamValue = serializedObject.FindProperty("parameterType");
EditorGUILayout.PropertyField(animParamValue, new GUIContent("Type"));

EditorGUILayout.PropertyField(serializedObject.FindProperty("_boolValue"), new GUIContent("Target value"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("boolValue"), new GUIContent("Desired value"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("_intValue"), new GUIContent("Target value"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("intValue"), new GUIContent("Desired value"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("_floatValue"), new GUIContent("Target value"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("floatValue"), new GUIContent("Desired value"));
break;
}

15
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/GroundGravityActionSO.cs


using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "GroundGravity", menuName = "State Machines/Actions/Ground Gravity")]
public class GroundGravityActionSO : StateActionSO
public class GroundGravityActionSO : StateActionSO<GroundGravityAction>
[SerializeField] private float _verticalPull = -5f;
protected override StateAction CreateAction() => new GroundGravityAction(_verticalPull);
public float verticalPull = -5f;
}
public class GroundGravityAction : StateAction

private float _verticalPull;
public GroundGravityAction(float slideSpeed)
{
_verticalPull = slideSpeed;
}
private GroundGravityActionSO _originSO => (GroundGravityActionSO)base.OriginSO; // The SO this StateAction spawned from
public override void Awake(StateMachine stateMachine)
{

public override void OnUpdate()
{
_protagonistScript.movementVector.y = _verticalPull;
_protagonistScript.movementVector.y = _originSO.verticalPull;
}
}

21
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/HorizontalMoveActionSO.cs


using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "HorizontalMove", menuName = "State Machines/Actions/Horizontal Move")]
public class HorizontalMoveActionSO : StateActionSO
public class HorizontalMoveActionSO : StateActionSO<HorizontalMoveAction>
[Tooltip("Horizontal XZ plane speed multiplier")] [SerializeField] private float _speed = 8f;
protected override StateAction CreateAction() => new WalkAction(_speed);
[Tooltip("Horizontal XZ plane speed multiplier")]
public float speed = 8f;
public class WalkAction : StateAction
public class HorizontalMoveAction : StateAction
private float _speed;
public WalkAction(float speed)
{
_speed = speed;
}
private HorizontalMoveActionSO _originSO => (HorizontalMoveActionSO)base.OriginSO; // The SO this StateAction spawned from
public override void Awake(StateMachine stateMachine)
{

public override void OnUpdate()
{
_protagonistScript.movementVector.x = _protagonistScript.movementInput.x * _speed;
_protagonistScript.movementVector.z = _protagonistScript.movementInput.z * _speed;
_protagonistScript.movementVector.x = _protagonistScript.movementInput.x * _originSO.speed;
_protagonistScript.movementVector.z = _protagonistScript.movementInput.z * _originSO.speed;
}
}

23
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/PlayAudioCueActionSO.cs


using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
public class PlayAudioCueActionSO : StateActionSO
public class PlayAudioCueActionSO : StateActionSO<PlayAudioCueAction>
[SerializeField] private AudioCueSO _audioCue = default;
[SerializeField] private AudioCueEventChannelSO _audioCueEventChannel = default;
[SerializeField] private AudioConfigurationSO _audioConfiguration = default;
protected override StateAction CreateAction() => new PlayAudioCueAction(_audioCue, _audioCueEventChannel, _audioConfiguration);
public AudioCueSO audioCue = default;
public AudioCueEventChannelSO audioCueEventChannel = default;
public AudioConfigurationSO audioConfiguration = default;
private AudioCueEventChannelSO _audioCueEventChannel;
private AudioCueSO _audioCue;
private AudioConfigurationSO _audioConfiguration;
public PlayAudioCueAction(AudioCueSO audioCue, AudioCueEventChannelSO audioCueEventChannel, AudioConfigurationSO audioConfiguration)
{
_audioCue = audioCue;
_audioCueEventChannel = audioCueEventChannel;
_audioConfiguration = audioConfiguration;
}
private PlayAudioCueActionSO _originSO => (PlayAudioCueActionSO)base.OriginSO; // The SO this StateAction spawned from
public override void Awake(StateMachine stateMachine)
{

public override void OnStateEnter()
{
_audioCueEventChannel.RaiseEvent(_audioCue, _audioConfiguration, _stateMachineTransform.position);
_originSO.audioCueEventChannel.RaiseEvent(_originSO.audioCue, _originSO.audioConfiguration, _stateMachineTransform.position);
}
}

15
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/RotateActionSO.cs


using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "RotateAction", menuName = "State Machines/Actions/Rotate")]
public class RotateActionSO : StateActionSO
public class RotateActionSO : StateActionSO<RotateAction>
[Tooltip("Smoothing for rotating the character to their movement direction")] [SerializeField] private float _turnSmoothTime = 0.2f;
protected override StateAction CreateAction() => new RotateAction(_turnSmoothTime);
[Tooltip("Smoothing for rotating the character to their movement direction")]
public float turnSmoothTime = 0.2f;
}
public class RotateAction : StateAction

private Transform _transform;
private float _turnSmoothTime;
public RotateAction(float turnSmoothTime)
{
_turnSmoothTime = turnSmoothTime;
}
private RotateActionSO _originSO => (RotateActionSO)base.OriginSO; // The SO this StateAction spawned from
public override void Awake(StateMachine stateMachine)
{

_transform.eulerAngles.y,
targetRotation,
ref _turnSmoothSpeed,
_turnSmoothTime);
_originSO.turnSmoothTime);
}
}
}

18
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/SlideActionSO.cs


using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "SlideAction", menuName = "State Machines/Actions/Slide")]
public class SlideActionSO : StateActionSO
public class SlideActionSO : StateActionSO<SlideAction>
[SerializeField] private float _slideSpeed = 6f;
protected override StateAction CreateAction() => new SlideAction(_slideSpeed);
public float slideSpeed = 10f;
}
public class SlideAction : StateAction

private float _slideSpeed;
public SlideAction(float slideSpeed)
{
_slideSpeed = slideSpeed;
}
private SlideActionSO _originSO => (SlideActionSO)base.OriginSO; // The SO this StateAction spawned from
public override void Awake(StateMachine stateMachine)
{

public override void OnUpdate()
{
Vector3 hitNormal = _protagonistScript.lastHit.normal;
_protagonistScript.movementVector.x = (1f - hitNormal.y) * hitNormal.x * _slideSpeed;
_protagonistScript.movementVector.z = (1f - hitNormal.y) * hitNormal.z * _slideSpeed;
_protagonistScript.movementVector.x = (1f - hitNormal.y) * hitNormal.x * _originSO.slideSpeed;
_protagonistScript.movementVector.z = (1f - hitNormal.y) * hitNormal.z * _originSO.slideSpeed;
}
public override void OnStateExit()

2
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/HasHitHeadConditionSO.cs


using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "HasHitHead", menuName = "State Machines/Conditions/Has Hit the Head")]
[CreateAssetMenu(menuName = "State Machines/Conditions/Has Hit the Head")]
public class HasHitHeadConditionSO : StateConditionSO<HasHitHeadCondition> { }
public class HasHitHeadCondition : Condition

2
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsCharacterControllerGroundedConditionSO.cs


using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "IsGrounded", menuName = "State Machines/Conditions/Is Character Controller Grounded")]
[CreateAssetMenu(menuName = "State Machines/Conditions/Is Character Controller Grounded")]
public class IsCharacterControllerGroundedConditionSO : StateConditionSO<IsCharacterControllerGroundedCondition> { }
public class IsCharacterControllerGroundedCondition : Condition

2
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsHoldingExtraActionConditionSO.cs


using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "IsHoldingExtraAction", menuName = "State Machines/Conditions/Is Holding ExtraAction")]
[CreateAssetMenu(menuName = "State Machines/Conditions/Is Holding ExtraAction")]
public class IsHoldingExtraActionConditionSO : StateConditionSO<IsHoldingExtraActionCondition> { }
public class IsHoldingExtraActionCondition : Condition

2
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsHoldingJumpConditionSO.cs


using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "IsHoldingJump", menuName = "State Machines/Conditions/Is Holding Jump")]
[CreateAssetMenu(menuName = "State Machines/Conditions/Is Holding Jump")]
public class IsHoldingJumpConditionSO : StateConditionSO<IsHoldingJumpCondition> { }
public class IsHoldingJumpCondition : Condition

17
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsMovingConditionSO.cs


using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "StartedMoving", menuName = "State Machines/Conditions/Started Moving")]
public class IsMovingConditionSO : StateConditionSO
[CreateAssetMenu(menuName = "State Machines/Conditions/Started Moving")]
public class IsMovingConditionSO : StateConditionSO<IsMovingCondition>
[SerializeField] private float _treshold = 0.02f;
protected override Condition CreateCondition() => new IsMovingCondition(_treshold);
public float treshold = 0.02f;
private float _treshold;
private IsMovingConditionSO _originSO => (IsMovingConditionSO)base.OriginSO; // The SO this Condition spawned from
public override void Awake(StateMachine stateMachine)
{

public IsMovingCondition(float treshold)
{
_treshold = treshold;
}
return movementVector.sqrMagnitude > _treshold;
return movementVector.sqrMagnitude > _originSO.treshold;
}
public override void OnStateExit()

16
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/TimeElapsedConditionSO.cs


using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "TimeElapsed", menuName = "State Machines/Conditions/Time elapsed")]
public class TimeElapsedConditionSO : StateConditionSO
[CreateAssetMenu(menuName = "State Machines/Conditions/Time elapsed")]
public class TimeElapsedConditionSO : StateConditionSO<TimeElapsedCondition>
[SerializeField] float _timerLength = .5f;
protected override Condition CreateCondition() => new TimeElapsedCondition(_timerLength);
public float timerLength = .5f;
private float _timerLength;
private TimeElapsedConditionSO _originSO => (TimeElapsedConditionSO)base.OriginSO; // The SO this Condition spawned from
public override void OnStateEnter()
{

public TimeElapsedCondition(float timerLength)
{
_timerLength = timerLength;
}
protected override bool Statement() => Time.time >= _startTime + _timerLength;
protected override bool Statement() => Time.time >= _startTime + _originSO.timerLength;
}

2
UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/InitOnlyAttributeDrawer.cs


[CustomPropertyDrawer(typeof(InitOnlyAttribute))]
public class InitOnlyAttributeDrawer : PropertyDrawer
{
private static readonly string _text = "Changes to this parameter during play mode will only take effect on new state machine instances, or the next time you enter play mode.";
private static readonly string _text = "Changes to this parameter during Play mode won't be reflected on existing StateMachines";
private static readonly GUIStyle _style = new GUIStyle(GUI.skin.GetStyle("helpbox")) { padding = new RectOffset(5, 5, 5, 5) };
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)

15
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravityGround.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5e724f945a0fb204fa0f39919afe653b, type: 3}
m_Name: GravityGround
m_EditorClassIdentifier:
verticalPull: -5

15
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravitySliding.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5e724f945a0fb204fa0f39919afe653b, type: 3}
m_Name: GravitySliding
m_EditorClassIdentifier:
verticalPull: -10

15
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/MoveOnTheGround.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 09fcb347b6cb3524c9f59fbde36ec7c7, type: 3}
m_Name: MoveOnTheGround
m_EditorClassIdentifier:
speed: 4

15
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GroundGravity.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5e724f945a0fb204fa0f39919afe653b, type: 3}
m_Name: GroundGravity
m_EditorClassIdentifier:
_verticalPull: -5

15
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/SlidingGravity.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5e724f945a0fb204fa0f39919afe653b, type: 3}
m_Name: SlidingGravity
m_EditorClassIdentifier:
_verticalPull: -10

15
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/Walk.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 09fcb347b6cb3524c9f59fbde36ec7c7, type: 3}
m_Name: Walk
m_EditorClassIdentifier:
_speed: 4

/UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GroundGravity.asset.meta → /UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravityGround.asset.meta

/UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/SlidingGravity.asset.meta → /UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravitySliding.asset.meta

/UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/Walk.asset.meta → /UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/MoveOnTheGround.asset.meta

正在加载...
取消
保存