浏览代码

Merge remote-tracking branch 'treivize/feature/npc-pathway-movement' into main

/devlogs-4-addressable-assets
Amel Negra 4 年前
当前提交
67e5ce82
共有 51 个文件被更改,包括 688 次插入135 次删除
  1. 14
      UOP1_Project/Assets/Prefabs/Characters/SlimeCritter_Base.prefab
  2. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/SlimeRockCritter_TransitionTable.asset
  3. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/States/Roaming.asset
  4. 4
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathWayNavMeshUI.cs
  5. 19
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs
  6. 19
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs
  7. 4
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs
  8. 4
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayNavMesh.cs
  9. 17
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCNotMoving.asset
  10. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCNotMoving.asset.meta
  11. 42
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.asset
  12. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.asset.meta
  13. 19
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCRoamingAroundCenter.asset
  14. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCRoamingAroundCenter.asset.meta
  15. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/SlimeCritterEventChannel.asset
  16. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/SlimeCritterEventChannel.asset.meta
  17. 14
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Actions/NPCMoveToNextDestination.asset
  18. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Actions/NPCMoveToNextDestination.asset.meta
  19. 14
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Conditions/NPCMovementStopElapsed.asset
  20. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Conditions/NPCMovementStopElapsed.asset.meta
  21. 15
      UOP1_Project/Assets/Scripts/Characters/Config/NPCMovementConfigSO.cs
  22. 11
      UOP1_Project/Assets/Scripts/Characters/Config/NPCMovementConfigSO.cs.meta
  23. 56
      UOP1_Project/Assets/Scripts/Characters/Config/PathwayConfigSO.cs
  24. 11
      UOP1_Project/Assets/Scripts/Characters/Config/PathwayConfigSO.cs.meta
  25. 19
      UOP1_Project/Assets/Scripts/Characters/Config/RoamingAroundCenterConfigSO.cs
  26. 11
      UOP1_Project/Assets/Scripts/Characters/Config/RoamingAroundCenterConfigSO.cs.meta
  27. 23
      UOP1_Project/Assets/Scripts/Characters/NPCMovement.cs
  28. 11
      UOP1_Project/Assets/Scripts/Characters/NPCMovement.cs.meta
  29. 8
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions.meta
  30. 62
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/NPCMoveToNextDestinationSO.cs
  31. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/NPCMoveToNextDestinationSO.cs.meta
  32. 27
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/NPCMovementStopConditionSO.cs
  33. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/NPCMovementStopConditionSO.cs.meta
  34. 18
      UOP1_Project/Assets/Scripts/Events/NPCMovementSwitcher.cs
  35. 11
      UOP1_Project/Assets/Scripts/Events/NPCMovementSwitcher.cs.meta
  36. 18
      UOP1_Project/Assets/Scripts/Events/ScriptableObjects/NPCMovementEventChannelSO.cs
  37. 11
      UOP1_Project/Assets/Scripts/Events/ScriptableObjects/NPCMovementEventChannelSO.cs.meta
  38. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/NPCMovementAction.cs
  39. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/NPCMovementAction.cs.meta
  40. 53
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/PathwayMovementAction.cs
  41. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/PathwayMovementAction.cs.meta
  42. 58
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/RoamingMovementAction.cs
  43. 8
      UOP1_Project/Assets/Prefabs/Gameplay/Pathway.meta
  44. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Actions/RoamingAroundSpawningPositionAction.asset
  45. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Actions/RoamingAroundSpawningPositionAction.asset.meta
  46. 68
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/RoamingAroundSpawningPositionActionSO.cs
  47. 8
      UOP1_Project/Assets/Scripts/Pathway.meta
  48. 0
      /UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/RoamingMovementAction.cs.meta

14
UOP1_Project/Assets/Prefabs/Characters/SlimeCritter_Base.prefab


_getHitEffectSO: {fileID: 11400000, guid: efe1f84589f6f1f47a7a10a1a215e843, type: 2}
_mainMeshRenderer: {fileID: 7464116941563462636}
_droppableRewardSO: {fileID: 11400000, guid: 6158158d6ef9a3d47827f7851295bcef, type: 2}
--- !u!114 &4729545407786248701
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8687264390989375961}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ac26da34fd58af544a84bf1977bcc424, type: 3}
m_Name:
m_EditorClassIdentifier:
_npcMovementConfig: {fileID: 11400000, guid: ae318779135f76f4d8c1213cf19d2312, type: 2}
_channel: {fileID: 0}
--- !u!1001 &2135821800440209491
PrefabInstance:
m_ObjectHideFlags: 0

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/SlimeRockCritter_TransitionTable.asset


Condition: {fileID: 11400000, guid: 27c06ead5f7a1ed4d89197fe9a61d0c2, type: 2}
Operator: 0
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 6519cfc02b3c6c34d8607ac0645ef287, type: 2}
Condition: {fileID: 11400000, guid: 7bcf4f38958f2d34b97fee183d1d7c25, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 4b41f0e0e0982384b8f7a718509ea3a9, type: 2}
ToState: {fileID: 11400000, guid: 0fe0dc68c0fc2604ca06ad36d16b1117, type: 2}

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/States/Roaming.asset


m_EditorClassIdentifier:
_actions:
- {fileID: 11400000, guid: 46af8bb2ed6efed4ab26d05dfc1b560f, type: 2}
- {fileID: 11400000, guid: 768de7a24359ece438c9e7cdb6f9670e, type: 2}
- {fileID: 11400000, guid: 976208a7240935042a5f8bbcb0d35914, type: 2}

4
UOP1_Project/Assets/Scripts/Editor/Pathway/PathWayNavMeshUI.cs


public class PathWayNavMeshUI
{
private Pathway _pathway;
private PathwayConfigSO _pathway;
public PathWayNavMeshUI(Pathway pathway)
public PathWayNavMeshUI(PathwayConfigSO pathway)
{
_pathway = pathway;
_pathwayNavMesh = new PathwayNavMesh(pathway);

19
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs


using UnityEditorInternal;
using System.Linq;
[CustomEditor(typeof(Pathway))]
[CustomEditor(typeof(PathwayConfigSO))]
private Pathway _pathway;
private PathwayConfigSO _pathway;
private PathwayHandles _pathwayHandles;
private PathWayNavMeshUI _pathWayNavMeshUI;
private enum LIST_MODIFICATION { ADD, SUPP, DRAG, OTHER };

public void OnSceneGUI()
public void OnSceneGUI(SceneView sceneView)
PathwayGizmos.DrawGizmosSelected(_pathway);
}
public override void OnInspectorGUI()

_reorderableList.DoLayoutList();
_pathWayNavMeshUI.OnInspectorGUI();
Tools.hidden = _pathway.HidePathway;
serializedObject.ApplyModifiedProperties();
}

_reorderableList.onRemoveCallback += RemoveItem;
_reorderableList.onChangedCallback += ListModified;
_reorderableList.onMouseDragCallback += DragItem;
_pathway = (target as Pathway);
_pathway = (target as PathwayConfigSO);
SceneView.duringSceneGui += this.OnSceneGUI;
}
private void OnDisable()

_reorderableList.onRemoveCallback -= RemoveItem;
_reorderableList.onChangedCallback -= ListModified;
_reorderableList.onMouseDragCallback -= DragItem;
_pathway.waypoints = _pathway.Waypoints.Select(x => x.waypoint).ToArray();
SceneView.duringSceneGui -= this.OnSceneGUI;
GUI.Label(rect, Pathway.TITLE_LABEL);
GUI.Label(rect, PathwayConfigSO.TITLE_LABEL);
item.vector3Value = EditorGUI.Vector3Field(rect, Pathway.FIELD_LABEL + index, item.vector3Value);
item.vector3Value = EditorGUI.Vector3Field(rect, PathwayConfigSO.FIELD_LABEL + index, item.vector3Value);
}
private void AddItem(ReorderableList list)

