Exemplo n.º 1
0
 protected virtual void OnDestroy()
 {
     AllCanvas.Remove(this);
     HCanvas.ReleaseCanvas(this);
     canvas    = null;
     ContextID = 0;
 }
Exemplo n.º 2
0
        static void AddUV1(HCanvas canvas, int[] ids, HVertex[] vertices, int l)
        {
            int len = vertices.Length;

            for (int i = 0; i < l; i++)
            {
                switch (ids[i])
                {
                case 0:
                    UV1[i].x = 0;
                    UV1[i].y = 0;
                    break;

                case 1:
                    UV1[i].x = 0;
                    UV1[i].y = 1;
                    break;

                case 2:
                    UV1[i].x = 1;
                    UV1[i].y = 0;
                    break;

                case 3:
                    UV1[i].x = 1;
                    UV1[i].y = 1;
                    break;
                }
            }
            for (int i = 0; i < len; i++)
            {
                canvas.uv1.Add(UV1[vertices[i].picture]);
            }
        }
Exemplo n.º 3
0
        static void AddUV1(HCanvas canvas, int tid, int vertCount)
        {
            Vector2[] uv1 = new Vector2[vertCount];
            switch (tid)
            {
            case 1:
                for (int i = 0; i < uv1.Length; i++)
                {
                    uv1[i].y = 1;
                }
                break;

            case 2:
                for (int i = 0; i < uv1.Length; i++)
                {
                    uv1[i].x = 1;
                }
                break;

            case 3:
                for (int i = 0; i < uv1.Length; i++)
                {
                    uv1[i].x = 1;
                    uv1[i].y = 1;
                }
                break;
            }
            canvas.uv1.AddRange(uv1);
        }
Exemplo n.º 4
0
 protected override void Update()
 {
     MainCanvas = this;
     UserAction.Update();
     Keyboard.InfoCollection();
     DispatchUserAction();
     AnimationManage.Manage.Update();
     if (UIPage.CurrentPage != null)
     {
         UIPage.CurrentPage.Update(UserAction.TimeSlice);
     }
     TextInput.Dispatch();
     InputCaret.UpdateCaret();
     CheckSize();
     ThreadMission.ExtcuteMain();
 }
Exemplo n.º 5
0
        public void Refresh()
        {
            if (Application.isPlaying)
            {
                return;
            }
            MatCollector.renderQueue = renderQueue;
            MainCanvas = this;
            point      = 1;
            max        = 0;
            top_txt    = 0;
            Collection(transform, -1, 0);
            int len = max;

            for (int i = 0; i < len; i++)
            {
                var grap = scripts[i] as HGraphics;
                if (grap != null)
                {
                    if (grap.m_material != null)
                    {
                        grap.MatID = grap.m_material.GetInstanceID();
                    }
                    else
                    {
                        grap.MatID = 0;
                    }
                    grap.m_dirty        = true;
                    grap.m_vertexChange = true;
                }
            }
            for (int i = 0; i < max; i++)
            {
                Resize(scripts[i], false);
            }
            for (int i = 0; i < max; i++)
            {
                scripts[i].MainUpdate();
            }
            for (int i = 0; i < top_txt; i++)
            {
                texts[i].Populate();
            }
            Batch();
            ApplyToCamera();
            ApplyShareMesh();
        }
