Example #1
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    exUIElement PickElement(Vector2 _pos)
    {
        if (useRayCast)
        {
            Ray ray = GetComponent <Camera>().ScreenPointToRay(_pos);
            ray.origin = new Vector3(ray.origin.x, ray.origin.y, GetComponent <Camera>().transform.position.z);
            RaycastHit[] hits = Physics.RaycastAll(ray);
            // DISABLE {
            // System.Array.Sort(hits, raycastSorter);
            // if ( hits.Length > 0 ) {
            //     for ( int i = 0; i < hits.Length; ++i ) {
            //         RaycastHit hit = hits[i];
            //         GameObject go = hit.collider.gameObject;
            //         exUIElement el = go.GetComponent<exUIElement>();
            //         if ( el && el.enabled ) {
            //             return el;
            //         }
            //     }
            // }
            // return null;
            // } DISABLE end

            // TODO: consider clipping plane

            List <exUIElement> elements = new List <exUIElement>();
            for (int i = 0; i < hits.Length; ++i)
            {
                RaycastHit hit = hits[i];
                GameObject go  = hit.collider.gameObject;
                exUIElement el = go.GetComponent <exUIElement>();
                if (el && el.isActive)
                {
                    elements.Add(el);
                }
            }
            if (elements.Count > 0)
            {
                elements.Sort(elementSorter);
                return(elements[elements.Count - 1]);
            }
            return(null);
        }
        else
        {
            Vector3 worldPointerPos = GetComponent <Camera>().ScreenToWorldPoint(_pos);
            rootElements.Sort(elementSorterByZ);
            for (int i = 0; i < rootElements.Count; ++i)
            {
                exUIElement el       = rootElements[i];
                exUIElement resultEL = RecursivelyGetUIElement(el, worldPointerPos);
                if (resultEL != null)
                {
                    return(resultEL);
                }
            }
            return(null);
        }
    }
Example #2
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected float GetContentHeight()
    {
        float cHeight = 0.0f;

        for (int i = 0; i < children.Count; ++i)
        {
            exUIElement el = children[i];
            cHeight += el.boundingRect.height;
        }
        return(cHeight);
    }
Example #3
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public void UpdateChildPosition()
    {
        float y = 0.0f;

        for (int i = 0; i < children.Count; ++i)
        {
            exUIElement el = children[i];

            y -= el.style.margin.top;
            el.transform.localPosition = new Vector3(0.0f, y, 0.0f);
            y -= el.boundingRect.height;
            y -= el.style.margin.bottom;
        }
    }
Example #4
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected float GetContentWidth()
    {
        float maxWidth = 9999.0f;

        for (int i = 0; i < children.Count; ++i)
        {
            exUIElement el = children[i];
            if (el.boundingRect.width > maxWidth)
            {
                maxWidth = el.boundingRect.width;
            }
        }
        return(maxWidth);
    }
Example #5
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public exUIElement FindParent()
    {
        Transform tranParent = transform.parent;

        while (tranParent != null)
        {
            exUIElement el = tranParent.GetComponent <exUIElement>();
            if (el != null)
            {
                return(el);
            }
            tranParent = tranParent.parent;
        }
        return(null);
    }
Example #6
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    static void FindAndAddChildRecursively(exUIElement _el, Transform _trans)
    {
        foreach (Transform child in _trans)
        {
            exUIElement child_el = child.GetComponent <exUIElement>();
            if (child_el)
            {
                _el.AddChild(child_el);
                exUIElement.FindAndAddChild(child_el);
            }
            else
            {
                FindAndAddChildRecursively(_el, child);
            }
        }
    }
