Exemplo n.º 1
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.º 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
    /// <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.º 4
0
    /// <summary>
    /// Fill the specified geometry buffer with vertices that would highlight the current selection.
    /// </summary>

    public void PrintOverlay(int start, int end, UIGeometry caret, UIGeometry highlight, Color caretColor, Color highlightColor)
    {
        if (caret != null)
        {
            caret.Clear();
        }
        if (highlight != null)
        {
            highlight.Clear();
        }
        if (!isValid)
        {
            return;
        }

        string text = processedText;

        UpdateNGUIText();

        int     startingCaretVerts = caret.verts.size;
        Vector2 center             = new Vector2(0.5f, 0.5f);
        float   alpha = finalAlpha;

        // If we have a highlight to work with, fill the buffer
        if (highlight != null && start != end)
        {
            int startingVertices = highlight.verts.size;
            NGUIText.PrintCaretAndSelection(text, start, end, caret.verts, highlight.verts);

            if (highlight.verts.size > startingVertices)
            {
                ApplyOffset(highlight.verts, startingVertices);

                Color32 c = new Color(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a * alpha);

                for (int i = startingVertices; i < highlight.verts.size; ++i)
                {
                    highlight.uvs.Add(center);
                    highlight.cols.Add(c);
                }
            }
        }
        else
        {
            NGUIText.PrintCaretAndSelection(text, start, end, caret.verts, null);
        }

        // Fill the caret UVs and colors
        ApplyOffset(caret.verts, startingCaretVerts);
        Color32 cc = new Color(caretColor.r, caretColor.g, caretColor.b, caretColor.a * alpha);

        for (int i = startingCaretVerts; i < caret.verts.size; ++i)
        {
            caret.uvs.Add(center);
            caret.cols.Add(cc);
        }
    }
