更改文件架构

This commit is contained in:
CortexCore
2023-06-07 18:38:07 +08:00
parent 93292b1a59
commit ed84166723
720 changed files with 297 additions and 65 deletions

View File

@@ -0,0 +1,18 @@
{
"name": "BITKit.PathProvider",
"rootNamespace": "",
"references": [
"GUID:a209c53514018594f9f482516f2a6781",
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7e67c9a4b0b46654ca8966b4e75013b5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,105 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class LineObstacleProvider : PathProvider
{
public LayerMask layerMask;
public int distance;
public float tolerance = 0.32f;
public int accuracy;
protected Vector3 startPos;
protected Vector3 endPos;
protected Vector3 currentPos;
public override bool IsValid(ref Vector3 startPos)
{
if (TryGetObstacle(out var raycastHit))
{
if (TryGetCrossLocation(out var location))
{
this.startPos = startPos;
endPos = location;
return true;
}
}
return false;
}
void OnDrawGizmos()
{
Gizmos.DrawWireSphere(currentPos, 0.1f);
Gizmos.DrawWireSphere(endPos, 0.1f);
}
public override Vector3 Evaluate(float time)
{
currentPos = Vector3.Lerp(startPos, endPos, time);
return currentPos;
}
public bool TryGetObstacle(out RaycastHit raycastHit)
{
var originPos = transform.position;
var endPos = originPos + distance * transform.forward;
raycastHit = default;
for (int i = 0; i < accuracy; i++)
{
var weight = i / (float)accuracy;
var tolerance = this.tolerance * Vector3.up;
var vectorUp = Vector3.Lerp(-tolerance, tolerance, weight);
if (Physics.Linecast(originPos, endPos + vectorUp, out raycastHit, layerMask))
{
Debug.DrawLine(originPos, endPos, Color.yellow, 2);
return true;
}
}
return false;
}
public bool TryGetCrossLocation(out Location location, float radius = 0.2f, float height = 1f)
{
location = default;
if (TryGetObstacle(out var raycastHit))
{
var rotation = Quaternion.LookRotation(-raycastHit.normal, Vector3.up);
var edgePoint = raycastHit.point;
for (int i = 0; i < accuracy; i++)
{
var weight = i / (float)accuracy;
var vectorUp = Vector3.Lerp(Vector3.zero, Vector3.up * 0.32f, weight);
var originPos = raycastHit.point + vectorUp - transform.forward * 0.1f;
var endPos = originPos + transform.forward;
if (Physics.Linecast(originPos, endPos, out var raycast, layerMask))
{
edgePoint = raycast.point;
Debug.DrawLine(originPos, edgePoint, Color.red, i);
}
else
{
Debug.DrawLine(originPos, endPos, Color.green, i);
edgePoint.y = originPos.y;
var startPos = edgePoint + transform.forward * radius;
if (Physics.Raycast(startPos, Vector3.down, out raycast, layerMask))
{
var point0 = raycast.point;
point0.y += radius + 0.01f;
var point1 = point0 + Vector3.up * height;
point1.y -= radius;
var colliders = Physics.OverlapCapsule(point0, point1, radius, layerMask);
if (colliders.Length is 0)
{
location = new Location()
{
position = raycast.point,
rotation = rotation
};
return true;
}
Debug.DrawLine(startPos, raycast.point, Color.cyan, 2);
}
}
}
}
return false;
}
}
}

View File

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

View File

@@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public interface IPathProvider
{
bool IsValid(ref Vector3 startPos);
Vector3 Evaluate(float ex);
}
public abstract class PathProvider : MonoBehaviour, IPathProvider
{
public abstract bool IsValid(ref Vector3 startPos);
public abstract Vector3 Evaluate(float time);
}
}

View File

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