This repository has been archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathBoxObstacle.cs
35 lines (32 loc) · 1.57 KB
/
BoxObstacle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using RVO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// BoxCollider转化为RVO障碍物
/// </summary>
public class BoxObstacle : ShapeObstacleBase
{
[SerializeField] UnityEngine.Vector2 boxSize = UnityEngine.Vector2.one;
[SerializeField] UnityEngine.Vector2 center = UnityEngine.Vector2.one;
protected override void CalculatePoints()
{
var curPos = transform.position;
var halfSize = new UnityEngine.Vector2(transform.lossyScale.x, transform.lossyScale.z) * boxSize * 0.5f;
var rotation = Quaternion.Euler(0f, transform.eulerAngles.y, 0f);
var pointA = curPos + rotation * (Vector3.right * (halfSize.x + center.x) + Vector3.forward * (halfSize.y + center.y));
var pointB = curPos + rotation * (Vector3.left * (halfSize.x - center.x) + Vector3.forward * (halfSize.y + center.y));
var pointC = curPos + rotation * (Vector3.left * (halfSize.x - center.x) + Vector3.back * (halfSize.y - center.y));
var pointD = curPos + rotation * (Vector3.right * (halfSize.x + center.x) + Vector3.back * (halfSize.y - center.y));
mCacheVertexList.Add(new Vector2(pointA.x, pointA.z));
mCacheVertexList.Add(new Vector2(pointB.x, pointB.z));
mCacheVertexList.Add(new Vector2(pointC.x, pointC.z));
mCacheVertexList.Add(new Vector2(pointD.x, pointD.z));
#if UNITY_EDITOR
mEditorDebugVertexList.Add(pointA);
mEditorDebugVertexList.Add(pointB);
mEditorDebugVertexList.Add(pointC);
mEditorDebugVertexList.Add(pointD);
#endif
}
}