Example #1
0
    private void Insert(Trigger trigger)
    {
        // Build stack of trigger's lineage up to (and excluding) the Event root.
        Stack<GameObject> triggerParents = new Stack<GameObject>();
        Transform current = trigger.transform.parent.transform;
        while (current != null && current != _rootNode.GameObject.transform)
        {
            triggerParents.Push(current.gameObject);
            current = current.parent;
        }

        // Pop the oldest ancestor and traverse tree down lineage adding new nodes as necessary.
        GameObject currentGameObject;
        TriggerCollectionNode currentNode = _rootNode;
        while (triggerParents.Count > 0)
        {
            currentGameObject = triggerParents.Pop();
            TriggerCollectionNode node = currentNode.FirstOrDefault((otherNode) => otherNode.GameObject == currentGameObject);
            if (node != null)
            {
                currentNode = node;
            }
            else
            {
                TriggerCollectionNode newNode = new TriggerCollectionNode(_context, _overviewContext, currentGameObject);
                currentNode.AddChild(newNode);
                currentNode = newNode;
            }
        }

        currentNode.AddChild(new TriggerCollectionNode(_context, _overviewContext, trigger.gameObject));
    }
Example #2
0
    private void BuildTree(TriggerCollectionNode node)
    {
        foreach (Transform child in node.GameObject.transform)
        {
            var childNode = new TriggerCollectionNode(_context, _overviewContext, child.gameObject);
            node.AddChild(childNode);

            if (child.gameObject.GetComponent<Trigger>())
            {
                continue;
            }
            BuildTree(childNode);
        }
        /*
        foreach (Trigger trigger in triggers)
        {
            Insert(trigger);
        }*/
    }