Example #7
0
    ///////////////////////////////////////////////////////////////////////////////
    // functions
    ///////////////////////////////////////////////////////////////////////////////

    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public void Init()
    {
        if (initialized)
        {
            return;
        }

        //
        if (GetComponent <Camera>() == null)
        {
            Debug.LogError("The exUIMng should attach to a camera");
            return;
        }

        //
        for (int i = 0; i < 10; ++i)
        {
            touchStateList[i] = new TouchState();
        }

        // recursively add ui-tree
        exUIElement[] elements = FindObjectsOfType(typeof(exUIElement)) as exUIElement[];
        for (int i = 0; i < elements.Length; ++i)
        {
            exUIElement el        = elements[i];
            exUIElement parent_el = el.FindParent();
            if (parent_el == null)
            {
                exUIElement.FindAndAddChild(el);

                //
                if (rootElements.IndexOf(el) == -1)
                {
                    rootElements.Add(el);
                }
            }
        }

        //
        mouseState.currentPos     = Vector2.zero;
        mouseState.currentButtons = exUIEvent.MouseButtonFlags.None;
        mouseState.hotElement     = null;
        mouseState.focusElement   = null;

        initialized = true;
    }
Example #8
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    void DispatchEvents()
    {
        for (int i = 0; i < eventInfoList.Count; ++i)
        {
            EventInfo   info     = eventInfoList[i];
            bool        used     = info.primaryElement.OnEvent(info.uiEvent);
            exUIElement uiParent = info.primaryElement;
            while (used == false)
            {
                uiParent = uiParent.parent;
                if (uiParent == null)
                {
                    break;
                }
                used = uiParent.OnEvent(info.uiEvent);
            }
        }
        eventInfoList.Clear();
    }
Example #9
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public void AddElement(exUIElement _el)
    {
        int lastEl = children.Count - 1;

        AddChild(_el);

        if (lastEl == -1)
        {
            _el.transform.parent        = contentAnchor;
            _el.transform.localPosition = new Vector3(0.0f, -_el.style.margin.top, 0.0f);
        }
        else
        {
            _el.transform.parent = contentAnchor;
            float y = children[lastEl].transform.localPosition.y
                      - (children[lastEl].boundingRect.height
                         + children[lastEl].style.margin.bottom
                         + _el.style.margin.top)
            ;
            _el.transform.localPosition = new Vector3(0.0f, y, 0.0f);
        }
    }
Example #10
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    exUIElement RecursivelyGetUIElement(exUIElement _el, Vector2 _pos)
    {
        if (_el.enabled == false)
        {
            return(null);
        }

        // if we are out of clipping plane
        if (_el.clippingPlane != null)
        {
            Vector2 clipPos = new Vector2(_pos.x - _el.clippingPlane.transform.position.x,
                                          _pos.y - _el.clippingPlane.transform.position.y);
            if (_el.clippingPlane.boundingRect.Contains(clipPos) == false)
            {
                return(null);
            }
        }

        //
        Vector2 localPos = new Vector2(_pos.x - _el.transform.position.x,
                                       _pos.y - _el.transform.position.y);

        if (_el.boundingRect.Contains(localPos))
        {
            _el.children.Sort(elementSorterByZ);
            for (int i = 0; i < _el.children.Count; ++i)
            {
                exUIElement childEL  = _el.children[i];
                exUIElement resultEL = RecursivelyGetUIElement(childEL, _pos);
                if (resultEL != null)
                {
                    return(resultEL);
                }
            }
            return(_el);
        }

        return(null);
    }
Example #11
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public void UpdateLayout()
    {
        float y = 0.0f;
        float x = 0.0f;

        for (int i = 0; i < children.Count; ++i)
        {
            exUIElement el  = children[i];
            Vector3     pos = el.transform.localPosition;
            pos.x = el.style.margin.left;
            pos.y = y + el.style.margin.top + el.style.margin.bottom;
            y     = pos.y + el.boundingRect.height;
            if (el.boundingRect.width > x)
            {
                x = el.boundingRect.width;
            }
        }

        contentHeight = Mathf.Max(y, 0.1f);
        contentWidth  = Mathf.Max(x, 0.1f);

        minX = 0.0f;
        maxX = Mathf.Max(contentWidth - clipRect.width, 0.0f);

        minY = -Mathf.Max(contentHeight - clipRect.height, 0.0f);
        maxY = 0.0f;

        if (horizontalSlider)
        {
            horizontalSlider.width = (contentWidth <= clipRect.width) ? clipRect.width : clipRect.width / contentWidth * clipRect.width;
        }
        if (verticalSlider)
        {
            verticalSlider.height = (contentHeight <= clipRect.height) ? clipRect.height : clipRect.height / contentHeight * clipRect.height;
        }
    }
