浏览代码

Adjusted test scene. Renamed StateAction.Perform() to OnUpdate(). Added a couple of Tooltips and comments.

The test scene was adjusted to display how to override the behaviour of the Spheres by attatching a different `ChaseDataSO` to the `StateMachine`, specifying a different target.
Tooltips and comments were added to try to explain the workflow of overriding Action and Condition data.
/main
DeivSky 4 年前
当前提交
b89a8e11
共有 18 个文件被更改,包括 421 次插入140 次删除
  1. 428
      UOP1_Project/Assets/Scenes/StateMachines.unity
  2. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data/ChaseData.asset
  3. 3
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/States/Attacking.asset
  4. 2
      UOP1_Project/Assets/Scripts/StateMachine/Core/State.cs
  5. 8
      UOP1_Project/Assets/Scripts/StateMachine/Core/StateAction.cs
  6. 4
      UOP1_Project/Assets/Scripts/StateMachine/Core/StateCondition.cs
  7. 13
      UOP1_Project/Assets/Scripts/StateMachine/Core/StateMachine.cs
  8. 3
      UOP1_Project/Assets/Scripts/StateMachineTest/ChaseActionSO.cs
  9. 2
      UOP1_Project/Assets/Scripts/StateMachineTest/EatActionSO.cs
  10. 2
      UOP1_Project/Assets/Scripts/StateMachineTest/HungerActionSO.cs
  11. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data/ChaseData 1.asset
  12. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data/ChaseData 1.asset.meta
  13. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data/ChaseData 2.asset
  14. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data/ChaseData 2.asset.meta
  15. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/AttackDurationOverride.asset
  16. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/AttackDurationOverride.asset.meta
  17. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/EatDurationOverride.asset
  18. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/EatDurationOverride.asset.meta

428
UOP1_Project/Assets/Scenes/StateMachines.unity


m_Father: {fileID: 0}
m_RootOrder: 13
m_LocalEulerAnglesHint: {x: -3.5180001, y: 26.323002, z: -19.474}
--- !u!1001 &328964990
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalPosition.x
value: -23.929703
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalPosition.z
value: -16.00095
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_RootOrder
value: 32
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957531, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_Name
value: Sphere (3)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2ae670cd29a6f4843aa75201aa44ef31, type: 3}
--- !u!1 &353533559
GameObject:
m_ObjectHideFlags: 0

m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &557383924
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalPosition.x
value: 3.58
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.73
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalPosition.z
value: -32.29
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_RootOrder
value: 36
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957525, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _maxFullness
value: 50
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957525, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _hungerPerSecond
value: 4
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957525, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _isHungryThreshold
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.data[0]
value:
objectReference: {fileID: 11400000, guid: ca8b5f6d1a6a0474d9ce887a85bc0d2b,
type: 2}
- target: {fileID: 8065985805251957531, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_Name
value: Sphere (5)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2ae670cd29a6f4843aa75201aa44ef31, type: 3}
--- !u!1001 &659246790
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 211818859182309264, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: gameplayCamera
value:
objectReference: {fileID: 1961065790}
- target: {fileID: 3341179906418240709, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_Name
value: Pig (1)
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalPosition.x
value: -8.85
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalPosition.z
value: -15.732899
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_RootOrder
value: 29
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0fa393e1e37bc9e4e829c25a9452bcd3, type: 3}
--- !u!1 &695792052
GameObject:
m_ObjectHideFlags: 0

- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_RootOrder
value: 30
value: 32
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}

