更改文件架构

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,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public interface IClosePoint
{
bool TryGetClosePoint(out Vector3 vector3);
}
[System.Serializable]
public class GetClosePointFromCollider : IClosePoint
{
public Transform root;
public LayerMask layerMask;
public float distance;
public bool TryGetClosePoint(out Vector3 vector3)
{
vector3 = default;
if (Physics.Raycast(root.position, root.forward, out var raycastHit, distance, layerMask))
{
var collider = raycastHit.collider;
switch (collider)
{
case MeshCollider meshCollider:
if (meshCollider.convex is false)
return false;
break;
}
vector3 = collider.ClosestPoint(root.position + Vector3.up);
return vector3.y == collider.bounds.center.y + collider.bounds.extents.y;
}
return false;
}
}
}

View File

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

View File

@@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public interface IPhysicsImpact
{
void AddImpact(Vector3 force);
}
}

View File

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

View File

@@ -0,0 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace BITKit
{
public class OnPhysics : MonoBehaviour
{
[Header(Constant.Header.Settings)]
public bool debug;
[Header(Constant.Header.Events)]
public UnityEvent<Collider> onTriggerEnter = new();
public UnityEvent<Collider> onTriggerExit = new();
public UnityEvent<Collider> onTriggerStay = new();
public UnityEvent<Collision> onCollisionEnter = new();
public UnityEvent<Collision> onCollisionExit = new();
public UnityEvent<Collision> onCollisionStay = new();
void OnTriggerEnter(Collider collider)
{
onTriggerEnter.Invoke(collider);
if (debug) Debug.Log(collider.name);
}
void OnTriggerExit(Collider collider)
{
onTriggerExit.Invoke(collider);
if (debug) Debug.Log(collider.name);
}
void OnTriggerStay(Collider collider)
{
onTriggerStay.Invoke(collider);
if (debug) Debug.Log(collider.name);
}
void OnCollisionEnter(Collision collision)
{
onCollisionEnter.Invoke(collision);
if (debug) Debug.Log(collision.collider.name);
}
void OnCollisionExit(Collision collision)
{
onCollisionExit.Invoke(collision);
if (debug) Debug.Log(collision.collider.name);
}
void OnCollisionStay(Collision collision)
{
onCollisionStay.Invoke(collision);
if (debug) Debug.Log(collision.collider.name);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7d5be83ba6a0d9c4a9a5911d9e2815e4
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;
using Cysharp.Threading.Tasks;
namespace BITKit
{
public static class PhysicsHelper
{
public static async void AddForceAtPositionAsync(this Rigidbody rigidbody, Vector3 force, Vector3 position)
{
await UniTask.DelayFrame(8);
if (rigidbody is not null)
rigidbody.AddForceAtPosition(force, position);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c64ae248a5362a948908f6f09d31be9d
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 class PhysicsImpacter : MonoBehaviour
{
void OnCollisionEnter(Collision collision)
{
if (collision.transform.TryGetComponent<IPhysicsImpact>(out var impact))
{
impact.AddImpact(collision.relativeVelocity);
}
}
}
}

View File

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

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public interface IPhysicsInfo
{
Rigidbody GetRigidbody();
Collider GetCollider();
}
public class PhysicsInfo : MonoBehaviour, IPhysicsInfo
{
[SerializeField] Rigidbody mRigidbody;
[SerializeField] Collider mCollider;
public Rigidbody GetRigidbody() => mRigidbody;
public Collider GetCollider() => mCollider;
}
}

View File

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