Ejemplo n.º 1
0
    /// <summary>
    /// Remove the selection.
    /// </summary>

    void OnDisable()
    {
        if (NGUICamera.IsHighlighted(gameObject))
        {
            OnSelect(false);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Layer is used to ensure that if it changes, widgets get moved as well.
    /// </summary>

    void Start()
    {
        mLayer = gameObject.layer;
        NGUICamera uic = NGUICamera.FindCameraForLayer(mLayer);

        mCam = (uic != null) ? uic.cachedCamera : NGUITools.FindCameraForLayer(mLayer);
    }
Ejemplo n.º 3
0
 void OnEnable()
 {
     if (mStarted && mHighlighted)
     {
         OnHover(NGUICamera.IsHighlighted(gameObject));
     }
 }
Ejemplo n.º 4
0
    /// <summary>
    /// If the object is currently highlighted, it should also be selected.
    /// </summary>

    void OnEnable()
    {
        if (NGUICamera.IsHighlighted(gameObject))
        {
            OnSelect(true);
        }
    }
Ejemplo n.º 5
0
 public virtual void OnPress(bool isPressed)
 {
     if (enabled)
     {
         if (!mStarted)
         {
             Start();
         }
         TweenColor.Begin(tweenTarget, duration, isPressed ? pressed : (NGUICamera.IsHighlighted(gameObject) ? hover : mColor));
     }
 }
Ejemplo n.º 6
0
 void OnPress(bool isPressed)
 {
     if (enabled)
     {
         if (!mStarted)
         {
             Start();
         }
         TweenPosition.Begin(tweenTarget.gameObject, duration, isPressed ? mPos + pressed :
                             (NGUICamera.IsHighlighted(gameObject) ? mPos + hover : mPos)).method = NGUITweener.Method.EaseInOut;
     }
 }
Ejemplo n.º 7
0
    protected override void ProcessActive()
    {
        if (!mStarted)
        {
            Start();
        }
        mPos    = m_isActive ? mDefaultPos + pressed : mDefaultPos;
        pressed = m_isActive ? Vector3.zero : mDefaultPressed;

        TweenPosition.Begin(tweenTarget.gameObject, duration,
                            (NGUICamera.IsHighlighted(gameObject) ? mPos + hover : mPos)).method = NGUITweener.Method.EaseInOut;
    }
Ejemplo n.º 8
0
 void OnPress(bool isPressed)
 {
     if (enabled)
     {
         if (!mStarted)
         {
             Start();
         }
         TweenRotation.Begin(tweenTarget.gameObject, duration, isPressed ? mRot * Quaternion.Euler(pressed) :
                             (NGUICamera.IsHighlighted(gameObject) ? mRot * Quaternion.Euler(hover) : mRot)).method = NGUITweener.Method.EaseInOut;
     }
 }
Ejemplo n.º 9
0
    /// <summary>
    /// Static comparison function used for sorting.
    /// </summary>

    static int CompareFunc(NGUICamera a, NGUICamera b)
    {
        if (a.cachedCamera.depth < b.cachedCamera.depth)
        {
            return(1);
        }
        if (a.cachedCamera.depth > b.cachedCamera.depth)
        {
            return(-1);
        }
        return(0);
    }
Ejemplo n.º 10
0
 void OnPress(bool isPressed)
 {
     if (enabled)
     {
         if (!mStarted)
         {
             Start();
         }
         TweenScale.Begin(tweenTarget.gameObject, duration, isPressed ? Vector3.Scale(mScale, pressed) :
                          (NGUICamera.IsHighlighted(gameObject) ? Vector3.Scale(mScale, hover) : mScale)).method = NGUITweener.Method.EaseInOut;
     }
 }
Ejemplo n.º 11
0
    protected override void ProcessActive()
    {
        if (!mStarted)
        {
            Start();
        }

        defaultColor = m_isActive ? pressed : mDefaultColor;

        if (enabled)
        {
            TweenColor.Begin(tweenTarget, duration, (NGUICamera.IsHighlighted(gameObject) ? hover : mColor));
        }
    }
Ejemplo n.º 12
0
 void OnEnable()
 {
     if (target != null)
     {
         if (isEnabled)
         {
             target.spriteName = NGUICamera.IsHighlighted(gameObject) ? hoverSprite : normalSprite;
             ProcessActive();
         }
         else
         {
             UpdateImageState(false);
         }
     }
 }
Ejemplo n.º 13
0
    /// <summary>
    /// Find the camera responsible for handling events on objects of the specified layer.
    /// </summary>

    static public NGUICamera FindCameraForLayer(int layer)
    {
        int layerMask = 1 << layer;

        for (int i = 0; i < mList.Count; ++i)
        {
            NGUICamera cam = mList[i];
            Camera     uc  = cam.cachedCamera;
            if ((uc != null) && (uc.cullingMask & layerMask) != 0)
            {
                return(cam);
            }
        }
        return(null);
    }
Ejemplo n.º 14
0
        public override void Update()
        {
            base.Update();

            InventoryLight.intensity = Mathf.Lerp(InventoryLight.intensity, TargetLightIntensity, 0.25f);

            if (ScreenTarget != null)
            {
                //figure out how big the list is
                gColliderBounds = NGUIMath.CalculateAbsoluteWidgetBounds(tr);
                //now get the actual final on-screen point from our ngui cameara so we can check against edges
                gColliderBounds.center = ScreenTarget.position;
                if (ScreenTargetCamera != null)
                {
                    gScreenBounds.SetMinMax(ScreenTargetCamera.WorldToScreenPoint(gColliderBounds.min), ScreenTargetCamera.WorldToScreenPoint(gColliderBounds.max));
                    //gScreenBounds.center = ScreenTargetCamera.WorldToScreenPoint(ScreenTarget.position);
                }
                else
                {
                    gScreenBounds.SetMinMax(NGUICamera.WorldToScreenPoint(gColliderBounds.min), NGUICamera.WorldToScreenPoint(gColliderBounds.max));
                    //gScreenBounds.center = NGUICamera.WorldToScreenPoint(ScreenTarget.position);
                }
                //keep the center from going off screen
                gScreenOffset = Vector3.zero;
                if (gScreenBounds.max.x > Screen.width)
                {
                    gScreenOffset.x = Screen.width - gScreenBounds.max.x;
                }
                if (gScreenBounds.max.y > Screen.height)
                {
                    gScreenOffset.y = Screen.height - gScreenBounds.max.y;
                }
                if (gScreenBounds.min.x < 0)
                {
                    gScreenOffset.x = 0f - gScreenBounds.min.x;
                }
                if (gScreenBounds.min.y < 0)
                {
                    gScreenOffset.y = 0f - gScreenBounds.min.y;
                }
                gWorldPoint   = NGUICamera.ScreenToWorldPoint(gScreenBounds.center + gScreenOffset);
                gWorldPoint.z = tr.position.z;
                tr.position   = gWorldPoint;
            }
        }
Ejemplo n.º 15
0
 protected void UpdateSelectedStackDisplay()
 {
     if (Player.Local.Inventory.SelectedStack.HasTopItem)
     {
         SelectedStackDisplayTransform.position = NGUICamera.GetComponent <Camera>().ScreenToWorldPoint(InterfaceActionManager.MousePosition);
         SelectedStackDoppleganger = WorldItems.GetDoppleganger(Player.Local.Inventory.SelectedStack.TopItem, SelectedStackDisplayOffsetTransform, SelectedStackDoppleganger, WIMode.Selected);
         StackNumberLabel.enabled  = true;
     }
     else
     {
         if (SelectedStackDoppleganger != null)
         {
             GameObject.Destroy(SelectedStackDoppleganger);
             SelectedStackDoppleganger = null;
         }
         StackNumberLabel.enabled = false;
     }
 }
Ejemplo n.º 16
0
    protected override void ProcessActive()
    {
        //LogManager.Log_Error(logObjName(this) + "ProccACT: " + m_isActive + " isEnable: " + isEnabled + " colors: " + pressed + defaultColor + mDefaultColor + disabledColor);
        if (tweenTarget)
        {
            if (!mStarted)
            {
                mStarted = true;
                Init();
            }

            defaultColor = m_isActive ? pressed : (isEnabled ? mDefaultColor : disabledColor);
            //Color c = isEnabled ? (NGUICamera.IsHighlighted(gameObject) ? hover : defaultColor) : disabledColor;
            Color      c  = isEnabled ? (NGUICamera.IsHighlighted(gameObject) ? hover : defaultColor) : (m_isActive? defaultColor : disabledColor);
            TweenColor tc = TweenColor.Begin(tweenTarget, duration, c);

            //LogManager.Log_Error(logObjName(this) + "ProccACT: " + m_isActive + " isEnable: " + isEnabled + " colors: "+ c + pressed + defaultColor + mDefaultColor + disabledColor);

            tc.color   = c;
            tc.enabled = false;
        }
    }
Ejemplo n.º 17
0
    /// <summary>
    /// Check the input and send out appropriate events.
    /// </summary>
    void Update()
    {
        // Only the first UI layer should be processing events
        if (!Application.isPlaying || !handlesEvents) return;

        current = this;

        // Update mouse input
        if (useMouse || (useTouch && mIsEditor)) ProcessMouse();

        // Process touch input
        if (useTouch) ProcessTouches();

        // Custom input processing
        if (onCustomInput != null) onCustomInput();

        // Clear the selection on the cancel key, but only if mouse input is allowed
        if (useMouse && mSel != null && ((cancelKey0 != KeyCode.None && Input.GetKeyDown(cancelKey0)) ||
            (cancelKey1 != KeyCode.None && Input.GetKeyDown(cancelKey1)))) selectedObject = null;

        // Forward the input to the selected object
        if (mSel != null)
        {
            string input = Input.inputString;

            //Merge the input string. Backspace always come first and the other characters
            //if the backspace is found in the current string no \b will be added so in practicve lastInputEvents will be always empty
            //if no backspace is found and a backspace has been reported, this will be added to lastInputEvents
            //next update the string will be notified and changed
            lastInputEvents = input + lastInputEvents;

            // Adding support for some macs only having the "Delete" key instead of "Backspace"
            if (useKeyboard && Input.GetKeyDown(KeyCode.Delete) && lastInputEvents.LastIndexOf('\b') == -1) lastInputEvents += "\b";

            if (lastInputEvents.Length > 0)
            {
                if (!stickyTooltip && mTooltip != null) ShowTooltip(false);
                Notify(mSel, "OnInput", lastInputEvents);
                //Nullify all the inputs
                lastInputEvents = System.String.Empty;
            }
        }
        else inputHasFocus = false;

        // Update the keyboard and joystick events
        if (mSel != null) ProcessOthers();

        // If it's time to show a tooltip, inform the object we're hovering over
        if (useMouse && mHover != null)
        {
            float scroll = Input.GetAxis(scrollAxisName);
            if (scroll != 0f) Notify(mHover, "OnScroll", scroll);

            if (showTooltips && mTooltipTime != 0f && (mTooltipTime < Time.realtimeSinceStartup ||
                Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
            {
                mTooltip = mHover;
                ShowTooltip(true);
            }
        }
        current = null;
    }
Ejemplo n.º 18
0
 void Awake()
 {
     uiCamera  = m_Camera.GetComponent <NGUICamera>();
     cachedLm  = uiCamera.eventReceiverMask;
     currentLm = cachedLm;
 }
Ejemplo n.º 19
0
    /// <summary>
    /// Convenience function that figures out the panel's correct change flag by searching the parents.
    /// </summary>

    int GetChangeFlag(NGUINode start)
    {
        int flag = start.changeFlag;

        if (flag == -1)
        {
            Transform trans = start.trans.parent;
            NGUINode  sub;

            // Keep going until we find a set flag
            for (;;)
            {
                // Check the parent's flag
#if USE_SIMPLE_DICTIONARY
                if (trans != null && mChildren.TryGetValue(trans, out sub))
                {
#else
                if (trans != null && mChildren.Contains(trans))
                {
                    sub = (NGUINode)mChildren[trans];
#endif
                    flag  = sub.changeFlag;
                    trans = trans.parent;

                    // If the flag hasn't been set either, add this child to the hierarchy
                    if (flag == -1)
                    {
                        mHierarchy.Add(sub);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    flag = 0;
                    break;
                }
            }

            // Update the parent flags
            for (int i = 0, imax = mHierarchy.size; i < imax; ++i)
            {
                NGUINode pc = mHierarchy.buffer[i];
                pc.changeFlag = flag;
            }
            mHierarchy.Clear();
        }
        return(flag);
    }

    /// <summary>
    /// Update the world-to-local transform matrix as well as clipping bounds.
    /// </summary>

    void UpdateTransformMatrix()
    {
        if (mUpdateTime == 0f || mMatrixTime != mUpdateTime)
        {
            mMatrixTime   = mUpdateTime;
            mWorldToLocal = cachedTransform.worldToLocalMatrix;

            if (mClipping != NGUIDrawCall.Clipping.None)
            {
                Vector2 size = new Vector2(mClipRange.z, mClipRange.w);

                if (size.x == 0f)
                {
                    size.x = (mCam == null) ? Screen.width  : mCam.pixelWidth;
                }
                if (size.y == 0f)
                {
                    size.y = (mCam == null) ? Screen.height : mCam.pixelHeight;
                }

                size *= 0.5f;

                mMin.x = mClipRange.x - size.x;
                mMin.y = mClipRange.y - size.y;
                mMax.x = mClipRange.x + size.x;
                mMax.y = mClipRange.y + size.y;
            }
        }
    }

    /// <summary>
    /// Run through all managed transforms and see if they've changed.
    /// </summary>

    void UpdateTransforms()
    {
        mChangedLastFrame = false;
        bool transformsChanged = false;
        bool shouldCull        = false;

#if UNITY_EDITOR
        shouldCull = (clipping != NGUIDrawCall.Clipping.None) && (!Application.isPlaying || mUpdateTime > mCullTime);
        if (!Application.isPlaying || !widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#else
        shouldCull = (clipping != NGUIDrawCall.Clipping.None) && (mUpdateTime > mCullTime);
        if (!widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#endif
        {
#if USE_SIMPLE_DICTIONARY
            foreach (KeyValuePair <Transform, NGUINode> child in mChildren)
            {
                NGUINode node = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                NGUINode node = (NGUINode)mChildren[i];
#endif
                if (node.trans == null)
                {
                    mRemoved.Add(node.trans);
                    continue;
                }

                if (node.HasChanged())
                {
                    node.changeFlag   = 1;
                    transformsChanged = true;
#if UNITY_EDITOR
                    Vector3 s   = node.trans.lossyScale;
                    float   min = Mathf.Abs(Mathf.Min(s.x, s.y));

                    if (min == 0f)
                    {
                        Debug.LogError("Scale of 0 is invalid! Zero cannot be divided by, which causes problems. Use a small value instead, such as 0.01\n" +
                                       node.trans.lossyScale, node.trans);
                    }
#endif
                }
                else
                {
                    node.changeFlag = -1;
                }
            }

            // Clean up the deleted transforms
            for (int i = 0, imax = mRemoved.Count; i < imax; ++i)
            {
                mChildren.Remove(mRemoved[i]);
            }
            mRemoved.Clear();
        }

        // If the children weren't culled but should be, check their visibility
        if (!mCulled && shouldCull)
        {
            mCheckVisibility = true;
        }

        // If something has changed, propagate the changes *down* the tree hierarchy (to children).
        // An alternative (but slower) approach would be to do a pc.trans.GetComponentsInChildren<NGUIWidget>()
        // in the loop above, and mark each one as dirty.

        if (mCheckVisibility || transformsChanged || mRebuildAll)
        {
#if USE_SIMPLE_DICTIONARY
            foreach (KeyValuePair <Transform, NGUINode> child in mChildren)
            {
                NGUINode pc = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                NGUINode pc = (NGUINode)mChildren[i];
#endif
                if (pc.widget != null)
                {
                    int visibleFlag = 1;

                    // No sense in checking the visibility if we're not culling anything (as the visibility is always 'true')
                    if (shouldCull || transformsChanged)
                    {
                        // If the change flag has not yet been determined...
                        if (pc.changeFlag == -1)
                        {
                            pc.changeFlag = GetChangeFlag(pc);
                        }

                        // Is the widget visible?
                        if (shouldCull)
                        {
                            visibleFlag = (mCheckVisibility || pc.changeFlag == 1) ? (IsVisible(pc.widget) ? 1 : 0) : pc.visibleFlag;
                        }
                    }

                    // If visibility changed, mark the node as changed as well
                    if (pc.visibleFlag != visibleFlag)
                    {
                        pc.changeFlag = 1;
                    }

                    // If the node has changed and the widget is visible (or was visible before)
                    if (pc.changeFlag == 1 && (visibleFlag == 1 || pc.visibleFlag != 0))
                    {
                        // Update the visibility flag
                        pc.visibleFlag = visibleFlag;
                        Material mat = pc.widget.material;

                        // Add this material to the list of changed materials
                        if (!mChanged.Contains(mat))
                        {
                            mChanged.Add(mat);
                            mChangedLastFrame = true;
                        }
                    }
                }
            }
        }
        mCulled          = shouldCull;
        mCheckVisibility = false;
        mWidgetsAdded    = false;
    }

    /// <summary>
    /// Update all widgets and rebuild their geometry if necessary.
    /// </summary>

    void UpdateWidgets()
    {
#if USE_SIMPLE_DICTIONARY
        foreach (KeyValuePair <Transform, NGUINode> c in mChildren)
        {
            NGUINode pc = c.Value;
#else
        for (int i = 0, imax = mChildren.Count; i < imax; ++i)
        {
            NGUINode pc = (NGUINode)mChildren[i];
#endif
            NGUIWidget w = pc.widget;

            // If the widget is visible, update it
            if (pc.visibleFlag == 1 && w != null && w.UpdateGeometry(this, ref mWorldToLocal, (pc.changeFlag == 1), generateNormals))
            {
                // We will need to refill this buffer
                if (!mChanged.Contains(w.material))
                {
                    mChanged.Add(w.material);
                    mChangedLastFrame = true;
                }
            }
            pc.changeFlag = 0;
        }
    }

    /// <summary>
    /// Update the clipping rect in the shaders and draw calls' positions.
    /// </summary>

    public void UpdateDrawcalls()
    {
        Vector4 range = Vector4.zero;

        if (mClipping != NGUIDrawCall.Clipping.None)
        {
            range = new Vector4(mClipRange.x, mClipRange.y, mClipRange.z * 0.5f, mClipRange.w * 0.5f);
        }

        if (range.z == 0f)
        {
            range.z = Screen.width * 0.5f;
        }
        if (range.w == 0f)
        {
            range.w = Screen.height * 0.5f;
        }

        RuntimePlatform platform = Application.platform;

        if (platform == RuntimePlatform.WindowsPlayer ||
            platform == RuntimePlatform.WindowsWebPlayer ||
            platform == RuntimePlatform.WindowsEditor)
        {
            range.x -= 0.5f;
            range.y += 0.5f;
        }

        Transform t = cachedTransform;

        for (int i = 0, imax = mDrawCalls.size; i < imax; ++i)
        {
            NGUIDrawCall dc = mDrawCalls.buffer[i];
            dc.clipping     = mClipping;
            dc.clipRange    = range;
            dc.clipSoftness = mClipSoftness;
            dc.depthPass    = depthPass && mClipping == NGUIDrawCall.Clipping.None;

            // Set the draw call's transform to match the panel's.
            // Note that parenting directly to the panel causes unity to crash as soon as you hit Play.
            Transform dt = dc.transform;
            dt.position   = t.position;
            dt.rotation   = t.rotation;
            dt.localScale = t.lossyScale;
        }
    }

    /// <summary>
    /// Set the draw call's geometry responsible for the specified material.
    /// </summary>

    void Fill(Material mat)
    {
        // Cleanup deleted widgets
        for (int i = mWidgets.size; i > 0;)
        {
            if (mWidgets[--i] == null)
            {
                mWidgets.RemoveAt(i);
            }
        }

        // Fill the buffers for the specified material
        for (int i = 0, imax = mWidgets.size; i < imax; ++i)
        {
            NGUIWidget w = mWidgets.buffer[i];

            if (w.visibleFlag == 1 && w.material == mat)
            {
                NGUINode node = GetNode(w.cachedTransform);

                if (node != null)
                {
                    if (generateNormals)
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, mNorms, mTans);
                    }
                    else
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, null, null);
                    }
                }
                else
                {
                    Debug.LogError("No transform found for " + NGUITools.GetHierarchy(w.gameObject), this);
                }
            }
        }

        if (mVerts.size > 0)
        {
            // Rebuild the draw call's mesh
            NGUIDrawCall dc = GetDrawCall(mat, true);
            dc.depthPass = depthPass && mClipping == NGUIDrawCall.Clipping.None;
            dc.Set(mVerts, generateNormals ? mNorms : null, generateNormals ? mTans : null, mUvs, mCols);
        }
        else
        {
            // There is nothing to draw for this material -- eliminate the draw call
            NGUIDrawCall dc = GetDrawCall(mat, false);

            if (dc != null)
            {
                mDrawCalls.Remove(dc);
                NGUITools.DestroyImmediate(dc.gameObject);
            }
        }

        // Cleanup
        mVerts.Clear();
        mNorms.Clear();
        mTans.Clear();
        mUvs.Clear();
        mCols.Clear();
    }

    /// <summary>
    /// Main update function
    /// </summary>

    void LateUpdate()
    {
        mUpdateTime = Time.realtimeSinceStartup;
        UpdateTransformMatrix();
        UpdateTransforms();

        // Always move widgets to the panel's layer
        if (mLayer != gameObject.layer)
        {
            mLayer = gameObject.layer;
            NGUICamera uic = NGUICamera.FindCameraForLayer(mLayer);
            mCam = (uic != null) ? uic.cachedCamera : NGUITools.FindCameraForLayer(mLayer);
            SetChildLayer(cachedTransform, mLayer);
            var cache = drawCalls;
            for (int i = 0, imax = cache.size; i < imax; ++i)
            {
                mDrawCalls.buffer[i].gameObject.layer = mLayer;
            }
        }

        UpdateWidgets();

        // If the depth has changed, we need to re-sort the widgets
        if (mDepthChanged)
        {
            mDepthChanged = false;
            mWidgets.Sort(NGUIWidget.CompareFunc);
        }


        var dcInit = drawCalls;

        // Fill the draw calls for all of the changed materials
        for (int i = 0, imax = mChanged.size; i < imax; ++i)
        {
            Fill(mChanged.buffer[i]);
        }

        // Update the clipping rects
        UpdateDrawcalls();
        mChanged.Clear();
        mRebuildAll = false;

#if UNITY_EDITOR
        mScreenSize = new Vector2(Screen.width, Screen.height);
#endif
    }
Ejemplo n.º 20
0
 /// <summary>
 /// Static comparison function used for sorting.
 /// </summary>
 static int CompareFunc(NGUICamera a, NGUICamera b)
 {
     if (a.cachedCamera.depth < b.cachedCamera.depth) return 1;
     if (a.cachedCamera.depth > b.cachedCamera.depth) return -1;
     return 0;
 }
Ejemplo n.º 21
0
    /// <summary>
    /// Check the input and send out appropriate events.
    /// </summary>

    void Update()
    {
        // Only the first UI layer should be processing events
        if (!Application.isPlaying || !handlesEvents)
        {
            return;
        }

        current = this;

        // Update mouse input
        if (useMouse || (useTouch && mIsEditor))
        {
            ProcessMouse();
        }

        // Process touch input
        if (useTouch)
        {
            ProcessTouches();
        }

        // Custom input processing
        if (onCustomInput != null)
        {
            onCustomInput();
        }

        // Clear the selection on the cancel key, but only if mouse input is allowed
        if (useMouse && mSel != null && ((cancelKey0 != KeyCode.None && Input.GetKeyDown(cancelKey0)) ||
                                         (cancelKey1 != KeyCode.None && Input.GetKeyDown(cancelKey1))))
        {
            selectedObject = null;
        }

        // Forward the input to the selected object
        if (mSel != null)
        {
            string input = Input.inputString;

            //Merge the input string. Backspace always come first and the other characters
            //if the backspace is found in the current string no \b will be added so in practicve lastInputEvents will be always empty
            //if no backspace is found and a backspace has been reported, this will be added to lastInputEvents
            //next update the string will be notified and changed
            lastInputEvents = input + lastInputEvents;

            // Adding support for some macs only having the "Delete" key instead of "Backspace"
            if (useKeyboard && Input.GetKeyDown(KeyCode.Delete) && lastInputEvents.LastIndexOf('\b') == -1)
            {
                lastInputEvents += "\b";
            }

            if (lastInputEvents.Length > 0)
            {
                if (!stickyTooltip && mTooltip != null)
                {
                    ShowTooltip(false);
                }
                Notify(mSel, "OnInput", lastInputEvents);
                //Nullify all the inputs
                lastInputEvents = System.String.Empty;
            }
        }
        else
        {
            inputHasFocus = false;
        }

        // Update the keyboard and joystick events
        if (mSel != null)
        {
            ProcessOthers();
        }

        // If it's time to show a tooltip, inform the object we're hovering over
        if (useMouse && mHover != null)
        {
            float scroll = Input.GetAxis(scrollAxisName);
            if (scroll != 0f)
            {
                Notify(mHover, "OnScroll", scroll);
            }

            if (showTooltips && mTooltipTime != 0f && (mTooltipTime < Time.realtimeSinceStartup ||
                                                       Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
            {
                mTooltip = mHover;
                ShowTooltip(true);
            }
        }
        current = null;
    }
Ejemplo n.º 22
0
    /// <summary>
    /// Returns the object under the specified position.
    /// </summary>

    static public bool Raycast(Vector3 inPos, ref RaycastHit hit)
    {
        for (int i = 0; i < mList.Count; ++i)
        {
            NGUICamera cam = mList[i];

            // Skip inactive scripts
            if (!cam.enabled || !NGUITools.GetActive(cam.gameObject))
            {
                continue;
            }

            // Convert to view space
            currentCamera = cam.cachedCamera;
            Vector3 pos = currentCamera.ScreenToViewportPoint(inPos);

            // If it's outside the camera's viewport, do nothing
            if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f)
            {
                continue;
            }

            // Cast a ray into the screen
            Ray ray = currentCamera.ScreenPointToRay(inPos);

            // Raycast into the screen
            int   mask = currentCamera.cullingMask & (int)cam.eventReceiverMask;
            float dist = (cam.rangeDistance > 0f) ? cam.rangeDistance : currentCamera.farClipPlane - currentCamera.nearClipPlane;

            // If raycasts should be clipped by panels, we need to find a panel for each hit
            if (cam.clipRaycasts)
            {
                RaycastHit[] hits = Physics.RaycastAll(ray, dist, mask);

                if (hits.Length > 1)
                {
                    System.Array.Sort(hits, delegate(RaycastHit r1, RaycastHit r2) { return(r1.distance.CompareTo(r2.distance)); });

                    for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                    {
                        if (IsVisible(ref hits[b]))
                        {
                            hit = hits[b];
                            return(true);
                        }
                    }
                }
                else if (hits.Length == 1 && IsVisible(ref hits[0]))
                {
                    hit = hits[0];
                    return(true);
                }
                continue;
            }
            if (Physics.Raycast(ray, out hit, dist, mask))
            {
                return(true);
            }
        }
        return(false);
    }
Ejemplo n.º 23
0
    /// <summary>
    /// Display the drop-down list when the game object gets clicked on.
    /// </summary>

    void OnClick()
    {
        if (mChild == null && atlas != null && font != null && items.Count > 0)
        {
            mLabelList.Clear();

            // Disable the navigation script
            handleEvents = true;

            // Automatically locate the panel responsible for this object
            if (mPanel == null)
            {
                mPanel = NGUIPanel.Find(transform, true);
            }

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Transform myTrans = transform;
            Bounds    bounds  = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans);

            // Create the root object for the list
            mChild       = new GameObject("Drop-down List");
            mChild.layer = gameObject.layer;

            Transform t = mChild.transform;
            t.parent        = myTrans.parent;
            t.localPosition = bounds.min;
            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;

            // Add a sprite for the background
            mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
            mBackground.pivot = NGUIWidget.Pivot.TopLeft;
            mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
            mBackground.color = backgroundColor;

            // We need to know the size of the background sprite for padding purposes
            Vector4 bgPadding = mBackground.border;
            mBgBorder = bgPadding.y;

            mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);

            // Add a sprite used for the selection
            mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
            mHighlight.pivot = NGUIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            NGUIAtlas.Sprite hlsp = mHighlight.GetAtlasSprite();
            if (hlsp == null)
            {
                return;
            }

            float            hlspHeight = hlsp.inner.yMin - hlsp.outer.yMin;
            float            fontScale = font.size * font.pixelSize * textScale;
            float            x = 0f, y = -padding.y;
            List <NGUILabel> labels = new List <NGUILabel>();

            // Run through all items and create labels for each one
            for (int i = 0, imax = items.Count; i < imax; ++i)
            {
                string s = items[i];

                NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(mChild);
                lbl.pivot = NGUIWidget.Pivot.TopLeft;
                lbl.font  = font;
                lbl.text  = (isLocalized && Localization.instance != null) ? Localization.instance.Get(s) : s;
                lbl.color = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -0.01f);
                lbl.MakePixelPerfect();

                if (textScale != 1f)
                {
                    Vector3 scale = lbl.cachedTransform.localScale;
                    lbl.cachedTransform.localScale = scale * textScale;
                }
                labels.Add(lbl);

                y -= fontScale;
                y -= padding.y;
                x  = Mathf.Max(x, lbl.relativeSize.x * fontScale);

                // Add an event listener
                NGUIEventListener listener = NGUIEventListener.Get(lbl.gameObject);
                listener.onHover   = OnItemHover;
                listener.onPress   = OnItemPress;
                listener.parameter = s;

                // Move the selection here if this is the right label
                if (mSelectedItem == s)
                {
                    Highlight(lbl, true);
                }

                // Add this label to the list
                mLabelList.Add(lbl);
            }

            // The triggering widget's width should be the minimum allowed width
            x = Mathf.Max(x, bounds.size.x - (bgPadding.x + padding.x) * 2f);

            Vector3 bcCenter = new Vector3((x * 0.5f) / fontScale, -0.5f, 0f);
            Vector3 bcSize   = new Vector3(x / fontScale, (fontScale + padding.y) / fontScale, 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                NGUILabel   lbl = labels[i];
                BoxCollider bc  = NGUITools.AddWidgetCollider(lbl.gameObject);
                bcCenter.z = bc.center.z;
                bc.center  = bcCenter;
                bc.size    = bcSize;
            }

            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.cachedTransform.localScale = new Vector3(x, -y + bgPadding.y, 1f);

            // Scale the highlight sprite to envelop a single item
            mHighlight.cachedTransform.localScale = new Vector3(
                x - (bgPadding.x + padding.x) * 2f + (hlsp.inner.xMin - hlsp.outer.xMin) * 2f,
                fontScale + hlspHeight * 2f, 1f);

            bool placeAbove = (position == Position.Above);

            if (position == Position.Auto)
            {
                NGUICamera cam = NGUICamera.FindCameraForLayer(gameObject.layer);

                if (cam != null)
                {
                    Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(myTrans.position);
                    placeAbove = (viewPos.y < 0.5f);
                }
            }

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                float bottom = y + fontScale;
                Animate(mHighlight, placeAbove, bottom);
                for (int i = 0, imax = labels.Count; i < imax; ++i)
                {
                    Animate(labels[i], placeAbove, bottom);
                }
                AnimateColor(mBackground);
                AnimateScale(mBackground, placeAbove, bottom);
            }

            // If we need to place the popup list above the item, we need to reposition everything by the size of the list
            if (placeAbove)
            {
                t.localPosition = new Vector3(bounds.min.x, bounds.max.y - y - bgPadding.y, bounds.min.z);
            }
        }
        else
        {
            OnSelect(false);
        }
    }
Ejemplo n.º 24
0
 void Awake()
 {
     uiCamera = m_Camera.GetComponent<NGUICamera>();
     cachedLm = uiCamera.eventReceiverMask;
     currentLm = cachedLm;
 }
Ejemplo n.º 25
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIPanel panel = target as NGUIPanel;
        BetterList <NGUIDrawCall> drawcalls = panel.drawCalls;

        EditorGUIUtility.LookLikeControls(80f);

        //NGUIEditorTools.DrawSeparator();
        EditorGUILayout.Space();

        float alpha = EditorGUILayout.Slider("Alpha", panel.alpha, 0f, 1f);

        if (alpha != panel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", panel);
            panel.alpha = alpha;
        }

        if (panel.showInPanelTool != EditorGUILayout.Toggle("Panel Tool", panel.showInPanelTool))
        {
            panel.showInPanelTool = !panel.showInPanelTool;
            EditorUtility.SetDirty(panel);
            EditorWindow.FocusWindowIfItsOpen <NGUIPanelTool>();
        }

        GUILayout.BeginHorizontal();
        bool norms = EditorGUILayout.Toggle("Normals", panel.generateNormals, GUILayout.Width(100f));

        GUILayout.Label("Needed for lit shaders");
        GUILayout.EndHorizontal();

        if (panel.generateNormals != norms)
        {
            panel.generateNormals = norms;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        GUILayout.BeginHorizontal();
        bool depth = EditorGUILayout.Toggle("Depth Pass", panel.depthPass, GUILayout.Width(100f));

        GUILayout.Label("Doubles draw calls, saves fillrate");
        GUILayout.EndHorizontal();

        if (panel.depthPass != depth)
        {
            panel.depthPass = depth;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        if (depth)
        {
            NGUICamera cam = NGUICamera.FindCameraForLayer(panel.gameObject.layer);

            if (cam == null || cam.camera.isOrthoGraphic)
            {
                EditorGUILayout.HelpBox("Please note that depth pass will only save fillrate when used with 3D NGUIs, and only NGUIs drawn by the game camera. If you are using a separate camera for the UI, you will not see any benefit!", MessageType.Warning);
            }
        }

        GUILayout.BeginHorizontal();
        bool stat = EditorGUILayout.Toggle("Static", panel.widgetsAreStatic, GUILayout.Width(100f));

        GUILayout.Label("Check if widgets won't move");
        GUILayout.EndHorizontal();

        if (panel.widgetsAreStatic != stat)
        {
            panel.widgetsAreStatic = stat;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        EditorGUILayout.LabelField("Widgets", panel.widgets.size.ToString());
        EditorGUILayout.LabelField("Draw Calls", drawcalls.size.ToString());

        NGUIPanel.DebugInfo di = (NGUIPanel.DebugInfo)EditorGUILayout.EnumPopup("Debug Info", panel.debugInfo);

        if (panel.debugInfo != di)
        {
            panel.debugInfo = di;
            EditorUtility.SetDirty(panel);
        }

        NGUIDrawCall.Clipping clipping = (NGUIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", panel.clipping);

        if (panel.clipping != clipping)
        {
            panel.clipping = clipping;
            EditorUtility.SetDirty(panel);
        }

        if (panel.clipping != NGUIDrawCall.Clipping.None)
        {
            Vector4 range = panel.clipRange;

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (panel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                panel.clipRange = range;
                EditorUtility.SetDirty(panel);
            }

            if (panel.clipping == NGUIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", panel.clipSoftness);
                GUILayout.EndHorizontal();

                if (soft.x < 1f)
                {
                    soft.x = 1f;
                }
                if (soft.y < 1f)
                {
                    soft.y = 1f;
                }

                if (panel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                    panel.clipSoftness = soft;
                    EditorUtility.SetDirty(panel);
                }
            }

#if !UNITY_3_5 && (UNITY_ANDROID || UNITY_IPHONE)
            if (PlayerSettings.targetGlesGraphics == TargetGlesGraphics.OpenGLES_1_x)
            {
                EditorGUILayout.HelpBox("Clipping requires shader support!\n\nOpen File -> Build Settings -> Player Settings -> Other Settings, then set:\n\n- Graphics Level: OpenGL ES 2.0.", MessageType.Error);
            }
#endif
        }

        if (clipping == NGUIDrawCall.Clipping.HardClip)
        {
            EditorGUILayout.HelpBox("Hard clipping has been removed due to major performance issues on certain Android devices. Alpha clipping will be used instead.", MessageType.Warning);
        }

        if (clipping != NGUIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(panel.gameObject);
            }
        }

        foreach (NGUIDrawCall dc in drawcalls)
        {
            NGUIEditorTools.DrawSeparator();
            EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false);
            EditorGUILayout.LabelField("Triangles", dc.triangles.ToString());

            if (clipping != NGUIDrawCall.Clipping.None && !dc.isClipped)
            {
                EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.",
                                        MessageType.Warning);
            }
        }
    }
Ejemplo n.º 26
0
    /// <summary>
    /// Helper function used to print things in columns.
    /// </summary>

    void DrawRow(Camera cam)
    {
        if (cam != null)
        {
            NGUIEditorTools.HighlightLine(new Color(0.6f, 0.6f, 0.6f));
        }

        GUILayout.BeginHorizontal();
        {
            bool enabled = (cam == null || (NGUITools.GetActive(cam.gameObject) && cam.enabled));

            GUI.color = Color.white;

            if (cam != null)
            {
                if (enabled != EditorGUILayout.Toggle(enabled, GUILayout.Width(20f)))
                {
                    cam.enabled = !enabled;
                    EditorUtility.SetDirty(cam.gameObject);
                }
            }
            else
            {
                GUILayout.Space(30f);
            }

            bool highlight = (cam == null || Selection.activeGameObject == null) ? false :
                             (0 != (cam.cullingMask & (1 << Selection.activeGameObject.layer)));

            if (enabled)
            {
                GUI.color = highlight ? new Color(0f, 0.8f, 1f) : Color.white;
            }
            else
            {
                GUI.color = highlight ? new Color(0f, 0.5f, 0.8f) : Color.grey;
            }

            string camName, camLayer;

            if (cam == null)
            {
                camName  = "Camera's Name";
                camLayer = "Layer";
            }
            else
            {
                camName  = cam.name + (cam.orthographic ? " (2D)" : " (3D)");
                camLayer = LayerMask.LayerToName(cam.gameObject.layer);
            }

#if UNITY_3_4
            if (GUILayout.Button(camName, EditorStyles.structHeadingLabel, GUILayout.MinWidth(100f)) && cam != null)
#else
            if (GUILayout.Button(camName, EditorStyles.label, GUILayout.MinWidth(100f)) && cam != null)
#endif
            {
                Selection.activeGameObject = cam.gameObject;
                EditorUtility.SetDirty(cam.gameObject);
            }
            GUILayout.Label(camLayer, GUILayout.Width(70f));

            GUI.color = enabled ? Color.white : new Color(0.7f, 0.7f, 0.7f);

            if (cam == null)
            {
                GUILayout.Label("EV", GUILayout.Width(26f));
            }
            else
            {
                NGUICamera uic = cam.GetComponent <NGUICamera>();
                bool       ev  = (uic != null && uic.enabled);

                if (ev != EditorGUILayout.Toggle(ev, GUILayout.Width(20f)))
                {
                    if (uic == null)
                    {
                        uic = cam.gameObject.AddComponent <NGUICamera>();
                    }
                    uic.enabled = !ev;
                }
            }

            if (cam == null)
            {
                GUILayout.Label("Mask", GUILayout.Width(100f));
            }
            else
            {
                int mask = LayerMaskField(cam.cullingMask, GUILayout.Width(105f));

                if (cam.cullingMask != mask)
                {
                    NGUIEditorTools.RegisterUndo("Camera Mask Change", cam);
                    cam.cullingMask = mask;
                }
            }
        }
        GUILayout.EndHorizontal();
    }