示例#1
0
        public hgRect CalcRealRect(float[] margin, ALIGN align, float iwidth, float iheight, Vector2 disparea)
        {
            var    rbase  = CalcPadding(margin);
            hgRect r2     = new hgRect(rbase);
            var    height = (iheight < 0) ? (r2.IsInifinityHeight() ? disparea.y : r2.height) * (-iheight) : iheight;

            r2.SetHeight(height);
            //r2.SetHeight(iheight);

            var width = (iwidth < 0) ? r2.width * (-iwidth) : iwidth; //Negative is a ratio.

            r2.SetWidth(iwidth);

            if (align == ALIGN.CENTER)
            {
                r2.SetCenterX(rbase.center.x);
            }
            else if (align == ALIGN.RIGHT)
            {
                var v = new Vector2(rbase._rightX - r2._rightX, 0);
                r2.Move(v);
            }

            return(r2);
        }
示例#2
0
        public bool CheckContains(hgRect x)
        {
            var tmp = new hgRect(this);

            tmp.Sample(x);
            return(CheckEqual(tmp));
        }
示例#3
0
        public static void CreateAnchor(List <hglRender.BASE> list)
        {
            foreach (var d in list)
            {
                if (d.xe == null)
                {
                    continue;
                }
                hgRect r  = d.doneRealRect;
                string nm = "BC.";
                if (d.xe.text != null)
                {
                    nm += d.xe.text;
                }
                GameObject o  = new GameObject(nm);
                var        bc = o.AddComponent <BoxCollider>();
                o.transform.parent        = d.xe.FindBone();
                o.transform.localPosition = Vector3.zero;

                bc.center = Vector3.zero;
                bc.size   = new Vector2(r.width, r.height);

                var button = o.AddComponent <hglButtonLink>();
                button.Init(d.xe);
            }
        }
示例#4
0
        //public class BLOCKDATA
        //{
        //    public List<hglHtmlRender.BASE>
        //}


        public static void CreateAnchor(List <CDDATA> list)
        {
            foreach (var d in list)
            {
                hgRect r = new hgRect();
                if (d.clamp.Count == 0)
                {
                    continue;
                }
                var    rcd = d.clamp[0];
                string nm  = "BC.";
                foreach (var cd in d.clamp)
                {
                    r.Sample(cd.outer_v);
                    nm += cd.ToString();
                }
                GameObject o  = new GameObject(nm);
                var        bc = o.AddComponent <BoxCollider>();
                o.transform.parent = rcd.xe.FindBone();

                if (rcd is hgMesh.CD_IMAGE)
                {
                    o.transform.localPosition = Vector3.zero;
                }
                else
                {
                    o.transform.localPosition = r.center;
                }
                bc.center = Vector3.zero;
                bc.size   = new Vector2(r.width, r.height);

                var button = o.AddComponent <hglButtonLink>();
                button.Init(rcd.xe);
            }
        }
示例#5
0
            public static void DrawAtlasREPEAT(hgRect r, float z, Vector2 offset, hgAtlasInfoData atlasInfo, string atlasPartName, int colorIndex, MeshSet meshSet, int boneIndex)
            {
                Vector3[] vs = r.GetVector3Positions(z);
                Vector2[] atlasUvs;
                Vector2   perfectSize;

                atlasInfo.GetRectOneMesh(atlasPartName, out perfectSize, out atlasUvs);
                hgMeshAtlas.DrawAtlas_REPEAT(atlasUvs, perfectSize, offset, meshSet, boneIndex, vs, colorIndex);
            }
示例#6
0
            public static void DrawAtlasFrame(hgRect r, float z, hgAtlasInfoData atlasInfo, string atlasPartName, int colorIndex, MeshSet meshSet, int boneIndex, int[] edgeSize)
            {
                Vector3[] vs = r.GetVector3Positions(z);
                Vector2[] atlasUvs;
                hgAtlasInfoData.RECTPATTERN pattern;
                Vector2 perfectSize;

                atlasInfo.GetRectForceEdgeSize(atlasPartName, edgeSize, out perfectSize, out atlasUvs, out pattern);
                hgMeshAtlas.DrawAtlas_Sub4(pattern, atlasUvs, edgeSize, perfectSize, meshSet, boneIndex, vs, colorIndex, hgAtlasInfoData.StrechMode.STRECH_CENTER, true);
            }