else
{
list.serializedProperty.InsertArrayElementAtIndex(list.serializedProperty.arraySize);
Vector3 previous = _pathway.transform.position;
Vector3 previous = Vector3.zero;
list.serializedProperty.GetArrayElementAtIndex(list.serializedProperty.arraySize - 1).FindPropertyRelative("waypoint").vector3Value = new Vector3(previous.x + 2, previous.y, previous.z + 2);
_indexCurrentModification = list.serializedProperty.arraySize - 1;
}

19
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs


public class PathwayGizmos
{
[DrawGizmo(GizmoType.Selected)]
private static void DrawGizmosSelected(Pathway pathway, GizmoType gizmoType)
public static void DrawGizmosSelected(PathwayConfigSO pathway)
{
if (!pathway.ToggledNavMeshDisplay)
{

}
private static void DrawLabel(Pathway pathway, Vector3 path, int index)
private static void DrawLabel(PathwayConfigSO pathway, Vector3 path, int index)
{
GUIStyle style = new GUIStyle();
Vector3 textHeight = Vector3.up;

Handles.Label(path + textHeight, index.ToString(), style);
}
private static void DrawHandlesPath(Pathway pathway)
private static void DrawHandlesPath(PathwayConfigSO pathway)
{
Handles.color = pathway.LineColor;

}
}
private static void DrawNavMeshPath(Pathway pathway)
private static void DrawNavMeshPath(PathwayConfigSO pathway)
{
Handles.color = pathway.LineColor;

}
}
private static void DrawHitPoints(Pathway pathway)
private static void DrawHitPoints(PathwayConfigSO pathway)
{
if (pathway.DisplayProbes)
{

{
if (pathway.Hits[i])
{
Gizmos.color = new Color(0, 255, 0, 0.5f);
Gizmos.DrawSphere(pathway.Waypoints[i].waypoint, sphereRadius);
Handles.color = new Color(0, 255, 0, 0.1f);
Handles.SphereHandleCap(0, pathway.Waypoints[i].waypoint, Quaternion.identity, sphereRadius, EventType.Repaint);
Gizmos.color = new Color(255, 0, 0, 0.5f);
Gizmos.DrawSphere(pathway.Waypoints[i].waypoint, sphereRadius);
Handles.color = new Color(255, 0, 0, 0.1f);
Handles.SphereHandleCap(0, pathway.Waypoints[i].waypoint, Quaternion.identity, sphereRadius, EventType.Repaint);
}
}
}

4
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs


public class PathwayHandles
{
private Pathway _pathway;
private PathwayConfigSO _pathway;
public PathwayHandles(Pathway pathway)
public PathwayHandles(PathwayConfigSO pathway)
{
_pathway = pathway;
}

4
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayNavMesh.cs


public class PathwayNavMesh
{
private Pathway _pathway;
private PathwayConfigSO _pathway;
public PathwayNavMesh(Pathway pathway)
public PathwayNavMesh(PathwayConfigSO pathway)
{
_pathway = pathway;
_pathway.Hits = new List<bool>();

17
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCNotMoving.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: 76542500a512494489526e9bcfd3a1b8, type: 3}
m_Name: NPCNotMoving
m_EditorClassIdentifier:
_stopDuration: 0
_speed: 0
_waypoints: []

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCNotMoving.asset.meta


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

42
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.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: 76542500a512494489526e9bcfd3a1b8, type: 3}
m_Name: NPCPathwayConfig
m_EditorClassIdentifier:
_stopDuration: 0.5
_speed: 1
_lineColor: {r: 0, g: 0.19270587, b: 1, a: 1}
_textSize: 20
_textColor: {r: 1, g: 1, b: 1, a: 1}
_probeRadius: 5
DisplayProbes: 0
ToggledNavMeshDisplay: 1
RealTimeEnabled: 1
Waypoints:
- waypoint: {x: -12.400441, y: 0.2169903, z: 14.62578}
corners:
- {x: -12.400441, y: 0.2169903, z: 14.62578}
- {x: -10.209248, y: 0.033730388, z: -9.870466}
- waypoint: {x: -10.209248, y: 0.033730388, z: -9.870466}
corners:
- {x: -10.209248, y: 0.033730388, z: -9.870466}
- {x: -4.5, y: 0.033730388, z: -9}
- {x: -0.8999996, y: 0.033730388, z: -8.5}
- {x: 11.389833, y: 0.18379807, z: 0.2561388}
- waypoint: {x: 11.389833, y: 0.18379807, z: 0.2561388}
corners:
- {x: 11.389833, y: 0.18379807, z: 0.2561388}
- {x: 7.3375273, y: 0.2178752, z: 16.793528}
- waypoint: {x: 7.3375273, y: 0.2178752, z: 16.793528}
corners:
- {x: 7.3375273, y: 0.2178752, z: 16.793528}
- {x: -12.400441, y: 0.2169903, z: 14.62578}

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.asset.meta


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

19
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCRoamingAroundCenter.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: 2724eed9fc9a3904b9edc8180dace7f2, type: 3}
m_Name: RoamingAroundCenter
m_EditorClassIdentifier:
_fromSpawningPoint: 1
_customCenter: {x: 0, y: 0, z: 0}
_radius: 0
_speed: 0
_stopDuration: 0

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCRoamingAroundCenter.asset.meta


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

15
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/SlimeCritterEventChannel.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: 0c96b3d50eb64e741a7219a67ca93bdf, type: 3}
m_Name: SlimeCritterEventChannel
m_EditorClassIdentifier:
description:

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/SlimeCritterEventChannel.asset.meta


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

