private void OnDrawGizmos()
        {
            UnityEngine.Random.seed = this.GetInstanceID();

            Polygon2Ex pol = new Polygon2Ex(GetComponent <PolygonCollider2D> ().points);

//			pol.GizmoColor = new Color (UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
//			pol.ShowGizmo ();

            Triangle2Ex[] tris = pol.ToTriangles();
            foreach (Triangle2Ex tri in tris)
            {
                tri.GizmoColor  = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
                tri.GizmoOffset = UnityEngine.Random.insideUnitCircle * .1f;
                tri.ShowGizmo();
            }


//			Polygon2Ex[] pols = pol.ToSimplePolygons ();
//
//			foreach (Polygon2Ex s_pol in pols) {
//				s_pol.GizmoColor = new Color (UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
//				s_pol.GizmoOffset = UnityEngine.Random.insideUnitCircle * .1f;
//				s_pol.ShowGizmo ();
//			}
        }
Example #2
0
        public void BuildFillingMesh(Polygon2Ex polygon)
        {
            if (polygon != null)
            {
                Polygon = polygon;
            }

            List <Vector2> vertice_list    = new List <Vector2> ();
            List <int>     triangle_points = new List <int> ();

            Polygon2Ex[] pols = Polygon.ToSimplePolygons();
            foreach (Polygon2Ex pol in pols)
            {
                int offset_idx = vertice_list.Count;
                vertice_list.AddRange(pol.Vertices);

                int[] vid_list = pol.ToTrianglesVertice();
                triangle_points.AddRange(vid_list.Select(_ => _ + offset_idx).ToArray());
            }

            //Build the uv array
            var scale  = UVScale != 0 ? (1f / UVScale) : 0;
            var matrix = Matrix4x4.TRS(-(Vector3)UVPosition, Quaternion.Euler(0, 0, UIRotation), new Vector3(scale, scale, 1));
            var uv     = new Vector2[vertice_list.Count];

            for (int i = 0; i < uv.Length; i++)
            {
                var p = matrix.MultiplyPoint(vertice_list [i]);
                uv [i] = new Vector2(p.x, p.y);
            }

            Transform fillingTran = transform.FindChild("Filling");

            MeshFilter meshFilter = fillingTran.GetComponent <MeshFilter> ();

            if (meshFilter == null)
            {
                meshFilter = fillingTran.gameObject.AddComponent <MeshFilter> ();
            }
            Mesh mesh = meshFilter.sharedMesh;

            if (mesh == null)
            {
                mesh            = new Mesh();
                mesh.name       = "filling mesh";
                meshFilter.mesh = mesh;
            }

            //Update the mesh
            mesh.Clear();
            mesh.vertices  = vertice_list.Select(v2 => (Vector3)v2).ToArray();
            mesh.uv        = uv;
            mesh.triangles = triangle_points.ToArray();
            mesh.RecalculateNormals();
            mesh.Optimize();
        }
Example #3
0
        public void BuildBorderMesh(Polygon2Ex polygon)
        {
//			Line2Ex line = new Line2Ex (Line2.CreateFromTwoPoints (polygon.Vertices [0], polygon.Vertices [1]));
//			Line2Ex p_line = line.ToParallel (.1f);
//			line.ShowGizmo ();
//			p_line.ShowGizmo ();

            Polygon2Ex border_extending_polygon = polygon.ToBorderExtendingPolygon(.2f);

            border_extending_polygon.ShowGizmo();
        }
Example #4
0
 public void Build(Polygon2Ex polygon)
 {
     Polygon = polygon;
     BuildFillingMesh(polygon);
     BuildBorderMesh(polygon);
 }
Example #5
0
        private void OnDrawGizmos()
        {
            Polygon2Ex pol = new Polygon2Ex(GetComponent <PolygonCollider2D> ().points);

            LimitedArea.Build(pol);
        }
Example #6
0
        // Use this for initialization
        void Start()
        {
            Polygon2Ex pol = new Polygon2Ex(GetComponent <PolygonCollider2D> ().points);

            LimitedArea.Build(pol);
        }