public void AddNode(CListable Node) { //Node.DisableGravity(); if (Nodes.Count == 0) { Nodes.Add(Node); layerManager.Layers.Add(Node.Layer); CenterNodes(); return; } // Check position of insert: float distFromLeft = Vector3.Dot((Node.transform.position - FarLeft), transform.right) // From center + ((Nodes.Count) * Spacing * 0.5f); // Add half of new range. int index = (int)(distFromLeft / Spacing); if (index <= 0) { AddNode(Node, 0); CenterNodes(); return; } else if (index > Nodes.Count) { Nodes.Add(Node); layerManager.Layers.Add(Node.Layer); CenterNodes(); return; } Debug.LogWarning("Dist from Left = " + distFromLeft + " " + index); AddNode(Node, index); }
void AddNode(CListable Node, int index) { Nodes.Insert(index, Node); layerManager.Layers.Insert(index, Node.Layer); // Scoot Adjacent Nodes CenterNodes(); }
private void OnTriggerEnter(Collider other) { CListable Node = other.GetComponent <CListable>(); if (Node != null && !Node.IsHeld()) { Node.Delete(); } }
// Maintain the size of the list but reposition elements. public void MoveNode(CListable Node) { // Adjust the position of the left or right element: float distFromTarget = Vector3.Dot((Node.transform.position - Node.TargetLoc), transform.right.normalized); if (distFromTarget > Spacing * 0.5f) { SwapNodes(Node.ListableIndex, Node.ListableIndex + 1); CenterNodes(); } else if (distFromTarget < -Spacing * 0.5f) { SwapNodes(Node.ListableIndex, Node.ListableIndex - 1); CenterNodes(); } }
private void SwapNodes(int thisIndex, int desiredIndex) { if (desiredIndex >= Nodes.Count || desiredIndex < 0) { return; } else { CListable temp = Nodes[desiredIndex]; Nodes[desiredIndex] = Nodes[thisIndex]; Nodes[thisIndex] = temp; CLayer temp2 = layerManager.Layers[desiredIndex]; layerManager.Layers[desiredIndex] = layerManager.Layers[thisIndex]; layerManager.Layers[thisIndex] = temp2; } }
public void RemoveNode(CListable Node) { Nodes.Remove(Node); layerManager.Layers.Remove(Node.Layer); CenterNodes(); }