Exemplo n.º 1
0
    /// <summary>
    /// Update the widget and fill its geometry if necessary. Returns whether something was changed.
    /// </summary>

    public bool UpdateGeometry(ref Matrix4x4 worldToPanel, bool parentMoved, bool generateNormals)
    {
        if (material == null)
        {
            return(false);
        }

        if (OnUpdate() || mChanged)
        {
            mChanged = false;
            mGeom.Clear();
            OnFill(mGeom.verts, mGeom.uvs, mGeom.cols);

            if (mGeom.hasVertices)
            {
                Vector3 offset = pivotOffset;
                Vector2 scale  = relativeSize;
                offset.x *= scale.x;
                offset.y *= scale.y;

                mGeom.ApplyOffset(offset);
                mGeom.ApplyTransform(worldToPanel * cachedTransform.localToWorldMatrix, generateNormals);
            }
            return(true);
        }
        else if (mGeom.hasVertices && parentMoved)
        {
            mGeom.ApplyTransform(worldToPanel * cachedTransform.localToWorldMatrix, generateNormals);
        }
        return(false);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Update the widget and fill its geometry if necessary. Returns whether something was changed.
    /// </summary>

    public bool UpdateGeometry(UIPanel p, bool forceVisible)
#endif
    {
        if (material != null && p != null)
        {
            mPanel = p;
            bool hasMatrix = false;
#if !OLD_UNITY
            float final          = finalAlpha;
            bool  visibleByAlpha = (final > 0.001f);
            bool  visibleByPanel = forceVisible || mVisibleByPanel;

            // Has transform moved?
            if (cachedTransform.hasChanged)
            {
                mTrans.hasChanged = false;

                // Check to see if the widget has moved relative to the panel that manages it
#if UNITY_EDITOR
                if (!mPanel.widgetsAreStatic || !Application.isPlaying)
#else
                if (!mPanel.widgetsAreStatic)
#endif
                {
                    Vector2 size    = relativeSize;
                    Vector2 offset  = pivotOffset;
                    Vector4 padding = relativePadding;

                    float x0 = offset.x * size.x - padding.x;
                    float y0 = offset.y * size.y + padding.y;

                    float x1 = x0 + size.x + padding.x + padding.z;
                    float y1 = y0 - size.y - padding.y - padding.w;

                    mLocalToPanel = p.worldToLocal * cachedTransform.localToWorldMatrix;
                    hasMatrix     = true;

                    Vector3 v0 = new Vector3(x0, y0, 0f);
                    Vector3 v1 = new Vector3(x1, y1, 0f);

                    v0 = mLocalToPanel.MultiplyPoint3x4(v0);
                    v1 = mLocalToPanel.MultiplyPoint3x4(v1);

                    if (Vector3.SqrMagnitude(mOldV0 - v0) > 0.000001f || Vector3.SqrMagnitude(mOldV1 - v1) > 0.000001f)
                    {
                        mChanged = true;
                        mOldV0   = v0;
                        mOldV1   = v1;
                    }
                }

                // Is the widget visible by the panel?
                if (visibleByAlpha || mForceVisible != forceVisible)
                {
                    mForceVisible  = forceVisible;
                    visibleByPanel = forceVisible || mPanel.IsVisible(this);
                }
            }
            else if (visibleByAlpha && mForceVisible != forceVisible)
            {
                mForceVisible  = forceVisible;
                visibleByPanel = mPanel.IsVisible(this);
            }

            // Is the visibility changing?
            if (mVisibleByPanel != visibleByPanel)
            {
                mVisibleByPanel = visibleByPanel;
                mChanged        = true;
            }

            // Has the alpha changed?
            if (mVisibleByPanel && mLastAlpha != final)
            {
                mChanged = true;
            }
            mLastAlpha = final;
#endif
            if (mChanged)
            {
                mChanged = false;

                if (isVisible)
                {
                    mGeom.Clear();
                    OnFill(mGeom.verts, mGeom.uvs, mGeom.cols);

                    // Want to see what's being filled? Uncomment this line.
                    //Debug.Log("Fill " + name + " (" + Time.time + ")");

                    if (mGeom.hasVertices)
                    {
                        Vector3 offset = pivotOffset;
                        Vector2 scale  = relativeSize;

                        offset.x *= scale.x;
                        offset.y *= scale.y;

                        if (!hasMatrix)
                        {
                            mLocalToPanel = p.worldToLocal * cachedTransform.localToWorldMatrix;
                        }

                        mGeom.ApplyOffset(offset);
                        mGeom.ApplyTransform(mLocalToPanel);
                    }
                    return(true);
                }
                else if (mGeom.hasVertices)
                {
                    mGeom.Clear();
                    return(true);
                }
            }
#if OLD_UNITY
            else if (parentMoved && mGeom.hasVertices)
            {
                mGeom.ApplyTransform(p.worldToLocal * cachedTransform.localToWorldMatrix);
            }
#endif
        }
        return(false);
    }
Exemplo n.º 3
0
 public bool UpdateGeometry(UIPanel p, bool forceVisible)
 {
     if (material != null && p != null)
     {
         mPanel = p;
         bool  flag       = false;
         float finalAlpha = this.finalAlpha;
         bool  flag2      = finalAlpha > 0.001f;
         bool  flag3      = forceVisible || mVisibleByPanel;
         if (cachedTransform.hasChanged)
         {
             mTrans.hasChanged = false;
             if (!mPanel.widgetsAreStatic)
             {
                 Vector2 relativeSize    = this.relativeSize;
                 Vector2 pivotOffset     = this.pivotOffset;
                 Vector4 relativePadding = this.relativePadding;
                 float   num             = pivotOffset.x * relativeSize.x - relativePadding.x;
                 float   num2            = pivotOffset.y * relativeSize.y + relativePadding.y;
                 float   x = num + relativeSize.x + relativePadding.x + relativePadding.z;
                 float   y = num2 - relativeSize.y - relativePadding.y - relativePadding.w;
                 mLocalToPanel = p.worldToLocal * cachedTransform.localToWorldMatrix;
                 flag          = true;
                 Vector3 v  = new Vector3(num, num2, 0f);
                 Vector3 v2 = new Vector3(x, y, 0f);
                 v  = mLocalToPanel.MultiplyPoint3x4(v);
                 v2 = mLocalToPanel.MultiplyPoint3x4(v2);
                 if (Vector3.SqrMagnitude(mOldV0 - v) > 1E-06f || Vector3.SqrMagnitude(mOldV1 - v2) > 1E-06f)
                 {
                     mChanged = true;
                     mOldV0   = v;
                     mOldV1   = v2;
                 }
             }
             if (flag2 || mForceVisible != forceVisible)
             {
                 mForceVisible = forceVisible;
                 flag3         = (forceVisible || mPanel.IsVisible(this));
             }
         }
         else if (flag2 && mForceVisible != forceVisible)
         {
             mForceVisible = forceVisible;
             flag3         = mPanel.IsVisible(this);
         }
         if (mVisibleByPanel != flag3)
         {
             mVisibleByPanel = flag3;
             mChanged        = true;
         }
         if (mVisibleByPanel && mLastAlpha != finalAlpha)
         {
             mChanged = true;
         }
         mLastAlpha = finalAlpha;
         if (mChanged)
         {
             mChanged = false;
             if (isVisible)
             {
                 mGeom.Clear();
                 OnFill(mGeom.verts, mGeom.uvs, mGeom.cols);
                 if (mGeom.hasVertices)
                 {
                     Vector3 pivotOffset2  = this.pivotOffset;
                     Vector2 relativeSize2 = this.relativeSize;
                     pivotOffset2.x *= relativeSize2.x;
                     pivotOffset2.y *= relativeSize2.y;
                     if (!flag)
                     {
                         mLocalToPanel = p.worldToLocal * cachedTransform.localToWorldMatrix;
                     }
                     mGeom.ApplyOffset(pivotOffset2);
                     mGeom.ApplyTransform(mLocalToPanel, p.generateNormals);
                 }
                 return(true);
             }
             if (mGeom.hasVertices)
             {
                 mGeom.Clear();
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 4
0
    public bool UpdateGeometry(UIPanel p, bool forceVisible)
    {
        if (material != null && p != null)
        {
            mPanel = p;
            var flag       = false;
            var finalAlpha = this.finalAlpha;
            var flag2      = finalAlpha > 0.001f;
            var flag3      = forceVisible || mVisibleByPanel;
            if (cachedTransform.hasChanged)
            {
                mTrans.hasChanged = false;
                if (!mPanel.widgetsAreStatic)
                {
                    var relativeSize    = this.relativeSize;
                    var pivotOffset     = this.pivotOffset;
                    var relativePadding = this.relativePadding;
                    var x    = pivotOffset.x * relativeSize.x - relativePadding.x;
                    var y    = pivotOffset.y * relativeSize.y + relativePadding.y;
                    var num4 = x + relativeSize.x + relativePadding.x + relativePadding.z;
                    var num5 = y - relativeSize.y - relativePadding.y - relativePadding.w;
                    mLocalToPanel = p.worldToLocal * cachedTransform.localToWorldMatrix;
                    flag          = true;
                    var v       = new Vector3(x, y, 0f);
                    var vector5 = new Vector3(num4, num5, 0f);
                    v       = mLocalToPanel.MultiplyPoint3x4(v);
                    vector5 = mLocalToPanel.MultiplyPoint3x4(vector5);
                    if (Vector3.SqrMagnitude(mOldV0 - v) > 1E-06f || Vector3.SqrMagnitude(mOldV1 - vector5) > 1E-06f)
                    {
                        mChanged = true;
                        mOldV0   = v;
                        mOldV1   = vector5;
                    }
                }

                if (flag2 || mForceVisible != forceVisible)
                {
                    mForceVisible = forceVisible;
                    flag3         = forceVisible || mPanel.IsVisible(this);
                }
            }
            else if (flag2 && mForceVisible != forceVisible)
            {
                mForceVisible = forceVisible;
                flag3         = mPanel.IsVisible(this);
            }

            if (mVisibleByPanel != flag3)
            {
                mVisibleByPanel = flag3;
                mChanged        = true;
            }

            if (mVisibleByPanel && mLastAlpha != finalAlpha)
            {
                mChanged = true;
            }

            mLastAlpha = finalAlpha;
            if (mChanged)
            {
                mChanged = false;
                if (isVisible)
                {
                    mGeom.Clear();
                    OnFill(mGeom.verts, mGeom.uvs, mGeom.cols);
                    if (mGeom.hasVertices)
                    {
                        Vector3 vector6 = pivotOffset;
                        var     vector7 = relativeSize;
                        vector6.x *= vector7.x;
                        vector6.y *= vector7.y;
                        if (!flag)
                        {
                            mLocalToPanel = p.worldToLocal * cachedTransform.localToWorldMatrix;
                        }

                        mGeom.ApplyOffset(vector6);
                        mGeom.ApplyTransform(mLocalToPanel, p.generateNormals);
                    }

                    return(true);
                }

                if (mGeom.hasVertices)
                {
                    mGeom.Clear();
                    return(true);
                }
            }
        }

        return(false);
    }