2023-10-24 23:38:22 +08:00
|
|
|
using System;
|
2023-06-05 19:57:17 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
namespace BITKit
|
|
|
|
{
|
|
|
|
public static class PhysicsHelper
|
|
|
|
{
|
2023-09-01 14:35:05 +08:00
|
|
|
public static async UniTask AddForceAtPositionAsync(this Rigidbody rigidbody, Vector3 force, Vector3 position,ForceMode forceMode=ForceMode.Force)
|
2023-06-05 19:57:17 +08:00
|
|
|
{
|
2023-11-06 01:17:23 +08:00
|
|
|
if (rigidbody is null) return;
|
2024-03-31 23:31:00 +08:00
|
|
|
await UniTask.DelayFrame(2);
|
2023-10-24 23:38:22 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
rigidbody.AddForceAtPosition(force, position,forceMode);
|
|
|
|
}
|
|
|
|
catch(MissingReferenceException){}
|
|
|
|
|
|
|
|
}
|
|
|
|
public static async void Explosion(Vector3 position,float radius,LayerMask layerMask,float force)
|
|
|
|
{
|
2024-03-31 23:31:00 +08:00
|
|
|
await UniTask.DelayFrame(2);
|
2023-10-24 23:38:22 +08:00
|
|
|
foreach (var x in UnityEngine.Physics.OverlapSphere(position,radius,layerMask))
|
|
|
|
{
|
|
|
|
if(x.attachedRigidbody is null)continue;
|
|
|
|
x.attachedRigidbody.AddExplosionForce(force,position,radius);
|
|
|
|
//Debug.Log(x);
|
|
|
|
}
|
2023-06-05 19:57:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|