Merge branch 'main' of http://gitlab.passervr.com/passer/csharp/controlcore
This commit is contained in:
commit
f28aea5441
17
Sensors/TouchSensor.cs
Normal file
17
Sensors/TouchSensor.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
namespace Passer.Control.Core {
|
||||||
|
public class TouchSensor : Thing {
|
||||||
|
//public Thing touchedThing = null;
|
||||||
|
public bool touchedSomething = false;
|
||||||
|
|
||||||
|
public TouchSensor(bool invokeEvent = true) : base(invokeEvent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UNITY_5_3_OR_NEWER
|
||||||
|
public override void CreateComponent() {
|
||||||
|
this.component = Unity.TouchSensor.Create(this);
|
||||||
|
this.component.core = this;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,6 @@ namespace Passer.Control.Unity {
|
|||||||
public class DistanceSensor : Thing {
|
public class DistanceSensor : Thing {
|
||||||
|
|
||||||
public new Core.DistanceSensor core {
|
public new Core.DistanceSensor core {
|
||||||
get => (Core.DistanceSensor)base.core;
|
|
||||||
get => (Core.DistanceSensor)base.core;
|
get => (Core.DistanceSensor)base.core;
|
||||||
set => base.core = value;
|
set => base.core = value;
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,8 @@ namespace Passer.Control.Unity {
|
|||||||
|
|
||||||
protected virtual void Update() {
|
protected virtual void Update() {
|
||||||
site.Update((ulong)(Time.time * 1000));
|
site.Update((ulong)(Time.time * 1000));
|
||||||
if (thingQueue.TryDequeue(out Core.Thing thing)) {
|
while (thingQueue.TryDequeue(out Core.Thing thing))
|
||||||
thing.CreateComponent();
|
thing.CreateComponent();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
57
Unity/TouchSensor.cs
Normal file
57
Unity/TouchSensor.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#if UNITY_5_3_OR_NEWER
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Passer.Control.Unity {
|
||||||
|
|
||||||
|
public class TouchSensor : Thing {
|
||||||
|
|
||||||
|
public Core.TouchSensor coreSensor {
|
||||||
|
get => (Core.TouchSensor)base.core;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Start() {
|
||||||
|
if (core == null)
|
||||||
|
SetCoreThing(new Core.TouchSensor());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TouchSensor Create(Core.TouchSensor core) {
|
||||||
|
GameObject gameObj = core.name != null ?
|
||||||
|
new(core.name) :
|
||||||
|
new("Touch Sensor");
|
||||||
|
TouchSensor component = gameObj.AddComponent<TouchSensor>();
|
||||||
|
Rigidbody rb = gameObj.AddComponent<Rigidbody>();
|
||||||
|
rb.isKinematic = true;
|
||||||
|
|
||||||
|
SphereCollider collider = gameObj.AddComponent<SphereCollider>();
|
||||||
|
collider.radius = 0.01F;
|
||||||
|
collider.isTrigger = true;
|
||||||
|
|
||||||
|
component.core = core;
|
||||||
|
if (core.parent != null && core.parent.component != null)
|
||||||
|
gameObj.transform.SetParent(core.parent.component.transform, false);
|
||||||
|
|
||||||
|
if (core.position != null)
|
||||||
|
gameObj.transform.localPosition = core.position.ToVector3();
|
||||||
|
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTriggerEnter(Collider other) {
|
||||||
|
if (other.isTrigger)
|
||||||
|
return;
|
||||||
|
if (this.transform.root == other.transform.root)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Debug.Log($"touched {other.gameObject.name}");
|
||||||
|
this.coreSensor.touchedSomething = true;
|
||||||
|
}
|
||||||
|
private void OnTriggerExit(Collider other) {
|
||||||
|
if (other.isTrigger)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.coreSensor.touchedSomething = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user