Skip to content

Commit 524d59a

Browse files
authored
Merge pull request #11 from batonPiotr/release/0.3.0
Release/0.3.0
2 parents b0b8546 + 0b19496 commit 524d59a

17 files changed

+156
-55
lines changed

Editor/AbilitiesDrawers/BaseAbilityDrawer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
6565
{
6666
var togglePosition = RectLayout.VerticalRect(position, 0);
6767
togglePosition.x += position.width - 22.0f;
68-
var value = ability.Enabled;
68+
var value = ability.IsEnabled;
6969
var newValue = EditorGUI.Toggle(togglePosition, enabledProperty.boolValue);
7070
if(newValue != enabledProperty.boolValue)
7171
{
@@ -79,7 +79,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
7979
enabledProperty.boolValue = newValue;
8080
}
8181
}
82-
82+
8383
foldout[ability] = EditorGUI.Foldout(RectLayout.VerticalRect(position, 0), shouldFoldout, ability.Name);
8484

8585

Runtime/Ability/Ability.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Ability : IAbility
1414
public bool IsActive => _IsActive;
1515
[SerializeField]
1616
private bool _Enabled = true;
17-
public bool Enabled => _Enabled;
17+
public bool IsEnabled => _Enabled;
1818

1919

2020
public event System.Action<IAbility> OnDidActivate;
@@ -24,7 +24,7 @@ public class Ability : IAbility
2424

