Esempio n. 1
0
    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);
    }
Esempio n. 2
0
    void AddNode(CListable Node, int index)
    {
        Nodes.Insert(index, Node);
        layerManager.Layers.Insert(index, Node.Layer);

        // Scoot Adjacent Nodes
        CenterNodes();
    }
Esempio n. 3
0
    private void OnTriggerEnter(Collider other)
    {
        CListable Node = other.GetComponent <CListable>();

        if (Node != null && !Node.IsHeld())
        {
            Node.Delete();
        }
    }
Esempio n. 4
0
    // 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();
        }
    }
Esempio n. 5
0
    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;
        }
    }
Esempio n. 6
0
 public void RemoveNode(CListable Node)
 {
     Nodes.Remove(Node);
     layerManager.Layers.Remove(Node.Layer);
     CenterNodes();
 }