Пример #1
0
        public Shape BuildLinkedSpline <T>(List <Vector2> points, float width, Color color, Material mat, bool loop = false) where T : BaseLineStyle
        {
            GameObject go   = new GameObject();
            Mesh       mesh = new Mesh();

            go.AddComponent <MeshFilter>().mesh = mesh;
            MeshRenderer mr = go.AddComponent <MeshRenderer>();

            _basicMaterial = mat;

            if (_basicMaterial == null)
            {
                _basicMaterial = Resources.Load("Basic2DMaterial") as Material;
            }
            mr.material = _basicMaterial;

            BaseLineStyle lineStyle = ScriptableObject.CreateInstance(typeof(T)) as BaseLineStyle;

            List <Vector2> splinePoints = MeshUtils.Vector3ToVector2(MeshUtils.CatmullRom(MeshUtils.Vector2ToVector3(points)));

            BuildLinkedMesh(mesh, splinePoints, color, width, loop, lineStyle);
            Shape s = go.AddComponent <Shape>();

            s.Col             = color;
            s.Points          = Vector3ToVector2(mesh.vertices);
            s.BuiltGameObject = go;
            s.LineStyle       = lineStyle;
            s.LinePoints      = splinePoints.ToArray();

            return(s);
        }
Пример #2
0
        public void RebuildLinkedSpline(Shape shape, List <Vector2> points, float width, bool loop = false)
        {
            Mesh m = shape.BuiltGameObject.GetComponent <MeshFilter>().sharedMesh;

            if (shape.LineStyle == null)
            {
                BaseLineStyle lineStyle = ScriptableObject.CreateInstance <BaseLineStyle>();
                shape.LineStyle = lineStyle;
            }

            List <Vector2> splinePoints = MeshUtils.Vector3ToVector2(MeshUtils.CatmullRom(MeshUtils.Vector2ToVector3(points)));

            BuildLinkedMesh(m, splinePoints, shape.Col, width, loop, shape.LineStyle);
            shape.Points     = Vector3ToVector2(m.vertices);
            shape.LinePoints = splinePoints.ToArray();
        }