This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Coolape
{
public static class CLAIPathUtl
{
/// <summary>
/// Softens the path.软化路径
/// </summary>
/// <param name="list">List.路径列表</param>
/// <param name="softenPathType">Soften path type.软化类型</param>
/// <param name="slerpFactor">Soften factor.曲面差值次数</param>
/// <param name="cellSize">Cell size.单元格大小</param>
public static void softenPath(ref List<Vector3> list, SoftenPathType softenPathType, int slerpFactor, float cellSize)
{
if (list == null || list.Count < 3)
{
return;
}
int i = 1;
float factor = 0.25f;
float slerpOffset = 0;
if (softenPathType == SoftenPathType.Slerp)
{
factor = 0.5f;
slerpFactor = slerpFactor == 0 ? 1 : slerpFactor;
slerpOffset = 1.0f / slerpFactor;
}
while (i < list.Count - 1)
{
Vector3 mid = list[i];
Vector3 left = list[i - 1];
Vector3 right = list[i + 1];
Vector3 angle1 = Utl.getAngle(mid, left);
Vector3 angle2 = Utl.getAngle(mid, right);
if (Mathf.Abs(Mathf.Abs(angle1.y - angle2.y) - 180) <= 20)
{
//基本在一条线上,直接跳过
i++;
continue;
}
Vector3 leftOffset = Vector3.zero;
float leftDis = Vector3.Distance(mid, left);
if (leftDis >= cellSize)
{
leftOffset = (left - mid).normalized * cellSize * factor;
}
else
{
leftOffset = (left - mid).normalized * leftDis * factor;
}
left = mid + leftOffset;
Vector3 rightOffset = Vector3.zero;
float rightDis = Vector3.Distance(mid, right);
if (rightDis >= cellSize)
{
rightOffset = (right - mid).normalized * cellSize * factor;
}
else
{
rightOffset = (right - mid).normalized * rightDis * factor;
}
right = mid + rightOffset;
Vector3 center = (left + right) / 2.0f;
Vector3 mid2 = center + (center - mid).normalized * Vector3.Distance(center, mid) * 4f;
list.RemoveAt(i); //把硬转角的点去掉
//接下来加入一些新的点
list.Insert(i, left);
i++;
if (softenPathType == SoftenPathType.Slerp)
{
//加入球面插值的点
Vector3 v1 = left - mid2;
Vector3 v2 = right - mid2;
for (int j = 0; j < slerpFactor; j++)
{
Vector3 pos = Vector3.Slerp(v1, v2, slerpOffset * j);
list.Insert(i, (pos + mid2));
i++;
}
}
list.Insert(i, right);
i++;
}
}
//============================================
//============================================
//============================================
public enum SoftenPathType
{
Line,
Slerp
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d4d4492acf2c24246b54b1e8c52846fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,96 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Coolape
{
public class CLAStarNode
{
public CLAStarNode left;
public CLAStarNode right;
public CLAStarNode up;
public CLAStarNode down;
public CLAStarNode leftUp;
public CLAStarNode leftDown;
public CLAStarNode rightUp;
public CLAStarNode rightDown;
public List<CLAStarNode> aroundList = new List<CLAStarNode>();
public int index;
public Vector3 position;
// 是障碍格子
public bool isObstruct = false;
//父节点需要一个key作缓存以免同时有多个寻路时parent值会冲突
Dictionary<string, CLAStarNode> parentNodesMap = new Dictionary<string, CLAStarNode>();
public CLAStarNode(int index, Vector3 pos)
{
this.index = index;
this.position = pos;
}
public void init(
CLAStarNode left,
CLAStarNode right,
CLAStarNode up,
CLAStarNode down,
CLAStarNode leftUp,
CLAStarNode leftDown,
CLAStarNode rightUp,
CLAStarNode rightDown)
{
aroundList.Clear();
this.left = left;
if(left != null) {
aroundList.Add(left);
}
this.right = right;
if (right != null)
{
aroundList.Add(right);
}
this.up = up;
if (up != null)
{
aroundList.Add(up);
}
this.down = down;
if (down != null)
{
aroundList.Add(down);
}
this.leftUp = leftUp;
if (leftUp != null)
{
aroundList.Add(leftUp);
}
this.leftDown = leftDown;
if (leftDown != null)
{
aroundList.Add(leftDown);
}
this.rightUp = rightUp;
if (rightUp != null)
{
aroundList.Add(rightUp);
}
this.rightDown = rightDown;
if (rightDown != null)
{
aroundList.Add(rightDown);
}
}
public void setParentNode(CLAStarNode preNode, string key)
{
parentNodesMap[key] = preNode;
}
public CLAStarNode getParentNode(string key)
{
CLAStarNode parent = null;
if(parentNodesMap.TryGetValue(key, out parent)) {
return parent;
}
return null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8085c87d606b547e29d32263db779eea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: