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 Init()
        {
            string generatedName     = "generated by " + GetType().Name;
            var    generatedTranform = transform.Find(generatedName);

            generated = generatedTranform != null ? generatedTranform.gameObject : UOUtility.Create(generatedName, gameObject,
                                                                                                    typeof(MeshFilter),
                                                                                                    typeof(MeshRenderer),
                                                                                                    typeof(MeshBender));

            generated.GetComponent <MeshRenderer>().material = material;

            if (generated.GetComponent <DecrepitEffect>() == null)
            {
                generated.AddComponent <DecrepitEffect>();
            }
            meshBender = generated.GetComponent <MeshBender>();
            spline     = GetComponent <Spline>();

            meshBender.Source = SourceMesh.Build(mesh)
                                .Rotate(Quaternion.Euler(rotation))
                                .Scale(scale);
            meshBender.Mode = MeshBender.FillingMode.StretchToInterval;
            meshBender.SetInterval(spline, 0, 0.01f);
        }
Exemplo n.º 3
0
 private void Contort()
 {
     if (generated != null)
     {
         meshBender.SetInterval(spline, spline.Length * rate);
         meshBender.ComputeIfNeeded();
     }
 }
Exemplo n.º 4
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 = SourceMesh.Build(tm.mesh)
                                .Translate(tm.translation)
                                .Rotate(Quaternion.Euler(tm.rotation))
                                .Scale(tm.scale);
                    mb.SetInterval(curve);
                    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.º 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();
            }
        }