Delete Unity weapon effect authority
This commit is contained in:
parent
11e43a0d3f
commit
d687e275d8
29 changed files with 59 additions and 1498 deletions
|
|
@ -4,181 +4,28 @@ using UnityEngine;
|
|||
|
||||
public sealed class AetheriaYmirPhysicsBridge : MonoBehaviour
|
||||
{
|
||||
private const string DaemonEntityBodyPrefix = "aetheria.daemon.entity.";
|
||||
|
||||
private static AetheriaYmirPhysicsBridge _instance;
|
||||
|
||||
public bool EnableProjectileCutover = true;
|
||||
public AetheriaDaemonObserver DaemonObserver;
|
||||
public IYmirDaemonBodySource DaemonBodySource { get; set; }
|
||||
|
||||
private readonly List<YmirPhysicsBody> _daemonBodies = new List<YmirPhysicsBody>();
|
||||
private readonly List<YmirSphereQueryBody> _clickableBodies = new List<YmirSphereQueryBody>();
|
||||
private readonly Dictionary<string, HullCollider> _hullBodyMap = new Dictionary<string, HullCollider>(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, ClickableCollider> _clickableBodyMap = new Dictionary<string, ClickableCollider>(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, ClickableCollider> _clickableBodyMap =
|
||||
new Dictionary<string, ClickableCollider>(StringComparer.Ordinal);
|
||||
|
||||
public bool EnableQueries = true;
|
||||
|
||||
public static AetheriaYmirPhysicsBridge Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance != null) return _instance;
|
||||
|
||||
_instance = FindAnyObjectByType<AetheriaYmirPhysicsBridge>();
|
||||
if (_instance != null) return _instance;
|
||||
|
||||
var bridge = new GameObject("Aetheria Ymir Physics Bridge");
|
||||
var bridge = new GameObject("Aetheria Ymir Presentation Query Bridge");
|
||||
DontDestroyOnLoad(bridge);
|
||||
_instance = bridge.AddComponent<AetheriaYmirPhysicsBridge>();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryOverlapDaemonBodies(
|
||||
Vector3 center,
|
||||
float radius,
|
||||
out IReadOnlyList<YmirCircleOverlapHit> hits)
|
||||
{
|
||||
hits = Array.Empty<YmirCircleOverlapHit>();
|
||||
if (!TryBuildDaemonWorld(null, null, out var world) || radius <= 0)
|
||||
return false;
|
||||
|
||||
var request = new YmirCircleOverlapRequest
|
||||
{
|
||||
world = world,
|
||||
center = ToVec2(center),
|
||||
radius = radius
|
||||
};
|
||||
|
||||
return TryOverlapCircle(request, out hits);
|
||||
}
|
||||
|
||||
public bool TryCastDaemonBodies(
|
||||
Vector3 origin,
|
||||
Vector3 direction,
|
||||
float distance,
|
||||
float radius,
|
||||
out IReadOnlyList<YmirCircleCastHit> hits)
|
||||
{
|
||||
hits = Array.Empty<YmirCircleCastHit>();
|
||||
if (!TryBuildDaemonWorld(null, null, out var world) || distance <= 0 || radius < 0)
|
||||
return false;
|
||||
|
||||
var planarDirection = new Vector3(direction.x, 0, direction.z);
|
||||
if (planarDirection.sqrMagnitude <= float.Epsilon)
|
||||
return false;
|
||||
|
||||
var request = new YmirCircleCastRequest
|
||||
{
|
||||
world = world,
|
||||
origin = ToVec2(origin),
|
||||
direction = ToVec2(planarDirection.normalized),
|
||||
distance = distance,
|
||||
radius = radius
|
||||
};
|
||||
|
||||
return TryCastCircle(request, "Ymir daemon body circle cast query", out hits);
|
||||
}
|
||||
|
||||
public bool TryOverlapTargetHulls(
|
||||
EntityInstance target,
|
||||
Vector3 center,
|
||||
float radius,
|
||||
out IReadOnlyList<AetheriaYmirOverlapHit> hits)
|
||||
{
|
||||
hits = Array.Empty<AetheriaYmirOverlapHit>();
|
||||
if (!EnableProjectileCutover || target == null || radius <= 0)
|
||||
return false;
|
||||
|
||||
if (!TryBuildDaemonWorld(null, TargetDaemonEntityIndex(target), out var world))
|
||||
return false;
|
||||
|
||||
var request = new YmirCircleOverlapRequest
|
||||
{
|
||||
center = ToVec2(center),
|
||||
radius = radius,
|
||||
world = world
|
||||
};
|
||||
|
||||
if (!TryOverlapCircle(request, out var ymirHits))
|
||||
return false;
|
||||
|
||||
var resolved = new List<AetheriaYmirOverlapHit>();
|
||||
foreach (var hit in ymirHits)
|
||||
{
|
||||
if (!TryResolveTargetDaemonHull(target, hit.bodyId, out var hull))
|
||||
continue;
|
||||
|
||||
resolved.Add(new AetheriaYmirOverlapHit(
|
||||
hull,
|
||||
new Vector3(hit.point.x, center.y, hit.point.y),
|
||||
new Vector3(hit.normal.x, 0, hit.normal.y).normalized,
|
||||
hit.penetration,
|
||||
hit.distance));
|
||||
}
|
||||
|
||||
hits = resolved;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryOverlapSphere(
|
||||
IReadOnlyList<YmirSphereQueryBody> bodies,
|
||||
Vector3 center,
|
||||
float radius,
|
||||
out IReadOnlyList<YmirSphereOverlapHit> hits)
|
||||
{
|
||||
hits = Array.Empty<YmirSphereOverlapHit>();
|
||||
if (bodies == null || bodies.Count == 0)
|
||||
return false;
|
||||
|
||||
var bodyArray = bodies as YmirSphereQueryBody[] ?? CopySphereQueryBodies(bodies);
|
||||
return TryOverlapSphere(bodyArray, center, radius, "Ymir sphere overlap query", out hits);
|
||||
}
|
||||
|
||||
public bool TryCastTargetHulls(
|
||||
EntityInstance target,
|
||||
Vector3 origin,
|
||||
Vector3 direction,
|
||||
float distance,
|
||||
float radius,
|
||||
out IReadOnlyList<AetheriaYmirCastHit> hits)
|
||||
{
|
||||
hits = Array.Empty<AetheriaYmirCastHit>();
|
||||
if (!EnableProjectileCutover || target == null || distance <= 0 || direction.sqrMagnitude <= 0.000001f)
|
||||
return false;
|
||||
|
||||
if (!TryBuildDaemonWorld(null, TargetDaemonEntityIndex(target), out var world))
|
||||
return false;
|
||||
|
||||
var request = new YmirCircleCastRequest
|
||||
{
|
||||
origin = ToVec2(origin),
|
||||
direction = ToVec2(direction.normalized),
|
||||
distance = distance,
|
||||
radius = Mathf.Max(0, radius),
|
||||
world = world
|
||||
};
|
||||
|
||||
if (!TryCastCircle(request, "Ymir daemon target cast query", out var ymirHits))
|
||||
return false;
|
||||
|
||||
var resolved = new List<AetheriaYmirCastHit>();
|
||||
foreach (var hit in ymirHits)
|
||||
{
|
||||
if (!TryResolveTargetDaemonHull(target, hit.bodyId, out var hull))
|
||||
continue;
|
||||
|
||||
resolved.Add(new AetheriaYmirCastHit(
|
||||
hull,
|
||||
ResolveShield(hull),
|
||||
new Vector3(hit.point.x, origin.y, hit.point.y),
|
||||
new Vector3(hit.normal.x, 0, hit.normal.y).normalized,
|
||||
hit.distance));
|
||||
}
|
||||
|
||||
hits = resolved;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryCastClickables(
|
||||
IReadOnlyList<ClickableCollider> clickables,
|
||||
Ray ray,
|
||||
|
|
@ -186,19 +33,18 @@ public sealed class AetheriaYmirPhysicsBridge : MonoBehaviour
|
|||
out AetheriaYmirClickableHit hit)
|
||||
{
|
||||
hit = default;
|
||||
if (!EnableProjectileCutover || clickables == null || clickables.Count == 0 || distance <= 0)
|
||||
if (!EnableQueries || clickables == null || clickables.Count == 0 || distance <= 0)
|
||||
return false;
|
||||
|
||||
_clickableBodyMap.Clear();
|
||||
_clickableBodies.Clear();
|
||||
for (var i = 0; i < clickables.Count; i++)
|
||||
for (var index = 0; index < clickables.Count; index++)
|
||||
{
|
||||
var clickable = clickables[i];
|
||||
if (clickable == null || !clickable.isActiveAndEnabled)
|
||||
continue;
|
||||
var clickable = clickables[index];
|
||||
if (clickable == null || !clickable.isActiveAndEnabled) continue;
|
||||
|
||||
var bounds = clickable.ClickBounds;
|
||||
var bodyId = $"aetheria.clickable.{i}";
|
||||
var bodyId = $"eve.clickable.{index}";
|
||||
_clickableBodyMap[bodyId] = clickable;
|
||||
_clickableBodies.Add(new YmirSphereQueryBody
|
||||
{
|
||||
|
|
@ -208,467 +54,42 @@ public sealed class AetheriaYmirPhysicsBridge : MonoBehaviour
|
|||
});
|
||||
}
|
||||
|
||||
if (_clickableBodies.Count == 0)
|
||||
return false;
|
||||
if (_clickableBodies.Count == 0) return false;
|
||||
|
||||
var bodyArray = _clickableBodies.ToArray();
|
||||
var request = new YmirSphereCastRequest
|
||||
YmirSphereCastResult result;
|
||||
try
|
||||
{
|
||||
origin = ToVec3(ray.origin),
|
||||
direction = ToVec3(ray.direction.normalized),
|
||||
distance = distance,
|
||||
radius = 0,
|
||||
bodies = bodyArray
|
||||
};
|
||||
|
||||
if (!TryCastSphere(request, "Ymir clickable cast query", out var ymirHits))
|
||||
return false;
|
||||
|
||||
foreach (var resultHit in ymirHits)
|
||||
result = YmirPhysicsQueries.CastSphere(new YmirSphereCastRequest
|
||||
{
|
||||
origin = ToVec3(ray.origin),
|
||||
direction = ToVec3(ray.direction.normalized),
|
||||
distance = distance,
|
||||
radius = 0,
|
||||
bodies = _clickableBodies.ToArray()
|
||||
});
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
if (!_clickableBodyMap.TryGetValue(resultHit.bodyId, out var clickable) || clickable == null)
|
||||
Debug.LogWarning($"Ymir clickable presentation query failed: {error.Message}");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var candidate in result?.hits ?? Array.Empty<YmirSphereCastHit>())
|
||||
{
|
||||
if (!_clickableBodyMap.TryGetValue(candidate.bodyId, out var clickable) || clickable == null)
|
||||
continue;
|
||||
|
||||
hit = new AetheriaYmirClickableHit(
|
||||
clickable,
|
||||
ToVector3(resultHit.point),
|
||||
ToVector3(resultHit.normal).normalized,
|
||||
resultHit.distance);
|
||||
ToVector3(candidate.point),
|
||||
ToVector3(candidate.normal).normalized,
|
||||
candidate.distance);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryOverlapZoneHulls(
|
||||
ZoneRenderer zoneRenderer,
|
||||
Entity sourceEntity,
|
||||
Vector3 center,
|
||||
float radius,
|
||||
out IReadOnlyList<AetheriaYmirOverlapHit> hits)
|
||||
{
|
||||
hits = Array.Empty<AetheriaYmirOverlapHit>();
|
||||
if (!EnableProjectileCutover || zoneRenderer == null || radius <= 0)
|
||||
return false;
|
||||
|
||||
if (!TryBuildDaemonWorld(sourceEntity, null, out var world))
|
||||
return false;
|
||||
|
||||
var request = new YmirCircleOverlapRequest
|
||||
{
|
||||
center = ToVec2(center),
|
||||
radius = radius,
|
||||
world = world
|
||||
};
|
||||
|
||||
if (!TryOverlapCircle(request, out var ymirHits))
|
||||
return false;
|
||||
|
||||
var resolved = new List<AetheriaYmirOverlapHit>();
|
||||
foreach (var hit in ymirHits)
|
||||
{
|
||||
if (!TryResolveDaemonEntityHull(zoneRenderer, hit.bodyId, out var hull))
|
||||
continue;
|
||||
|
||||
resolved.Add(new AetheriaYmirOverlapHit(
|
||||
hull,
|
||||
new Vector3(hit.point.x, center.y, hit.point.y),
|
||||
new Vector3(hit.normal.x, 0, hit.normal.y).normalized,
|
||||
hit.penetration,
|
||||
hit.distance));
|
||||
}
|
||||
|
||||
hits = resolved;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryCastZoneHulls(
|
||||
ZoneRenderer zoneRenderer,
|
||||
Entity sourceEntity,
|
||||
Vector3 origin,
|
||||
Vector3 direction,
|
||||
float distance,
|
||||
float radius,
|
||||
out IReadOnlyList<AetheriaYmirCastHit> hits)
|
||||
{
|
||||
hits = Array.Empty<AetheriaYmirCastHit>();
|
||||
if (!EnableProjectileCutover || zoneRenderer == null || distance <= 0 || direction.sqrMagnitude <= 0.000001f)
|
||||
return false;
|
||||
|
||||
if (!TryBuildDaemonWorld(sourceEntity, null, out var world))
|
||||
return false;
|
||||
|
||||
var request = new YmirCircleCastRequest
|
||||
{
|
||||
origin = ToVec2(origin),
|
||||
direction = ToVec2(direction.normalized),
|
||||
distance = distance,
|
||||
radius = Mathf.Max(0, radius),
|
||||
world = world
|
||||
};
|
||||
|
||||
if (!TryCastCircle(request, "Ymir daemon zone cast query", out var ymirHits))
|
||||
return false;
|
||||
|
||||
var resolved = new List<AetheriaYmirCastHit>();
|
||||
foreach (var hit in ymirHits)
|
||||
{
|
||||
if (!TryResolveDaemonEntityHull(zoneRenderer, hit.bodyId, out var hull))
|
||||
continue;
|
||||
|
||||
resolved.Add(new AetheriaYmirCastHit(
|
||||
hull,
|
||||
ResolveShield(hull),
|
||||
new Vector3(hit.point.x, origin.y, hit.point.y),
|
||||
new Vector3(hit.normal.x, 0, hit.normal.y).normalized,
|
||||
hit.distance));
|
||||
}
|
||||
|
||||
hits = resolved;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryBuildDaemonWorld(Entity sourceEntity, int? onlyDaemonEntityIndex, out YmirWorld world)
|
||||
{
|
||||
world = null;
|
||||
if (DaemonBodySource != null)
|
||||
{
|
||||
_daemonBodies.Clear();
|
||||
if (!DaemonBodySource.TryAppendDaemonBodies(sourceEntity, onlyDaemonEntityIndex, _daemonBodies) ||
|
||||
_daemonBodies.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
world = new YmirWorld
|
||||
{
|
||||
time = Time.time,
|
||||
bodies = _daemonBodies.ToArray(),
|
||||
fields = Array.Empty<YmirRadialField>()
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
var observer = ResolveDaemonObserver();
|
||||
if (observer == null || !observer.HasRenderNativeView)
|
||||
return false;
|
||||
|
||||
var view = observer.LastRenderNativeView;
|
||||
if (!view.IsCreated || !view.HasEntityIndex || !view.HasPhysicsRadius)
|
||||
return false;
|
||||
|
||||
_daemonBodies.Clear();
|
||||
for (var i = 0; i < view.Count; i++)
|
||||
{
|
||||
var radius = view.PhysicsBodyRadius[i];
|
||||
if (radius <= 0)
|
||||
continue;
|
||||
|
||||
var daemonEntityIndex = view.EntityIndex[i];
|
||||
if (sourceEntity != null && sourceEntity.DaemonEntityIndex == daemonEntityIndex)
|
||||
continue;
|
||||
if (onlyDaemonEntityIndex.HasValue && onlyDaemonEntityIndex.Value != daemonEntityIndex)
|
||||
continue;
|
||||
|
||||
var inverseMass = view.HasPhysicsInverseMass ? view.PhysicsBodyInverseMass[i] : 1.0f;
|
||||
var mass = view.HasPhysicsMass && view.PhysicsBodyMass[i] > 0
|
||||
? view.PhysicsBodyMass[i]
|
||||
: inverseMass > 0
|
||||
? 1.0f / inverseMass
|
||||
: 1.0f;
|
||||
var rotation = view.HasRotation ? view.RotationRadians[i] : 0;
|
||||
var position = view.Position[i];
|
||||
var velocity = view.HasVelocity ? view.Velocity[i] : default;
|
||||
|
||||
_daemonBodies.Add(new YmirPhysicsBody
|
||||
{
|
||||
id = DaemonEntityBodyPrefix + daemonEntityIndex,
|
||||
position = new YmirVec2 { x = position.x, y = position.z },
|
||||
velocity = view.HasVelocity
|
||||
? new YmirVec2 { x = velocity.x, y = velocity.z }
|
||||
: default,
|
||||
direction = new YmirVec2 { x = Mathf.Sin(rotation), y = Mathf.Cos(rotation) },
|
||||
angularVelocity = 0,
|
||||
torque = 0,
|
||||
momentOfInertia = 1,
|
||||
radius = radius,
|
||||
mass = Mathf.Max(mass, 0.001f),
|
||||
isStatic = view.HasPhysicsInverseMass && inverseMass <= 0,
|
||||
restitution = 0
|
||||
});
|
||||
}
|
||||
|
||||
if (_daemonBodies.Count == 0)
|
||||
return false;
|
||||
|
||||
world = new YmirWorld
|
||||
{
|
||||
time = Time.time,
|
||||
bodies = _daemonBodies.ToArray(),
|
||||
fields = Array.Empty<YmirRadialField>()
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int TargetDaemonEntityIndex(EntityInstance target)
|
||||
{
|
||||
return target != null && target.Entity != null ? target.Entity.DaemonEntityIndex : -1;
|
||||
}
|
||||
|
||||
private static bool TryResolveTargetDaemonHull(
|
||||
EntityInstance target,
|
||||
string bodyId,
|
||||
out HullCollider hull)
|
||||
{
|
||||
hull = null;
|
||||
if (target == null ||
|
||||
target.HullColliders == null ||
|
||||
!TryParseDaemonEntityBodyId(bodyId, out var daemonEntityIndex) ||
|
||||
TargetDaemonEntityIndex(target) != daemonEntityIndex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < target.HullColliders.Length; i++)
|
||||
{
|
||||
hull = target.HullColliders[i];
|
||||
if (hull != null)
|
||||
return true;
|
||||
}
|
||||
|
||||
hull = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool TryResolveDaemonEntityHull(
|
||||
ZoneRenderer zoneRenderer,
|
||||
string bodyId,
|
||||
out HullCollider hull)
|
||||
{
|
||||
hull = null;
|
||||
if (zoneRenderer == null || !TryParseDaemonEntityBodyId(bodyId, out var daemonEntityIndex))
|
||||
return false;
|
||||
|
||||
if (!zoneRenderer.TryGetEntityInstance(daemonEntityIndex, out var instance) ||
|
||||
instance == null ||
|
||||
instance.HullColliders == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < instance.HullColliders.Length; i++)
|
||||
{
|
||||
hull = instance.HullColliders[i];
|
||||
if (hull != null)
|
||||
return true;
|
||||
}
|
||||
|
||||
hull = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool TryParseDaemonEntityBodyId(string bodyId, out int daemonEntityIndex)
|
||||
{
|
||||
daemonEntityIndex = -1;
|
||||
return !string.IsNullOrWhiteSpace(bodyId) &&
|
||||
bodyId.StartsWith(DaemonEntityBodyPrefix, StringComparison.Ordinal) &&
|
||||
int.TryParse(
|
||||
bodyId.Substring(DaemonEntityBodyPrefix.Length),
|
||||
out daemonEntityIndex);
|
||||
}
|
||||
|
||||
private AetheriaDaemonObserver ResolveDaemonObserver()
|
||||
{
|
||||
if (DaemonObserver != null)
|
||||
return DaemonObserver;
|
||||
|
||||
DaemonObserver = FindAnyObjectByType<AetheriaDaemonObserver>();
|
||||
return DaemonObserver;
|
||||
}
|
||||
|
||||
private bool TryOverlapSphere(
|
||||
YmirSphereQueryBody[] bodies,
|
||||
Vector3 center,
|
||||
float radius,
|
||||
string failureContext,
|
||||
out IReadOnlyList<YmirSphereOverlapHit> hits)
|
||||
{
|
||||
hits = Array.Empty<YmirSphereOverlapHit>();
|
||||
if (!EnableProjectileCutover || bodies == null || bodies.Length == 0 || radius <= 0)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var result = YmirPhysicsQueries.OverlapSphere(new YmirSphereOverlapRequest
|
||||
{
|
||||
center = ToVec3(center),
|
||||
radius = radius,
|
||||
bodies = bodies
|
||||
});
|
||||
hits = result.hits ?? Array.Empty<YmirSphereOverlapHit>();
|
||||
return true;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
Debug.LogWarning($"{failureContext} failed: {error.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryCastSphere(
|
||||
YmirSphereCastRequest request,
|
||||
string failureContext,
|
||||
out IReadOnlyList<YmirSphereCastHit> hits)
|
||||
{
|
||||
hits = Array.Empty<YmirSphereCastHit>();
|
||||
if (!EnableProjectileCutover || request == null || request.bodies == null || request.bodies.Length == 0 || request.distance <= 0 || request.radius < 0)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var result = YmirPhysicsQueries.CastSphere(request);
|
||||
hits = result.hits ?? Array.Empty<YmirSphereCastHit>();
|
||||
return true;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
Debug.LogWarning($"{failureContext} failed: {error.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryOverlapCircle(
|
||||
YmirCircleOverlapRequest request,
|
||||
out IReadOnlyList<YmirCircleOverlapHit> hits)
|
||||
{
|
||||
hits = Array.Empty<YmirCircleOverlapHit>();
|
||||
if (!EnableProjectileCutover || request == null || request.world == null || request.world.bodies == null || request.world.bodies.Length == 0 || request.radius <= 0)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var result = YmirPhysicsQueries.OverlapCircle(request);
|
||||
hits = result.hits ?? Array.Empty<YmirCircleOverlapHit>();
|
||||
return true;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
Debug.LogWarning($"Ymir circle overlap query failed: {error.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryCastCircle(
|
||||
YmirCircleCastRequest request,
|
||||
string failureContext,
|
||||
out IReadOnlyList<YmirCircleCastHit> hits)
|
||||
{
|
||||
hits = Array.Empty<YmirCircleCastHit>();
|
||||
if (!EnableProjectileCutover || request == null || request.world == null || request.world.bodies == null || request.world.bodies.Length == 0 || request.distance <= 0 || request.radius < 0)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var result = YmirPhysicsQueries.CastCircle(request);
|
||||
hits = result.hits ?? Array.Empty<YmirCircleCastHit>();
|
||||
return true;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
Debug.LogWarning($"{failureContext} failed: {error.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static YmirSphereQueryBody[] CopySphereQueryBodies(IReadOnlyList<YmirSphereQueryBody> bodies)
|
||||
{
|
||||
var copy = new YmirSphereQueryBody[bodies.Count];
|
||||
for (var i = 0; i < copy.Length; i++)
|
||||
copy[i] = bodies[i];
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static YmirPhysicsBody FindBody(YmirWorld world, string bodyId)
|
||||
{
|
||||
foreach (var body in world.bodies ?? Array.Empty<YmirPhysicsBody>())
|
||||
{
|
||||
if (string.Equals(body.id, bodyId, StringComparison.Ordinal))
|
||||
return body;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ShieldManager ResolveShield(HullCollider hull)
|
||||
{
|
||||
var instance = hull != null ? hull.GetComponentInParent<EntityInstance>() : null;
|
||||
return instance != null ? instance.Shield : null;
|
||||
}
|
||||
|
||||
private static YmirVec2 ToVec2(Vector3 value) => new YmirVec2 { x = value.x, y = value.z };
|
||||
|
||||
private static YmirVec2 ToVec2(CultMath.float2 value) => new YmirVec2 { x = value.x, y = value.y };
|
||||
|
||||
private static YmirVec3 ToVec3(Vector3 value) => new YmirVec3 { x = value.x, y = value.y, z = value.z };
|
||||
|
||||
private static Vector3 ToVector3(YmirVec3 value) => new Vector3(value.x, value.y, value.z);
|
||||
|
||||
private static Bounds ObjectBounds(GameObject gameObject, Vector3 fallbackCenter)
|
||||
{
|
||||
var renderers = gameObject.GetComponentsInChildren<Renderer>();
|
||||
if (renderers.Length == 0)
|
||||
return new Bounds(fallbackCenter, Vector3.one);
|
||||
|
||||
var bounds = renderers[0].bounds;
|
||||
for (var i = 1; i < renderers.Length; i++)
|
||||
bounds.Encapsulate(renderers[i].bounds);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IYmirDaemonBodySource
|
||||
{
|
||||
bool TryAppendDaemonBodies(
|
||||
Entity sourceEntity,
|
||||
int? onlyDaemonEntityIndex,
|
||||
List<YmirPhysicsBody> bodies);
|
||||
}
|
||||
|
||||
public readonly struct AetheriaYmirOverlapHit
|
||||
{
|
||||
public AetheriaYmirOverlapHit(HullCollider hull, Vector3 point, Vector3 normal, float penetration, float distance)
|
||||
{
|
||||
Hull = hull;
|
||||
Point = point;
|
||||
Normal = normal;
|
||||
Penetration = penetration;
|
||||
Distance = distance;
|
||||
}
|
||||
|
||||
public HullCollider Hull { get; }
|
||||
public Vector3 Point { get; }
|
||||
public Vector3 Normal { get; }
|
||||
public float Penetration { get; }
|
||||
public float Distance { get; }
|
||||
}
|
||||
|
||||
public readonly struct AetheriaYmirCastHit
|
||||
{
|
||||
public AetheriaYmirCastHit(HullCollider hull, ShieldManager shield, Vector3 point, Vector3 normal, float distance)
|
||||
{
|
||||
Hull = hull;
|
||||
Shield = shield;
|
||||
Point = point;
|
||||
Normal = normal;
|
||||
Distance = distance;
|
||||
}
|
||||
|
||||
public HullCollider Hull { get; }
|
||||
public ShieldManager Shield { get; }
|
||||
public Vector3 Point { get; }
|
||||
public Vector3 Normal { get; }
|
||||
public float Distance { get; }
|
||||
}
|
||||
|
||||
public readonly struct AetheriaYmirClickableHit
|
||||
|
|
|
|||
Loading…
Reference in a new issue