2525
public void Disable()
2626
{
27-
if(!Enabled)
27+
if(!IsEnabled)
2828
return;
2929
_Enabled = false;
3030
if(Agent == null)
@@ -37,7 +37,7 @@ public void Disable()
3737

3838
public void Enable()
3939
{
40-
if(Enabled)
40+
if(IsEnabled)
4141
return;
4242
_Enabled = true;
4343

@@ -59,24 +59,24 @@ protected virtual void OnStop(StopReason reason) {}
5959

6060
public virtual bool ShouldStopMyselfDueToActivatingAbility(IAbility abilityThatBlocks) => false;
6161

62-
public bool TryToAdd(IAgent agent)
62+
protected virtual bool ShouldBeAddedToAgent(IAgent agent) => true;
63+
protected virtual bool ShouldBeActivated() => true;
64+
65+
bool IAbility.TryToAdd(IAgent agent)
6366
{
6467
if(Agent != null)
6568
return false;
6669
if(agent == null)
6770
return false;
68-
if(!ValidateAgent(agent))
71+
if(!ShouldBeAddedToAgent(agent))
6972
return false;
7073
_Agent = agent;
7174
return true;
7275
}
7376

74-
protected virtual bool ValidateAgent(IAgent agent) => true;
75-
protected virtual bool ShouldBeActivated() => true;
76-
77-
public bool TryToActivate()
77+
bool IAbility.TryToActivate()
7878
{
79-
if(!IsActive && Enabled && Agent != null && ShouldBeActivated())
79+
if(!IsActive && IsEnabled && Agent != null && ShouldBeActivated())
8080
{
8181
_IsActive = true;
8282
OnDidActivate?.Invoke(this);
@@ -92,7 +92,7 @@ public void Stop()
9292

9393
public virtual void Dispose() {}
9494

95-
public void DetachFromAgent()
95+
void IAbility.DetachFromAgent()
9696
{
9797
Stop();
9898
_Agent = null;

Runtime/Ability/Animator/ChangeSpeed.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ChangeSpeed : Ability, IChangeSpeedAbility
1313

1414
public void SetSpeedMultiplier(float multiplier)
1515
{
16-
if(!Enabled)
16+
if(!IsEnabled)
1717
return;
1818
if(!IsActive)
1919
{
@@ -24,7 +24,7 @@ public void SetSpeedMultiplier(float multiplier)
2424
Complete();
2525
}
2626

27-
protected override bool ValidateAgent(IAgent agent)
27+
protected override bool ShouldBeAddedToAgent(IAgent agent)
2828
{
2929
movementProperties = agent.GetProperties<MovementProperties>();
3030
if(movementProperties == null)

Runtime/Ability/Animator/MoveAbility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void SetInputVector(Vector2 input)
7474
Complete();
7575
}
7676

77-
protected override bool ValidateAgent(IAgent agent)
77+
protected override bool ShouldBeAddedToAgent(IAgent agent)
7878
{
7979
animator = agent.GameObject.GetComponent<Animator>();
8080
UpdateHashes();

Runtime/Ability/Animator/StrafeAbility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void SetInput(float value)
5656
Complete();
5757
}
5858

59-
protected override bool ValidateAgent(IAgent agent)
59+
protected override bool ShouldBeAddedToAgent(IAgent agent)
6060
{
6161
animator = agent.GameObject.GetComponent<Animator>();
6262
UpdateHashes();

Runtime/Ability/Generic/FollowAbility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public float UpdateTargetPositionInterval
3333

3434
private object currentScheduledTask = null;
3535

36-
override protected bool ValidateAgent(IAgent agent)
36+
override protected bool ShouldBeAddedToAgent(IAgent agent)
3737
{
3838
goToAbility = agent.GetAbility<IGoToAbility>();
3939

Runtime/Ability/Generic/GoToAbility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class GoToAbility : Ability, IGoToAbility, IUpdate
1212
private IMoveAbility moveAbility;
1313
private NavMeshAgent navMeshAgent;
1414

15-
override protected bool ValidateAgent(IAgent agent)
15+
override protected bool ShouldBeAddedToAgent(IAgent agent)
1616
{
1717
moveAbility = agent.GetAbility<IMoveAbility>();
1818
navMeshAgent = agent.GameObject.GetComponent<NavMeshAgent>();

Runtime/Ability/IAbility.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public enum StopReason
2929
Completion
3030
}
3131

32+
internal interface IInternal {}
33+
3234
public interface IAbility: IDisposable
3335
{
3436
/// <summary>
@@ -65,7 +67,7 @@ public interface IAbility: IDisposable
6567
/// <summary>
6668
/// Tells if this ability can be activated
6769
/// </summary>
68-
bool Enabled { get; }
70+
bool IsEnabled { get; }
6971

7072
/// <summary>
7173
/// Turns on the ability. It does not activate it, it just allows to run.
@@ -102,17 +104,20 @@ public interface IAbility: IDisposable
102104
/// Called when this ability is being added to the agent. It analyzes if the agent contains required components.
103105
/// </summary>
104106
/// <param name="agent">Agent to validate</param>
105-
bool TryToAdd(IAgent agent);
107+
internal bool TryToAdd(IAgent agent);
106108

107-
void DetachFromAgent();
109+
/// <summary>
110+
/// It detaches the ability from the agent. It shouldn't be called directly, only through Agent.RemoveAbility(IAbility ability)
111+
/// </summary>
112+
internal void DetachFromAgent();
108113

109114
/// <summary>
110115
/// Called if someone wants to activate this ability through agent. This ability has to meet following minimal requirements in order to be activated:
111116
/// - It must be enabled. All abilities are disabled upon creation
112117
/// - It must not be activated.
113118
/// - It must be assigned to an agent.
114119
/// </summary>
115-
bool TryToActivate();
120+
internal bool TryToActivate();
116121

117122
/// <summary>
118123
/// It will end the ability with the reason 'Interruption'

Runtime/Ability/Rigidbody/RigidbodyMovement.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class RigidbodyMovement : Ability, IMoveAbility, IFixedUpdate
1414
private float speedMultiplier = 1.0f;
1515
public float SpeedMultiplier { get => speedMultiplier; set => speedMultiplier = value; }
1616

17-
protected override bool ValidateAgent(IAgent agent)
17+
protected override bool ShouldBeAddedToAgent(IAgent agent)
1818
{
1919
rigidbody = agent.GameObject.GetComponent<Rigidbody>();
2020
if(rigidbody == null)
@@ -35,7 +35,7 @@ public void FixedUpdate()
3535
}
3636
rigidbody.AddRelativeForce(new Vector3(inputVector.x, 0.0f, inputVector.y) * 100.0f * speedMultiplier);
3737
inputVector = Vector2.zero;
38-
38+
3939
if(rigidbody.velocity.sqrMagnitude < 0.001f)
4040
_IsActive = false;
4141
}

Runtime/Ability/Rigidbody/RigidbodyRotation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class RigidbodyRotation : Ability, IRotateAbility, IFixedUpdate
1010
private float rotationInput;
1111
private Rigidbody rigidbody;
1212

13-
protected override bool ValidateAgent(IAgent agent)
13+
protected override bool ShouldBeAddedToAgent(IAgent agent)
1414
{
1515
rigidbody = agent.GameObject.GetComponent<Rigidbody>();
1616
if(rigidbody == null)

0 commit comments

Comments
 (0)