Example #12
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    void ProcessMouse()
    {
        // get current position and delta pos
        Vector2 lastPointerPos = mouseState.currentPos;

        mouseState.currentPos = Input.mousePosition;
        Vector2 deltaPos = mouseState.currentPos - lastPointerPos;

        // get current mouse button
        exUIEvent.MouseButtonFlags lastButtons = mouseState.currentButtons;
        exUIEvent.MouseButtonFlags buttonDown  = exUIEvent.MouseButtonFlags.None;
        exUIEvent.MouseButtonFlags buttonUp    = exUIEvent.MouseButtonFlags.None;

        // handle pressed
        mouseState.currentButtons = exUIEvent.MouseButtonFlags.None;
        if (Input.anyKey)
        {
            if (Input.GetMouseButton(0))
            {
                mouseState.currentButtons |= exUIEvent.MouseButtonFlags.Left;
            }
            if (Input.GetMouseButton(1))
            {
                mouseState.currentButtons |= exUIEvent.MouseButtonFlags.Right;
            }
            if (Input.GetMouseButton(2))
            {
                mouseState.currentButtons |= exUIEvent.MouseButtonFlags.Middle;
            }
        }

        // handle press
        if (Input.anyKeyDown)
        {
            if (Input.GetMouseButtonDown(0))
            {
                buttonDown = exUIEvent.MouseButtonFlags.Left;
            }
            else if (Input.GetMouseButtonDown(1))
            {
                buttonDown = exUIEvent.MouseButtonFlags.Right;
            }
            else if (Input.GetMouseButtonDown(2))
            {
                buttonDown = exUIEvent.MouseButtonFlags.Middle;
            }
        }

        // handle release
        if (lastButtons != mouseState.currentButtons)
        {
            if (Input.GetMouseButtonUp(0))
            {
                buttonUp = exUIEvent.MouseButtonFlags.Left;
            }
            else if (Input.GetMouseButtonUp(1))
            {
                buttonUp = exUIEvent.MouseButtonFlags.Right;
            }
            else if (Input.GetMouseButtonUp(2))
            {
                buttonUp = exUIEvent.MouseButtonFlags.Middle;
            }
        }

        // get hot element
        exUIElement lastHotElement = mouseState.hotElement;

        mouseState.hotElement = PickElement(mouseState.currentPos);

        // process hover event
        if (lastHotElement != mouseState.hotElement)
        {
            // add hover-in event
            if (mouseState.hotElement != null)
            {
                exUIEvent e = new exUIEvent();
                e.category = exUIEvent.Category.Mouse;
                e.type     = exUIEvent.Type.MouseEnter;
                e.position = mouseState.currentPos;
                e.delta    = deltaPos;
                e.buttons  = mouseState.currentButtons;

                EventInfo info = new EventInfo();
                info.primaryElement = mouseState.hotElement;
                info.uiEvent        = e;
                eventInfoList.Add(info);
            }

            // add hover-out event
            if (lastHotElement != null)
            {
                exUIEvent e = new exUIEvent();
                e.category = exUIEvent.Category.Mouse;
                e.type     = exUIEvent.Type.MouseExit;
                e.position = mouseState.currentPos;
                e.delta    = deltaPos;
                e.buttons  = mouseState.currentButtons;

                EventInfo info = new EventInfo();
                info.primaryElement = lastHotElement;
                info.uiEvent        = e;
                eventInfoList.Add(info);
            }
        }

        // add pointer-move event
        if ((mouseState.hotElement != null || mouseState.focusElement != null) && deltaPos != Vector2.zero)
        {
            exUIEvent e = new exUIEvent();
            e.category = exUIEvent.Category.Mouse;
            e.type     = exUIEvent.Type.MouseMove;
            e.position = mouseState.currentPos;
            e.delta    = deltaPos;
            e.buttons  = mouseState.currentButtons;

            EventInfo info = new EventInfo();
            info.primaryElement = (mouseState.focusElement != null) ? mouseState.focusElement : mouseState.hotElement;
            info.uiEvent        = e;
            eventInfoList.Add(info);
        }

        // add pointer-press event
        if (mouseState.hotElement != null && buttonDown != exUIEvent.MouseButtonFlags.None)
        {
            exUIEvent e = new exUIEvent();
            e.category = exUIEvent.Category.Mouse;
            e.type     = exUIEvent.Type.MouseDown;
            e.position = mouseState.currentPos;
            e.delta    = deltaPos;
            e.buttons  = buttonDown;

            EventInfo info = new EventInfo();
            info.primaryElement = mouseState.hotElement;
            info.uiEvent        = e;
            eventInfoList.Add(info);
        }

        // add pointer-release event
        if (mouseState.focusElement != null && buttonUp != exUIEvent.MouseButtonFlags.None)
        {
            exUIEvent e = new exUIEvent();
            e.category = exUIEvent.Category.Mouse;
            e.type     = exUIEvent.Type.MouseUp;
            e.position = mouseState.currentPos;
            e.delta    = deltaPos;
            e.buttons  = buttonUp;

            EventInfo info = new EventInfo();
            info.primaryElement = mouseState.focusElement;
            info.uiEvent        = e;
            eventInfoList.Add(info);
        }
    }