Exemplo n.º 5
0
 static public int Clear(IntPtr l)
 {
     try {
         UIGeometry self = (UIGeometry)checkSelf(l);
         self.Clear();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 6
0
    public void PrintOverlay(int start, int end, UIGeometry caret, UIGeometry highlight, Color caretColor, Color highlightColor)
    {
        if (caret != null)
        {
            caret.Clear();
        }
        if (highlight != null)
        {
            highlight.Clear();
        }
        if (!this.isValid)
        {
            return;
        }
        string processedText = this.processedText;

        this.UpdateNGUIText();
        int     size       = caret.verts.size;
        Vector2 item       = new Vector2(0.5f, 0.5f);
        float   finalAlpha = this.finalAlpha;

        if (highlight != null && start != end)
        {
            int size2 = highlight.verts.size;
            NGUIText.PrintCaretAndSelection(processedText, start, end, caret.verts, highlight.verts);
            if (highlight.verts.size > size2)
            {
                this.ApplyOffset(highlight.verts, size2);
                Color32 item2 = new Color(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a * finalAlpha);
                for (int i = size2; i < highlight.verts.size; i++)
                {
                    highlight.uvs.Add(item);
                    highlight.cols.Add(item2);
                }
            }
        }
        else
        {
            NGUIText.PrintCaretAndSelection(processedText, start, end, caret.verts, null);
        }
        this.ApplyOffset(caret.verts, size);
        Color32 item3 = new Color(caretColor.r, caretColor.g, caretColor.b, caretColor.a * finalAlpha);

        for (int j = size; j < caret.verts.size; j++)
        {
            caret.uvs.Add(item);
            caret.cols.Add(item3);
        }
        NGUIText.bitmapFont  = null;
        NGUIText.dynamicFont = null;
    }
Exemplo n.º 7
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.º 8
0
    public void PrintOverlay(int start, int end, UIGeometry caret, UIGeometry highlight, Color caretColor, Color highlightColor)
    {
        caret?.Clear();
        highlight?.Clear();
        if (!isValid)
        {
            return;
        }
        string text = processedText;

        UpdateNGUIText();
        int     size = caret.verts.size;
        Vector2 item = new Vector2(0.5f, 0.5f);
        float   num  = finalAlpha;

        if (highlight != null && start != end)
        {
            int size2 = highlight.verts.size;
            NGUIText.PrintCaretAndSelection(text, start, end, caret.verts, highlight.verts);
            if (highlight.verts.size > size2)
            {
                ApplyOffset(highlight.verts, size2);
                Color32 item2 = new Color(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a * num);
                for (int i = size2; i < highlight.verts.size; i++)
                {
                    highlight.uvs.Add(item);
                    highlight.cols.Add(item2);
                }
            }
        }
        else
        {
            NGUIText.PrintCaretAndSelection(text, start, end, caret.verts, null);
        }
        ApplyOffset(caret.verts, size);
        Color32 item3 = new Color(caretColor.r, caretColor.g, caretColor.b, caretColor.a * num);

        for (int i = size; i < caret.verts.size; i++)
        {
            caret.uvs.Add(item);
            caret.cols.Add(item3);
        }
    }
Exemplo n.º 9
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.º 10
0
    /// <summary>
    /// Fill the specified geometry buffer with vertices that would highlight the current selection.
    /// </summary>

    public void PrintOverlay(int start, int end, UIGeometry caret, UIGeometry highlight, Color caretColor, Color highlightColor) {
        if (caret != null) caret.Clear();
        if (highlight != null) highlight.Clear();
        if (!isValid) return;

        string text = processedText;
        UpdateNGUIText();

        int startingCaretVerts = caret.verts.size;
        Vector2 center = new Vector2(0.5f, 0.5f);
        float alpha = finalAlpha;

        // If we have a highlight to work with, fill the buffer
        if (highlight != null && start != end) {
            int startingVertices = highlight.verts.size;
            NGUIText.PrintCaretAndSelection(text, start, end, caret.verts, highlight.verts);

            if (highlight.verts.size > startingVertices) {
                ApplyOffset(highlight.verts, startingVertices);

                Color32 c = new Color(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a * alpha);

                for (int i = startingVertices; i < highlight.verts.size; ++i) {
                    highlight.uvs.Add(center);
                    highlight.cols.Add(c);
                }
            }
        }
        else NGUIText.PrintCaretAndSelection(text, start, end, caret.verts, null);

        // Fill the caret UVs and colors
        ApplyOffset(caret.verts, startingCaretVerts);
        Color32 cc = new Color(caretColor.r, caretColor.g, caretColor.b, caretColor.a * alpha);

        for (int i = startingCaretVerts; i < caret.verts.size; ++i) {
            caret.uvs.Add(center);
            caret.cols.Add(cc);
        }

        NGUIText.bitmapFont = null;
        NGUIText.dynamicFont = null;
    }
Exemplo n.º 11
0
 public void PrintOverlay(int start, int end, UIGeometry caret, UIGeometry highlight, Color caretColor, Color highlightColor)
 {
     if (caret != null)
     {
         caret.Clear();
     }
     if (highlight != null)
     {
         highlight.Clear();
     }
     if (!this.isValid)
     {
         return;
     }
     string processedText = this.processedText;
     this.UpdateNGUIText();
     int size = caret.verts.size;
     Vector2 item = new Vector2(0.5f, 0.5f);
     float finalAlpha = this.finalAlpha;
     if (highlight != null && start != end)
     {
         int size2 = highlight.verts.size;
         NGUIText.PrintCaretAndSelection(processedText, start, end, caret.verts, highlight.verts);
         if (highlight.verts.size > size2)
         {
             this.ApplyOffset(highlight.verts, size2);
             Color32 item2 = new Color(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a * finalAlpha);
             for (int i = size2; i < highlight.verts.size; i++)
             {
                 highlight.uvs.Add(item);
                 highlight.cols.Add(item2);
             }
         }
     }
     else
     {
         NGUIText.PrintCaretAndSelection(processedText, start, end, caret.verts, null);
     }
     this.ApplyOffset(caret.verts, size);
     Color32 item3 = new Color(caretColor.r, caretColor.g, caretColor.b, caretColor.a * finalAlpha);
     for (int j = size; j < caret.verts.size; j++)
     {
         caret.uvs.Add(item);
         caret.cols.Add(item3);
     }
     NGUIText.bitmapFont = null;
     NGUIText.dynamicFont = null;
 }
Exemplo n.º 12
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.º 13
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);
    }