Exemplo n.º 6
0
        /// <summary>
        /// 添加UV
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="tid"></param>
        /// <param name="vertCount"></param>
        static void AddUV1(HCanvas canvas, int tid, ref BlockInfo <HVertex> dat)
        {
            Vector2 v = Vector2.zero;

            v.x  = tid;
            v.x *= 0.1f;
            var dc = dat.DataCount;

            unsafe
            {
                var hv = dat.Addr;
                for (int i = 0; i < dc; i++)
                {
                    v.y = hv[i].fillColor;
                    canvas.uv1.Add(v);
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 更新内容包含:UI动画,UI页面更新,UI通知页更新,用户事件采集,键盘信息采集,事件派发,屏幕尺寸监测,执行分线程的委托任务
 /// </summary>
 protected virtual void Update()
 {
     if (Pause)
     {
         return;
     }
     MainCanvas = this;
     AnimationManage.Manage.Update();
     if (UIPage.CurrentPage != null)
     {
         UIPage.CurrentPage.Update(UserAction.TimeSlice);
     }
     UINotify.UpdateAll(UserAction.TimeSlice);
     UserAction.Update();
     Keyboard.InfoCollection();
     DispatchUserAction();
     CheckSize();
     ThreadMission.ExtcuteMain();
 }
Exemplo n.º 8
0
        /// <summary>
        /// 合批处理
        /// </summary>
        /// <param name="canvas">画布实例</param>
        /// <param name="pipeLine">UI流水线</param>
        public static void Batch(HCanvas canvas, HGUIElement[] pipeLine)
        {
            HGUIElement root = pipeLine[0];

            if (root.script != null)
            {
                canvas.MatCollector.Start();
                int c  = root.childCount;
                int os = root.childOffset;
                for (int i = 0; i < c; i++)
                {
                    if (pipeLine[os].active)
                    {
                        Batch(pipeLine, os, canvas, new Vector4(0, 0, 1, 1));
                    }
                    os++;
                }
                canvas.MatCollector.End();
            }
        }
Exemplo n.º 9
0
        unsafe static void AddUV1(HCanvas canvas, int[] ids, HVertex *vertices, int vc, int l)
        {
            for (int i = 0; i < l; i++)
            {
                switch (ids[i])
                {
                case 0:
                    UV1[i].x = 0;
                    UV1[i].y = 0;
                    break;

                case 1:
                    UV1[i].x = 0;
                    UV1[i].y = 1;
                    break;

                case 2:
                    UV1[i].x = 1;
                    UV1[i].y = 0;
                    break;

                case 3:
                    UV1[i].x = 1;
                    UV1[i].y = 1;
                    break;
                }
            }
            for (int i = 0; i < vc; i++)
            {
                int p = vertices[i].picture;
                if (p < 0 | p > 3)
                {
                    Debug.LogError("out of index");
                }
                else
                {
                    canvas.uv1.Add(UV1[p]);
                }
            }
        }
Exemplo n.º 10
0
 unsafe static void AddUV1(HCanvas canvas, int[] ids, HVertex *vertices, int vc, int l)
 {
     for (int i = 0; i < l; i++)
     {
         float x = ids[i];
         UV1[i].x = x * 0.1f;
         UV1[i].y = 0;
     }
     for (int i = 0; i < vc; i++)
     {
         int p = vertices[i].picture;
         if (p < 0 | p > 3)
         {
             Debug.LogError("out of index");
         }
         else
         {
             UV1[p].y = vertices[i].fillColor;
             canvas.uv1.Add(UV1[p]);
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// 合批处理
        /// </summary>
        /// <param name="canvas">画布实例</param>
        /// <param name="pipeLine">UI流水线</param>
        public static void Batch(HCanvas canvas, HGUIElement[] pipeLine)
        {
            HGUIElement root = pipeLine[0];

            if (root.script != null)
            {
                canvas.MatCollector.Start();
                int   c  = root.childCount;
                int   os = root.childOffset;
                float hw = canvas.m_sizeDelta.x * 0.5f;
                float hh = canvas.m_sizeDelta.y * 0.5f;
                for (int i = 0; i < c; i++)
                {
                    if (pipeLine[os].active)
                    {
                        Batch(pipeLine, os, canvas, new Vector4(-hw, -hh, hw, hh), Vector2.zero, new Vector2(hw, hh));
                    }
                    os++;
                }
                canvas.MatCollector.End();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 添加阴影
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="canvas"></param>
        /// <param name="q"></param>
        /// <param name="scale"></param>
        /// <param name="o"></param>
        /// <param name="clip"></param>
        static void AddShadow(HGraphics graphics, HCanvas canvas, ref Quaternion q, ref Vector3 scale, ref Vector3 o, ref Vector4 clip, ref Vector2 center, ref Vector2 half)
        {
            var vs = canvas.vertex;
            var vc = vs.Count;
            int dc = graphics.vertInfo.DataCount;
            var os = graphics.shadowOffsset;

            if (dc > 0)
            {
                float   px  = (0.5f - graphics.Pivot.x) * graphics.SizeDelta.x + os.x;
                float   py  = (0.5f - graphics.Pivot.y) * graphics.SizeDelta.y + os.y;
                Vector2 uv2 = Vector2.zero;
                unsafe
                {
                    HVertex *vert = graphics.vertInfo.Addr;
                    for (int j = 0; j < dc; j++)
                    {
                        var tp = vert[j].position;//局部顶点
                        tp.x += px;
                        tp.y += py;
                        var t = q * tp;
                        t.x  *= scale.x;
                        t.y  *= scale.y;
                        t    += o;
                        t.z   = 0;
                        uv2.x = (t.x - center.x) / half.x * 0.001f + 0.5f;
                        uv2.y = (t.y - center.y) / half.y * 0.001f + 0.5f;
                        vs.Add(t);
                        canvas.colors.Add(graphics.shadowColor);
                        canvas.uv.Add(vert[j].uv);
                        canvas.uv2.Add(uv2);
                        canvas.uv3.Add(vert[j].uv3);
                        canvas.uv4.Add(vert[j].uv4);
                    }
                }
                AddTris(graphics, canvas, vc, dc);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 添加UV
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="tid"></param>
        /// <param name="vertCount"></param>
        static void AddUV1(HCanvas canvas, int tid, int vertCount)
        {
            Vector2 v = Vector2.zero;

            switch (tid)
            {
            case 1:
                v.y = 1;
                break;

            case 2:
                v.x = 1;
                break;

            case 3:
                v.x = 1;
                v.y = 1;
                break;
            }
            for (int i = 0; i < vertCount; i++)
            {
                canvas.uv1.Add(v);
            }
        }
Exemplo n.º 14
0
        public static void RegCanvas(HGUIRender render)
        {
            for (int i = 0; i < AllCanvas.Count; i++)
            {
                if (AllCanvas[i].render == render)
                {
                    render.canvas = AllCanvas[i];
                    return;
                }
            }
            var can = render.canvas;

            if (can == null)
            {
                can             = new HCanvas();
                can.m_sizeDelta = render.DesignSize;
                can.DesignSize  = render.DesignSize;
                can.Pause       = render.Pause;
                can.name        = render.name;
            }
            can.render    = render;
            render.canvas = can;
            AllCanvas.Add(can);
        }
Exemplo n.º 15
0
        static void AddUV1(HCanvas canvas, int[] ids, HVertex[] vertices)
        {
            int len = vertices.Length;

            Vector2[] uv1 = new Vector2[len];
            for (int i = 0; i < ids.Length; i++)
            {
                switch (ids[i])
                {
                case 0:
                    UV1[i].x = 0;
                    UV1[i].y = 0;
                    break;

                case 1:
                    UV1[i].x = 0;
                    UV1[i].y = 1;
                    break;

                case 2:
                    UV1[i].x = 1;
                    UV1[i].y = 0;
                    break;

                case 3:
                    UV1[i].x = 1;
                    UV1[i].y = 1;
                    break;
                }
            }
            for (int i = 0; i < len; i++)
            {
                uv1[i] = UV1[vertices[i].picture];
            }
            canvas.uv1.AddRange(uv1);
        }
Exemplo n.º 16
0
 protected override void Start()
 {
     MainCanvas           = this;
     Font.textureRebuilt += FontTextureRebuilt;
 }
Exemplo n.º 17
0
        /// <summary>
        /// 添加阴影
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="canvas"></param>
        /// <param name="q"></param>
        /// <param name="scale"></param>
        /// <param name="o"></param>
        /// <param name="clip"></param>
        static void AddShadow(HGraphics graphics, HCanvas canvas, ref Quaternion q, ref Vector3 scale, ref Vector3 o, ref Vector4 clip)
        {
            var vs = canvas.vertex;
            var vc = vs.Count;
            int dc = graphics.vertInfo.DataCount;
            var os = graphics.shadowOffsset;

            if (dc > 0)
            {
                float   px  = (0.5f - graphics.Pivot.x) * graphics.SizeDelta.x + os.x;
                float   py  = (0.5f - graphics.Pivot.y) * graphics.SizeDelta.y + os.y;
                Vector2 uv2 = Vector2.zero;
                unsafe
                {
                    HVertex *vert = graphics.vertInfo.Addr;
                    for (int j = 0; j < dc; j++)
                    {
                        var tp = vert[j].position;//局部顶点
                        tp.x += px;
                        tp.y += py;
                        var t = q * tp;
                        t.x  *= scale.x;
                        t.y  *= scale.y;
                        t    += o;
                        t.z   = 0;
                        uv2.x = (t.x + 10000) / 20000;
                        uv2.y = (t.y + 10000) / 20000;
                        vs.Add(t);
                        canvas.colors.Add(graphics.shadowColor);
                        canvas.uv.Add(vert[j].uv);
                        canvas.uv2.Add(uv2);
                        canvas.uv3.Add(vert[j].uv3);
                        canvas.uv4.Add(vert[j].uv4);
                    }
                }
                if (graphics.tris != null)
                {
                    int tid = 0;
                    var src = graphics.tris;
                    int len = src.Length;
                    if (len > 0)
                    {
                        for (int k = 0; k < len; k++)
                        {
                            TriBuffer[k] = src[k] + vc;
                        }
                        canvas.MatCollector.CombinationMaterial(graphics, TriBuffer, len, ref tid, ref clip);
                    }
                    AddUV1(canvas, tid, dc);
                }
                else if (graphics.trisInfo.DataCount > 0 | graphics.trisInfo2.DataCount > 0)
                {
                    int l  = 0;
                    int tc = graphics.trisInfo.DataCount;
                    if (tc > 0)
                    {
                        unsafe
                        {
                            int *ip = graphics.trisInfo.Addr;
                            for (int k = 0; k < tc; k++)
                            {
                                TriBuffer[k] = ip[k] + vc;
                            }
                        }
                        l = 1;
                    }
                    Arrays[0].Length = tc;
                    int tc2 = graphics.trisInfo2.DataCount;
                    if (tc2 > 0)
                    {
                        int ks = tc;
                        unsafe
                        {
                            int *ip = graphics.trisInfo2.Addr;
                            for (int k = 0; k < tc2; k++)
                            {
                                TriBuffer[ks] = ip[k] + vc;
                                ks++;
                            }
                        }
                        Arrays[1].Start  = tc;
                        Arrays[1].Length = tc2;
                        l = 2;
                    }
                    canvas.MatCollector.CombinationMaterial(graphics, TriBuffer, Arrays, IDBuffer, l, ref clip);
                    unsafe
                    {
                        HVertex *hv = graphics.vertInfo.Addr;
                        AddUV1(canvas, IDBuffer, hv, dc, l);
                    }
                }
                else
                {
                    AddUV1(canvas, 0, dc);
                }
            }
        }
Exemplo n.º 18
0
 public HCanvas()
 {
     CurrentCanvas = this;
 }
Exemplo n.º 19
0
        static void Batch(HGUIElement[] pipeLine, int index, HCanvas canvas, Vector3 pos, Vector3 scale, Quaternion quate, Vector4 clip)
        {
            if (!pipeLine[index].active)
            {
                return;
            }
            HGUIElement root = pipeLine[index];
            Vector3     p    = quate * pipeLine[index].localPosition;
            Vector3     o    = Vector3.zero;

            o.x = p.x * scale.x;
            o.y = p.y * scale.y;
            o.z = p.z * scale.z;
            o  += pos;
            Vector3 s = pipeLine[index].localScale;

            scale.x *= s.x;
            scale.y *= s.y;
            Quaternion q = quate * pipeLine[index].localRotation;

            bool mask   = false;
            var  script = root.script;

            if (script != null)
            {
                mask = script.Mask;
                if (mask)//计算遮挡区域
                {
                    float x  = script.SizeDelta.x;
                    float y  = script.SizeDelta.y;
                    float px = script.Pivot.x;
                    float py = script.Pivot.y;
                    float lx = x * -px;
                    float rx = x + lx;
                    float dy = y * -py;
                    float ty = y + dy;
                    lx *= s.x;
                    rx *= s.x;
                    dy *= s.y;
                    ty *= s.y;
                    Vector4 v = new Vector4(o.x + lx, o.y + dy, o.x + rx, o.y + ty);
                    v.x += 10000;
                    v.x /= 20000;
                    v.y += 10000;
                    v.y /= 20000;
                    v.z += 10000;
                    v.z /= 20000;
                    v.w += 10000;
                    v.w /= 20000;
                    clip = CutRect(clip, v);
                }
                var graphics = script as HGraphics;
                if (graphics != null)//计算图形
                {
                    if (graphics.Shadow)
                    {
                        AddShadow(graphics, canvas, ref q, ref scale, ref o, ref clip);
                    }
                    var vs   = canvas.vertex;
                    var vc   = vs.Count;
                    var vert = graphics.vertices;
                    if (vert != null)
                    {
                        float   px  = (0.5f - script.Pivot.x) * script.SizeDelta.x;
                        float   py  = (0.5f - script.Pivot.y) * script.SizeDelta.y;
                        Vector2 uv2 = Vector2.zero;
                        for (int j = 0; j < vert.Length; j++)
                        {
                            var tp = vert[j].position;//局部顶点
                            tp.x += px;
                            tp.y += py;
                            var t = q * tp;
                            t.x  *= scale.x;
                            t.y  *= scale.y;
                            t    += o;
                            t.z   = 0;
                            uv2.x = (t.x + 10000) / 20000;
                            uv2.y = (t.y + 10000) / 20000;
                            vs.Add(t);
                            canvas.colors.Add(vert[j].color);
                            canvas.uv.Add(vert[j].uv);
                            canvas.uv2.Add(uv2);
                            canvas.uv3.Add(vert[j].uv3);
                            canvas.uv4.Add(vert[j].uv4);
                        }
                        if (graphics.tris != null)
                        {
                            int tid = 0;
                            var src = graphics.tris;
                            if (src.Length > 0)
                            {
                                int[] tmp = new int[src.Length];
                                for (int k = 0; k < tmp.Length; k++)
                                {
                                    tmp[k] = src[k] + vc;
                                }
                                canvas.MatCollector.CombinationMaterial(graphics, tmp, ref tid, ref clip);
                            }
                            AddUV1(canvas, tid, vert.Length);
                        }
                        else if (graphics.subTris != null)
                        {
                            var subs = graphics.subTris;
                            int l    = subs.Length;
                            if (l > 0)
                            {
                                int[]   ids = new int[l];
                                int[][] buf = new int[l][];
                                for (int i = 0; i < l; i++)
                                {
                                    var   src = subs[i];
                                    int[] tmp = new int[src.Length];
                                    for (int k = 0; k < tmp.Length; k++)
                                    {
                                        tmp[k] = src[k] + vc;
                                    }
                                    buf[i] = tmp;
                                }
                                canvas.MatCollector.CombinationMaterial(graphics, buf, ids, ref clip);
                                AddUV1(canvas, ids, vert);
                            }
                            else
                            {
                                AddUV1(canvas, 0, vert.Length);
                            }
                        }
                        else
                        {
                            AddUV1(canvas, 0, vert.Length);
                        }
                    }
                }
            }

            int c  = root.childCount;
            int os = root.childOffset;

            for (int i = 0; i < c; i++)
            {
                Batch(pipeLine, os, canvas, o, scale, q, clip);
                os++;
            }
        }
Exemplo n.º 20
0
        static void Batch(HGUIElement[] pipeLine, int index, HCanvas canvas, Vector4 clip, Vector2 center, Vector2 half)
        {
            if (!pipeLine[index].active)
            {
                return;
            }

            Vector3    o     = pipeLine[index].Position;
            Vector3    scale = pipeLine[index].Scale;
            Quaternion q     = pipeLine[index].Rotation;

            bool mask   = false;
            var  script = pipeLine[index].script;

            if (script != null)
            {
                mask = script.Mask;
                if (mask)//计算遮挡区域
                {
                    float x  = script.SizeDelta.x;
                    float y  = script.SizeDelta.y;
                    float px = script.Pivot.x;
                    float py = script.Pivot.y;
                    float lx = x * -px;
                    float rx = x + lx;
                    float dy = y * -py;
                    float ty = y + dy;
                    lx *= scale.x;
                    rx *= scale.x;
                    dy *= scale.y;
                    ty *= scale.y;
                    Vector4 v = new Vector4(o.x + lx, o.y + dy, o.x + rx, o.y + ty);
                    clip     = CutRect(clip, v);
                    half.x   = (clip.z - clip.x) * 0.5f;
                    half.y   = (clip.w - clip.y) * 0.5f;
                    center.x = half.x + clip.x;
                    center.y = half.y + clip.y;
                }
                var graphics = script as HGraphics;
                if (graphics != null)//计算图形
                {
                    if (graphics.Shadow)
                    {
                        AddShadow(graphics, canvas, ref q, ref scale, ref o, ref clip, ref center, ref half);
                    }
                    var vs = canvas.vertex;
                    var vc = vs.Count;
                    int dc = graphics.vertInfo.DataCount;
                    if (dc > 0)
                    {
                        float   px  = (0.5f - script.Pivot.x) * script.m_sizeDelta.x;
                        float   py  = (0.5f - script.Pivot.y) * script.m_sizeDelta.y;
                        Vector2 uv2 = Vector2.zero;
                        unsafe
                        {
                            HVertex *hv = graphics.vertInfo.Addr;
                            for (int j = 0; j < dc; j++)
                            {
                                var tp = hv[j].position;//局部顶点
                                tp.z  = 0;
                                tp.x += px;
                                tp.y += py;
                                tp.x *= scale.x;
                                tp.y *= scale.y;
                                var t = q * tp;
                                t    += o;
                                t.z   = 0;
                                uv2.x = (t.x - center.x) / half.x * 0.001f + 0.5f;
                                uv2.y = (t.y - center.y) / half.y * 0.001f + 0.5f;
                                vs.Add(t);
                                canvas.colors.Add(hv[j].color);
                                canvas.uv.Add(hv[j].uv);
                                canvas.uv2.Add(uv2);
                                canvas.uv3.Add(hv[j].uv3);
                                canvas.uv4.Add(hv[j].uv4);
                            }
                        }
                        AddTris(graphics, canvas, vc, dc);
                    }
                }
            }

            int c  = pipeLine[index].childCount;
            int os = pipeLine[index].childOffset;

            for (int i = 0; i < c; i++)
            {
                Batch(pipeLine, os, canvas, clip, center, half);
                os++;
            }
        }
Exemplo n.º 21
0
        static void AddShadow(HGraphics graphics, HCanvas canvas, ref Quaternion q, ref Vector3 scale, ref Vector3 o, ref Vector4 clip)
        {
            var vs   = canvas.vertex;
            var vc   = vs.Count;
            var vert = graphics.vertices;
            var os   = graphics.shadowOffsset;

            if (vert != null)
            {
                float   px  = (0.5f - graphics.Pivot.x) * graphics.SizeDelta.x + os.x;
                float   py  = (0.5f - graphics.Pivot.y) * graphics.SizeDelta.y + os.y;
                Vector2 uv2 = Vector2.zero;
                for (int j = 0; j < vert.Length; j++)
                {
                    var tp = vert[j].position;//局部顶点
                    tp.x += px;
                    tp.y += py;
                    var t = q * tp;
                    t.x  *= scale.x;
                    t.y  *= scale.y;
                    t    += o;
                    t.z   = 0;
                    uv2.x = (t.x + 10000) / 20000;
                    uv2.y = (t.y + 10000) / 20000;
                    vs.Add(t);
                    canvas.colors.Add(graphics.shadowColor);
                    canvas.uv.Add(vert[j].uv);
                    canvas.uv2.Add(uv2);
                    canvas.uv3.Add(vert[j].uv3);
                    canvas.uv4.Add(vert[j].uv4);
                }
                if (graphics.tris != null)
                {
                    int tid = 0;
                    var src = graphics.tris;
                    if (src.Length > 0)
                    {
                        int[] tmp = new int[src.Length];
                        for (int k = 0; k < tmp.Length; k++)
                        {
                            tmp[k] = src[k] + vc;
                        }
                        canvas.MatCollector.CombinationMaterial(graphics, tmp, ref tid, ref clip);
                    }
                    AddUV1(canvas, tid, vert.Length);
                }
                else if (graphics.subTris != null)
                {
                    var subs = graphics.subTris;
                    int l    = subs.Length;
                    if (l > 0)
                    {
                        int[]   ids = new int[l];
                        int[][] buf = new int[l][];
                        for (int i = 0; i < l; i++)
                        {
                            var   src = subs[i];
                            int[] tmp = new int[src.Length];
                            for (int k = 0; k < tmp.Length; k++)
                            {
                                tmp[k] = src[k] + vc;
                            }
                            buf[i] = tmp;
                        }
                        canvas.MatCollector.CombinationMaterial(graphics, buf, ids, ref clip);
                        AddUV1(canvas, ids, vert);
                    }
                    else
                    {
                        AddUV1(canvas, 0, vert.Length);
                    }
                }
                else
                {
                    AddUV1(canvas, 0, vert.Length);
                }
            }
        }
Exemplo n.º 22
0
        static void AddTris(HGraphics graphics, HCanvas canvas, int vc, int dc)
        {
            int max = vc + dc;

            if (graphics.tris != null)
            {
                int tid = 0;
                var src = graphics.tris;
                int len = src.Length;
                if (len > 0)
                {
                    for (int k = 0; k < len; k++)
                    {
                        int index = TriBuffer[k] = src[k] + vc;
                        if (index >= max)
                        {
                            Debug.LogError("数组超标");
                        }
                    }
                    canvas.MatCollector.CombinationMaterial(graphics, graphics.MainTexture, TriBuffer, len, ref tid);
                }
                AddUV1(canvas, tid, ref graphics.vertInfo);
            }
            else if (graphics.trisInfo.DataCount > 0 | graphics.trisInfo1.DataCount > 0 | graphics.trisInfo2.DataCount > 0)
            {
                Arrays[0].Length = 0;
                Arrays[1].Length = 0;
                Arrays[2].Length = 0;
                int l  = 0;
                int tc = graphics.trisInfo.DataCount;
                if (tc > 0)
                {
                    unsafe
                    {
                        int *ip = graphics.trisInfo.Addr;
                        for (int k = 0; k < tc; k++)
                        {
                            TriBuffer[k] = ip[k] + vc;
                        }
                    }
                    l = 1;
                }
                Arrays[0].Length = tc;
                int tc2 = graphics.trisInfo1.DataCount;
                if (tc2 > 0)
                {
                    int ks = tc;
                    unsafe
                    {
                        int *ip = graphics.trisInfo1.Addr;
                        for (int k = 0; k < tc2; k++)
                        {
                            TriBuffer[ks] = ip[k] + vc;
                            ks++;
                        }
                    }
                    Arrays[1].Start  = tc;
                    Arrays[1].Length = tc2;
                    l = 2;
                }
                int tc3 = graphics.trisInfo2.DataCount;
                if (tc3 > 0)
                {
                    int ks = tc + tc2;
                    unsafe
                    {
                        int *ip = graphics.trisInfo2.Addr;
                        for (int k = 0; k < tc3; k++)
                        {
                            TriBuffer[ks] = ip[k] + vc;
                            ks++;
                        }
                    }
                    Arrays[2].Start  = tc + tc2;
                    Arrays[2].Length = tc3;
                    l = 3;
                }
                canvas.MatCollector.CombinationMaterial(graphics, TriBuffer, Arrays, IDBuffer, l);
                unsafe
                {
                    HVertex *hv = graphics.vertInfo.Addr;
                    AddUV1(canvas, IDBuffer, hv, dc, l);
                }
            }
            else
            {
                AddUV1(canvas, 0, ref graphics.vertInfo);
            }
        }
Exemplo n.º 23
0
        static void Batch(HGUIElement[] pipeLine, int index, HCanvas canvas, Vector4 clip)
        {
            if (!pipeLine[index].active)
            {
                return;
            }

            Vector3    o     = pipeLine[index].Position;
            Vector3    scale = pipeLine[index].Scale;
            Quaternion q     = pipeLine[index].Rotation;

            bool mask   = false;
            var  script = pipeLine[index].script;

            if (script != null)
            {
                mask = script.Mask;
                if (mask)//计算遮挡区域
                {
                    float x  = script.SizeDelta.x;
                    float y  = script.SizeDelta.y;
                    float px = script.Pivot.x;
                    float py = script.Pivot.y;
                    float lx = x * -px;
                    float rx = x + lx;
                    float dy = y * -py;
                    float ty = y + dy;
                    lx *= scale.x;
                    rx *= scale.x;
                    dy *= scale.y;
                    ty *= scale.y;
                    Vector4 v = new Vector4(o.x + lx, o.y + dy, o.x + rx, o.y + ty);
                    v.x += 10000;
                    v.x /= 20000;
                    v.y += 10000;
                    v.y /= 20000;
                    v.z += 10000;
                    v.z /= 20000;
                    v.w += 10000;
                    v.w /= 20000;
                    clip = CutRect(clip, v);
                }
                var graphics = script as HGraphics;
                if (graphics != null)//计算图形
                {
                    if (graphics.Shadow)
                    {
                        AddShadow(graphics, canvas, ref q, ref scale, ref o, ref clip);
                    }
                    var vs = canvas.vertex;
                    var vc = vs.Count;
                    int dc = graphics.vertInfo.DataCount;
                    if (dc > 0)
                    {
                        float   px  = (0.5f - script.Pivot.x) * script.m_sizeDelta.x;
                        float   py  = (0.5f - script.Pivot.y) * script.m_sizeDelta.y;
                        Vector2 uv2 = Vector2.zero;
                        unsafe
                        {
                            HVertex *hv = graphics.vertInfo.Addr;
                            for (int j = 0; j < dc; j++)
                            {
                                var tp = hv[j].position;//局部顶点
                                tp.z  = 0;
                                tp.x += px;
                                tp.y += py;
                                tp.x *= scale.x;
                                tp.y *= scale.y;
                                var t = q * tp;
                                t    += o;
                                t.z   = 0;
                                uv2.x = (t.x + 10000) / 20000;
                                uv2.y = (t.y + 10000) / 20000;
                                vs.Add(t);
                                canvas.colors.Add(hv[j].color);
                                canvas.uv.Add(hv[j].uv);
                                canvas.uv2.Add(uv2);
                                canvas.uv3.Add(hv[j].uv3);
                                canvas.uv4.Add(hv[j].uv4);
                            }
                        }

                        if (graphics.tris != null)
                        {
                            int tid = 0;
                            var src = graphics.tris;
                            int len = src.Length;
                            if (len > 0)
                            {
                                for (int k = 0; k < len; k++)
                                {
                                    TriBuffer[k] = src[k] + vc;
                                }
                                canvas.MatCollector.CombinationMaterial(graphics, TriBuffer, len, ref tid, ref clip);
                            }
                            AddUV1(canvas, tid, dc);
                        }
                        else if (graphics.trisInfo.DataCount > 0 | graphics.trisInfo2.DataCount > 0)
                        {
                            int l  = 0;
                            int tc = graphics.trisInfo.DataCount;
                            if (tc > 0)
                            {
                                unsafe {
                                    int *ip = graphics.trisInfo.Addr;
                                    for (int k = 0; k < tc; k++)
                                    {
                                        TriBuffer[k] = ip[k] + vc;
                                    }
                                }
                                l = 1;
                            }
                            Arrays[0].Length = tc;
                            int tc2 = graphics.trisInfo2.DataCount;
                            if (tc2 > 0)
                            {
                                int ks = tc;
                                unsafe
                                {
                                    int *ip = graphics.trisInfo2.Addr;
                                    for (int k = 0; k < tc2; k++)
                                    {
                                        TriBuffer[ks] = ip[k] + vc;
                                        ks++;
                                    }
                                }
                                Arrays[1].Start  = tc;
                                Arrays[1].Length = tc2;
                                l = 2;
                            }
                            canvas.MatCollector.CombinationMaterial(graphics, TriBuffer, Arrays, IDBuffer, l, ref clip);
                            unsafe
                            {
                                HVertex *hv = graphics.vertInfo.Addr;
                                AddUV1(canvas, IDBuffer, hv, dc, l);
                            }
                        }
                        else
                        {
                            AddUV1(canvas, 0, dc);
                        }
                    }
                }
            }

            int c  = pipeLine[index].childCount;
            int os = pipeLine[index].childOffset;

            for (int i = 0; i < c; i++)
            {
                Batch(pipeLine, os, canvas, clip);
                os++;
            }
        }
Exemplo n.º 24
0
 public void Awake()
 {
     HCanvas.RegCanvas(this);
     AllCanvas.Add(this);
 }