Example #13
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    void ProcessTouch()
    {
        for (int i = 0; i < Input.touches.Length; ++i)
        {
            Touch touch = Input.touches[i];
            if (touch.fingerId >= 10)
            {
                continue;
            }

            TouchState touchState  = null;
            exUIElement hotElement = PickElement(touch.position);

            //
            if (touch.phase == TouchPhase.Began)
            {
                if (hotElement != null)
                {
                    exUIEvent e = new exUIEvent();
                    e.category = exUIEvent.Category.Touch;
                    e.type     = exUIEvent.Type.TouchDown;
                    e.position = touch.position;
                    e.delta    = touch.deltaPosition;
                    e.touchID  = touch.fingerId;

                    EventInfo info = new EventInfo();
                    info.primaryElement = hotElement;
                    info.uiEvent        = e;
                    eventInfoList.Add(info);
                }

                // NOTE: it must be null
                SetTouchFocus(touch.fingerId, null);
                touchStateList[touch.fingerId].hotElement = hotElement;
            }
            else
            {
                // find the touch state
                touchState = touchStateList[touch.fingerId];

                // set the last and current hot element
                exUIElement focusElement   = null;
                exUIElement lastHotElement = null;
                if (touchState != null)
                {
                    lastHotElement        = touchState.hotElement;
                    touchState.hotElement = hotElement;
                    focusElement          = touchState.focusElement;
                }

                if (touch.phase == TouchPhase.Ended)
                {
                    if (touchState != null)
                    {
                        if (focusElement != null)
                        {
                            exUIEvent e = new exUIEvent();
                            e.category = exUIEvent.Category.Touch;
                            e.type     = exUIEvent.Type.TouchUp;
                            e.position = touch.position;
                            e.delta    = touch.deltaPosition;
                            e.touchID  = touch.fingerId;

                            EventInfo info = new EventInfo();
                            info.primaryElement = focusElement;
                            info.uiEvent        = e;
                            eventInfoList.Add(info);
                        }
                    }
                }
                else if (touch.phase == TouchPhase.Canceled)
                {
                    if (touchState != null)
                    {
                        SetTouchFocus(touch.fingerId, null);
                    }
                }
                else if (touch.phase == TouchPhase.Moved)
                {
                    // process hover event
                    if (lastHotElement != hotElement)
                    {
                        // add hover-in event
                        if (hotElement != null)
                        {
                            exUIEvent e = new exUIEvent();
                            e.category = exUIEvent.Category.Touch;
                            e.type     = exUIEvent.Type.TouchEnter;
                            e.position = touch.position;
                            e.delta    = touch.deltaPosition;
                            e.touchID  = touch.fingerId;

                            EventInfo info = new EventInfo();
                            info.primaryElement = hotElement;
                            info.uiEvent        = e;
                            eventInfoList.Add(info);
                        }

                        // add hover-out event
                        if (lastHotElement != null)
                        {
                            exUIEvent e = new exUIEvent();
                            e.category = exUIEvent.Category.Touch;
                            e.type     = exUIEvent.Type.TouchExit;
                            e.position = touch.position;
                            e.delta    = touch.deltaPosition;
                            e.touchID  = touch.fingerId;

                            EventInfo info = new EventInfo();
                            info.primaryElement = lastHotElement;
                            info.uiEvent        = e;
                            eventInfoList.Add(info);
                        }
                    }

                    //
                    if (hotElement != null || focusElement != null)
                    {
                        exUIEvent e = new exUIEvent();
                        e.category = exUIEvent.Category.Touch;
                        e.type     = exUIEvent.Type.TouchMove;
                        e.position = touch.position;
                        e.delta    = touch.deltaPosition;
                        e.touchID  = touch.fingerId;

                        EventInfo info = new EventInfo();
                        info.primaryElement = (focusElement != null) ? focusElement : hotElement;
                        info.uiEvent        = e;
                        eventInfoList.Add(info);
                    }
                }
            }
        }
    }
