浏览代码

Townsfolk state machine V1

/main
Amel 3 年前
当前提交
e5e6a42e
共有 18 个文件被更改,包括 13 次插入218 次删除
  1. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/States/TalkToProtagonist.asset
  2. 7
      UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Townsfolk/Townsfolk_TransitionTable.asset
  3. 13
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/PigChef_TransitionTable.asset
  4. 2
      UOP1_Project/Assets/Scripts/Characters/NPC.cs
  5. 16
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsNPCSayingTheLineSO.cs
  6. 1
      UOP1_Project/Assets/Scripts/Quests/StepController.cs
  7. 14
      UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Actions/SetLineSaid.asset
  8. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Actions/SetLineSaid.asset.meta
  9. 14
      UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Conditions/HasTheLineBeenSaid.asset
  10. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Conditions/HasTheLineBeenSaid.asset.meta
  11. 14
      UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Townsfolk/Conditions/IsPathReady.asset
  12. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Townsfolk/Conditions/IsPathReady.asset.meta
  13. 32
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/SetLineSaidSO.cs
  14. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/SetLineSaidSO.cs.meta
  15. 26
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsPathReadySO.cs
  16. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsPathReadySO.cs.meta
  17. 33
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/HasTheLineBeenSaidSO.cs
  18. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/HasTheLineBeenSaidSO.cs.meta

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/States/TalkToProtagonist.asset


m_Name: TalkToProtagonist
m_EditorClassIdentifier:
_actions:
- {fileID: 11400000, guid: 03153937dd23e9c4098ad347cab2eaef, type: 2}
- {fileID: 11400000, guid: be8f6701fa4f0db45ad7ae715ac49230, type: 2}

7
UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Townsfolk/Townsfolk_TransitionTable.asset


- FromState: {fileID: 11400000, guid: 3388e91c73e51e845a78aa522a2f2bda, type: 2}
ToState: {fileID: 11400000, guid: b815b7da412ff164abfb213e11d27ace, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 5ef92fc56785ca244a1415862e4e8e6e, type: 2}
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 4f15fe7b4afb565469f360b403d50f64, type: 2}
Operator: 1
- FromState: {fileID: 11400000, guid: b815b7da412ff164abfb213e11d27ace, type: 2}
ToState: {fileID: 11400000, guid: 3388e91c73e51e845a78aa522a2f2bda, type: 2}

Operator: 0
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: d69fc1702147f7640be8b4c4c88cac42, type: 2}
Operator: 1
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: f4c89ffbe6ca8fe46ae22ec9d191671a, type: 2}

13
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/PigChef_TransitionTable.asset


- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 050fbbaa48ac74961952b20dabfd6e88, type: 2}
Operator: 0
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 4f15fe7b4afb565469f360b403d50f64, type: 2}
Operator: 0
Condition: {fileID: 11400000, guid: 2bfa25e0277246b4ba0ea0117c40c18b, type: 2}
Operator: 1
Condition: {fileID: 11400000, guid: 050fbbaa48ac74961952b20dabfd6e88, type: 2}
Operator: 0
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 4f15fe7b4afb565469f360b403d50f64, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 614eeb7e93a91a949b3d833d68f347e5, type: 2}
ToState: {fileID: 11400000, guid: ff92a93d8a8694247b507d811c88e402, type: 2}
Conditions:

- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 4f15fe7b4afb565469f360b403d50f64, type: 2}
Operator: 0

2
UOP1_Project/Assets/Scripts/Characters/NPC.cs


{
public NPCState npcState; //This is checked by conditions in the StateMachine
public GameObject[] talkingTo;
public bool hasSaidLine=false;
}

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


