Exemplo n.º 1
0
        private void Update()
        {
            if (mTrans == null)
            {
                return;
            }
            Screen.showCursor = false;

            Vector3 pos = Input.mousePosition;

            pos = pos + new Vector3(mTrans.localScale.x / 2, -mTrans.localScale.y / 2, 0);

            if (uiCamera != null)
            {
                pos.x           = pos.x / Screen.width;
                pos.y           = (pos.y + 4) / Screen.height;//绘画的鼠标会比原广播底几像素.
                mTrans.position = uiCamera.ViewportToWorldPoint(pos);

                if (uiCamera.isOrthoGraphic)
                {
                    mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mTrans.localPosition, mTrans.localScale);
                }
            }
            else
            {
                pos.x -= Screen.width * 0.5f;
                pos.y -= Screen.height * 0.5f;
                mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(pos, mTrans.localScale);
            }
        }
Exemplo n.º 2
0
    void Update()
    {
        //if (mSprite.atlas != null)
        //{

        if (IsDragging)
        {
            Vector3 pos = Input.mousePosition;

            if (uiCamera != null)
            {
                pos.x           = Mathf.Clamp01(pos.x / Screen.width);
                pos.y           = Mathf.Clamp01(pos.y / Screen.height);
                mTrans.position = uiCamera.ViewportToWorldPoint(pos);

                if (uiCamera.isOrthoGraphic)
                {
                    mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mTrans.localPosition, mTrans.localScale);
                }
            }
            else
            {
                pos.x -= Screen.width * 0.5f;
                pos.y -= Screen.height * 0.5f;
                mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(pos, mTrans.localScale);
            }
        }
        //}
    }
Exemplo n.º 3
0
    /// <summary>
    /// Update the tooltip's alpha based on the target value.
    /// </summary>

    void Update()
    {
        if (mCurrent != mTarget)
        {
            mCurrent = Mathf.Lerp(mCurrent, mTarget, Time.deltaTime * appearSpeed);
            if (Mathf.Abs(mCurrent - mTarget) < 0.001f)
            {
                mCurrent = mTarget;
            }
            SetAlpha(mCurrent * mCurrent);

            if (scalingTransitions)
            {
                Vector3 offset = mSize * 0.25f;
                offset.y = -offset.y;

                Vector3 size = Vector3.one * (1.5f - mCurrent * 0.5f);
                Vector3 pos  = Vector3.Lerp(mPos - offset, mPos, mCurrent);
                pos = NGUIMath.ApplyHalfPixelOffset(pos);

                mTrans.localPosition = pos;
                mTrans.localScale    = size;
            }
        }
    }
    /// <summary>
    /// Reposition the sprite.
    /// </summary>

    void Update()
    {
        if (mSprite.atlas != null)
        {
            Vector3 pos = Input.mousePosition;

            if (uiCamera != null)
            {
                // Since the screen can be of different than expected size, we want to convert
                // mouse coordinates to view space, then convert that to world position.
                pos.x           = Mathf.Clamp01(pos.x / Screen.width);
                pos.y           = Mathf.Clamp01(pos.y / Screen.height);
                mTrans.position = uiCamera.ViewportToWorldPoint(pos);

                // For pixel-perfect results
                if (uiCamera.orthographic)
                {
                    mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mTrans.localPosition, mTrans.localScale);
                }
            }
            else
            {
                // Simple calculation that assumes that the camera is of fixed size
                pos.x -= Screen.width * 0.5f;
                pos.y -= Screen.height * 0.5f;
                mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(pos, mTrans.localScale);
            }
        }
    }
