2023-10-20 19:31:12 +08:00
|
|
|
using System;
|
2023-06-08 14:09:50 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
namespace BITKit
|
|
|
|
{
|
|
|
|
public static class PhysicsHelper
|
|
|
|
{
|
2023-08-27 02:58:19 +08:00
|
|
|
public static async UniTask AddForceAtPositionAsync(this Rigidbody rigidbody, Vector3 force, Vector3 position,ForceMode forceMode=ForceMode.Force)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-10-30 01:25:53 +08:00
|
|
|
if (rigidbody is null) return;
|
2023-06-08 14:09:50 +08:00
|
|
|
await UniTask.DelayFrame(8);
|
2023-10-20 19:31:12 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
rigidbody.AddForceAtPosition(force, position,forceMode);
|
|
|
|
}
|
|
|
|
catch(MissingReferenceException){}
|
|
|
|
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-10-24 23:37:59 +08:00
|
|
|
public static async void Explosion(Vector3 position,float radius,LayerMask layerMask,float force)
|
|
|
|
{
|
|
|
|
await UniTask.DelayFrame(8);
|
|
|
|
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-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
}
|