示例#7
0
            public static hgRect CalcRect(List <CD> list)
            {
                hgRect r = new hgRect();

                for (int i = 0; i < list.Count; i++)
                {
                    r.Sample(list[i].outer_v);
                }
                return(r);
            }
示例#8
0
        public void Sample(hgRect r)
        {
            Vector2 tmp_max, tmp_min;

            tmp_max = r.max_v;
            tmp_min = r.min_v;
            max_v.x = Mathf.Max(max_v.x, tmp_max.x);
            max_v.y = Mathf.Max(max_v.y, tmp_max.y);
            min_v.x = Mathf.Min(min_v.x, tmp_min.x);
            min_v.y = Mathf.Min(min_v.y, tmp_min.y);
        }
示例#9
0
            public static void DrawAtlas(hgRect r, float z, hgAtlasInfoData atlasInfo, string atlasPartName, int colorIndex, MeshSet meshSet, int boneIndex, bool frameOnly /*= false*/)
            {
                Vector3[] vs = r.GetVector3Positions(z);
                Vector2[] atlasUvs;
                int[]     size;
                hgAtlasInfoData.RECTPATTERN pattern;
                hgAtlasInfoData.StrechMode  strechmode;
                Vector2 perfectSize;

                atlasInfo.GetRect(atlasPartName, out perfectSize, out atlasUvs, out pattern, out size, out strechmode);
                hgMeshAtlas.DrawAtlas_Sub4(pattern, atlasUvs, size, perfectSize, meshSet, boneIndex, vs, colorIndex, strechmode, frameOnly);
            }
示例#10
0
        public hgRect CalcLocal(Transform cur, Transform target)
        {
            var max_v3 = hglEtc.toVector3(max_v);
            var min_v3 = hglEtc.toVector3(min_v);

            var new_max_v3 = hglEtc.CalcLocalPosition(cur, max_v3, target);
            var new_min_v3 = hglEtc.CalcLocalPosition(cur, min_v3, target);

            var newRect = new hgRect();

            newRect.max_v = hglEtc.toVector2(new_max_v3);
            newRect.min_v = hglEtc.toVector2(new_min_v3);

            return(newRect);
        }
示例#11
0
        public static float GetLeftPosition(float yPos, hgRect frame, List <hgRect> list)
        {
            for (var x = frame._leftX + 1; x < frame._rightX; x++)
            {
                Vector3 v = new Vector3(x, yPos, 0);
                foreach (var r in list)
                {
                    if (!r.CheckContains(v))
                    {
                        return(x);
                    }
                }
            }

            return(float.NaN);
        }
示例#12
0
            public static hgRect CalcRectwScan(List <CD> list, CD add, Vector3 ileftBase) //for wordwrap
            {
                hgRect r = new hgRect();

                Vector3 leftBase = ileftBase;

                for (int i = 0; i < list.Count; i++)
                {
                    CD.GetNextRightVertexUV(list, i, null, ref leftBase, -1);
                    r.Sample(list[i].outer_v);
                }
                if (add != null)
                {
                    List <CD> tlist = new List <CD>();
                    tlist.Add(add);
                    CD.GetNextRightVertexUV(tlist, 0, null, ref leftBase, -1);
                    r.Sample(add.outer_v);
                }

                return(r);
            }
