新增SensorToolkit
This commit is contained in:
36
Assets/SensorToolkit/Sensors/SignalProxy.cs
Normal file
36
Assets/SensorToolkit/Sensors/SignalProxy.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Micosmo.SensorToolkit {
|
||||
|
||||
/*
|
||||
* If a GameObject is detected and it has this component then the detected object will become
|
||||
* the 'ProxyTarget' this component points to.
|
||||
* This could be useful for example if you have characters with Rigidbodies/Colliders on
|
||||
* each of its limbs. You could put this component on each limb and point it to the root
|
||||
* GameObject of the character. Then if a sensor detects one or more of the limbs, it will
|
||||
* show the root GameObject in the list of detections. Otherwise the limbs would each be
|
||||
* detected separately.
|
||||
*/
|
||||
[AddComponentMenu("Sensors/Signal Proxy")]
|
||||
[HelpURL("https://micosmo.com/sensortoolkit2/docs/manual/proxy")]
|
||||
public class SignalProxy : MonoBehaviour {
|
||||
|
||||
public GameObject ProxyTarget;
|
||||
|
||||
public static GameObject GetProxyTarget(GameObject from) {
|
||||
GameObject target = from;
|
||||
SignalProxy proxy;
|
||||
while (target.TryGetComponent(out proxy)) {
|
||||
if (proxy.ProxyTarget == null || proxy.ProxyTarget == target) {
|
||||
break;
|
||||
}
|
||||
target = proxy.ProxyTarget;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user