Exemplo n.º 5
0
    private void Update()
    {
        if (mSprite.atlas == null)
        {
            return;
        }
        Vector3 mousePosition = Input.mousePosition;

        if (uiCamera != null)
        {
            mousePosition.x = Mathf.Clamp01(mousePosition.x / (float)Screen.width);
            mousePosition.y = Mathf.Clamp01(mousePosition.y / (float)Screen.height);
            mTrans.position = uiCamera.ViewportToWorldPoint(mousePosition);
            if (uiCamera.isOrthoGraphic)
            {
                mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mTrans.localPosition, mTrans.localScale);
            }
        }
        else
        {
            mousePosition.x     -= (float)Screen.width * 0.5f;
            mousePosition.y     -= (float)Screen.height * 0.5f;
            mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mousePosition, mTrans.localScale);
        }
    }
Exemplo n.º 6
0
    void Update()
    {
        if (!(PeInput.Get(PeInput.LogicFunction.Item_Drag) || UICamera.hoveredObject != null))
        {
            UpdateMouseIcon();
        }
        if ((UICamera.hoveredObject != null || PeInput.Get(PeInput.LogicFunction.Item_Drag)) && mIsShow)
        {
            DisableCursor(); //HideCursor();
        }
        if (PeInput.Get(PeInput.LogicFunction.InteractWithItem) || Input.GetMouseButtonDown(0))
        {
            PlayTipHideTween();
        }

        //更新位置
        if (mOpSprite.atlas != null)
        {
            Vector3 pos = Input.mousePosition;

            if (uiCamera != null)
            {
                // Since the screen can be of different than expected size, we want to convert
                // mouse coordinates to view space, then convert that to world position.
                pos.x           = Mathf.Clamp01(pos.x / Screen.width);
                pos.y           = Mathf.Clamp01(pos.y / Screen.height);
                mTrans.position = uiCamera.ViewportToWorldPoint(pos);
                // For pixel-perfect results
                if (uiCamera.orthographic)
                {
                    mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mTrans.localPosition, mTrans.localScale);
                }
            }
        }
    }
Exemplo n.º 7
0
 private void Update()
 {
     if (m_dragStopped)
     {
         CancelDragAction();
     }
     if (m_draggedItem != null)
     {
         Vector3   mousePosition = Input.mousePosition;
         Transform transform     = this.transform;
         if (m_camera != null)
         {
             mousePosition.x    = Mathf.Clamp01(mousePosition.x / Screen.width);
             mousePosition.y    = Mathf.Clamp01(mousePosition.y / Screen.height);
             transform.position = m_camera.ViewportToWorldPoint(mousePosition);
             if (m_camera.isOrthoGraphic)
             {
                 transform.localPosition = NGUIMath.ApplyHalfPixelOffset(transform.localPosition, transform.localScale);
             }
         }
         else
         {
             mousePosition.x        -= Screen.width * 0.5f;
             mousePosition.y        -= Screen.height * 0.5f;
             transform.localPosition = NGUIMath.ApplyHalfPixelOffset(mousePosition, transform.localScale);
         }
     }
 }
    void Update()
    {
        if (mSprite.atlas != null)
        {
            Vector3 pos = Input.mousePosition;

            if (UICamera != null)
            {
                pos.x           = Mathf.Clamp01(pos.x / Screen.width);
                pos.y           = Mathf.Clamp01(pos.y / Screen.height);
                mTrans.position = UICamera.ViewportToWorldPoint(pos);

                if (UICamera.isOrthoGraphic)
                {
                    mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mTrans.localPosition, mTrans.localScale);
                }
                if (Input.GetMouseButtonUp(0))
                {
                    if (Info != null)
                    {
                        if (isHovered == false)
                        {
                            if (PermissionCheck == true)
                            {
                                Clear();
                                NGUITools.PlaySound(ActionBarSettings.Instance.ButtonSound_Destroyed);
                            }
                        }
                    }
                }
            }
            else
            {
                pos.x -= Screen.width * 0.5f;
                pos.y -= Screen.height * 0.5f;
                mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(pos, mTrans.localScale);
            }
        }
    }
