Example #1
0
    public void CloseView(Action <GameObject, Vector2> buttonsMoveAnimationFunc)
    {
        ChildButtons.ForEach(b => buttonsMoveAnimationFunc(b, Vector2.zero));
        RootButton.SetActive(false);
        ParentButton.SetActive(false);
        NodeToButton.Clear();

        GameObject rootObj = CreateRootButton(Tree.Root);

        rootObj.GetComponent <Button>().onClick.AddListener(OpenView);
        CurrentMiddleNode = Tree.Root;
    }
Example #2
0
    public void ShowRoot(Action <GameObject, Vector2> buttonsMoveAnimationFunc)
    {
        ChildButtons.ForEach(b => b.SetActive(false));
        RootButton.SetActive(false);
        ParentButton.SetActive(false);
        NodeToButton.Clear();
        if (useSpringJoints)
        {
            ChildButtons.ForEach(b => b.GetComponent <TargetJoint2D>().enabled = false);
        }

        ArrangeNodes(Tree.Root.Children, radius, 0, 330, buttonsMoveAnimationFunc);

        GameObject centerNodeGO = CreateRootButton(Tree.Root);

        centerNodeGO.GetComponent <Button>().onClick.AddListener(() => OnRootNodeClick(Tree.Root));
        CurrentMiddleNode = Tree.Root;
    }
Example #3
0
    protected virtual void Start()
    {
        new GameObject("Lines Container");

        myRectTransform = GetComponent <RectTransform>();
        NodeToButton    = new Dictionary <TreeNode <E>, GameObject>();

        Tree = new Tree <E>(TreeValuesGetter);

        InitializeNodesPool(pooledNodes);

        childRadius = ChildButtons[0].GetComponent <RectTransform>().rect.width / 2;
        rootRadius  = RootButton.GetComponent <RectTransform>().rect.width / 2;


        Debug.Log("childRadius " + childRadius + " rootRadius" + rootRadius);


        CloseView((go, v2) => { });
    }
Example #4
0
    public void ShowNode(TreeNode <E> centralNode, Action <GameObject, Vector2> buttonsMoveAnimationFunc)
    {
        ChildButtons.ForEach(b => b.SetActive(false));
        RootButton.SetActive(false);
        ParentButton.SetActive(false);
        NodeToButton.Clear();
        if (useSpringJoints)
        {
            ChildButtons.ForEach(b => b.GetComponent <TargetJoint2D>().enabled = false);
        }

        ArrangeNodes(centralNode.Children, radius, 0, 270);

        GameObject centerNodeGO = CreateRootButton(centralNode);

        centerNodeGO.GetComponent <Button>().onClick.AddListener(() => OnCenterNodeClick(centralNode));

        GameObject    parentNodeGO     = CreateParentButton(centralNode.Parent);
        RectTransform parentRectTransf = parentNodeGO.GetComponent <RectTransform>();

        parentRectTransf.anchoredPosition = ComputeAnchoredPosition(315, radius + parentRectTransf.sizeDelta.x / 2);
        parentNodeGO.GetComponent <Button>().onClick.AddListener(() => OnParentNodeClick(centralNode.Parent));
        CurrentMiddleNode = centralNode;
    }
Example #5
0
    private void InitializeNodesPool(int desiredPoolSize)
    {
        ChildButtons = new List <GameObject>();
        for (int i = 0; i < desiredPoolSize; i++)
        {
            GameObject    newChildObj     = Instantiate(childPrefab);
            RectTransform childRectTransf = newChildObj.GetOrAddComponent <RectTransform>();
            childRectTransf.SetParent(this.transform, false);
            newChildObj.name = "ChildNode_" + (i + 1);

            ChildButtons.Add(newChildObj);
            newChildObj.SetActive(false);
        }

        RootButton = Instantiate(rootPrefab);
        RectTransform rootRectTransf = RootButton.GetOrAddComponent <RectTransform>();

        rootRectTransf.SetParent(this.transform, false);
        RootButton.name = "RootNode";

        RootButton.SetActive(false);

        ParentButton = Instantiate(rootPrefab);
        RectTransform parentRectTransf = ParentButton.GetOrAddComponent <RectTransform>();

        parentRectTransf.SetParent(this.transform, false);
        ParentButton.name = "ParentNode";


        float   scaleFactor = ChildButtons[0].GetComponent <RectTransform>().sizeDelta.x / rootRectTransf.sizeDelta.x;
        Vector3 newScale    = ChildButtons[0].transform.localScale * scaleFactor;

        ParentButton.transform.localScale = newScale;

        ParentButton.SetActive(false);
    }
Example #6
0
 public GameObject GetRootButton()
 {
     RootButton.GetComponent <Button>().interactable = true;
     RootButton.SetActive(true);
     return(RootButton);
 }