14
UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Actions/NPCMoveToNextDestination.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: 8e27de7dbba554640996a6eaf8778f75, type: 3}
m_Name: NPCMoveToNextDestination
m_EditorClassIdentifier:

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Actions/NPCMoveToNextDestination.asset.meta


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

14
UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Conditions/NPCMovementStopElapsed.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: 8dbbed255c260fd419d891a9bf6025cb, type: 3}
m_Name: NPCMovementStopElapsed
m_EditorClassIdentifier:

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Conditions/NPCMovementStopElapsed.asset.meta


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

15
UOP1_Project/Assets/Scripts/Characters/Config/NPCMovementConfigSO.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Localization;
public class NPCMovementConfigSO : ScriptableObject
{
[Tooltip("Waypoint stop duration")]
[SerializeField] private float _stopDuration;
[Tooltip("Roaming speed")]
[SerializeField] private float _speed;
public float Speed => _speed;
public float StopDuration => _stopDuration;
}

11
UOP1_Project/Assets/Scripts/Characters/Config/NPCMovementConfigSO.cs.meta


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

56
UOP1_Project/Assets/Scripts/Characters/Config/PathwayConfigSO.cs


using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class WaypointData
{
public Vector3 waypoint;
public List<Vector3> corners;
}
[CreateAssetMenu(fileName = "PathwayConfig", menuName = "EntityConfig/Pathway Config")]
public class PathwayConfigSO : NPCMovementConfigSO
{
[HideInInspector]
public List<WaypointData> Waypoints;
#if UNITY_EDITOR
[SerializeField]
private Color _lineColor = Color.black;
[SerializeField, Range(0, 100)]
private int _textSize = 20;
[SerializeField]
private Color _textColor = Color.white;
[SerializeField, Range(0, 100)]
[Tooltip("This function may reduce the frame rate if a large probe radius is specified. To avoid frame rate issues," +
" it is recommended that you specify a max distance of twice the agent height.")]
private float _probeRadius = 3;
[HideInInspector]
public bool DisplayProbes;
[HideInInspector]
public bool ToggledNavMeshDisplay;
private List<Vector3> _path;
private List<bool> _hits;
public const string FIELD_LABEL = "Point ";
public const string TITLE_LABEL = "Waypoints";
public Color LineColor { get => _lineColor; }
public Color TextColor { get => _textColor; }
public int TextSize { get => _textSize; }
public float ProbeRadius { get => _probeRadius; }
public List<Vector3> Path { get => _path; set => _path = value; }
public List<bool> Hits { get => _hits; set => _hits = value; }
public bool RealTimeEnabled;
#endif
}

