#if UNITY_5_3_OR_NEWER
using UnityEngine;

namespace Passer.Control.Unity {

    public class Thing : MonoBehaviour {

        [field: SerializeField]
        public Core.Thing core {get; set; }

        protected void SetCoreThing(Core.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