Example #14
0
 // ------------------------------------------------------------------
 // Desc:
 // ------------------------------------------------------------------
 public void RemoveChild( exUIElement _element )
 {
     _element.parent = null;
     children.Remove(_element);
 }
Example #15
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public void SetMouseFocus(exUIElement _el)
    {
        mouseState.focusElement = _el;
    }
Example #16
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public void SetTouchFocus(int _touchID, exUIElement _el)
    {
        touchStateList[_touchID].focusElement = _el;
    }
Example #17
0
 // ------------------------------------------------------------------
 // Desc:
 // ------------------------------------------------------------------
 static void FindAndAddChildRecursively( exUIElement _el, Transform _trans )
 {
     foreach ( Transform child in _trans ) {
         exUIElement child_el = child.GetComponent<exUIElement>();
         if ( child_el ) {
             _el.AddChild (child_el);
             exUIElement.FindAndAddChild (child_el);
         }
         else {
             FindAndAddChildRecursively( _el, child );
         }
     }
 }
Example #18
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    void HandleRezie(int _handleID, Vector3 _oldPos, Vector3 _newPos)
    {
        if (_oldPos == _newPos)
        {
            return;
        }

        exUIElement curEdit = target as exUIElement;

        //
        float dx, dy;

        GetDelatSize(_newPos - _oldPos, out dx, out dy);

        float oldWidth  = curEdit.width;
        float oldHeight = curEdit.height;
        float xRatio    = 1.0f;
        float yRatio    = 1.0f;

        // 0 -- 1 -- 2
        // |         |
        // 7         3
        // |         |
        // 6 -- 5 -- 4

        if (_handleID == 0)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = -1.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = -0.5f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = -0.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = -1.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = -0.5f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = -0.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = -1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = -0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = -0.0f; yRatio = 0.0f; break;
            }
            curEdit.width -= dx; curEdit.height += dy;
        }
        else if (_handleID == 1)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = 0.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = 0.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = 0.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = 0.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = 0.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = 0.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = 0.0f; yRatio = 0.0f; break;
            }
            curEdit.height += dy;
        }
        else if (_handleID == 2)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = 0.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = 0.5f; yRatio = 1.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = 1.0f; yRatio = 1.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = 0.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = 0.5f; yRatio = 0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = 1.0f; yRatio = 0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = 0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = 1.0f; yRatio = 0.0f; break;
            }
            curEdit.width += dx; curEdit.height += dy;
        }
        else if (_handleID == 3)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = 0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = 1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidCenter:   xRatio = 0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidRight:    xRatio = 1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotLeft:     xRatio = 0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = 0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = 1.0f; yRatio = 0.0f; break;
            }
            curEdit.width += dx;
        }
        else if (_handleID == 4)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = 0.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = 0.5f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = 1.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = 0.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = 0.5f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = 1.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = 0.0f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = 0.5f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = 1.0f; yRatio = -1.0f; break;
            }
            curEdit.width += dx; curEdit.height -= dy;
        }
        else if (_handleID == 5)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = 0.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = 0.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = 0.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = 0.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = 0.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = 0.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = 0.0f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = 0.0f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = 0.0f; yRatio = -1.0f; break;
            }
            curEdit.height -= dy;
        }
        else if (_handleID == 6)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = -1.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = -0.5f; yRatio = -0.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = -0.0f; yRatio = -0.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = -1.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidCenter:   xRatio = -0.5f; yRatio = -0.5f; break;

            case exPlane.Anchor.MidRight:    xRatio = -0.0f; yRatio = -0.5f; break;

            case exPlane.Anchor.BotLeft:     xRatio = -1.0f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = -0.5f; yRatio = -1.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = -0.0f; yRatio = -1.0f; break;
            }
            curEdit.width -= dx; curEdit.height -= dy;
        }
        else if (_handleID == 7)
        {
            switch (curEdit.anchor)
            {
            case exPlane.Anchor.TopLeft:     xRatio = -1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.TopCenter:   xRatio = -0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.TopRight:    xRatio = -0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidLeft:     xRatio = -1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidCenter:   xRatio = -0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.MidRight:    xRatio = -0.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotLeft:     xRatio = -1.0f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotCenter:   xRatio = -0.5f; yRatio = 0.0f; break;

            case exPlane.Anchor.BotRight:    xRatio = -0.0f; yRatio = 0.0f; break;
            }
            curEdit.width -= dx;
        }

        float offsetX = (curEdit.width - oldWidth) * xRatio;
        float offsetY = (curEdit.height - oldHeight) * yRatio;

        curEdit.Translate(offsetX, offsetY);
    }