private DialogueLineChannelSO _sayLineEvent;
private ActorSO _protagonistActor;
private bool _isNPCSayingTheLine = false;
private NPC _npcScript;
public IsNPCSayingTheLineCondition(DialogueLineChannelSO sayLineEvent, ActorSO protagonistActor)
{

public override void Awake(StateMachine stateMachine)
{
_npcScript = stateMachine.GetComponent<NPC>();
}
protected override bool Statement()
{

private void OnLineDisplayed(LocalizedString line, ActorSO actor)
{
//why is it not possible to do this from here?
SetTheLineToNotSaidYet();
if (actor.ActorName == _protagonistActor.ActorName)
{
_isNPCSayingTheLine = false;

_isNPCSayingTheLine = true;
}
}
private void SetTheLineToNotSaidYet()
{
_npcScript.hasSaidLine = false;
}
}

1
UOP1_Project/Assets/Scripts/Quests/StepController.cs


_winDialogueEvent.OnEventRaised += PlayWinDialogue;
_loseDialogueEvent.OnEventRaised += PlayLoseDialogue;
isInDialogue = true;
gameObject.GetComponent<NPC>().hasSaidLine = false;
}
void EndDialogue()
{

14
UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Actions/SetLineSaid.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: f4aac5d3cf204b74eb6305752b714f1f, type: 3}
m_Name: SetLineSaid
m_EditorClassIdentifier:

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Actions/SetLineSaid.asset.meta


fileFormatVersion: 2
guid: be8f6701fa4f0db45ad7ae715ac49230
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

14
UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Conditions/HasTheLineBeenSaid.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: dd262779da1c69e43856cadf0825800f, type: 3}
m_Name: HasTheLineBeenSaid
m_EditorClassIdentifier:

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Conditions/HasTheLineBeenSaid.asset.meta


fileFormatVersion: 2
guid: d69fc1702147f7640be8b4c4c88cac42
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

14
UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Townsfolk/Conditions/IsPathReady.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: d7d71e8bf881dee488a5491b967c81e1, type: 3}
m_Name: IsPathReady
m_EditorClassIdentifier:

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/NPC/Townsfolk/Conditions/IsPathReady.asset.meta


fileFormatVersion: 2
guid: 52996c38026c9e64da04a61709439cee
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

32
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/SetLineSaidSO.cs


using UnityEngine;
using UnityEngine.AI;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "SetLineSaidToTrue", menuName = "State Machines/Actions/Set Line Said To True SO")]
public class SetLineSaidSO : StateActionSO
{
protected override StateAction CreateAction() => new SetLineSaid();
}
public class SetLineSaid : StateAction
{
private NPC _npcScript;
public override void Awake(StateMachine stateMachine)
{
_npcScript = stateMachine.gameObject.GetComponent<NPC>();
}
public override void OnUpdate()
{
}
public override void OnStateExit()
{
_npcScript.hasSaidLine = true;
}
}

11
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/SetLineSaidSO.cs.meta


fileFormatVersion: 2
guid: f4aac5d3cf204b74eb6305752b714f1f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

26
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsPathReadySO.cs


using UnityEngine;
using UnityEngine.AI;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "IsPathReady", menuName = "State Machines/Conditions/Is Path Ready")]
public class IsPathReadySO : StateConditionSO
{
protected override Condition CreateCondition() => new IsPathReady();
}
public class IsPathReady : Condition
{
private NavMeshAgent _agent;
public override void Awake(StateMachine stateMachine)
{
_agent = stateMachine.gameObject.GetComponent<NavMeshAgent>();
}
protected override bool Statement()
{
return _agent.pathPending;
}
}

11
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsPathReadySO.cs.meta


fileFormatVersion: 2
guid: d7d71e8bf881dee488a5491b967c81e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

33
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/HasTheLineBeenSaidSO.cs


using UnityEngine;
using UnityEngine.Localization;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "HasTheLineBeenSaid", menuName = "State Machines/Conditions/Has The Line Been Said")]
public class HasTheLineBeenSaidSO : StateConditionSO<HasTheLineBeenSaidCondition> { }
public class HasTheLineBeenSaidCondition : Condition
{
//Component references
private NPC _npcScript;
public override void Awake(StateMachine stateMachine)
{
_npcScript = stateMachine.GetComponent<NPC>();
}
protected override bool Statement()
{
if (_npcScript.hasSaidLine)
{
return true;
}
else
{
return false;
}
}
}

11
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/HasTheLineBeenSaidSO.cs.meta


fileFormatVersion: 2
guid: dd262779da1c69e43856cadf0825800f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存