#if UNITY_5_3_OR_NEWER using UnityEngine; namespace RoboidControl.Unity { /// /// The Unity representation of a Roboid Control wheel /// public class Wheel : Motor { /// /// Create the Unity representation /// /// The core motor /// The Unity representation of a motorised wheel public static Wheel Create(RoboidControl.Motor core, float wheelRadius) { GameObject prefab = (GameObject)Resources.Load("Wheel"); if (prefab != null) { // Use resource prefab when available GameObject gameObj = Instantiate(prefab); Wheel component = gameObj.GetComponent(); if (component != null) component.core = core; return component; } else { // Fallback implementation GameObject gameObj = new(core.name); Wheel component = gameObj.AddComponent(); component.Init(core); Debug.Log("Create " + core.name); return component; } } public static Wheel Create(Transform parent, byte thingId) { GameObject prefab = (GameObject)Resources.Load("Wheel"); if (prefab != null) { // Use resource prefab when available GameObject gameObj = Instantiate(prefab); Wheel component = gameObj.GetComponent(); if (component != null) component.core = new RoboidControl.Thing(RoboidControl.Thing.Type.UncontrolledMotor, false); return component; } else { // Fallback implementation GameObject gameObj = new("Wheel"); gameObj.transform.parent = parent; Wheel component = gameObj.AddComponent(); SiteServer participant = FindAnyObjectByType(); RoboidControl.Thing core = participant.coreParticipant.Get(thingId); if (core == null) core = new(participant.coreParticipant, RoboidControl.Thing.Type.UncontrolledMotor, thingId, false); else { ; } component.Init(core); SphereCollider collider = gameObj.AddComponent(); collider.radius = 0.00001f; collider.material = slidingWheel; Debug.Log("Create placeholder Wheel "); return component; } } private static PhysicMaterial _slidingWheel; public static PhysicMaterial slidingWheel { get { if (_slidingWheel == null) { _slidingWheel = new() { dynamicFriction = 0.02f, // Dynamic friction staticFriction = 0.01f, // Static friction bounciness = 0f, // Bounciness (bounciness value between 0 and 1) // Set the friction combine and bounce combine methods frictionCombine = PhysicMaterialCombine.Minimum, // How to combine friction bounceCombine = PhysicMaterialCombine.Average // How to combine bounciness }; } return _slidingWheel; } } } } #endif