propertyPath: _isHungryThreshold
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.data[0]
value:
objectReference: {fileID: 11400000, guid: ca8b5f6d1a6a0474d9ce887a85bc0d2b,
type: 2}
- target: {fileID: 8065985805251957531, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_Name

m_Father: {fileID: 1502793902}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1184947906
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalPosition.x
value: 15.239536
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalPosition.z
value: -25.260427
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_RootOrder
value: 35
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.data[0]
value:
objectReference: {fileID: 11400000, guid: cd6e687e4cd39c64f94866ef95aacf5b,
type: 2}
- target: {fileID: 8065985805251957531, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_Name
value: Sphere (3)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2ae670cd29a6f4843aa75201aa44ef31, type: 3}
--- !u!1001 &1259640866
PrefabInstance:
m_ObjectHideFlags: 0

m_Father: {fileID: 0}
m_RootOrder: 22
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1502309802
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 211818859182309264, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: gameplayCamera
value:
objectReference: {fileID: 1961065790}
- target: {fileID: 3341179906418240709, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_Name
value: Pig (2)
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalPosition.x
value: -6.01
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalPosition.z
value: -15.732899
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_RootOrder
value: 30
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0fa393e1e37bc9e4e829c25a9452bcd3, type: 3}
--- !u!1 &1502793900
GameObject:
m_ObjectHideFlags: 0

- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_RootOrder
value: 33
value: 34
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}

- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.size
value: 2
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}

- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_RootOrder
value: 31
value: 33
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}

propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.data[0]
value:
objectReference: {fileID: 11400000, guid: cd6e687e4cd39c64f94866ef95aacf5b,
type: 2}
- target: {fileID: 8065985805251957531, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_Name

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1961065787}
m_LocalRotation: {x: 0.17952348, y: -0.3484549, z: 0.068184994, w: 0.91744286}
m_LocalRotation: {x: 0.17952347, y: -0.3484549, z: 0.068184994, w: 0.91744286}
m_LocalPosition: {x: 3.213417, y: 6, z: -23.211498}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2049112419}
m_LocalRotation: {x: 0.17952348, y: -0.3484549, z: 0.068184994, w: 0.9174428}
m_LocalRotation: {x: 0.17952347, y: -0.3484549, z: 0.068184994, w: 0.91744286}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_RootOrder
value: 29
value: 31
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957521, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}

2
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data/ChaseData.asset


m_Name: ChaseData
m_EditorClassIdentifier:
_targetName: Pig
_speed: 10
_speed: 8

3
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/States/Attacking.asset


m_Script: {fileID: 11500000, guid: 35432205b9a6a374bbbfe6b7cac92179, type: 3}
m_Name: Attacking
m_EditorClassIdentifier:
_actions:
- {fileID: 11400000, guid: 9ef29c5745eb46d47ba489ac9c524458, type: 2}
_actions: []
_transitions:
- {fileID: 11400000, guid: d6ac2d312106c3e408f440b6513dbbfb, type: 2}

2
UOP1_Project/Assets/Scripts/StateMachine/Core/State.cs


public void OnUpdate()
{
for (int i = 0; i < _actions.Length; i++)
_actions[i].Perform();
_actions[i].OnUpdate();
}
public void OnStateExit()

8
UOP1_Project/Assets/Scripts/StateMachine/Core/StateAction.cs


public abstract class StateAction : IStateComponent
{
/// <summary>
/// Perform the action this object represents.
/// Called every frame the <see cref="StateMachine"/> is in a <see cref="State"/> with this <see cref="StateAction"/>.
public abstract void Perform();
public abstract void OnUpdate();
/// <param name="stateMachine">The state machine this instance belongs to.</param>
/// <param name="stateMachine">The <see cref="StateMachine"/> this instance belongs to.</param>
/// <remarks>To allow overriding any default behaviour set internally or through the inspector, <see cref="StateMachine.TryGetScriptableObject{T}(out T)"/> can be used, overriding if T was found.
/// Make sure to specify the expected type of T and what exactly would get overrriden by it.</remarks>
public virtual void Awake(StateMachine stateMachine) { }
public virtual void OnStateEnter() { }

4
UOP1_Project/Assets/Scripts/StateMachine/Core/StateCondition.cs


/// <summary>
/// Awake is called when creating a new instance. Use this method to cache the components needed for the condition.
/// </summary>
/// <param name="stateMachine">The state machine this instance belongs to.</param>
/// <param name="stateMachine">The <see cref="StateMachine"/> this instance belongs to.</param>
/// <remarks>To allow overriding any default behaviour set internally or through the inspector, <see cref="StateMachine.TryGetScriptableObject{T}(out T)"/> can be used, overriding if T was found.
/// Make sure to specify the expected type of T and what exactly would get overrriden by it.</remarks>
public virtual void Awake(StateMachine stateMachine) { }
public virtual void OnStateEnter() { }
public virtual void OnStateExit() { }

13
UOP1_Project/Assets/Scripts/StateMachine/Core/StateMachine.cs


public string CurrentState;
public bool debug;
#endif
[Tooltip("Set the initial state of this StateMachine")]
[Space][Tooltip("Certain Actions and Conditions allow overriding their default behaviour through the use of ScriptableObjects. Place the SOs here so they can be accessed.")]
protected void Awake()
private void Awake()
{
_scriptableObjectsTypes = GetObjectTypes(_scriptableObjects);
_currentState = _initialStateSO.GetState(this);

public new T GetComponent<T>() where T : Component
=> TryGetComponent(out T component) ? component : throw new InvalidOperationException($"{typeof(T).Name} not found in {name}.");
protected void Update()
private void Update()
{
if (_currentState.TryGetTransition(out var transitionState))
Transition(transitionState);

CurrentState = _currentState.Name;
#endif
}
}
public abstract class StateMachine<T> : StateMachine
{
public abstract T GetContext();
}
}

