lab3 dop
This commit is contained in:
1 parent
854835878c
commit
fd3a472348
8 files changed
+1739
-2
No files matched your search
@@ -0,0 +1,170 @@
|
||||
using Code.Base;
|
||||
using Code.Lab1;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Lab3
|
||||
{
|
||||
public class BetterPathFollower : Seek
|
||||
{
|
||||
public Path path;
|
||||
private List<Vector3> _waypoints;
|
||||
private int _currentTargetIndex = -1;
|
||||
private List<int> _visitedIndices;
|
||||
private bool _reachedLastPoint;
|
||||
|
||||
public override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
target = new GameObject("BetterPathFollower_Target");
|
||||
_visitedIndices = new List<int>();
|
||||
InitializeWaypoints();
|
||||
}
|
||||
|
||||
private void InitializeWaypoints()
|
||||
{
|
||||
if (path == null || path.nodes == null || path.nodes.Count == 0) return;
|
||||
|
||||
_waypoints = path.nodes.Select(node => node.transform.position).ToList();
|
||||
FindClosestStartPoint();
|
||||
}
|
||||
|
||||
private void FindClosestStartPoint()
|
||||
{
|
||||
var minDistance = float.MaxValue;
|
||||
var closestIndex = 0;
|
||||
|
||||
for (var i = 0; i < _waypoints.Count; i++)
|
||||
{
|
||||
var distance = Vector3.Distance(transform.position, _waypoints[i]);
|
||||
|
||||
if (!(distance < minDistance)) continue;
|
||||
|
||||
minDistance = distance;
|
||||
closestIndex = i;
|
||||
}
|
||||
|
||||
_currentTargetIndex = closestIndex;
|
||||
_visitedIndices.Clear();
|
||||
_reachedLastPoint = false;
|
||||
|
||||
UpdateTargetPosition();
|
||||
}
|
||||
|
||||
public override Steering GetSteering()
|
||||
{
|
||||
if (_waypoints == null || _waypoints.Count == 0 || _reachedLastPoint)
|
||||
{
|
||||
return new Steering();
|
||||
}
|
||||
|
||||
var distanceToTarget = Vector3.Distance(transform.position, _waypoints[_currentTargetIndex]);
|
||||
|
||||
if (distanceToTarget < 1f)
|
||||
{
|
||||
if (!_visitedIndices.Contains(_currentTargetIndex))
|
||||
{
|
||||
_visitedIndices.Add(_currentTargetIndex);
|
||||
}
|
||||
|
||||
if (_visitedIndices.Count >= _waypoints.Count)
|
||||
{
|
||||
_reachedLastPoint = true;
|
||||
return new Steering();
|
||||
}
|
||||
|
||||
FindNextTarget();
|
||||
}
|
||||
|
||||
UpdateTargetPosition();
|
||||
return base.GetSteering();
|
||||
}
|
||||
|
||||
private void FindNextTarget()
|
||||
{
|
||||
var shortestDistance = float.MaxValue;
|
||||
var bestTargetIndex = -1;
|
||||
|
||||
for (var i = 0; i < _waypoints.Count; i++)
|
||||
{
|
||||
if (_visitedIndices.Contains(i))
|
||||
continue;
|
||||
|
||||
var distance = Vector3.Distance(transform.position, _waypoints[i]);
|
||||
|
||||
if (!(distance < shortestDistance)) continue;
|
||||
|
||||
shortestDistance = distance;
|
||||
bestTargetIndex = i;
|
||||
}
|
||||
|
||||
if (bestTargetIndex != -1)
|
||||
{
|
||||
_currentTargetIndex = bestTargetIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
_reachedLastPoint = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTargetPosition()
|
||||
{
|
||||
if (target && _currentTargetIndex >= 0 && _currentTargetIndex < _waypoints.Count)
|
||||
{
|
||||
target.transform.position = _waypoints[_currentTargetIndex];
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetPathFollowing()
|
||||
{
|
||||
_visitedIndices.Clear();
|
||||
FindClosestStartPoint();
|
||||
_reachedLastPoint = false;
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (_waypoints == null) return;
|
||||
|
||||
for (var i = 0; i < _waypoints.Count; i++)
|
||||
{
|
||||
if (_reachedLastPoint)
|
||||
{
|
||||
Gizmos.color = Color.gray;
|
||||
}
|
||||
else if (i == _currentTargetIndex)
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
}
|
||||
else if (_visitedIndices != null && _visitedIndices.Contains(i))
|
||||
{
|
||||
Gizmos.color = Color.blue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Gizmos.color = Color.yellow;
|
||||
}
|
||||
|
||||
Gizmos.DrawSphere(_waypoints[i], 0.3f);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.Handles.Label(_waypoints[i] + Vector3.up * 0.5f, i.ToString());
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!_reachedLastPoint && _visitedIndices != null)
|
||||
{
|
||||
Gizmos.color = Color.cyan;
|
||||
for (var i = 0; i < _waypoints.Count; i++)
|
||||
{
|
||||
if (!_visitedIndices.Contains(i) && i != _currentTargetIndex)
|
||||
{
|
||||
Gizmos.DrawLine(transform.position, _waypoints[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72c82bc35ab14441b1565276e3a0a9af
|
||||
timeCreated: 1771318815
|
||||
@@ -8,6 +8,7 @@ namespace Code.UI
|
||||
{
|
||||
[SerializeField] private Button toMenuButton;
|
||||
[SerializeField] private Button resetButton;
|
||||
[SerializeField] private Button dopButton;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -15,15 +16,19 @@ namespace Code.UI
|
||||
toMenuButton.onClick.AddListener(LoadMainMenu);
|
||||
if (resetButton != null)
|
||||
resetButton.onClick.AddListener(Reload);
|
||||
if (dopButton != null)
|
||||
dopButton.onClick.AddListener(LoadDop);
|
||||
}
|
||||
|
||||
private static void LoadMainMenu() => SceneManager.LoadScene("MainMenu");
|
||||
private static void Reload() => SceneManager.LoadScene("Lab3");
|
||||
private static void LoadDop() => SceneManager.LoadScene("Lab3Dop");
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (toMenuButton != null) toMenuButton.onClick.RemoveListener(LoadMainMenu);
|
||||
if (resetButton != null) resetButton.onClick.RemoveListener(Reload);
|
||||
if (dopButton != null) resetButton.onClick.RemoveListener(LoadDop);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1163,6 +1163,7 @@ RectTransform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 2080304810}
|
||||
- {fileID: 1570891462}
|
||||
- {fileID: 1447469624}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
@@ -1428,6 +1429,128 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Code.UI.Lab3Controller
|
||||
toMenuButton: {fileID: 2080304811}
|
||||
resetButton: {fileID: 1447469625}
|
||||
dopButton: {fileID: 1570891463}
|
||||
--- !u!1 &1570891461
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1570891462}
|
||||
- component: {fileID: 1570891465}
|
||||
- component: {fileID: 1570891464}
|
||||
- component: {fileID: 1570891463}
|
||||
m_Layer: 5
|
||||
m_Name: DopButton
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &1570891462
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1570891461}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1922289397}
|
||||
m_Father: {fileID: 1044328680}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 250}
|
||||
m_SizeDelta: {x: -1400, y: 100}
|
||||
m_Pivot: {x: 0.5, y: 0}
|
||||
--- !u!114 &1570891463
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1570891461}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Button
|
||||
m_Navigation:
|
||||
m_Mode: 3
|
||||
m_WrapAround: 0
|
||||
m_SelectOnUp: {fileID: 0}
|
||||
m_SelectOnDown: {fileID: 0}
|
||||
m_SelectOnLeft: {fileID: 0}
|
||||
m_SelectOnRight: {fileID: 0}
|
||||
m_Transition: 1
|
||||
m_Colors:
|
||||
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
|
||||
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
|
||||
m_ColorMultiplier: 1
|
||||
m_FadeDuration: 0.1
|
||||
m_SpriteState:
|
||||
m_HighlightedSprite: {fileID: 0}
|
||||
m_PressedSprite: {fileID: 0}
|
||||
m_SelectedSprite: {fileID: 0}
|
||||
m_DisabledSprite: {fileID: 0}
|
||||
m_AnimationTriggers:
|
||||
m_NormalTrigger: Normal
|
||||
m_HighlightedTrigger: Highlighted
|
||||
m_PressedTrigger: Pressed
|
||||
m_SelectedTrigger: Selected
|
||||
m_DisabledTrigger: Disabled
|
||||
m_Interactable: 1
|
||||
m_TargetGraphic: {fileID: 1570891464}
|
||||
m_OnClick:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
--- !u!114 &1570891464
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1570891461}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Image
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_Type: 1
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
--- !u!222 &1570891465
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1570891461}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &1575067291
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1608,6 +1731,143 @@ MeshFilter:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1621558121}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!1 &1922289396
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1922289397}
|
||||
- component: {fileID: 1922289399}
|
||||
- component: {fileID: 1922289398}
|
||||
m_Layer: 5
|
||||
m_Name: Text (TMP)
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &1922289397
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1922289396}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1570891462}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &1922289398
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1922289396}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Unity.TextMeshPro::TMPro.TextMeshProUGUI
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_text: Dop
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: bec623f98c6d4c87a996583e4e315f82, type: 2}
|
||||
m_sharedMaterial: {fileID: -3152264912835432353, guid: bec623f98c6d4c87a996583e4e315f82, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
m_fontMaterials: []
|
||||
m_fontColor32:
|
||||
serializedVersion: 2
|
||||
rgba: 4281479730
|
||||
m_fontColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
|
||||
m_enableVertexGradient: 0
|
||||
m_colorMode: 3
|
||||
m_fontColorGradient:
|
||||
topLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||
topRight: {r: 1, g: 1, b: 1, a: 1}
|
||||
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||
bottomRight: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_fontColorGradientPreset: {fileID: 0}
|
||||
m_spriteAsset: {fileID: 0}
|
||||
m_tintAllSprites: 0
|
||||
m_StyleSheet: {fileID: 0}
|
||||
m_TextStyleHashCode: -1183493901
|
||||
m_overrideHtmlColors: 0
|
||||
m_faceColor:
|
||||
serializedVersion: 2
|
||||
rgba: 4294967295
|
||||
m_fontSize: 72
|
||||
m_fontSizeBase: 72
|
||||
m_fontWeight: 400
|
||||
m_enableAutoSizing: 0
|
||||
m_fontSizeMin: 18
|
||||
m_fontSizeMax: 72
|
||||
m_fontStyle: 0
|
||||
m_HorizontalAlignment: 2
|
||||
m_VerticalAlignment: 512
|
||||
m_textAlignment: 65535
|
||||
m_characterSpacing: 0
|
||||
m_characterHorizontalScale: 1
|
||||
m_wordSpacing: 0
|
||||
m_lineSpacing: 0
|
||||
m_lineSpacingMax: 0
|
||||
m_paragraphSpacing: 0
|
||||
m_charWidthMaxAdj: 0
|
||||
m_TextWrappingMode: 1
|
||||
m_wordWrappingRatios: 0.4
|
||||
m_overflowMode: 0
|
||||
m_linkedTextComponent: {fileID: 0}
|
||||
parentLinkedComponent: {fileID: 0}
|
||||
m_enableKerning: 0
|
||||
m_ActiveFontFeatures: 6e72656b
|
||||
m_enableExtraPadding: 0
|
||||
checkPaddingRequired: 0
|
||||
m_isRichText: 1
|
||||
m_EmojiFallbackSupport: 1
|
||||
m_parseCtrlCharacters: 1
|
||||
m_isOrthographic: 1
|
||||
m_isCullingEnabled: 0
|
||||
m_horizontalMapping: 0
|
||||
m_verticalMapping: 0
|
||||
m_uvLineOffset: 0
|
||||
m_geometrySortingOrder: 0
|
||||
m_IsTextObjectScaleStatic: 0
|
||||
m_VertexBufferAutoSizeReduction: 0
|
||||
m_useMaxVisibleDescender: 1
|
||||
m_pageToDisplay: 1
|
||||
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_isUsingLegacyAnimationComponent: 0
|
||||
m_isVolumetricText: 0
|
||||
m_hasFontAssetChanged: 0
|
||||
m_baseMaterial: {fileID: 0}
|
||||
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
|
||||
--- !u!222 &1922289399
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1922289396}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &1972281804
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 730c0cda26d6600288a3972891f96dc1
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user