浏览代码
Removed ScriptableObjects array from StateMachine. Adjusted test scene. Single line methods now use brackets, properties still use lambda when possible.
Removed ScriptableObjects array from StateMachine. Adjusted test scene. Single line methods now use brackets, properties still use lambda when possible.
Removed the 'override' feature that was implemented as it was adding unnecessary complexity. Adjusted test scene to reflect the changes: - Added `ChaseComponent.cs`. It takes `Transform _target`, `float _speed` and has a `public void Chase()` function that moves the gameObject towards the target. - `ChaseAction` now simply calls `ChaseComponent.Chase()` in its `OnUpdate()`. - `ChaseComponent` also contains a public getter `Target => _target`. - `CloseToTargetCondition` gets `transform` from the `StateMachine` and the transform of the target from `ChaseComponent`, the `Statement()` remains the same. Another way to implement it would be to have a public getter `bool IsCloseToTarget` or `float DistanceToTarget` in `ChaseComponent` and evaluate that in the `Statement`. - Removed `ChaseData.cs`. - How much each sphear eats is now contro.../main
DeivSky
4 年前
当前提交
b7f0951d
共有 20 个文件被更改,包括 211 次插入 和 130 次删除
-
138UOP1_Project/Assets/Scenes/StateMachines.unity
-
2UOP1_Project/Assets/Scripts/StateMachine/Core/StateAction.cs
-
2UOP1_Project/Assets/Scripts/StateMachine/Core/StateCondition.cs
-
34UOP1_Project/Assets/Scripts/StateMachine/Core/StateMachine.cs
-
2UOP1_Project/Assets/Scripts/StateMachine/ScriptableObjects/StateActionSO.cs
-
2UOP1_Project/Assets/Scripts/StateMachine/ScriptableObjects/StateConditionSO.cs
-
4UOP1_Project/Assets/Scripts/StateMachine/ScriptableObjects/StateSO.cs
-
32UOP1_Project/Assets/Scripts/StateMachineTest/ChaseActionSO.cs
-
29UOP1_Project/Assets/Scripts/StateMachineTest/CloseToTargetConditionSO.cs
-
19UOP1_Project/Assets/Scripts/StateMachineTest/EatActionSO.cs
-
2UOP1_Project/Assets/Scripts/StateMachineTest/HungerActionSO.cs
-
17UOP1_Project/Assets/Scripts/StateMachineTest/HungerComponent.cs
-
6UOP1_Project/Assets/Scripts/StateMachineTest/HungerConditionSO.cs
-
15UOP1_Project/Assets/Scripts/StateMachineTest/TimerConditionSO.cs
-
2UOP1_Project/Assets/Scripts/StateMachineTest/ChaseComponent.cs.meta
-
17UOP1_Project/Assets/Scripts/StateMachineTest/ChaseComponent.cs
-
8UOP1_Project/Assets/ScriptableObjects/StateMachinesTest/Data.meta
-
10UOP1_Project/Assets/Scripts/StateMachineTest/ChaseDataSO.cs
-
0/UOP1_Project/Assets/Scripts/StateMachineTest/ChaseComponent.cs.meta
|
|||
using UnityEngine; |
|||
|
|||
public class ChaseComponent : MonoBehaviour |
|||
{ |
|||
[SerializeField] private Transform _target = default; |
|||
[SerializeField] private float _speed = 10f; |
|||
|
|||
public Transform Target => _target; |
|||
|
|||
public void Chase() |
|||
{ |
|||
transform.position = Vector3.MoveTowards( |
|||
transform.position, |
|||
_target.position, |
|||
_speed * Time.deltaTime); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 00e26cdf15cdc1348ac5f6fa154ddb6c |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
[CreateAssetMenu(fileName = "ChaseData", menuName = "State Machines/Tests/Data/Chase Data")] |
|||
public class ChaseDataSO : ScriptableObject |
|||
{ |
|||
[SerializeField] private string _targetName = "Player"; |
|||
[SerializeField] private float _speed = 10f; |
|||
public float Speed => _speed; |
|||
public string TargetName => _targetName; |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue