chore: updated Shape2D tween to look more aesthetic by choosing more linearly distributed vertices instead of the last vertex
This commit is contained in:
		@@ -14,15 +14,21 @@ public static class TweenShape2DExtensions
 | 
				
			|||||||
                t =>
 | 
					                t =>
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    shapeVertices.Clear();
 | 
					                    shapeVertices.Clear();
 | 
				
			||||||
                    int count = Math.Lerp(initialVertices.Count, targetShape2D.Vertices.Count, t).RoundToInt();
 | 
					                    int maxCount = initialVertices.Count.Max(targetShape2D.Vertices.Count);
 | 
				
			||||||
                    for (int i = 0; i < count; i++)
 | 
					                    for (int i = 0; i < maxCount; i++)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        int initialIndex = i.Min(initialVertices.Count);
 | 
					                        int initialIndex = (i * (initialVertices.Count / (float)maxCount)).RoundToInt(Math.RoundMode.Floor);
 | 
				
			||||||
                        int targetIndex = i.Min(targetShape2D.Vertices.Count);
 | 
					                        int targetIndex = (i * (targetShape2D.Vertices.Count / (float)maxCount)).RoundToInt(Math.RoundMode.Floor);
 | 
				
			||||||
                        shapeVertices.Add(targetShape2D.Vertices[targetIndex].Lerp(initialVertices[initialIndex], 1f - t));
 | 
					                        shapeVertices.Add(targetShape2D.Vertices[targetIndex].Lerp(initialVertices[initialIndex], 1f - t));
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    shape.Vertices = shapeVertices;
 | 
					                    shape.Vertices = shapeVertices;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            );
 | 
					            ).OnComplete(() =>
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                shapeVertices.Clear();
 | 
				
			||||||
 | 
					                for (int i = 0; i < targetShape2D.Vertices.Count; i++)
 | 
				
			||||||
 | 
					                    shapeVertices.Add(targetShape2D.Vertices[i]);
 | 
				
			||||||
 | 
					                shape.Vertices = shapeVertices;
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user