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(ref Matrix4x4 worldToPanel, bool parentMoved)
    {
        if (material == null)
        {
            return(false);
        }

        if (OnUpdate() || mChanged || changeFlag == 1)
        {
            mChanged = false;
            mGeom.Clear();
            changeFlag = -1;

            OnFill(mGeom.verts, mGeom.uvs, mGeom.cols);

            if (mGeom.hasVertices)
            {
                // cachedTransform.rotation = new Quaternion(0, 0, cachedTransform.rotation.z, 0);
                cachedTransform.eulerAngles = new Vector3(0, 0, cachedTransform.eulerAngles.z);
                mGeom.ApplyTransform(worldToPanel * cachedTransform.localToWorldMatrix);
            }
            return(true);
        }
        else if (mGeom.hasVertices && parentMoved)
        {
            //cachedTransform.rotation = new Quaternion(0, 0, cachedTransform.rotation.z,0);
            cachedTransform.eulerAngles = new Vector3(0, 0, cachedTransform.eulerAngles.z);
            mGeom.ApplyTransform(worldToPanel * cachedTransform.localToWorldMatrix);
        }
        return(false);
    }
Exemplo n.º 3
0
    public bool UpdateGeometry(int frame)
    {
        float num = CalculateFinalAlpha(frame);

        if (mIsVisibleByAlpha && mLastAlpha != num)
        {
            mChanged = true;
        }
        mLastAlpha = num;
        if (mChanged)
        {
            mChanged = false;
            if (mIsVisibleByAlpha && num > 0.001f && shader != null)
            {
                bool hasVertices = geometry.hasVertices;
                if (fillGeometry)
                {
                    geometry.Clear();
                    OnFill(geometry.verts, geometry.uvs, geometry.cols);
                }
                if (geometry.hasVertices)
                {
                    if (mMatrixFrame != frame)
                    {
                        mLocalToPanel = panel.worldToLocal * base.cachedTransform.localToWorldMatrix;
                        mMatrixFrame  = frame;
                    }
                    geometry.ApplyTransform(mLocalToPanel);
                    mMoved = false;
                    return(true);
                }
                return(hasVertices);
            }
            if (geometry.hasVertices)
            {
                if (fillGeometry)
                {
                    geometry.Clear();
                }
                mMoved = false;
                return(true);
            }
        }
        else if (mMoved && geometry.hasVertices)
        {
            if (mMatrixFrame != frame)
            {
                mLocalToPanel = panel.worldToLocal * base.cachedTransform.localToWorldMatrix;
                mMatrixFrame  = frame;
            }
            geometry.ApplyTransform(mLocalToPanel);
            mMoved = false;
            return(true);
        }
        mMoved = false;
        return(false);
    }
