コード例 #1
0
    /* FUNCTIONS THAT BUILD THE LEDGE SYSTEM */
    #region Instantiation

    // Instantiates and adds a vertex to the ledge
    private void CreateVertex()
    {
        List <LedgeVertex> vertices = m_target.Vertices;

        GameObject  instance       = Instantiate(Resources.Load("LedgeVertex", typeof(GameObject))) as GameObject;
        LedgeVertex instanceVertex = instance.GetComponent <LedgeVertex>();

        instance.name             = "LedgeVertex " + (vertices.Count + 1);
        instance.transform.parent = m_target.transform;
        if (vertices.Count == 0)
        {
            // Add first
            instance.transform.rotation = m_target.transform.rotation;
            instance.transform.position = m_target.transform.position;
        }
        else
        {
            instance.transform.position = vertices[vertices.Count - 1].transform.position;
            instance.transform.rotation = vertices[vertices.Count - 1].transform.rotation;
            LedgeVertex lastVertex = vertices[vertices.Count - 1];
            // Create edge to previous
            CreateEdge(lastVertex, instanceVertex, m_target.Edges.Count + 1);
            // Neighbour this to previous
            lastVertex.RightNeighbour    = instanceVertex;
            instanceVertex.LeftNeighbour = lastVertex;

            // Switch selection
            GameObject[] selection = new GameObject[1];
            selection[0]      = instance;
            Selection.objects = selection;
        }

        // Add LedgeVertex to list
        m_target.AddVertex(instanceVertex);
        EditorUtility.SetDirty(m_target);
    }