浏览代码

Use Game States In State Machine

/main
uChema 3 年前
当前提交
1d6b8128
共有 25 个文件被更改,包括 258 次插入40 次删除
  1. 6
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/PlantCritter/PlantCritter_TransitionTable.asset
  2. 6
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/RockCritter/RockCritter_TransitionTable.asset
  3. 2
      UOP1_Project/Assets/Scripts/Dialogues/DialogueManager.cs
  4. 10
      UOP1_Project/Assets/Scripts/Gameplay/GameManager.cs
  5. 4
      UOP1_Project/Assets/Scripts/Gameplay/GameStateSO.cs
  6. 4
      UOP1_Project/Assets/Scripts/Input/InputReader.cs
  7. 24
      UOP1_Project/Assets/Scripts/Quests/StepController.cs
  8. 2
      UOP1_Project/Assets/Scripts/StateMachine/Debugging/StateMachineDebugger.cs
  9. 41
      UOP1_Project/Assets/Scripts/UI/UIManager.cs
  10. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions.meta
  11. 36
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsInParticualGameStateSO.cs
  12. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsInParticualGameStateSO.cs.meta
  13. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInCombatGameState.asset
  14. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInCombatGameState.asset.meta
  15. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInDialogueGameState.asset
  16. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInDialogueGameState.asset.meta
  17. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInGameplayGameState.asset
  18. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInGameplayGameState.asset.meta
  19. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInInventoryGameState.asset
  20. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInInventoryGameState.asset.meta
  21. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInPauseGameState.asset
  22. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInPauseGameState.asset.meta
  23. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInTransitionGameState.asset
  24. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInTransitionGameState.asset.meta

6
UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/PlantCritter/PlantCritter_TransitionTable.asset


- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 3d30788033cfd9d4fa24fa5112d9430c, type: 2}
Operator: 0
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: a8068be10543378448af346b992d58e2, type: 2}
Operator: 0
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 6316a637501d09e48b48b42da59e4410, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 879aebdccfac8334089096e432810559, type: 2}
ToState: {fileID: 11400000, guid: f61658c3057e2714088359f412d8983e, type: 2}
Conditions:

6
UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/RockCritter/RockCritter_TransitionTable.asset


- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 050fbbaa48ac74961952b20dabfd6e88, type: 2}
Operator: 0
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: 6316a637501d09e48b48b42da59e4410, type: 2}
Operator: 0
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: a8068be10543378448af346b992d58e2, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: ea7a8e48b1a87c241bb721da98d1d812, type: 2}
ToState: {fileID: 11400000, guid: 5b0e38103a74c054cb968153b3227b71, type: 2}
Conditions:

2
UOP1_Project/Assets/Scripts/Dialogues/DialogueManager.cs


/// <param name="dialogueDataSO"></param>
public void DisplayDialogueData(DialogueDataSO dialogueDataSO)
{
if (_gameState.CurrentGameState != GameState.Cutscene)
if (_gameState.CurrentGameState != GameState.Cutscene) // the dialogue state is implied in the cutscene state
_gameState.UpdateGameState(GameState.Dialogue);
_counterDialogue = 0;
_counterLine = 0;

10
UOP1_Project/Assets/Scripts/Gameplay/GameManager.cs


}
void AddRockCandyRecipe()
{
Debug.Log("Add rock candy Recipe ");
Debug.Log("Add sweet dough Recipe ");
_inventory.Add(_sweetDoughRecipe);
}

_gameState.UpdateGameState(GameState.Gameplay);
_questManager.StartGame();
}
public void PauseGame()
{
}
public void UnpauseGame()
{
_gameState.ResetToPreviousGameState();
}
}

4
UOP1_Project/Assets/Scripts/Gameplay/GameStateSO.cs