3
UOP1_Project/Assets/Scripts/StateMachineTest/ChaseActionSO.cs


[CreateAssetMenu(fileName = "Chase", menuName = "State Machines/Tests/Actions/Chase")]
public class ChaseActionSO : StateActionSO
{
[Tooltip("Object that specifies the speed and the target to chase. This can be overriden in the StateMachine.")]
[SerializeField] private ChaseDataSO _chaseData = null;
protected override StateAction CreateAction() => new ChaseAction(_chaseData);

_chaseTransform = GameObject.Find(_chaseData.TargetName).transform;
}
public override void Perform()
public override void OnUpdate()
{
_transform.position = Vector3.MoveTowards(
_transform.position,

2
UOP1_Project/Assets/Scripts/StateMachineTest/EatActionSO.cs


public override void Awake(StateMachine stateMachine)
=> _hungerComponent = stateMachine.GetComponent<HungerComponent>();
public override void Perform() { }
public override void OnUpdate() { }
public override void OnStateExit() => _hungerComponent.Eat(_amount);
}

2
UOP1_Project/Assets/Scripts/StateMachineTest/HungerActionSO.cs


public override void Awake(StateMachine stateMachine)
=> _hungerComponent = stateMachine.GetComponent<HungerComponent>();
public override void Perform() { }
public override void OnUpdate() { }
public override void OnStateEnter() => _hungerComponent.ToggleHunger(true);
public override void OnStateExit() => _hungerComponent.ToggleHunger(false);

16
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data/ChaseData 1.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: e566d72e94cd1744d9ca5a211685aeda, type: 3}
m_Name: ChaseData 1
m_EditorClassIdentifier:
_targetName: Pig (2)
_speed: 8

8
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data/ChaseData 1.asset.meta


fileFormatVersion: 2
guid: cd6e687e4cd39c64f94866ef95aacf5b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

16
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data/ChaseData 2.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: e566d72e94cd1744d9ca5a211685aeda, type: 3}
m_Name: ChaseData 2
m_EditorClassIdentifier:
_targetName: Pig (1)
_speed: 8

8
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data/ChaseData 2.asset.meta


fileFormatVersion: 2
guid: ca8b5f6d1a6a0474d9ce887a85bc0d2b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/AttackDurationOverride.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: 9ea14bb700bdcb64e9855f6bd0837d08, type: 3}
m_Name: AttackDurationOverride
m_EditorClassIdentifier:
Duration: 0.2

8
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/AttackDurationOverride.asset.meta


fileFormatVersion: 2
guid: de18ec8184ba9ec418cfb61f39582a79
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/EatDurationOverride.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: 9ea14bb700bdcb64e9855f6bd0837d08, type: 3}
m_Name: EatDurationOverride
m_EditorClassIdentifier:
Duration: 3

8
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/EatDurationOverride.asset.meta


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