Exemplo n.º 14
0
	/// <summary>
	/// Fill the specified geometry buffer with vertices that would highlight the current selection.
	/// </summary>

	public void PrintOverlay (int start, int end, UIGeometry caret, UIGeometry highlight, Color caretColor, Color highlightColor)
	{
		if (caret != null) caret.Clear();
		if (highlight != null) highlight.Clear();
		if (!isValid) return;

		string text = processedText;
		float pixelSize = (mFont != null) ? mFont.pixelSize : 1f;
		float scale = mScale * pixelSize;
		bool usePS = usePrintedSize;

		if (usePS) UpdateNGUIText(mPrintedSize, mWidth, mHeight);
		else UpdateNGUIText(fontSize, Mathf.RoundToInt(mWidth / scale), mHeight);

		int startingCaretVerts = caret.verts.size;
		Vector2 center = new Vector2(0.5f, 0.5f);
		float alpha = finalAlpha;

		// If we have a highlight to work with, fill the buffer
		if (highlight != null && start != end)
		{
			int startingVertices = highlight.verts.size;
			NGUIText.PrintCaretAndSelection(text, start, end, caret.verts, highlight.verts);

			if (highlight.verts.size > startingVertices)
			{
				ApplyOffset(highlight.verts, usePS, scale, startingVertices);

				Color32 c = new Color(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a * alpha);

				for (int i = startingVertices; i < highlight.verts.size; ++i)
				{
					highlight.uvs.Add(center);
					highlight.cols.Add(c);
				}
			}
		}
		else NGUIText.PrintCaretAndSelection(text, start, end, caret.verts, null);

		// Fill the caret UVs and colors
		ApplyOffset(caret.verts, usePS, scale, startingCaretVerts);
		Color32 cc = new Color(caretColor.r, caretColor.g, caretColor.b, caretColor.a * alpha);

		for (int i = startingCaretVerts; i < caret.verts.size; ++i)
		{
			caret.uvs.Add(center);
			caret.cols.Add(cc);
		}
	}
Exemplo n.º 15
0
    public bool UpdateGeometry(ref Matrix4x4 worldToPanel, bool parentMoved, bool generateNormals)
    {
        if (this.material == null)
        {
            return(false);
        }
        UIGeometry mGeom = this.mGeom;

        if ((!this.OnUpdate() && !this.mChangedCall) && !this.mForcedChanged)
        {
            if (mGeom.hasVertices && parentMoved)
            {
                Matrix4x4 widgetToPanel = worldToPanel * this.cachedTransform.localToWorldMatrix;
                mGeom.Apply(ref widgetToPanel);
            }
            return(false);
        }
        this.mChangedCall   = false;
        this.mForcedChanged = false;
        mGeom.Clear();
        if (this.mAlphaUnchecked || !NGUITools.ZeroAlpha(this.mColor.a))
        {
            this.OnFill(mGeom.meshBuffer);
        }
        if (mGeom.hasVertices)
        {
            Vector3 vector;
            Vector2 vector2;
            Vector2 vector3;
            switch (((WidgetFlags)((byte)(this.widgetFlags & (WidgetFlags.CustomPivotOffset | WidgetFlags.CustomRelativeSize)))))
            {
            case WidgetFlags.CustomPivotOffset:
                tempWidgetFlags[0] = WidgetFlags.CustomPivotOffset;
                this.GetCustomVector2s(0, 1, tempWidgetFlags, tempVector2s);
                vector2   = tempVector2s[0];
                vector3.x = vector3.y = 1f;
                break;

            case WidgetFlags.CustomRelativeSize:
                tempWidgetFlags[0] = WidgetFlags.CustomRelativeSize;
                this.GetCustomVector2s(0, 1, tempWidgetFlags, tempVector2s);
                vector3 = tempVector2s[0];
                vector2 = DefaultPivot(this.mPivot);
                break;

            case (WidgetFlags.CustomPivotOffset | WidgetFlags.CustomRelativeSize):
                tempWidgetFlags[0] = WidgetFlags.CustomPivotOffset;
                tempWidgetFlags[1] = WidgetFlags.CustomRelativeSize;
                this.GetCustomVector2s(0, 2, tempWidgetFlags, tempVector2s);
                vector2 = tempVector2s[0];
                vector3 = tempVector2s[1];
                break;

            default:
                vector2   = DefaultPivot(this.mPivot);
                vector3.x = vector3.y = 1f;
                break;
            }
            vector.x = vector2.x * vector3.x;
            vector.y = vector2.y * vector3.y;
            vector.z = 0f;
            Matrix4x4 matrixx = worldToPanel * this.cachedTransform.localToWorldMatrix;
            mGeom.Apply(ref vector, ref matrixx);
        }
        return(true);
    }