private GameState _previousGameState = default;
public GameState CurrentGameState => _currentGameState;
List<Transform> _enemiesInCombat = new List<Transform>();
private void Awake()
{
_enemiesInCombat = new List<Transform>();
}
public void ChangeStateToCombat(Transform enemy)
{
if (!_enemiesInCombat.Exists(o => o == enemy))

4
UOP1_Project/Assets/Scripts/Input/InputReader.cs


public event UnityAction<float> TabSwitched = delegate { };
private GameInput gameInput;
public GameStateSO gameStateManager;
private void OnEnable()
{
if (gameInput == null)

public void OnInteract(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
if ((context.phase == InputActionPhase.Performed) && (gameStateManager.CurrentGameState == GameState.Gameplay)) // Interaction is only possible when in gameplay GameState
interactEvent.Invoke();
}

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


[SerializeField] private ActorSO _actor = default;
[SerializeField] private DialogueDataSO _defaultDialogue = default;
[SerializeField] private QuestManagerSO _questData = default;
[SerializeField]
private GameStateSO _gameStateManager = default;
[Header("Listening to channels")]
[SerializeField] private DialogueActorChannelSO _interactionEvent = default;

//when interaction again, restart same dialogue.
public void InteractWithCharacter()
{
DialogueDataSO displayDialogue = _questData.InteractWithCharacter(_actor, false, false);
//Debug.Log("dialogue " + displayDialogue + "actor" + _actor);
if (displayDialogue != null)
if (_gameStateManager.CurrentGameState == GameState.Gameplay)
_currentDialogue = displayDialogue;
StartDialogue();
}
else
{
PlayDefaultDialogue();
DialogueDataSO displayDialogue = _questData.InteractWithCharacter(_actor, false, false);
//Debug.Log("dialogue " + displayDialogue + "actor" + _actor);
if (displayDialogue != null)
{
_currentDialogue = displayDialogue;
StartDialogue();
}
else
{
PlayDefaultDialogue();
}
}
}

2
UOP1_Project/Assets/Scripts/StateMachine/Debugging/StateMachineDebugger.cs


_logBuilder.AppendLine();
_logBuilder.Append("--------------------------------");
// Debug.Log(_logBuilder.ToString());
Debug.Log(_logBuilder.ToString());
}
}
}

41
UOP1_Project/Assets/Scripts/UI/UIManager.cs


[SerializeField] private UISettings _settingScreen = default;
[Header("Gameplay Components")]
[SerializeField] private GameStateSO _gameState = default;
[SerializeField] private GameStateSO _gameStateManager = default;
[SerializeField] private MenuSO _mainMenu = default;
[SerializeField] private InputReader _inputReader = default;

_inputReader.menuPauseEvent -= OpenUIPause; // you can open UI pause menu again, if it's closed
// Time.timeScale = 0; // Pause time
Time.timeScale = 0; // Pause time
_pauseScreen.SettingsScreenOpened += OpenSettingScreen;//once the UI Pause popup is open, listen to open Settings
_pauseScreen.BackToMainRequested += ShowBackToMenuConfirmationPopup;//once the UI Pause popup is open, listen to back to menu button

_pauseScreen.gameObject.SetActive(true);
_inputReader.EnableMenuInput();
_gameState.UpdateGameState(GameState.Pause);
_gameStateManager.UpdateGameState(GameState.Pause);
}
void CloseUIPause()

_inputReader.EnableGameplayInput();
_selectionHandler.Unselect();
_gameState.ResetToPreviousGameState();
_gameStateManager.ResetToPreviousGameState();
}
void OpenSettingScreen()

}
void SetInventoryScreenForCooking()
{
isForCooking = true;
OpenInventoryScreen();
if (_gameStateManager.CurrentGameState == GameState.Gameplay)
{
isForCooking = true;
OpenInventoryScreen();
}
isForCooking = false;
OpenInventoryScreen();
if (_gameStateManager.CurrentGameState == GameState.Gameplay)
{
isForCooking = false;
OpenInventoryScreen();
}
_inputReader.menuPauseEvent -= OpenUIPause; // you cant open the UI Pause again when you are in inventory
_inputReader.menuUnpauseEvent -= CloseUIPause; // you can close the UI Pause popup when you are in inventory
_inputReader.menuPauseEvent -= OpenUIPause; // player cant open the UI Pause again when they are in inventory
_inputReader.menuUnpauseEvent -= CloseUIPause; // player can close the UI Pause popup when they are in inventory
_inputReader.closeInventoryEvent += CloseInventoryScreen;
if (isForCooking)
{

_inputReader.EnableMenuInput();
_gameState.UpdateGameState(GameState.Inventory);
_gameStateManager.UpdateGameState(GameState.Inventory);
}
void CloseInventoryScreen()
{

}
_selectionHandler.Unselect();
_inputReader.EnableGameplayInput();
_gameState.ResetToPreviousGameState();
_gameStateManager.ResetToPreviousGameState();
if (isOpenEvent)
if (_gameStateManager.CurrentGameState == GameState.Gameplay)
_interactionPanel.FillInteractionPanel(interactionType);
if (isOpenEvent)
{
_interactionPanel.FillInteractionPanel(interactionType);
}
_interactionPanel.gameObject.SetActive(isOpenEvent);
_interactionPanel.gameObject.SetActive(isOpenEvent);
}

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions.meta