Exemplo n.º 9
0
 private void Update()
 {
     if (this.mSprite.atlas != null)
     {
         Vector3 mousePosition = Input.mousePosition;
         if (this.uiCamera != null)
         {
             mousePosition.x      = Mathf.Clamp01(mousePosition.x / ((float)Screen.width));
             mousePosition.y      = Mathf.Clamp01(mousePosition.y / ((float)Screen.height));
             this.mTrans.position = this.uiCamera.ViewportToWorldPoint(mousePosition);
             if (this.uiCamera.isOrthoGraphic)
             {
                 this.mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(this.mTrans.localPosition, this.mTrans.localScale);
             }
         }
         else
         {
             mousePosition.x          -= Screen.width * 0.5f;
             mousePosition.y          -= Screen.height * 0.5f;
             this.mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mousePosition, this.mTrans.localScale);
         }
     }
 }
Exemplo n.º 10
0
    void Update()
    {
        //if (mSprite.atlas != null)
        {
            //Vector3 pos = Input.mousePosition;
            Vector3 pos = Vector3.zero;

            if (uiCamera != null)
            {
                if (Input.touchCount == 1)
                {
                    // we've got only a single touch here, handle what it comes
                    Touch touch = Input.GetTouch(0);
                    pos = touch.position;
                }
                else
                {
                    pos = Input.mousePosition;

                    /*
                     * if ( Input.touchCount == 0 && mSprite.atlas != null )
                     * {
                     *      Debug.Log ( "###################     mouse down : " + Input.GetMouseButtonDown( 0 ) );
                     *      Debug.Log ( "###################     mouse up : " + Input.GetMouseButtonUp( 0 ) );
                     * }
                     */
                    if ((Input.GetMouseButtonUp(0) && mSprite.atlas != null))
                    {
                        if (dialogController != null)
                        {
                            mSprite.atlas = null;
                            dialogController.SendMessage("OnCursorUpError", this, SendMessageOptions.DontRequireReceiver);
                        }
                    }
                }


                // Since the screen can be of different than expected size, we want to convert
                // mouse or touch coordinates to view space, then convert that to world position.
                pos.x           = Mathf.Clamp01(pos.x / Screen.width);
                pos.y           = Mathf.Clamp01(pos.y / Screen.height);
                mTrans.position = uiCamera.ViewportToWorldPoint(pos);

                //Debug.Log( "##########################################     position: " + mTrans.position );


                // For pixel-perfect results
                if (uiCamera.isOrthoGraphic)
                {
                    mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mTrans.localPosition, mTrans.localScale);
                }
            }
            else
            {
                // Simple calculation that assumes that the camera is of fixed size
                pos.x -= Screen.width * 0.5f;
                pos.y -= Screen.height * 0.5f;
                mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(pos, mTrans.localScale);
            }
        }
    }