示例#13
0
        public static bool CheckCollision(hgRect frame, List <hgRect> list) //Chack last one only.
        {
            var    last = list[list.Count - 1];
            hgRect tr   = new hgRect(frame);

            tr.Sample(last);
            if (!tr.CheckEqual(last))
            {
                return(true);
            }
            if (list.Count > 1)
            {
                for (int i = 0; i < list.Count - 1; i++)
                {
                    if (CheckCollision(last, list[i]))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#14
0
        public static bool CheckCollision(hgRect _1, hgRect _2)
        {
            /* http://wiki.processing.org/w/Rect-Rect_intersection
             * return !(
             *  (_1._x > _2._x + _2.width )  //x_1 > x_2+width_2
             ||
             || (_1._x + _1.width < _2._x)   //x_1+width_1 < x_2
             ||
             || (_1._y > _2._y + _2.height)  //y_1 > y_2+height_2
             ||
             || (_1._y + _1.height < _2._y)  //y_1+height_1 < y_2
             || );
             */
            float dx = Mathf.Abs(_1.center.x - _2.center.x);
            float dy = Mathf.Abs(_1.center.y - _2.center.y);

            return(
                (dx <= _1.ext_w + _2.ext_w)
                &&
                (dy <= _1.ext_h + _2.ext_h)
                );
        }
示例#15
0
        /*
         *  Management of Atlas Objects
         */


        public static void Create(hgMesh.CD_IMAGE cd, Func <int> getBoneIndex, hgMesh.MeshSet ms)
        {
            int boneIndex = getBoneIndex();

            hgRect r = new hgRect(cd.inner_v);

            Vector2[] atlas_r;
            hgAtlasInfoData.RECTPATTERN pattern;
            hgAtlasInfoData.StrechMode  mode;
            int[]   size;
            Vector2 perfectSize;

            cd.atlasInfo.GetRect(cd.atlasName, out perfectSize, out atlas_r, out pattern, out size, out mode);
            hgMeshAtlas.DrawAtlas_Sub4(pattern, atlas_r, size, perfectSize, ms, boneIndex, cd.inner_v, cd.colorIndex, mode, false);

            var abone = CreateBone(ms, cd.atlasName + ".", boneIndex, cd.bone, new Vector3(r.center.x, r.center.y, 0), true);

            if (cd.xe != null)
            {
                cd.xe.bone1 = abone;
            }
        }
示例#16
0
        public hgRect CreateCenterPivotRect()
        {
            hgRect nr = new hgRect(-width / 2, height / 2, width, height);

            return(nr);
        }
示例#17
0
 public bool CheckPosition(hgRect x)
 {
     return(max_v != x.max_v || min_v != x.min_v);
 }
示例#18
0
 public bool CheckSizeNotEqual(hgRect x)
 {
     return(x.width != width || x.height != height);
 }
示例#19
0
        public void Create(Material mat, hgMesh.CD_IMAGE cd)
        {
            if (m_list == null)
            {
                m_list = new List <DATA>();
            }

            int        cur = cd.id;
            DATA       dt  = null;
            GameObject obj = null;
            MeshFilter mf  = null;

            hgRect r = new hgRect(cd.inner_v);

            if (cur < 0)
            {
                dt = new DATA();
                m_list.Add(dt);
                cur = m_list.Count - 1;

                if (cd.texture == null)
                {
                    return;
                }

                obj = new GameObject(cd.texture.name);
                obj.AddComponent <MeshFilter>();
                obj.AddComponent <MeshRenderer>();
                obj.renderer.material             = new Material(mat);
                obj.renderer.material.mainTexture = cd.texture;
                mf      = obj.GetComponent <MeshFilter>();
                mf.mesh = hgUserMesh.CreateOneRectangle(r.width, r.height);
                mf.mesh.RecalculateBounds();
                obj.transform.parent        = cd.bone;
                obj.transform.localScale    = Vector3.one;
                obj.transform.localPosition = new Vector3(r.center.x, r.center.y, 0);

                cd.bone = obj.transform;

                if (cd.xe != null)
                {
                    cd.xe.bone1 = obj.transform;
                }
            }
            //else
            //{
            //    dt = m_list[cur];
            //    obj = dt.go;
            //    mf  = obj.GetComponent<MeshFilter>();
            //    if (r.CheckSizeNotEqual(dt.rect))
            //    {
            //        mf.mesh = UserMesh.CreateOneRectangle(r.width,r.height);
            //        mf.mesh.RecalculateBounds();
            //    }
            //    if (obj.renderer.material.mainTexture != cd.texture)
            //    {
            //        obj.renderer.material.mainTexture=cd.texture;
            //    }
            //    if (r.CheckPosition(dt.rect))
            //    {
            //        obj.transform.localPosition = new Vector3(r.center.x, r.center.y,0);
            //    }
            //}
            //
            //dt.go = obj;
            //dt.rect = r;
            //
            //cd.id = cur;
        }
示例#20
0
 public hgRect(hgRect x)
 {
     max_v = x.max_v;
     min_v = x.min_v;
 }
示例#21
0
 public bool CheckEqual(hgRect x)
 {
     return(x.max_v == max_v && x.min_v == min_v);
 }