11
UOP1_Project/Assets/Scripts/Characters/Config/PathwayConfigSO.cs.meta


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

19
UOP1_Project/Assets/Scripts/Characters/Config/RoamingAroundCenterConfigSO.cs


using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "RoamingAroundCenter", menuName = "EntityConfig/Roaming Around Center")]
public class RoamingAroundCenterConfigSO : NPCMovementConfigSO
{
[Tooltip("Is roaming from spwaning center")]
[SerializeField] private bool _fromSpawningPoint = true;
[Tooltip("Custom roaming center")]
[SerializeField] private Vector3 _customCenter;
[Tooltip("Roaming distance from center")]
[SerializeField] private float _radius;
public bool FromSpawningPoint => _fromSpawningPoint;
public Vector3 CustomCenter => _customCenter;
public float Radius => _radius;
}

11
UOP1_Project/Assets/Scripts/Characters/Config/RoamingAroundCenterConfigSO.cs.meta


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

23
UOP1_Project/Assets/Scripts/Characters/NPCMovement.cs


using UnityEngine;
using System.Collections;
public class NPCMovement : MonoBehaviour
{
[SerializeField] NPCMovementConfigSO _npcMovementConfig;
[SerializeField] NPCMovementEventChannelSO _channel;
public NPCMovementConfigSO NPCMovementConfig => _npcMovementConfig;
private void OnEnable()
{
if (_channel != null)
_channel.OnEventRaised += Respond;
}
private void Respond(NPCMovementConfigSO value)
{
_npcMovementConfig = value;
}
}

11
UOP1_Project/Assets/Scripts/Characters/NPCMovement.cs.meta


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

8
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions.meta


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

62
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/NPCMoveToNextDestinationSO.cs


using UnityEngine;
using UnityEngine.AI;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "NPCMoveToNextDestination", menuName = "State Machines/Actions/NPC Move To Next Destination")]
public class NPCMoveToNextDestinationSO : StateActionSO
{
protected override StateAction CreateAction() => new NPCMoveToNextDestination();
}
public class NPCMoveToNextDestination : StateAction
{
private NPCMovement _npcMovement;
private NPCMovementConfigSO _config;
private NPCMovementAction _action;
private NavMeshAgent _agent;
public override void Awake(StateMachine stateMachine)
{
_agent = stateMachine.GetComponent<NavMeshAgent>();
_npcMovement = stateMachine.GetComponent<NPCMovement>();
InitMovementStrategy(_npcMovement.NPCMovementConfig);
}
public override void OnStateEnter()
{
if (_config != _npcMovement.NPCMovementConfig)
{
InitMovementStrategy(_npcMovement.NPCMovementConfig);
}
_action.OnStateEnter();
}
public override void OnUpdate()
{
_action.OnUpdate();
}
public override void OnStateExit()
{
_action.OnStateExit();
}
private void InitMovementStrategy(NPCMovementConfigSO config)
{
_config = config;
if (_npcMovement.NPCMovementConfig is RoamingAroundCenterConfigSO)
{
_action = new RoamingMovementAction(
(RoamingAroundCenterConfigSO)_npcMovement.NPCMovementConfig,
_agent,
_npcMovement.transform.position);
}
else if (_npcMovement.NPCMovementConfig is PathwayConfigSO)
{
_action = new PathwayMovementAction(
(PathwayConfigSO)_npcMovement.NPCMovementConfig,
_agent);
}
}
}

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


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

27
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/NPCMovementStopConditionSO.cs