Exemplo n.º 4
0
 static public int ApplyTransform(IntPtr l)
 {
     try {
         UIGeometry            self = (UIGeometry)checkSelf(l);
         UnityEngine.Matrix4x4 a1;
         checkValueType(l, 2, out a1);
         self.ApplyTransform(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 5
0
    // update widget and fill geo
    public bool UpdateGeometry(int frame)
    {
        geometry.Clear();
        OnFill(geometry.verts, geometry.uvs, geometry.cols);

        mLocalToPanel = panel.worldToLocal * cachedTransform.localToWorldMatrix;

        // 最终verts = verts实际在world中的位置
        //          = widget一开始是在world中心点的一块矩形
        //              * 变换为Panel的局部坐标
        //              * 再从Panel坐标变换为World坐标
        // worldVerts = widget dimension verts(vert as world) * worldVertToPanel * PanelToworld
        geometry.ApplyTransform(mLocalToPanel);
        //mMoved = false;
        return(false);
    }
Exemplo n.º 6
0
    /// <summary>
    /// Update the widget and fill its geometry if necessary. Returns whether something was changed.
    /// </summary>

    public bool UpdateGeometry(bool forceVisible)
    {
        bool  hasMatrix      = false;
        float final          = finalAlpha;
        bool  visibleByAlpha = (final > 0.001f);
        bool  visibleByPanel = forceVisible || mVisibleByPanel;
        bool  moved          = false;

        // Check to see if the widget has moved relative to the panel that manages it
        if (HasTransformChanged())
        {
#if UNITY_EDITOR
            if (!mPanel.widgetsAreStatic || !Application.isPlaying)
#else
            if (!mPanel.widgetsAreStatic)
#endif
            {
                mLocalToPanel = mPanel.worldToLocal * cachedTransform.localToWorldMatrix;
                hasMatrix     = true;

                Vector2 offset = pivotOffset;

                float x0 = -offset.x * mWidth;
                float y0 = -offset.y * mHeight;
                float x1 = x0 + mWidth;
                float y1 = y0 + mHeight;

                Transform wt = cachedTransform;

                Vector3 v0 = wt.TransformPoint(x0, y0, 0f);
                Vector3 v1 = wt.TransformPoint(x1, y1, 0f);

                v0 = mPanel.worldToLocal.MultiplyPoint3x4(v0);
                v1 = mPanel.worldToLocal.MultiplyPoint3x4(v1);

                if (Vector3.SqrMagnitude(mOldV0 - v0) > 0.000001f ||
                    Vector3.SqrMagnitude(mOldV1 - v1) > 0.000001f)
                {
                    moved  = 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;

        if (mChanged)
        {
            mChanged = false;

            if (isVisible && shader != null)
            {
                bool hadVertices = mGeom.hasVertices;
                mGeom.Clear();
                OnFill(mGeom.verts, mGeom.uvs, mGeom.cols);

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

                    if (!hasMatrix)
                    {
                        mLocalToPanel = mPanel.worldToLocal * cachedTransform.localToWorldMatrix;
                    }
                    mGeom.ApplyTransform(mLocalToPanel);
                    return(true);
                }
                return(hadVertices);
            }
            else if (mGeom.hasVertices)
            {
                mGeom.Clear();
                return(true);
            }
        }
        else if (moved && mGeom.hasVertices)
        {
            if (!hasMatrix)
            {
                mLocalToPanel = mPanel.worldToLocal * cachedTransform.localToWorldMatrix;
            }
            mGeom.ApplyTransform(mLocalToPanel);
            return(true);
        }
        return(false);
    }
Exemplo n.º 7
0
    /// <summary>
    /// Update the widget and fill its geometry if necessary. Returns whether something was changed.
    /// </summary>

    public bool UpdateGeometry(int frame)
    {
        // Has the alpha changed?
        float finalAlpha = CalculateFinalAlpha(frame);

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

        if (mChanged)
        {
            mChanged = false;

            if (mIsVisibleByAlpha && finalAlpha > 0.001f && shader != null)
            {
                bool hadVertices = geometry.hasVertices;

                if (fillGeometry)
                {
                    geometry.Clear();
                    OnFill(geometry.verts, geometry.uvs, geometry.cols);
                }

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

                    if (mMatrixFrame != frame)
                    {
                        mLocalToPanel = panel.worldToLocal * cachedTransform.localToWorldMatrix;
                        mMatrixFrame  = frame;
                    }
                    geometry.ApplyTransform(mLocalToPanel);
                    mMoved = false;
                    return(true);
                }
                return(hadVertices);
            }
            else if (geometry.hasVertices)
            {
                if (fillGeometry)
                {
                    geometry.Clear();
                }
                mMoved = false;
                return(true);
            }
        }
        else if (mMoved && geometry.hasVertices)
        {
            if (mMatrixFrame != frame)
            {
                mLocalToPanel = panel.worldToLocal * cachedTransform.localToWorldMatrix;
                mMatrixFrame  = frame;
            }
            geometry.ApplyTransform(mLocalToPanel);
            mMoved = false;
            return(true);
        }
        mMoved = false;
        return(false);
    }
Exemplo n.º 8
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.º 9
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.º 10
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);
    }