Ngui processing effects display and panel display mezzanine issues

Source: Internet
Author: User

Ngui is pretty good, but one of the more tangled is that when you display special effects on the panel, you'll find that you either cover the effects or the panels never cover the effects. Many people say change renderqueue, then can show, and then the next pile of landlord to force .... Oh.

First of all, the Ngui is to show the different layers by adjusting the renderqueue, and then the shader is not writing Z-values, and the effects are just not written to Z-values, so you
To control the relationship between the effects and the UI, you can really only pass renderqueue. But if you simply make renderqueue very big, then the effects will always be on the panel.
If you want two panels to clip the effects, then you need to look at the Ngui source code.
Here I would like you to see for yourself, I directly paste the revised program:
if (This.widgetinfrontofme! = NULL && This.widgetInFrontOfMe.drawCall! = null) {
The int rq = this.widgetInFrontOfMe.drawCall.renderQueue + 1;
Debug.Log (RQ);
foreach (Material Material in m_renderer.materials) {
if (material.renderqueue! = RQ)
{
Material.renderqueue = RQ;
}
}
}


The first piece of code is to adjust the renderqueu of the effect to the front of the object you want to place. Then if you do this in update () or lateupdate ()
Section code, you will find that it works well, is occasionally flashing, this is because the code is updated first, and then Ngui update, resulting in a lag frame. For a perfectionist like me, it's not
can accept. So I modified the source code of the UIPanel, but after all the updates are complete, then call this function. Haha, everything is perfect.
The complete code is as follows: using Unityengine;
Using System.Collections.Generic;

public class Uisortbehavior:monobehaviour
{
public UIPanel Panel;
Public Uiwidget Widgetinfrontofme;
public bool Addqueue=true;

[System.nonserialized]
Renderer M_renderer;

void Awake () {
M_renderer = This.renderer;
}

public void Initpanel (UIPanel p)
{
panel = p;
}

void Start ()
{
Panel.adduisort (this);
}

public void Updatesortui ()
{
if (This.widgetinfrontofme! = NULL && This.widgetInFrontOfMe.drawCall! = null) {
The int rq = this.widgetInFrontOfMe.drawCall.renderQueue + 1;
if (! Addqueue)
RQ-= 2;
foreach (Material Material in m_renderer.materials) {
if (material.renderqueue! = RQ)
{
Material.renderqueue = RQ;
}
}
}
}

void OnDestroy ()
{
if (panel! = null)
Panel.removeuisort (this);
}

}


Of course the UIPanel also want to modify:
void Lateupdate ()
{
if (mupdateframe! = time.framecount)
{
Mupdateframe = Time.framecount;

Update each panel in order
for (int i = 0; i < list.size; ++i)
List. Updateself ();

RQ int = 3000;

Update all draw calls, making them draw with the right order
for (int i = 0; i < list.size; ++i)
{
UIPanel p = List.buffer;

if (P.renderqueue = = renderqueue.automatic)
{
P.startingrenderqueue = RQ;
P.updatedrawcalls ();
RQ + = P.drawcalls.size;
RQ + = P.drawcalls.size * 2;
}
else if (P.renderqueue = = Renderqueue.startat)
{
P.updatedrawcalls ();
if (p.drawcalls.size! = 0)
RQ = Mathf.max (RQ, P.startingrenderqueue + p.drawcalls.size * 2);
RQ = Mathf.max (RQ, P.startingrenderqueue + p.drawcalls.size);
}
else//Explicit
{
P.updatedrawcalls ();
if (p.drawcalls.size! = 0)
RQ = Mathf.max (RQ, P.startingrenderqueue + 2);
RQ = Mathf.max (RQ, P.startingrenderqueue + 1);
}
P.updateuisort ();
}


}
}

list<uisortbehavior> container = new list<uisortbehavior> ();

public void Adduisort (Uisortbehavior uisort)
{
if (container. Contains (Uisort))
{
Return
}
Container. ADD (Uisort);
}

public void Removeuisort (Uisortbehavior uisort)
{
Container. Remove (Uisort);
}

public void Updateuisort ()
{
for (int i = 0; i < container. Count; i++)
{
Container. Updatesortui ();
}
}

void Updatedrawcalls ()
{
Transform trans = Cachedtransform;
bool Isui = Usedforui;

if (clipping! = UIDrawCall.Clipping.None)
{
Drawcallcliprange = finalclipregion;
Drawcallcliprange.z *= 0.5f;
DRAWCALLCLIPRANGE.W *= 0.5f;
}
else Drawcallcliprange = Vector4.zero;

Legacy functionality
if (drawcallcliprange.z = = 0f) drawcallcliprange.z = Screen.width * 0.5f;
if (DRAWCALLCLIPRANGE.W = = 0f) DRAWCALLCLIPRANGE.W = Screen.height * 0.5f;

DirectX 9 Half-pixel Offset
if (Halfpixeloffset)
{
Drawcallcliprange.x-= 0.5f;
Drawcallcliprange.y + = 0.5f;
}

Vector3 POS;

We want the position to always being on even pixels so that the
Panel ' s contents always appear pixel-perfect.
if (Isui)
{
Transform parent = cachedtransform.parent;
pos = cachedtransform.localposition;

if (parent! = NULL)
{
float x = Mathf.round (pos.x);
Float y = mathf.round (POS.Y);

Drawcallcliprange.x + = Pos.x-x;
Drawcallcliprange.y + = pos.y-y;

pos.x = x;
Pos.y = y;
pos = parent. Transformpoint (POS);
}
pos + = Drawcalloffset;
}
else pos = trans.position;

quaternion rot = trans.rotation;
Vector3 scale = Trans.lossyscale;

for (int i = 0; i < drawcalls.size; ++i)
{
Uidrawcall DC = Drawcalls.buffer;

Transform t = dc.cachedtransform;
T.position = pos;
T.rotation = rot;
T.localscale = scale;

Dc.renderqueue = (Renderqueue = = renderqueue.explicit)? Startingrenderqueue:startingrenderqueue + i;
Dc.renderqueue = (Renderqueue = = renderqueue.explicit)? Startingrenderqueue:startingrenderqueue + i * 2;
Dc.alwaysonscreen = Alwaysonscreen &&
(mclipping = = UIDrawCall.Clipping.None | | mclipping = = UIDrawCall.Clipping.ConstrainButDontClip);
#if! Unity_3_5 &&! Unity_4_0 &&! Unity_4_1 &&! Unity_4_2
Dc.sortingorder = Msortingorder;
#endif
}
}

Ngui processing effects display and panel display mezzanine issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.