39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
#if UNITY_5_3_OR_NEWER
|
|
using UnityEngine;
|
|
|
|
namespace Passer.RoboidControl.Unity {
|
|
|
|
public class Thing : MonoBehaviour {
|
|
|
|
[field: SerializeField]
|
|
public RoboidControl.Thing core {get; set; }
|
|
|
|
protected void SetCoreThing(RoboidControl.Thing thing) {
|
|
core = thing;
|
|
core.component = this;
|
|
|
|
SiteServer siteServer = FindAnyObjectByType<SiteServer>();
|
|
if (siteServer == null) {
|
|
Debug.LogWarning("No site server found");
|
|
return;
|
|
}
|
|
siteServer.site.Add(thing);
|
|
}
|
|
|
|
protected virtual void Update() {
|
|
if (core == null)
|
|
return;
|
|
|
|
if (core.linearVelocity != null) {
|
|
Vector3 direction = Quaternion.AngleAxis(core.linearVelocity.direction.horizontal, Vector3.up) * Vector3.forward;
|
|
this.transform.Translate(core.linearVelocity.distance * Time.deltaTime * direction);
|
|
}
|
|
if (core.angularVelocity != null) {
|
|
Vector3 angularVelocity = core.angularVelocity.ToVector3();
|
|
this.transform.rotation *= Quaternion.Euler(angularVelocity * Time.deltaTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
#endif |