Skip to content

Commit edafc7a

Browse files
committed
Update with walk action manager.
1 parent 3b1b6fb commit edafc7a

File tree

12 files changed

+102
-45
lines changed

12 files changed

+102
-45
lines changed

Assets/JCSUnity/Scripts/Actions/3D/AI/JCS_3DWalkAction.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ public class JCS_3DWalkAction
5454
[SerializeField]
5555
private JCS_3DWalkType mWalkType = JCS_3DWalkType.SELF_IN_DISTANCE;
5656

57+
[Tooltip("Allow each walk action having the same destination.")]
58+
[SerializeField]
59+
private bool mAllowOverlapDestination = false;
60+
61+
[Tooltip("Distance that would count as overlap destination.")]
62+
[Range(0.0f, 30.0f)]
63+
private float mOverlapDistance = 0.5f;
64+
5765
[Tooltip("What value count as path complete action.")]
5866
[SerializeField]
5967
[Range(0.0f, 30.0f)]
@@ -104,6 +112,9 @@ public class JCS_3DWalkAction
104112
public float MinOffDistance { get { return this.mMinOffDistance; } set { this.mMinOffDistance = value; } }
105113
public float MaxOffDistance { get { return this.mMaxOffDistance; } set { this.mMaxOffDistance = value; } }
106114

115+
public bool AllowOverlapDestination { get { return this.mAllowOverlapDestination; } set { this.mAllowOverlapDestination = value; } }
116+
public float OverlapDistance { get { return this.mOverlapDistance; } set { this.mOverlapDistance = value; } }
117+
107118
public float RangeDistance { get { return this.mRangeDistance; } set { this.mRangeDistance = value; } }
108119
public float AdjustRangeDistance { get { return this.mAdjustRangeDistance; } set { this.mAdjustRangeDistance = value; } }
109120

@@ -121,6 +132,12 @@ private void Awake()
121132
this.mStartingPosition = this.transform.position;
122133
}
123134

135+
private void Start()
136+
{
137+
JCS_3DWalkActionManager wam = JCS_3DWalkActionManager.instance;
138+
wam.AddWalkAction(this);
139+
}
140+
124141
/// <summary>
125142
/// Target one player and do in target action.
126143
/// </summary>
@@ -137,6 +154,8 @@ public void TargetOne(Transform target)
137154
return;
138155
}
139156

157+
JCS_3DWalkActionManager wam = JCS_3DWalkActionManager.instance;
158+
140159
if (mSearchCount == 2)
141160
{
142161
// reset search count.
@@ -156,6 +175,12 @@ public void TargetOne(Transform target)
156175
// set to the destination.
157176
bool found = mNavMeshAgent.SetDestination(targetPos);
158177

178+
if (!mAllowOverlapDestination)
179+
{
180+
if (found)
181+
found = !wam.OverlapWithOthers(targetPos, mOverlapDistance);
182+
}
183+
159184
// increase the search count.
160185
++mSearchCount;
161186

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* $File: JCS_3DWalkActionManager.cs $
3+
* $Date: 2020-05-06 22:44:11 $
4+
* $Revision: $
5+
* $Creator: Jen-Chieh Shen $
6+
* $Notice: See LICENSE.txt for modification and distribution information
7+
* Copyright © 2020 by Shen, Jen-Chieh $
8+
*/
9+
using System.Collections;
10+
using System.Collections.Generic;
11+
using UnityEngine;
12+
13+
namespace JCSUnity
14+
{
15+
/// <summary>
16+
/// Manages all the 3D walk action in scene.
17+
/// </summary>
18+
public class JCS_3DWalkActionManager
19+
: JCS_Managers<JCS_3DWalkActionManager>
20+
{
21+
/* Variables */
22+
23+
[Header("** Check Variables (JCS_3DWalkActionManager) **")]
24+
25+
[Tooltip("All walk action that get manages.")]
26+
[SerializeField]
27+
private List<JCS_3DWalkAction> mWalkActions = null;
28+
29+
/* Setter & Getter */
30+
31+
public List<JCS_3DWalkAction> WalkActions { get { return this.mWalkActions; } }
32+
33+
/* Functions */
34+
35+
private void Awake()
36+
{
37+
instance = this;
38+
}
39+
40+
/// <summary>
41+
/// Add walk action to get manage.
42+
/// </summary>
43+
/// <param name="wa"> Target walk action you want to get manage. </param>
44+
public void AddWalkAction(JCS_3DWalkAction wa)
45+
{
46+
mWalkActions = JCS_Utility.RemoveEmptySlotIncludeMissing<JCS_3DWalkAction>(mWalkActions);
47+
48+
mWalkActions.Add(wa);
49+
}
50+
51+
/// <summary>
52+
/// Check if there are other walk action having the same destination.
53+
/// </summary>
54+
/// <param name="targetPos"> Current targeting position. </param>
55+
/// <param name="overlapDistance"> Allow overlapping distance. </param>
56+
/// <returns>
57+
/// Return true, if it does overlaps with other walk action.
58+
/// Return false, if it does NOT overlap with other walk action.
59+
/// </returns>
60+
public bool OverlapWithOthers(Vector3 targetPos, float overlapDistance)
61+
{
62+
foreach (JCS_3DWalkAction wa in mWalkActions)
63+
{
64+
Vector3 dest = wa.navMeshAgent.destination;
65+
float distance = Vector3.Distance(targetPos, dest);
66+
if (distance < overlapDistance)
67+
return true;
68+
}
69+
return false;
70+
}
71+
}
72+
}

Assets/JCSUnity/Scripts/Managers/Indie/JCS_IndieManager.cs.meta renamed to Assets/JCSUnity/Scripts/Managers/3D/JCS_3DWalkActionManager.cs.meta

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/JCSUnity/Scripts/Managers/Indie/JCS_IndieManager.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

Assets/JCSUnity/Scripts/Managers/Indie/NOTICE.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.
File renamed without changes.

Assets/JCSUnity/Scripts/Managers/Indie/JCS_ClimbableManager.cs renamed to Assets/JCSUnity/Scripts/Managers/Others/JCS_ClimbableManager.cs

File renamed without changes.

Assets/JCSUnity/Scripts/Managers/Indie/JCS_ClimbableManager.cs.meta renamed to Assets/JCSUnity/Scripts/Managers/Others/JCS_ClimbableManager.cs.meta

File renamed without changes.

Assets/JCSUnity/Scripts/Managers/Indie/JCS_PortalManager.cs renamed to Assets/JCSUnity/Scripts/Managers/Others/JCS_PortalManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ private void SetPlayerToPortalByLabel()
5656
if (!jcsPs.RESET_POSITION_AT_START)
5757
return;
5858

59+
mPortals = JCS_Utility.RemoveEmptySlotIncludeMissing<JCS_2DPortal>(mPortals);
60+
5961
foreach (JCS_2DPortal portal in mPortals)
6062
{
6163
if (portal.PortalLabel == jcsPs.SCENE_PORTAL_LABEL)

Assets/JCSUnity/Scripts/Managers/Indie/JCS_PortalManager.cs.meta renamed to Assets/JCSUnity/Scripts/Managers/Others/JCS_PortalManager.cs.meta

File renamed without changes.

0 commit comments

Comments
 (0)