Example #19
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected virtual void OnSceneGUI()
    {
        exUIElement curEdit = target as exUIElement;

        //
        Vector3[] vertices = new Vector3[4];
        Vector3[] corners  = new Vector3[5];
        Vector3[] controls = new Vector3[8];

        float halfWidthScaled  = curEdit.width * 0.5f;
        float halfHeightScaled = curEdit.height * 0.5f;
        float offsetX          = 0.0f;
        float offsetY          = 0.0f;

        //
        switch (curEdit.anchor)
        {
        case exPlane.Anchor.TopLeft: offsetX = -halfWidthScaled;   offsetY = -halfHeightScaled;  break;

        case exPlane.Anchor.TopCenter: offsetX = 0.0f;               offsetY = -halfHeightScaled;  break;

        case exPlane.Anchor.TopRight: offsetX = halfWidthScaled;    offsetY = -halfHeightScaled;  break;

        case exPlane.Anchor.MidLeft: offsetX = -halfWidthScaled;   offsetY = 0.0f;               break;

        case exPlane.Anchor.MidCenter: offsetX = 0.0f;               offsetY = 0.0f;               break;

        case exPlane.Anchor.MidRight: offsetX = halfWidthScaled;    offsetY = 0.0f;               break;

        case exPlane.Anchor.BotLeft: offsetX = -halfWidthScaled;   offsetY = halfHeightScaled;   break;

        case exPlane.Anchor.BotCenter: offsetX = 0.0f;               offsetY = halfHeightScaled;   break;

        case exPlane.Anchor.BotRight: offsetX = halfWidthScaled;    offsetY = halfHeightScaled;   break;

        default: offsetX = 0.0f;               offsetY = 0.0f;               break;
        }
        offsetX += curEdit.offset.x;
        offsetY += curEdit.offset.y;

        //
        vertices[0] = new Vector3(-halfWidthScaled - offsetX, halfHeightScaled + offsetY, 0.0f);
        vertices[1] = new Vector3(halfWidthScaled - offsetX, halfHeightScaled + offsetY, 0.0f);
        vertices[2] = new Vector3(halfWidthScaled - offsetX, -halfHeightScaled + offsetY, 0.0f);
        vertices[3] = new Vector3(-halfWidthScaled - offsetX, -halfHeightScaled + offsetY, 0.0f);

        // 0 -- 1
        // |    |
        // 3 -- 2

        Transform trans = curEdit.transform;

        corners[0] = trans.localToWorldMatrix * new Vector4(vertices[0].x, vertices[0].y, vertices[0].z, 1.0f);
        corners[1] = trans.localToWorldMatrix * new Vector4(vertices[1].x, vertices[1].y, vertices[1].z, 1.0f);
        corners[2] = trans.localToWorldMatrix * new Vector4(vertices[2].x, vertices[2].y, vertices[2].z, 1.0f);
        corners[3] = trans.localToWorldMatrix * new Vector4(vertices[3].x, vertices[3].y, vertices[3].z, 1.0f);
        corners[4] = corners[0];
        Handles.DrawPolyLine(corners);

        // 0 -- 1 -- 2
        // |         |
        // 7         3
        // |         |
        // 6 -- 5 -- 4

        controls[0] = corners[0];
        controls[1] = (corners[0] + corners[1]) / 2.0f;
        controls[2] = corners[1];
        controls[3] = (corners[1] + corners[2]) / 2.0f;
        controls[4] = corners[2];
        controls[5] = (corners[2] + corners[3]) / 2.0f;
        controls[6] = corners[3];
        controls[7] = (corners[3] + corners[0]) / 2.0f;

        // TEMP: not sure this is good {
        Event e = Event.current;

        if (e.type == EventType.MouseDown && e.button == 0 && e.clickCount == 1)
        {
            Undo.RegisterSceneUndo("ex2D.Scene");
        }
        // } TEMP end

        //
        for (int i = 0; i < controls.Length; ++i)
        {
            Vector3 pos = controls[i];
            Handles.color = new Color(1.0f, 1.0f, 0.0f, 0.5f);

            Vector3 newPos = Handles.FreeMoveHandle(pos,
                                                    curEdit.transform.rotation,
                                                    HandleUtility.GetHandleSize(pos) / 20.0f,
                                                    Vector3.zero,
                                                    Handles.DotCap
                                                    );
            HandleRezie(i, pos, newPos);
        }
        // Handles.Label( curEdit.transform.position + Vector3.up * 2,
        //                "Size = " + curEdit.width + " x " + curEdit.height );

        // DELME {
        // if ( EditorApplication.isPlaying == false )
        //     curEdit.Sync();
        // } DELME end

        if (GUI.changed)
        {
            EditorUtility.SetDirty(curEdit);
        }
    }
