Ejemplo n.º 1
0
    // Use this for initialization
    void Initialize()
    {
        m_vertices = Icosphere.GenerateIcosphere(1f, m_nbSubdivisions);

        m_segments = new List <IcoSegment>();

        for (int i = 0; i < m_vertices.Count / 3; ++i)
        {
            Vector3 v0 = m_vertices[3 * i + 0];
            Vector3 v1 = m_vertices[3 * i + 1];
            Vector3 v2 = m_vertices[3 * i + 2];

            GameObject segment = new GameObject();
            segment.transform.position = transform.position;
            segment.name             = "segment" + i;
            segment.transform.parent = transform;
            segment.AddComponent <MeshRenderer>();
            segment.GetComponent <MeshRenderer>().material = m_segmentMaterial;
            segment.layer = LayerMask.NameToLayer("Planet");

            IcoSegment icoSeg = segment.AddComponent <IcoSegment>();
            m_segments.Add(icoSeg);
            icoSeg.heightLevel = m_defaultHeightLevel;
            icoSeg.icoPlanet   = this;
            icoSeg.SetBaseVertices(v0, v1, v2);

            m_segmentJoints.Add(segment.AddComponent <MTK_PlanetSegmentJoint>());
            MTK_Interactable interactable = segment.AddComponent <MTK_Interactable>();
            interactable.isDistanceGrabbable = false;
            interactable.isGrabbable         = false;
            interactable.isDroppable         = false;
        }
    }