浏览代码

Removed serializable actions/conditions. Added current state name in state machine component. Added more spheres to test scene.

/main
DeivSky 4 年前
当前提交
32a19461
共有 15 个文件被更改,包括 573 次插入155 次删除
  1. 488
      UOP1_Project/Assets/Scenes/StateMachines.unity
  2. 3
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Actions/Eat.asset
  3. 3
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/AttackDuration.asset
  4. 3
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/EatDuration.asset
  5. 5
      UOP1_Project/Assets/Scripts/StateMachine/Core/StateMachine.cs
  6. 6
      UOP1_Project/Assets/Scripts/StateMachine/Scriptables/ScriptableStateAction.cs
  7. 6
      UOP1_Project/Assets/Scripts/StateMachine/Scriptables/ScriptableStateCondition.cs
  8. 17
      UOP1_Project/Assets/Scripts/StateMachineTest/ScriptableEatAction.cs
  9. 15
      UOP1_Project/Assets/Scripts/StateMachineTest/ScriptableTimedCondition.cs
  10. 129
      UOP1_Project/Assets/Prefabs/Sphere.prefab
  11. 7
      UOP1_Project/Assets/Prefabs/Sphere.prefab.meta
  12. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/AttackDurationOverride.asset
  13. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/AttackDurationOverride.asset.meta
  14. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/EatDurationOverride.asset
  15. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/EatDurationOverride.asset.meta

488
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: 25
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 12.259001}
--- !u!1001 &987108458
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: 30
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 (1)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2ae670cd29a6f4843aa75201aa44ef31, type: 3}
--- !u!1 &1057381576
GameObject:
m_ObjectHideFlags: 0

m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1514199910
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1514199916}
- component: {fileID: 1514199915}
- component: {fileID: 1514199914}
- component: {fileID: 1514199913}
- component: {fileID: 1514199912}
- component: {fileID: 1514199911}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1514199911
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1514199910}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1eeda163c70b3cb4ebb88ba92f608fd8, type: 3}
m_Name:
m_EditorClassIdentifier:
debug: 1
_initialStateSO: {fileID: 11400000, guid: 4b9ef9df9c479aa469d161e9019b218e, type: 2}
_scriptableObjects: []
--- !u!114 &1514199912
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1514199910}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 42ecc2ef8dcbbe4449a3f1d0bb1d04b2, type: 3}
m_Name:
m_EditorClassIdentifier:
_maxFullness: 100
_hungerPerSecond: 10
_isHungryThreshold: 0.4
_currentFullness: 0
--- !u!135 &1514199913
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1514199910}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1514199914
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1514199910}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &1514199915
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1514199910}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1514199916
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1514199910}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.10087514, y: 0.73, z: -15.743169}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 29
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1523164311
GameObject:
m_ObjectHideFlags: 0

m_Father: {fileID: 0}
m_RootOrder: 27
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1531195266
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: -11.646828
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: -35.98156
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: 33
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: 2
objectReference: {fileID: 0}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.data[0]
value:
objectReference: {fileID: 11400000, guid: de18ec8184ba9ec418cfb61f39582a79,
type: 2}
- target: {fileID: 8065985805251957530, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: _scriptableObjects.Array.data[1]
value:
objectReference: {fileID: 11400000, guid: 2af0b23535059f54dbaef36909481aea,
type: 2}
- target: {fileID: 8065985805251957531, guid: 2ae670cd29a6f4843aa75201aa44ef31,
type: 3}
propertyPath: m_Name
value: Sphere (4)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2ae670cd29a6f4843aa75201aa44ef31, type: 3}
--- !u!1 &1559010558
GameObject:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: ac0b09e7857660247b1477e93731de29, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &1926130911
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: 31
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 (2)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2ae670cd29a6f4843aa75201aa44ef31, type: 3}
--- !u!1 &1961065787
GameObject:
m_ObjectHideFlags: 0

objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: fe3004506b4c6cd478eb2cca639b3713, type: 3}
--- !u!1001 &8065985805952354429
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: 9.62
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: -15.743169
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: 29
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
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2ae670cd29a6f4843aa75201aa44ef31, type: 3}

3
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Actions/Eat.asset


m_Script: {fileID: 11500000, guid: 73b2ab05b3639324fa7ee388464d5a23, type: 3}
m_Name: Eat
m_EditorClassIdentifier:
_action:
amount: 40
amount: 40

3
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/AttackDuration.asset


m_Script: {fileID: 11500000, guid: 9ea14bb700bdcb64e9855f6bd0837d08, type: 3}
m_Name: AttackDuration
m_EditorClassIdentifier:
_condition:
_duration: 0.5
Duration: 0.5