Example #20
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    public void AddElement( exUIElement _el )
    {
        int lastEl = children.Count-1;
        AddChild(_el);

        if ( lastEl == -1 ) {
            _el.transform.parent = contentAnchor;
            _el.transform.localPosition = new Vector3( 0.0f, -_el.style.margin.top, 0.0f );
        }
        else {
            _el.transform.parent = contentAnchor;
            float y = children[lastEl].transform.localPosition.y
                - ( children[lastEl].boundingRect.height
                    + children[lastEl].style.margin.bottom
                    + _el.style.margin.top )
                ;
            _el.transform.localPosition = new Vector3 ( 0.0f, y, 0.0f );
        }
    }
Example #21
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public void RemoveChild(exUIElement _element)
    {
        _element.parent = null;
        children.Remove(_element);
    }
Example #22
0
 // ------------------------------------------------------------------
 // Desc:
 // ------------------------------------------------------------------
 public void AddChild( exUIElement _element )
 {
     _element.parent = this;
     children.Add(_element);
 }
Example #23
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public static void FindAndAddChild(exUIElement _el)
    {
        _el.children.Clear();
        FindAndAddChildRecursively(_el, _el.transform);
    }
Example #24
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public void AddChild(exUIElement _element)
    {
        _element.parent = this;
        children.Add(_element);
    }
Example #25
0
 // ------------------------------------------------------------------
 // Desc:
 // ------------------------------------------------------------------
 public static void FindAndAddChild( exUIElement _el )
 {
     _el.children.Clear();
     FindAndAddChildRecursively (_el, _el.transform );
 }