Exemplo n.º 16
0
    public bool UpdateGeometry(ref Matrix4x4 worldToPanel, bool parentMoved, bool generateNormals)
    {
        Vector3 vector3 = new Vector3();
        Vector2 vector2;
        Vector2 vector21 = new Vector2();
        float   single;

        if (!this.material)
        {
            return(false);
        }
        UIGeometry uIGeometry = this.mGeom;

        if (!this.OnUpdate() && !this.mChangedCall && !this.mForcedChanged)
        {
            if (uIGeometry.hasVertices && parentMoved)
            {
                Matrix4x4 matrix4x4 = worldToPanel * this.cachedTransform.localToWorldMatrix;
                uIGeometry.Apply(ref matrix4x4);
            }
            return(false);
        }
        this.mChangedCall   = false;
        this.mForcedChanged = false;
        uIGeometry.Clear();
        if (this.mAlphaUnchecked || !NGUITools.ZeroAlpha(this.mColor.a))
        {
            this.OnFill(uIGeometry.meshBuffer);
        }
        if (uIGeometry.hasVertices)
        {
            switch ((byte)(this.widgetFlags & (UIWidget.WidgetFlags.CustomPivotOffset | UIWidget.WidgetFlags.CustomRelativeSize)))
            {
            case 1:
            {
                UIWidget.tempWidgetFlags[0] = UIWidget.WidgetFlags.CustomPivotOffset;
                this.GetCustomVector2s(0, 1, UIWidget.tempWidgetFlags, UIWidget.tempVector2s);
                vector2 = UIWidget.tempVector2s[0];
                float single1 = 1f;
                single     = single1;
                vector21.y = single1;
                vector21.x = single;
                break;
            }

            case 2:
            {
                UIWidget.tempWidgetFlags[0] = UIWidget.WidgetFlags.CustomRelativeSize;
                this.GetCustomVector2s(0, 1, UIWidget.tempWidgetFlags, UIWidget.tempVector2s);
                vector21 = UIWidget.tempVector2s[0];
                vector2  = UIWidget.DefaultPivot(this.mPivot);
                break;
            }

            case 3:
            {
                UIWidget.tempWidgetFlags[0] = UIWidget.WidgetFlags.CustomPivotOffset;
                UIWidget.tempWidgetFlags[1] = UIWidget.WidgetFlags.CustomRelativeSize;
                this.GetCustomVector2s(0, 2, UIWidget.tempWidgetFlags, UIWidget.tempVector2s);
                vector2  = UIWidget.tempVector2s[0];
                vector21 = UIWidget.tempVector2s[1];
                break;
            }

            default:
            {
                vector2 = UIWidget.DefaultPivot(this.mPivot);
                float single2 = 1f;
                single     = single2;
                vector21.y = single2;
                vector21.x = single;
                break;
            }
            }
            vector3.x = vector2.x * vector21.x;
            vector3.y = vector2.y * vector21.y;
            vector3.z = 0f;
            Matrix4x4 matrix4x41 = worldToPanel * this.cachedTransform.localToWorldMatrix;
            uIGeometry.Apply(ref vector3, ref matrix4x41);
        }
        return(true);
    }
Exemplo n.º 17
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.º 18
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.º 19
0
    /// <summary>
    /// Fill the specified geometry buffer with vertices that would highlight the current selection.
    /// </summary>

    public void PrintOverlay(int start, int end, UIGeometry caret, UIGeometry highlight, Color caretColor, Color highlightColor)
    {
        if (caret != null)
        {
            caret.Clear();
        }
        if (highlight != null)
        {
            highlight.Clear();
        }
        if (!isValid)
        {
            return;
        }

        string text      = processedText;
        float  pixelSize = (mFont != null) ? mFont.pixelSize : 1f;
        float  scale     = mScale * pixelSize;
        bool   usePS     = usePrintedSize;

        if (usePS)
        {
            UpdateNGUIText(mPrintedSize, mWidth, mHeight);
        }
        else
        {
            UpdateNGUIText(fontSize, Mathf.RoundToInt(mWidth / scale), mHeight);
        }

        int     startingCaretVerts = caret.verts.size;
        Vector2 center             = new Vector2(0.5f, 0.5f);
        float   alpha = finalAlpha;

        // If we have a highlight to work with, fill the buffer
        if (highlight != null && start != end)
        {
            int startingVertices = highlight.verts.size;
            NGUIText.PrintCaretAndSelection(text, start, end, caret.verts, highlight.verts);

            if (highlight.verts.size > startingVertices)
            {
                ApplyOffset(highlight.verts, usePS, scale, startingVertices);

                Color32 c = new Color(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a * alpha);

                for (int i = startingVertices; i < highlight.verts.size; ++i)
                {
                    highlight.uvs.Add(center);
                    highlight.cols.Add(c);
                }
            }
        }
        else
        {
            NGUIText.PrintCaretAndSelection(text, start, end, caret.verts, null);
        }

        // Fill the caret UVs and colors
        ApplyOffset(caret.verts, usePS, scale, startingCaretVerts);
        Color32 cc = new Color(caretColor.r, caretColor.g, caretColor.b, caretColor.a * alpha);

        for (int i = startingCaretVerts; i < caret.verts.size; ++i)
        {
            caret.uvs.Add(center);
            caret.cols.Add(cc);
        }
    }