Exemplo n.º 11
0
    /// <summary>
    /// Set the tooltip's text to the specified string.
    /// </summary>

    void SetText(string tooltipText)
    {
        if (!string.IsNullOrEmpty(tooltipText))
        {
            mTarget = 1f;

            if (text != null)
            {
                text.text = tooltipText;
            }

            // Orthographic camera positioning is trivial
            mPos = Input.mousePosition;

            if (background != null)
            {
                Transform backgroundTrans = background.transform;

                if (text != null && text.font != null)
                {
                    Transform textTrans = text.transform;
                    Vector3   offset    = textTrans.localPosition;
                    Vector3   textScale = textTrans.localScale;

                    // Calculate the dimensions of the printed text
                    mSize = text.font.CalculatePrintedSize(tooltipText, true);

                    // Scale by the transform and adjust by the padding offset
                    mSize.x *= textScale.x;
                    mSize.y *= textScale.y;
                    mSize.x += offset.x * 2f;
                    mSize.y -= offset.y * 2f;
                    mSize.z  = 1f;

                    backgroundTrans.localScale = mSize;
                }
            }

            if (uiCamera != null)
            {
                // Since the screen can be of different than expected size, we want to convert
                // mouse coordinates to view space, then convert that to world position.
                mPos.x = Mathf.Clamp01(mPos.x / Screen.width);
                mPos.y = Mathf.Clamp01(mPos.y / Screen.height);

                // Calculate the ratio of the camera's target orthographic size to current screen size
                float activeSize = uiCamera.orthographicSize / mTrans.parent.lossyScale.y;
                float ratio      = (Screen.height * 0.5f) / activeSize;

                // Calculate the maximum on-screen size of the tooltip window
                Vector2 max = new Vector2(ratio * mSize.x / Screen.width, ratio * mSize.y / Screen.height);

                // Limit the tooltip to always be visible
                mPos.x = Mathf.Min(mPos.x, 1f - max.x);
                mPos.y = Mathf.Max(mPos.y, max.y);

                // Update the absolute position and save the local one
                mTrans.position = uiCamera.ViewportToWorldPoint(mPos);
                mPos            = mTrans.localPosition;
            }
            else
            {
                // Don't let the tooltip leave the screen area
                if (mPos.x + mSize.x > Screen.width)
                {
                    mPos.x = Screen.width - mSize.x;
                }
                if (mPos.y - mSize.y < 0f)
                {
                    mPos.y = mSize.y;
                }

                // Simple calculation that assumes that the camera is of fixed size
                mPos.x -= Screen.width * 0.5f;
                mPos.y -= Screen.height * 0.5f;
            }

            // Set the final position
            mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mPos);
        }
        else
        {
            mTarget = 0f;
        }
    }
Exemplo n.º 12
0
    void Update()
    {
        Vector3 pos = Input.mousePosition;

        pos.x                = Mathf.Clamp01(pos.x / Screen.width);
        pos.y                = Mathf.Clamp01(pos.y / Screen.height);
        cursor.position      = uiCamera.ViewportToWorldPoint(pos) + Vector3.forward * 0.1f;
        cursor.localPosition = NGUIMath.ApplyHalfPixelOffset(cursor.localPosition, cursor.localScale);


        if (slot == null)
        {
            cursorRenderer.enabled = false;
        }
        else
        {
            cursorRenderer.enabled              = true;
            cursorRenderer.mainTexture          = slot.item.Texture;
            cursorRenderer.pivot                = UIWidget.Pivot.Center;
            cursorRenderer.transform.localScale = new Vector3(slot.item.Texture.width, slot.item.Texture.height, 0);
            //transform.localScale = new Vector3(inner.width, inner.height);
        }

        //Rect inner = cursorRenderer.sprite.inner;
        //transform.localScale = new Vector3(inner.width, inner.height);
        //cursorRenderer.sprite = _Loader.atlas.GetSprite(a);
        if (!Input.GetMouseButton(0) && slot != null)
        {
            if (!ongui)
            {
                Vector3    p = _Player.pos;
                RaycastHit h;
                if (Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out h, 100, 1 << (int)Layer.Level))
                {
                    p = h.point;
                }
                var g = (GameObject)Instantiate(_Database.DropAnimation, p, Quaternion.identity);
                g.GetComponent <DroppedItem>().item = slot.item;
                var g2 = (GameObject)Instantiate(slot.item.weaponPrefab, p + slot.item.weaponPrefab.transform.position, Quaternion.identity);
                g2.AddComponent <BoxCollider>();
                g2.gameObject.layer = (int)Layer.Coin;
                g2.transform.parent = g.transform;
                g2.name             = "Rifle_PH";
                slot.item           = null;
                slot.dragging       = false;
                slot.Refresh();
                slot = null;
            }
            else
            {
                var sl = UICamera.hoveredObject.GetComponent <Slot>();

                if (sl != null && (slot.item.slotType == sl.slotType || sl.slotType == SlotType.Inventory))
                {
                    _Cursor.slot.dragging = false;
                    Switch(ref _Cursor.slot.item, ref sl.item);
                    slot.Refresh();
                    sl.Refresh();
                    slot = null;
                }
                else
                {
                    slot.dragging = false;
                    slot          = null;
                }
            }
        }
    }