using UnityEngine;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(menuName = "State Machines/Conditions/NPC Movement Stop Elapsed")]
public class NPCMovementStopConditionSO : StateConditionSO<NPCMovementStopCondition>
{
}
public class NPCMovementStopCondition : Condition
{
private float _startTime;
private NPCMovement _npcMovement;
public override void Awake(StateMachine stateMachine)
{
_npcMovement = stateMachine.GetComponent<NPCMovement>();
}
public override void OnStateEnter()
{
_startTime = Time.time;
}
protected override bool Statement() => Time.time >= _startTime + _npcMovement.NPCMovementConfig.StopDuration;
}

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


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

18
UOP1_Project/Assets/Scripts/Events/NPCMovementSwitcher.cs


using UnityEngine;
using System.Collections;
public class NPCMovementSwitcher : MonoBehaviour
{
[SerializeField] private NPCMovementEventChannelSO _movementChannel;
[SerializeField] private NPCMovementConfigSO _movementConfig;
[ContextMenu("Trigger NPC Movement switch")]
public void SwitchMovement()
{
if (_movementChannel != null && _movementConfig != null)
{
_movementChannel.RaiseEvent(_movementConfig);
}
}
}

11
UOP1_Project/Assets/Scripts/Events/NPCMovementSwitcher.cs.meta


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

18
UOP1_Project/Assets/Scripts/Events/ScriptableObjects/NPCMovementEventChannelSO.cs


using UnityEngine.Events;
using UnityEngine;
/// <summary>
/// This class is used for Events that have one NPCMovementConfigSO argument.
/// </summary>
[CreateAssetMenu(menuName = "Events/NPC Movement Event Channel")]
public class NPCMovementEventChannelSO : EventChannelBaseSO
{
public UnityAction<NPCMovementConfigSO> OnEventRaised;
public void RaiseEvent(NPCMovementConfigSO value)
{
if (OnEventRaised != null)
OnEventRaised.Invoke(value);
}
}

11
UOP1_Project/Assets/Scripts/Events/ScriptableObjects/NPCMovementEventChannelSO.cs.meta


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

11
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/NPCMovementAction.cs


using UnityEngine;
using System.Collections;
public abstract class NPCMovementAction
{
public abstract void OnUpdate();
public abstract void OnStateEnter();
public abstract void OnStateExit();
}

11
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/NPCMovementAction.cs.meta


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

53
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/PathwayMovementAction.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class PathwayMovementAction : NPCMovementAction
{
private NavMeshAgent _agent;
private bool _isActiveAgent;
private List<WaypointData> _wayppoints;
private int _wayPointIndex;
private float _roamingSpeed;
public PathwayMovementAction(
PathwayConfigSO config, NavMeshAgent agent)
{
_agent = agent;
_isActiveAgent = _agent != null && _agent.isActiveAndEnabled && _agent.isOnNavMesh;
_wayPointIndex = 0;
_roamingSpeed = config.Speed;
_wayppoints = config.Waypoints;
}
public override void OnUpdate()
{
}
public override void OnStateEnter()
{
if (_isActiveAgent)
{
_agent.speed = _roamingSpeed;
_agent.isStopped = false;
_agent.SetDestination(GetNextDestination());
}
}
public override void OnStateExit()
{
}
private Vector3 GetNextDestination()
{
Vector3 result = _agent.transform.position;
if (_wayppoints.Count > 0)
{
_wayPointIndex = (_wayPointIndex + 1) % _wayppoints.Count;
result = _wayppoints[_wayPointIndex].waypoint;
}
return result;
}
}

11
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/PathwayMovementAction.cs.meta


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

58
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/RoamingMovementAction.cs