3
UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Conditions/EatDuration.asset


m_Script: {fileID: 0}
m_Name: EatDuration
m_EditorClassIdentifier: Assembly-CSharp::ScriptableTimedCondition
_condition:
_duration: 2
Duration: 2

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


public class StateMachine : MonoBehaviour
{
#if UNITY_EDITOR
public string CurrentState;
public bool debug;
#endif
[SerializeField] private Scriptables.ScriptableState _initialStateSO = null;

_scriptableObjectsTypes = GetObjectTypes(_scriptableObjects);
_currentState = _initialStateSO.GetState(this);
_currentState.OnStateEnter();
#if UNITY_EDITOR
CurrentState = _currentState.Name;
#endif
}
private static List<Type> GetObjectTypes(object[] objects)

#if UNITY_EDITOR
if (debug)
Debug.Log($"{name} entering state {_currentState.Name}");
CurrentState = _currentState.Name;
#endif
}
}

6
UOP1_Project/Assets/Scripts/StateMachine/Scriptables/ScriptableStateAction.cs


{
protected override StateAction CreateAction() => new T();
}
public abstract class SerializableStateAction<T> : ScriptableStateAction where T : StateAction, new()
{
[SerializeField] private T _action = new T();
protected override StateAction CreateAction() => _action;
}
}

6
UOP1_Project/Assets/Scripts/StateMachine/Scriptables/ScriptableStateCondition.cs


{
protected override Condition CreateCondition() => new T();
}
public abstract class SerializableStateCondition<T> : ScriptableStateCondition where T : Condition, new()
{
[SerializeField] private T _condition = new T();
protected override Condition CreateCondition() => _condition;
}
}

17
UOP1_Project/Assets/Scripts/StateMachineTest/ScriptableEatAction.cs


using System;
using DeivSky.StateMachine;
using DeivSky.StateMachine;
public class ScriptableEatAction : SerializableStateAction<EatAction> { }
public class ScriptableEatAction : ScriptableStateAction
{
public float amount = 10f;
protected override StateAction CreateAction() => new EatAction(amount);
}
[Serializable]
[SerializeField] private float amount = 10f;
private float _amount = 10f;
public EatAction(float amount) => _amount = amount;
public override void OnStateExit() => _hungerComponent.Eat(amount);
public override void OnStateExit() => _hungerComponent.Eat(_amount);
}

15
UOP1_Project/Assets/Scripts/StateMachineTest/ScriptableTimedCondition.cs


using System;
using DeivSky.StateMachine;
using DeivSky.StateMachine;
public class ScriptableTimedCondition : SerializableStateCondition<TimedCondition> { }
public class ScriptableTimedCondition : ScriptableStateCondition
{
public float Duration = 10f;
protected override Condition CreateCondition() => new TimedCondition(Duration);
}
[Serializable]
[SerializeField] private float _duration = 10f;
private float _duration = 10f;
public TimedCondition(float duration) => _duration = duration;
public override void OnStateEnter() => _time = Time.time + _duration;

129
UOP1_Project/Assets/Prefabs/Sphere.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &8065985805251957531
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8065985805251957521}
- component: {fileID: 8065985805251957526}
- component: {fileID: 8065985805251957527}
- component: {fileID: 8065985805251957524}
- component: {fileID: 8065985805251957525}
- component: {fileID: 8065985805251957530}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8065985805251957521
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8065985805251957531}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 9.62, y: 0.73, z: -15.743169}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &8065985805251957526
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8065985805251957531}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &8065985805251957527
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8065985805251957531}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &8065985805251957524
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8065985805251957531}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &8065985805251957525
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8065985805251957531}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 42ecc2ef8dcbbe4449a3f1d0bb1d04b2, type: 3}
m_Name:
m_EditorClassIdentifier:
_maxFullness: 100
_hungerPerSecond: 10
_isHungryThreshold: 0.4
_currentFullness: 0
--- !u!114 &8065985805251957530
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8065985805251957531}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1eeda163c70b3cb4ebb88ba92f608fd8, type: 3}
m_Name:
m_EditorClassIdentifier:
CurrentState:
debug: 1
_initialStateSO: {fileID: 11400000, guid: 4b9ef9df9c479aa469d161e9019b218e, type: 2}
_scriptableObjects: []

7
UOP1_Project/Assets/Prefabs/Sphere.prefab.meta


fileFormatVersion: 2
guid: 2ae670cd29a6f4843aa75201aa44ef31
PrefabImporter:
externalObjects: {}
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:
正在加载...
取消
保存