Пример #1
0
 void OnEnable()
 {
     if (m_CSServoControllerInstance == null)
     {
         m_CSServoControllerInstance = target as CSServoController;
     }
 }
Пример #2
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        // MODEL AND WORLD REPRESENTATION OF SERVO
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        internal void AttachGameObject(GameObject _go)
        {
            m_worldGameObject = _go;

            // Add components
            m_arduinoServerController    = m_worldGameObject.AddComponent <CSServoController>();
            m_arduinoServerController.ID = GetID();

            // Attach Model
            {
                Color c = GetAxisOfRotation().x == 1 ? Color.red : Color.green;

                GameObject sphereViz = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                sphereViz.name                    = GetName() + "_Point";
                sphereViz.transform.parent        = m_worldGameObject.transform;
                sphereViz.transform.localPosition = Vector3.zero;
                sphereViz.transform.localRotation = Quaternion.identity;
                sphereViz.transform.localScale    = Vector3.one * 0.01f;
                sphereViz.GetComponent <MeshRenderer>().material.color = c;

                Quaternion cylinderCorrection = GetAxisOfRotation().x == 1 ?
                                                Quaternion.Euler(0, 0, 90) : Quaternion.Euler(0, 0, 0);

                GameObject axisRotation = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                axisRotation.name                    = GetName() + "_Axis";
                axisRotation.transform.parent        = sphereViz.transform;
                axisRotation.transform.localPosition = Vector3.zero;
                axisRotation.transform.rotation      = m_worldGameObject.transform.rotation * cylinderCorrection;
                axisRotation.transform.localScale    = Vector3.one * 0.30f;

                axisRotation.GetComponent <MeshRenderer>().material.color = c;
                axisRotation.GetComponent <CapsuleCollider>().enabled     = false;
                axisRotation.transform.localScale += Vector3.up * 10f; // Up is the direction of the primitive cylinder
            }

            // Child game object for rotation
            m_rotationGameObject                         = new GameObject();
            m_rotationGameObject.name                    = GetName() + "_AxisRotation";
            m_rotationGameObject.transform.parent        = m_worldGameObject.transform;
            m_rotationGameObject.transform.localPosition = Vector3.zero;
            m_rotationGameObject.transform.localRotation = Quaternion.identity;
        }