private void Contort()
        {
            float nodeDistance = 0;
            int   i            = 0;

            foreach (var n in spline.nodes)
            {
                Vector2 finalScale       = spline.nodes[0].Scale;
                float   nodeDistanceRate = nodeDistance / spline.Length;
                float   nodeScale        = startScale * (rate - (nodeDistanceRate));
                if (rate > 1)
                {
                    rate = 1;
                }
                n.Scale = new Vector2(nodeScale, nodeScale);
                if (i < spline.curves.Count)
                {
                    nodeDistance += spline.curves[i++].Length;
                }
            }

            if (generated != null)
            {
                meshBender.SetInterval(spline, 0, spline.Length * rate);
                meshBender.ComputeIfNeeded();
            }
        }
Exemplo n.º 2
0
 private void Contort()
 {
     if (generated != null)
     {
         meshBender.SetInterval(spline, spline.Length * rate);
         meshBender.ComputeIfNeeded();
     }
 }
Exemplo n.º 3
0
        public void CreateMeshes()
        {
            List <GameObject> used = new List <GameObject>();

            for (int i = 0; i < spline.GetCurves().Count; i++)
            {
                var curve = spline.GetCurves()[i];
                foreach (var tm in segments[i].transformedMeshes)
                {
                    if (tm.mesh == null)
                    {
                        // if there is no mesh specified for this segment, we ignore it.
                        continue;
                    }

                    // we try to find a game object previously generated. this avoids destroying/creating
                    // game objects at each update, wich is faster.
                    var        childName      = "segment " + i + " mesh " + segments[i].transformedMeshes.IndexOf(tm);
                    var        childTransform = generated.transform.Find(childName);
                    GameObject go;
                    if (childTransform == null)
                    {
                        go = UOUtility.Create(childName,
                                              generated,
                                              typeof(MeshFilter),
                                              typeof(MeshRenderer),
                                              typeof(MeshBender),
                                              typeof(MeshCollider));
                        go.isStatic = true;
                    }
                    else
                    {
                        go = childTransform.gameObject;
                    }
                    go.GetComponent <MeshRenderer>().material = tm.material;
                    go.GetComponent <MeshCollider>().material = tm.physicMaterial;

                    // we update the data in the bender. It will decide itself if the bending must be recalculated.
                    MeshBender mb = go.GetComponent <MeshBender>();
                    mb.Source      = tm.mesh;
                    mb.Curve       = curve;
                    mb.Translation = tm.translation;
                    mb.Rotation    = Quaternion.Euler(tm.rotation);
                    mb.Scale       = tm.scale;
                    mb.ComputeIfNeeded();
                    used.Add(go);
                }
            }

            // finally, we destroy the unused objects
            foreach (var go in generated.transform
                     .Cast <Transform>()
                     .Select(child => child.gameObject).Except(used))
            {
                UOUtility.Destroy(go);
            }
        }
Exemplo n.º 4
0
        public void CreateMeshes()
        {
            UOUtility.DestroyChildren(generated);

            int i = 0;

            foreach (CubicBezierCurve curve in spline.GetCurves())
            {
                GameObject go = UOUtility.Create("SplineMesh" + i++, generated,
                                                 typeof(MeshFilter),
                                                 typeof(MeshRenderer),
                                                 typeof(MeshBender));
                go.GetComponent <MeshRenderer>().material = material;
                MeshBender mb = go.GetComponent <MeshBender>();
                mb.Source   = mesh;
                mb.Rotation = Quaternion.Euler(rotation);
                mb.Curve    = curve;
                mb.ComputeIfNeeded();
            }
        }
Exemplo n.º 5
0
        private void Contort()
        {
            float nodeDistance = 0;
            int   i            = 0;

            foreach (var n in spline.nodes)
            {
                float currentPosition = spline.Length * rate;
                // Debug.Log(currentPosition);

                float nodeScale = startScale;


                n.Scale = new Vector2(nodeScale, nodeScale);
            }


            if (generated != null)
            {
                meshBender.SetInterval(spline, spline.Length * rate);
                meshBender.ComputeIfNeeded();
            }
        }