Exemplo n.º 1
0
    public h2_TreeUIItem AddChild(h2_TreeUIItem child)
    {
#if DEV_MODE
        {
            if (!IsValidChild(child))
            {
                return(this);
            }

            if (child.parent == this)
            {
                Debug.LogWarning("Child.parent already == this");
                return(this);
            }
            if (children.Contains(child))
            {
                Debug.LogWarning("Something broken, child already in this.children list <" + child +
                                 "> but its parent not set to this");
                return(this);
            }
        }
#endif

        if (child.parent != null)
        {
            child.parent.RemoveChild(child);
        }
        child.parent = this;
        children.Add(child);

        var delta = child.GetNVisible(_treeStamp);
        SetDeltaVisible(delta, _treeStamp);
        return(this);
    }
Exemplo n.º 2
0
    public h2_TreeUIItem RemoveChild(h2_TreeUIItem child)
    {
#if DEV_MODE
        {
            if (!IsValidChild(child))
            {
                return(this);
            }

            if (child.parent != this)
            {
                Debug.LogWarning("child.parent != this, can not remove");
                return(this);
            }

            if (!children.Contains(child))
            {
                Debug.LogWarning("Something broken, child.parent == this but this.children does not contains child");
                return(this);
            }
        }
#endif


        child.parent = null;
        children.Remove(child);

        //Recursive update nVIsible items up the tree
        var delta = child.GetNVisible(_treeStamp);
        SetDeltaVisible(-delta, _treeStamp);

        return(this);
    }
Exemplo n.º 3
0
    public void Draw(h2_TreeUIItem root)
    {
        var evtType = Event.current.type;
        var r       = GUILayoutUtility.GetRect(1f, Screen.width, 16f, Screen.height);

        if (evtType != EventType.layout)
        {
            visibleRect = r;
        }

        var n           = root.GetNVisible(Mathf.Max(root._treeStamp, 1));
        var contentRect = new Rect(0f, 0f, 1f, n * itemH);
        var nVisible    = Mathf.RoundToInt(visibleRect.height / itemH) + 1;
        var min         = Mathf.Max(0, Mathf.FloorToInt(position.y / itemH));
        var max         = Mathf.Min(min + nVisible, n);
        var noScroll    = contentRect.height < visibleRect.height;

        //Debug.Log("Drawing :: " + min + ":" + max + ":" + n);

        if (noScroll)
        {
            position = Vector2.zero;
        }

        position = GUI.BeginScrollView(visibleRect, position, contentRect);
        {
            var rect    = new Rect(0, 0, r.width - (noScroll ? 4f : 16f), itemH);
            var current = 0;
            root.Draw(min, max, ref rect, ref current);
        }

        GUI.EndScrollView();
    }
Exemplo n.º 4
0
 private bool IsValidChild(h2_TreeUIItem child)
 {
     if (child == null)
     {
         Debug.LogWarning("Child should not be null <" + child + ">");
         return(false);
     }
     //if (child.target == null){
     //	Debug.LogWarning("Child's target should not be null <" + child + ">");
     //	return false;
     //}
     return(true);
 }