-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…tarted FromAnyStateTransitions #8.
- Loading branch information
Showing
20 changed files
with
150 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
Assets/FSMScriptables/Decisions/FSM Decision Is Interested.asset
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
Assets/FSMScriptables/Decisions/FSM Decision Is Interested.asset.meta
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ MonoBehaviour: | |
m_EditorClassIdentifier: | ||
Action: [] | ||
Transitions: [] | ||
RemainState: 0 | ||
RemainState: 1 |
17 changes: 0 additions & 17 deletions
17
Assets/FSMScriptables/Transitions/Done Investigating Object Transition.asset
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
Assets/FSMScriptables/Transitions/Done Investigating Object Transition.asset.meta
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
using UnityEngine; | ||
|
||
public abstract class FSMAction : ScriptableObject | ||
public abstract class FSMAction : ScriptableObject, ISerializationCallbackReceiver | ||
{ | ||
public bool ExecuteOnce = false; | ||
|
||
public bool Executed { get; private set; } = false; | ||
|
||
[System.NonSerialized] | ||
public bool IsExecuted = false; | ||
|
||
public virtual void Execute(FSMCharacter stateMachine) | ||
{ | ||
if (ExecuteOnce) | ||
Executed = true; | ||
IsExecuted = true; | ||
} | ||
|
||
public void SetExecuted(bool isExecuted) | ||
{ | ||
Executed = isExecuted; | ||
IsExecuted = isExecuted; | ||
} | ||
|
||
public void OnAfterDeserialize() | ||
{ | ||
IsExecuted = false; | ||
} | ||
|
||
public void OnBeforeSerialize() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
Assets/Scripts/CharacterAndAI/FSMDecisions/FSMDecisionInterestingInSight.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
using UnityEngine; | ||
using System.Linq; | ||
|
||
[CreateAssetMenu(menuName = "FSM/Decisions/In Line Of Sight")] | ||
public class FSMDecisionInterestingInSight : FSMDecision | ||
[CreateAssetMenu(menuName = "FSM/Decisions/Investigate Interesting Sighted Object")] | ||
public class FSMDecisionInterestingInSight : FSMDecision | ||
{ | ||
public override bool Decide(FSMCharacter stateMachine) | ||
{ | ||
public override bool Decide(FSMCharacter stateMachine) | ||
{ | ||
AISensor enemySightSensor = stateMachine.GetComponent<AISensor>(); | ||
return enemySightSensor.Objects.FirstOrDefault() != null ? true : false; | ||
} | ||
AISensor enemySightSensor = stateMachine.GetComponent<AISensor>(); | ||
|
||
InterestingObject firstInterestingObject = enemySightSensor.Objects.Select(go => go.GetComponent<InterestingObject>()).FirstOrDefault(); | ||
return firstInterestingObject?.IsStillInteresting() ?? false; | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
Assets/Scripts/CharacterAndAI/FSMDecisions/FSMDecisionIsInterested.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
using UnityEngine; | ||
|
||
[CreateAssetMenu(menuName = "FSM/Transition")] | ||
public sealed class FSMTransition : ScriptableObject | ||
public sealed class FSMTransition : ScriptableObject, ISerializationCallbackReceiver | ||
{ | ||
public FSMDecision Decision; | ||
public FSMState TrueState; | ||
public FSMState FalseState; | ||
|
||
[System.NonSerialized] | ||
private FSMState previousState = null; | ||
|
||
public void Execute(FSMCharacter stateMachine) | ||
{ | ||
if (Decision.Decide(stateMachine) && !TrueState.RemainState) | ||
{ | ||
//TrueState and falseState to simply FSMState instead of base state. | ||
// | ||
stateMachine.CurrentState = TrueState; | ||
//Prevent transition to same state | ||
if (TrueState != previousState) | ||
{ | ||
//Reset executed actions when state changes | ||
TrueState.Action.ForEach(action => action.SetExecuted(false)); | ||
previousState = stateMachine.CurrentState = TrueState; | ||
} | ||
} | ||
else if (!FalseState.RemainState) | ||
{ | ||
stateMachine.CurrentState = FalseState; | ||
//Prevent transition to same state | ||
if (FalseState != previousState) | ||
{ | ||
//Reset executed actions when state changes | ||
TrueState.Action.ForEach(action => action.SetExecuted(false)); | ||
previousState = stateMachine.CurrentState = FalseState; | ||
} | ||
} | ||
} | ||
|
||
public void OnAfterDeserialize() | ||
{ | ||
previousState = null; | ||
} | ||
|
||
public void OnBeforeSerialize() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
using UnityEngine; | ||
public class ReadOnlyAttribute : PropertyAttribute | ||
{ | ||
|
||
} | ||
public class ReadOnlyAttribute : PropertyAttribute { } |
Oops, something went wrong.