_xiaofang/xiaofang/Assets/Obi/Samples/Common/SampleResources/Scripts/ColliderHighlighter.cs
杨号敬 bcc74f0465 add
2024-12-18 02:18:45 +08:00

46 lines
873 B
C#

using UnityEngine;
using Obi;
[RequireComponent(typeof(ObiSolver))]
public class ColliderHighlighter : MonoBehaviour {
ObiSolver solver;
void Awake(){
solver = GetComponent<Obi.ObiSolver>();
}
void OnEnable () {
solver.OnCollision += Solver_OnCollision;
}
void OnDisable(){
solver.OnCollision -= Solver_OnCollision;
}
void Solver_OnCollision (object sender, ObiNativeContactList e)
{
var colliderWorld = ObiColliderWorld.GetInstance();
for(int i = 0; i < e.count; ++i)
{
Oni.Contact c = e[i];
// make sure this is an actual contact:
if (c.distance < 0.01f)
{
// get the collider:
var col = colliderWorld.colliderHandles[c.bodyB].owner;
if (col != null)
{
// make it blink:
Blinker blinker = col.GetComponent<Blinker>();
if (blinker)
blinker.Blink();
}
}
}
}
}