// Instantiates and adds a edge between to vertices private void CreateEdge(LedgeVertex from, LedgeVertex to, int edgeNum) { GameObject instance = Instantiate(Resources.Load("LedgeEdge", typeof(GameObject))) as GameObject; LedgeEdge instanceEdge = instance.GetComponent <LedgeEdge>(); instance.name = "LedgeEdge " + edgeNum; instanceEdge.VertexClosestToOrigin = from; instanceEdge.VertexFurthestFromOrigin = to; instance.transform.position = from.transform.position + (to.transform.position - from.transform.position) * 0.5f; instance.transform.parent = from.transform; from.EdgeFurthestFromOrigin = instanceEdge; to.EdgeClosestToOrigin = instanceEdge; m_target.AddEdge(instanceEdge); }
public void SetFurthestOutNeighbours() { if (m_targets.Count > 0) { LedgeVertex furthestOutVert = null; LedgeEdge forwardNeigbourEdge = null; if ((furthestOutVert = VertexFurthestFromOrigin) != null) { if ((forwardNeigbourEdge = furthestOutVert.EdgeFurthestFromOrigin) != null) { ClimbTarget furthestInOnNeighbourEdge; if ((furthestInOnNeighbourEdge = forwardNeigbourEdge.FirstTarget) != null) { ClimbTarget furthestOutTarget = LastTarget; furthestOutTarget.RightNeigbour = furthestInOnNeighbourEdge; furthestInOnNeighbourEdge.LeftNeigbour = furthestOutTarget; } } } } }
/* 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); }
public void AddVertex(LedgeVertex vertex) { m_vertices.Add(vertex); }