#if UNITY_5_3_OR_NEWER using UnityEngine; namespace Passer.RoboidControl.Unity { /// /// The representation of a Thing in Unity /// public class Thing : MonoBehaviour { /// /// The core C# thing /// [field: SerializeField] public RoboidControl.Thing core {get; set; } /// /// Set the core C# thing /// protected void SetCoreThing(RoboidControl.Thing thing) { core = thing; core.component = this; SiteServer siteServer = FindAnyObjectByType(); if (siteServer == null) { Debug.LogWarning("No site server found"); return; } siteServer.site.Add(thing); } /// /// Update the Unity representation /// 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