using UnityEngine;
using UnityEngine.AI;
public class RoamingMovementAction : NPCMovementAction
{
private NavMeshAgent _agent;
private bool _isActiveAgent;
private Vector3 _startPosition;
private float _roamingSpeed;
private float _roamingDistance;
private Vector3 _roamingTargetPosition;
public RoamingMovementAction(
RoamingAroundCenterConfigSO config, NavMeshAgent agent, Vector3 startPosition)
{
_agent = agent;
_isActiveAgent = _agent != null && _agent.isActiveAndEnabled && _agent.isOnNavMesh;
if (config.FromSpawningPoint)
{
_startPosition = startPosition;
}
else
{
_startPosition = config.CustomCenter;
}
_roamingSpeed = config.Speed;
_roamingDistance = config.Radius;
}
public override void OnUpdate()
{
}
public override void OnStateEnter()
{
if (_isActiveAgent)
{
_roamingTargetPosition = GetRoamingPositionAroundPosition(_startPosition);
_agent.speed = _roamingSpeed;
_agent.isStopped = false;
_agent.SetDestination(_roamingTargetPosition);
}
}
public override void OnStateExit()
{
}
// Compute a random target position around the starting position.
private Vector3 GetRoamingPositionAroundPosition(Vector3 position)
{
return position + new Vector3(Random.Range(-1, 1), 0.0f, Random.Range(-1, 1)).normalized * Random.Range(_roamingDistance / 2, _roamingDistance);
}
}

8
UOP1_Project/Assets/Prefabs/Gameplay/Pathway.meta


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

16
UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Actions/RoamingAroundSpawningPositionAction.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: a65678f74cbc33e45bf1e019ca88652e, type: 3}
m_Name: RoamingAroundSpawningPositionAction
m_EditorClassIdentifier:
_roamingSpeed: 1
_roamingDistance: 10

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Critters/SlimeRockCritter/Actions/RoamingAroundSpawningPositionAction.asset.meta


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

68
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/RoamingAroundSpawningPositionActionSO.cs


using UnityEngine;
using UnityEngine.AI;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "RoamingAroundSpawningPositionAction", menuName = "State Machines/Actions/Roaming Around Spawning Position Action")]
public class RoamingAroundSpawningPositionActionSO : StateActionSO
{
[Tooltip("NPC roaming speed.")]
[SerializeField] private float _roamingSpeed = default;
[Tooltip("How far the NPC can roam around its spawning point.")]
[SerializeField] private float _roamingDistance = default;
public float RoamingSpeed => _roamingSpeed;
public float RoamingDistance => _roamingDistance;
protected override StateAction CreateAction() => new RoamingAroundSpawningPositionAction();
}
public class RoamingAroundSpawningPositionAction : StateAction
{
private NavMeshAgent _agent;
private bool _isActiveAgent;
private Vector3 _startPosition;
private float _roamingSpeed;
private float _roamingDistance;
private Vector3 _roamingTargetPosition;
public override void Awake(StateMachine stateMachine)
{
RoamingAroundSpawningPositionActionSO config = (RoamingAroundSpawningPositionActionSO)OriginSO;
_agent = stateMachine.gameObject.GetComponent<NavMeshAgent>();
_isActiveAgent = _agent != null && _agent.isActiveAndEnabled && _agent.isOnNavMesh;
_startPosition = stateMachine.gameObject.transform.position;
_roamingSpeed = config.RoamingSpeed;
_roamingDistance = config.RoamingDistance;
}
public override void OnUpdate()
{
}
public override void OnStateEnter()
{
if (_isActiveAgent)
{
_roamingTargetPosition = GetRoamingPositionAroundPosition(_startPosition);
_agent.speed = _roamingSpeed;
_agent.isStopped = false;
_agent.SetDestination(_roamingTargetPosition);
}
}
public override void OnStateExit()
{
}
// Compute a random target position around the starting position.
private Vector3 GetRoamingPositionAroundPosition(Vector3 position)
{
return position + new Vector3(Random.Range(-1, 1), 0.0f, Random.Range(-1, 1)).normalized * Random.Range(_roamingDistance / 2, _roamingDistance);
}
}

8
UOP1_Project/Assets/Scripts/Pathway.meta


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

/UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/RoamingAroundSpawningPositionActionSO.cs.meta → /UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/RoamingMovementAction.cs.meta

正在加载...
取消
保存