fileFormatVersion: 2
guid: a0a5a32d65cee744c84fd543f34a826b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

36
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsInParticualGameStateSO.cs


using UnityEngine;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(menuName = "State Machines/Conditions/Is In Particular GameState")]
public class IsInParticualGameStateSO : StateConditionSO<IsInParticualGameStateCondition>
{
public GameState _currentGameState;
public GameStateSO _gameStateManager;
protected override Condition CreateCondition() => new IsInParticualGameStateCondition();
}
public class IsInParticualGameStateCondition : Condition
{
private IsInParticualGameStateSO _originSO => (IsInParticualGameStateSO)base.OriginSO; // The SO this Condition spawned from
public override void Awake(StateMachine stateMachine)
{
}
protected override bool Statement()
{
return _originSO._currentGameState == _originSO._gameStateManager.CurrentGameState;
}
private void EventReceived()
{
}
public override void OnStateExit()
{
}
}

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


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

16
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInCombatGameState.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: 7019e587931b79440a550f74f9fffb47, type: 3}
m_Name: IsInCombatGameState
m_EditorClassIdentifier:
_currentGameState: 6
_gameStateManager: {fileID: 11400000, guid: 159f9c22d98e249ceb08f2c5de2311a4, type: 2}

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInCombatGameState.asset.meta


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

16
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInDialogueGameState.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: 7019e587931b79440a550f74f9fffb47, type: 3}
m_Name: IsInDialogueGameState
m_EditorClassIdentifier:
_currentGameState: 3
_gameStateManager: {fileID: 11400000, guid: 159f9c22d98e249ceb08f2c5de2311a4, type: 2}

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInDialogueGameState.asset.meta


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

16
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInGameplayGameState.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: 7019e587931b79440a550f74f9fffb47, type: 3}
m_Name: IsInGameplayGameState
m_EditorClassIdentifier:
_currentGameState: 0
_gameStateManager: {fileID: 11400000, guid: 159f9c22d98e249ceb08f2c5de2311a4, type: 2}

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInGameplayGameState.asset.meta


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

16
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInInventoryGameState.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: 7019e587931b79440a550f74f9fffb47, type: 3}
m_Name: IsInInventoryGameState
m_EditorClassIdentifier:
_currentGameState: 2
_gameStateManager: {fileID: 11400000, guid: 159f9c22d98e249ceb08f2c5de2311a4, type: 2}

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInInventoryGameState.asset.meta


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

16
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInPauseGameState.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: 7019e587931b79440a550f74f9fffb47, type: 3}
m_Name: IsInPauseGameState
m_EditorClassIdentifier:
_currentGameState: 1
_gameStateManager: {fileID: 11400000, guid: 159f9c22d98e249ceb08f2c5de2311a4, type: 2}

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInPauseGameState.asset.meta


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

16
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInTransitionGameState.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: 7019e587931b79440a550f74f9fffb47, type: 3}
m_Name: IsInTransitionGameState
m_EditorClassIdentifier:
_currentGameState: 5
_gameStateManager: {fileID: 11400000, guid: 159f9c22d98e249ceb08f2c5de2311a4, type: 2}

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/GameState/Conditions/IsInTransitionGameState.asset.meta


fileFormatVersion: 2
guid: ea663d109be12284baf599786bb2a172
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存