Exemplo n.º 1
0
        /// <summary>
        /// 頂点の設定。始点と終点が結ばれていること
        /// </summary>
        public void SetVertices(List <Vector2> vertices, Color color)
        {
            //包括矩形から原点からのオフセットを求め適用する
            Rect rect = GeomUtil.CalculateRect(vertices);

            for (int i = 0; i < vertices.Count; ++i)
            {
                vertices[i] -= rect.center;
            }
            this.vertices = vertices;
            //座標をずらす
            transform.localPosition = rect.center;
            //改めて包括矩形を求める
            inclusionRect = GeomUtil.CalculateRect(vertices);
            //ポリゴンの生成
            //末尾を削除(一時的)
            vertices.RemoveAt(vertices.Count - 1);
            polygon = new ConcavePolygon(vertices);
            //末尾に先頭を追加
            vertices.Add(vertices[0]);

            //簡易メッシュの確保
            drawEMesh = polygon.ToEasyMesh(color);
            subEMesh  = polygon.ToEasyMesh(color);

            //描画用メッシュの領域確保
            drawEMeshes = new EasyMesh[2];

            //色
            SetPolygonColor(color);

            draw = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新
        /// </summary>
        public void Update()
        {
            if (!processing)
            {
                return;
            }
            //更新
            float t = processSpeed * Time.deltaTime;

            lerpStart.Update(t, EPSILON);
            lerpEnd.Update(t, EPSILON);
            lerpInner.Update(t, EPSILON);
            lerpOuter.Update(t, EPSILON);

            //処理中確認
            processing = lerpStart.Update(t, EPSILON) || lerpEnd.Update(t, EPSILON) || lerpInner.Update(t, EPSILON) || lerpOuter.Update(t, EPSILON);
            //processing = start.processing || end.processing || inner.processing || outer.processing;
            //簡易メッシュの作成
            if (!processing && converge)
            {
                cache = null;
            }
            else
            {
                cache = MakeEasyMesh();
            }
            cacheUpdated = true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 描画
        /// </summary>
        private void Draw()
        {
            if (!draw)
            {
                return;
            }
            //描画用簡易ポリゴンの作成
            drawEMeshes[0] = drawEMesh;                                                               //本体
            drawEMeshes[1] = EasyMesh.MakePolyLine2D(vertices, outlineWidth, lerpOutlineColor.Value); //アウトライン
            Mesh mesh = EasyMesh.ToMesh(drawEMeshes);

            //描画
            mf.mesh = mesh;
            if (mc)
            {
                if (!disabled)
                {
                    mc.sharedMesh = mesh;
                }
                else
                {
                    mc.sharedMesh = null;
                }
            }
            draw = false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 頂点の設定
        /// </summary>
        public void SetVertices(List <Vector2> vertices)
        {
            //包括矩形から原点からのオフセットを求め適用する
            Rect rect = GeomUtil.CalculateRect(vertices);

            for (int i = 0; i < vertices.Count; ++i)
            {
                vertices[i] -= rect.center;
            }
            this.vertices = vertices;
            //座標をずらす
            transform.localPosition = rect.center;
            //改めて包括矩形を求める
            inclusionRect = GeomUtil.CalculateRect(vertices);
            //ポリゴンの生成
            vertices.RemoveAt(vertices.Count - 1);                      //末尾を一時的に削除
            polygon = new ConcavePolygon(vertices);
            vertices.Add(vertices[0]);                                  //末尾に始点を追加

            //簡易メッシュの確保
            drawEMesh        = polygon.ToEasyMesh(polygonColor);
            targetColorEMesh = polygon.ToEasyMesh(polygonColor);

            //描画用簡易メッシュ領域の確保
            eMeshes = new EasyMesh[2];

            //コールバック
            onVertexChanged.Invoke(this);

            draw = true;
        }
Exemplo n.º 5
0
        public override EasyMesh GetEasyMesh(Color color)
        {
            List <Vector2> list = new List <Vector2>();

            list.Add(a);
            list.Add(b);
            return(EasyMesh.MakePolyLine2D(list, 0.1f, color));
        }
Exemplo n.º 6
0
 /// <summary>
 /// 補助線の描画
 /// </summary>
 public void Draw()
 {
     //描画
     EasyMesh[] eMeshes = new EasyMesh[snaps.Count];
     for (int i = 0; i < snaps.Count; ++i)
     {
         eMeshes[i] = snaps[i].snap.GetEasyMesh(color);
     }
     mf.mesh = EasyMesh.ToMesh(eMeshes);
 }
Exemplo n.º 7
0
 /// <summary>
 /// 描画
 /// </summary>
 private void Draw()
 {
     if (!draw)
     {
         return;
     }
     eMeshes[0] = mainLine.MakeLine(width, color);
     eMeshes[1] = subLine.MakeLine(width, color * subLineColorScale);
     mf.mesh    = EasyMesh.ToMesh(eMeshes);
     draw       = false;
 }
Exemplo n.º 8
0
 /// <summary>
 /// 描画
 /// </summary>
 private void Draw()
 {
     if (!draw)
     {
         return;
     }
     EasyMesh[] eMeshes = new EasyMesh[2];
     eMeshes[0] = polyLine.MakeSubLineRange(0f, nowDistance, width, color);
     eMeshes[1] = noticeLine.MakeLine(width, color);
     mf.mesh    = EasyMesh.ToMesh(eMeshes);
     draw       = false;
 }
        /// <summary>
        /// 多角形の設定
        /// </summary>
        public void SetPolygon(ConcavePolygon polygon)
        {
            origin = polygon;
            eMesh  = polygon.ToEasyMesh(Color.white);
            Mesh mesh = eMesh.ToMesh();

            mf.mesh = mesh;
            if (mc)
            {
                mc.sharedMesh = mesh;
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// 描画
 /// </summary>
 private void Draw()
 {
     if (!draw)
     {
         return;
     }
     EasyMesh[] eMeshes = new EasyMesh[2];
     eMeshes[0] = mainLine.MakeLine(width, color);
     eMeshes[1] = subLine.MakeLine(width, color * 0.5f);
     mf.mesh    = EasyMesh.ToMesh(eMeshes);
     draw       = false;
 }
Exemplo n.º 11
0
 /// <summary>
 /// 更新と描画用メッシュの作成
 /// </summary>
 private void UpdateFragment()
 {
     if (!circle.Processing)
     {
         return;
     }
     //更新
     circle.Update();
     //描画キャッシュが更新されていれば更新
     if (circle.CacheUpdated)
     {
         EasyMesh eMesh = circle.Cache;
         Mesh     mesh  = null;
         if (eMesh != null)
         {
             mesh = eMesh.ToMesh();
         }
         mf.mesh = mesh;
         //当たり判定用メッシュの設定
         if (!visibled)
         {
             if (circle.GetAvgDelta() > SET_MESH_EPSILON)
             {
                 mc.sharedMesh = mesh;
             }
             else
             {
                 mc.sharedMesh = null;
             }
         }
         else
         {
             mc.sharedMesh = mesh;
         }
     }
     //更新の結果処理が終わった場合
     if (!circle.Processing)
     {
         if (!visibled)
         {
             gameObject.SetActive(false);
         }
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// 簡易メッシュの設定
        /// </summary>
        public void SetEasyMesh(EasyMesh src)
        {
            //サイズの調整
            List <Vector2> vertices = new List <Vector2>();

            foreach (var e in src.verts)
            {
                vertices.Add(e);
            }
            Rect meshRect = GeomUtil.CalculateRect(vertices);
            //拡大率の計算
            Rect  rect   = rectTransform.rect;
            float xScale = rect.width / meshRect.width;
            float yScale = rect.height / meshRect.height;

            eMesh = new EasyMesh(src);
            eMesh.Scaling(Mathf.Abs(xScale < yScale ? xScale : yScale));

            SetVerticesDirty();
        }
Exemplo n.º 13
0
        /// <summary>
        /// 描画
        /// </summary>
        public void Draw()
        {
            //要素数確認
            int count = snaps.Count;

            if (count <= 0)
            {
                return;
            }

            //簡易メッシュ群の作成
            EasyMesh[] eMeshes = new EasyMesh[count];
            for (int i = 0; i < snaps.Count; ++i)
            {
                eMeshes[i] = snaps[i].snap.GetEasyMesh(color);
            }

            //描画
            mf.mesh = EasyMesh.ToMesh(eMeshes);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 部分線の簡易メッシュを作成。(範囲指定)
        /// </summary>
        public EasyMesh MakeSubLineRange(float start, float end, float width, Color color)
        {
            //値確認
            if (start >= end)
            {
                return(null);
            }

            //下準備
            List <Vector2> points   = new List <Vector2>();
            float          range    = end - start;
            float          sumRange = 0f;
            int            i        = 0;

            //開始位置/終了位置を探す
            int startIndex = 0;
            int endIndex   = 0;

            for (; i < edges.Count; ++i)
            {
                if (sumRange <= start && start <= sumRange + edges[i].range)
                {
                    points.Add(edges[i].direction * (start - sumRange) + edges[i].a);
                    startIndex = 0;
                    break;
                }
                sumRange += edges[i].range;
            }
            for (; i < edges.Count; ++i)
            {
                if (sumRange <= end && end <= sumRange + edges[i].range)
                {
                    points.Add(edges[i].direction * (end - sumRange) + edges[i].a);
                    break;
                }
                points.Add(edges[i].b);
                sumRange += edges[i].range;
            }

            return(EasyMesh.MakePolyLine2D(points, width, color));
        }
Exemplo n.º 15
0
        /// <summary>
        /// 簡易メッシュに変換
        /// </summary>
        public EasyMesh ToEasyMesh(Color color)
        {
            List <Vector3> verts   = new List <Vector3>();
            List <Color>   colors  = new List <Color>();
            List <int>     indices = new List <int>();

            int size = vertices.Count;

            for (int i = 0; i < size; ++i)
            {
                verts.Add(vertices[i]);
                colors.Add(color);
            }

            for (int i = 1; i < size; i += 1)
            {
                if (rotation == Rotation.CW)
                {
                    //時計回り
                    indices.Add(0);
                    indices.Add(i);
                    indices.Add((i + 1) % size);
                }
                else
                {
                    //反時計回り
                    indices.Add(0);
                    indices.Add((i + 1) % size);
                    indices.Add(i);
                }
            }

            EasyMesh eMesh = new EasyMesh();

            eMesh.verts   = verts.ToArray();
            eMesh.colors  = colors.ToArray();
            eMesh.indices = indices.ToArray();
            return(eMesh);
        }
Exemplo n.º 16
0
 /// <summary>
 /// 現在のパラメータでキャッシュを更新
 /// </summary>
 public void UpdateCache()
 {
     cache        = MakeEasyMesh();
     cacheUpdated = true;
 }
Exemplo n.º 17
0
 /// <summary>
 /// 簡易メッシュを作成
 /// </summary>
 public EasyMesh MakeLine(float width, Color color)
 {
     return(EasyMesh.MakePolyLine2D(vertices, width, color));
 }
Exemplo n.º 18
0
        /// <summary>
        /// 簡易メッシュの作成
        /// </summary>
        private EasyMesh MakeEasyMesh()
        {
            EasyMesh eMesh = new EasyMesh();
            //角度
            float diffAngle = lerpEnd.Value - lerpStart.Value;
            float addAngle  = (diffAngle > 0 ? 1f : -1f) * density;
            float angle     = 0f;
            int   addNum    = (int)(diffAngle / addAngle);
            int   i         = 0;

            //下準備
            Vector3[] verts   = new Vector3[(addNum + 2) * 2];
            Color[]   colors  = new Color[verts.Length];
            int[]     indices = new int[(addNum + 1) * 6];

            do
            {
                //verts
                verts[i * 2 + 0] = GeomUtil.DegToVector2(angle + lerpStart.Value) * lerpInner.Value;
                verts[i * 2 + 1] = GeomUtil.DegToVector2(angle + lerpStart.Value) * lerpOuter.Value;

                //colors
                colors[i * 2 + 0] = drawColor;
                colors[i * 2 + 1] = drawColor;

                //indices
                if (diffAngle > 0)
                {
                    indices[i * 6 + 0] = (i + 0) * 2 + 0;
                    indices[i * 6 + 1] = (i + 1) * 2 + 0;
                    indices[i * 6 + 2] = (i + 0) * 2 + 1;
                    indices[i * 6 + 3] = (i + 1) * 2 + 0;
                    indices[i * 6 + 4] = (i + 1) * 2 + 1;
                    indices[i * 6 + 5] = (i + 0) * 2 + 1;
                }
                else
                {
                    indices[i * 6 + 0] = (i + 0) * 2 + 0;
                    indices[i * 6 + 1] = (i + 0) * 2 + 1;
                    indices[i * 6 + 2] = (i + 1) * 2 + 0;
                    indices[i * 6 + 3] = (i + 1) * 2 + 0;
                    indices[i * 6 + 4] = (i + 0) * 2 + 1;
                    indices[i * 6 + 5] = (i + 1) * 2 + 1;
                }
                angle += addAngle;
                ++i;
            } while(addNum >= i);
            angle = diffAngle;
            //verts
            verts[i * 2 + 0] = GeomUtil.DegToVector2(lerpEnd.Value) * lerpInner.Value;
            verts[i * 2 + 1] = GeomUtil.DegToVector2(lerpEnd.Value) * lerpOuter.Value;

            //colors
            colors[i * 2 + 0] = drawColor;
            colors[i * 2 + 1] = drawColor;

            eMesh.verts   = verts;
            eMesh.colors  = colors;
            eMesh.indices = indices;

            return(eMesh);
        }