public DebugDrawPathCurve FitPath(List <Vector2> path, int windowSizeCount, int polynomialOrder) { var windowSize = new WindowSize(windowSizeCount); var subCurveFunctions = new List <CurveFunc>(); for (int i = 0; i <= path.Count - windowSize.FullSize; i++) { var subcurvePoints = path.Skip(i).Take(windowSize.FullSize).ToList(); var xArray = subcurvePoints.Select(c => (double)c.x).ToArray(); var yArray = subcurvePoints.Select(c => (double)c.y).ToArray(); var tArray = Enumerable.Range(0, subcurvePoints.Count) .Select(c => (double)c / (subcurvePoints.Count - 1)).ToArray(); var xFunc = Fit.PolynomialFunc(tArray, xArray, polynomialOrder); var yFunc = Fit.PolynomialFunc(tArray, yArray, polynomialOrder); subCurveFunctions.Add(new CurveFunc((t) => new Vector2((float)xFunc(t), (float)yFunc(t)))); } return(new DebugDrawPathCurve() { FinalCurve = PathCurve.Create(path, subCurveFunctions, windowSizeCount), SubCurves = subCurveFunctions }); }
public void StartMove(List <Vector3> _path) { mPath = PathCurve.GetCurved(_path.ToArray()); mStartTime = Time.time; mMoveIndex = 0; mStartPosition = mTransform.position; mTransform.LookAt(mPath[0]); }
public IEnumerator Animate(PathCurve path, AnimationCurve animationCurve, float rotation, float animationLength) { RectTransform rect = GetComponent <RectTransform>(); float startTime = Time.time; while (Time.time < startTime + animationLength) { yield return(new WaitForFixedUpdate()); float t = animationCurve.Evaluate((Time.time - startTime) / animationLength); rect.position = path.Lerp(t); rect.rotation = Quaternion.AngleAxis(rotation * t, Vector3.forward); } }
public void NewCards() { audioSource.PlayOneShot(shuffleSound); List <Shape> s = shapes.GetRange(deckOffset, 3); ShowShapes(s); deckOffset += 3; Vector3 outsidePos = new Vector3(1500, cardPositions[0].y, 0); foreach (ShapeCard c in cards) { c.GetComponent <RectTransform>().position = outsidePos; } StartCoroutine(WithDelay(cards[0].Animate(PathCurve.CreateStraight(outsidePos, cardPositions[0]), curve, 0, animationLength), 0.5f)); StartCoroutine(WithDelay(cards[1].Animate(PathCurve.CreateStraight(outsidePos, cardPositions[1]), curve, 0, animationLength), 1f)); StartCoroutine(WithDelay(cards[2].Animate(PathCurve.CreateStraight(outsidePos, cardPositions[2]), curve, 0, animationLength), 1.5f)); }
public IEnumerator ShowCreditsAnimation() { RectTransform creditsTransform = credits.transform as RectTransform; Vector3 startPos = new Vector3(850, -150, 0); Vector3 endPos = new Vector3(2200, visiblePos.y, 0); credits.gameObject.SetActive(true); foreach (CreditText ct in texts) { what.text = ct.what; who.text = ct.who; creditsTransform.position = startPos; yield return(credits.Animate(PathCurve.CreateWithRandomMiddle(startPos, visiblePos), curve, 0, animationTime)); yield return(new WaitForSeconds(pauseTime)); yield return(credits.Animate(PathCurve.CreateStraight(visiblePos, endPos), curve, 0, animationTime)); } creditsCoroutine = null; EndCredits(); }
public IEnumerator PlaceCard(ShapeCard targetCard, Vector3 worldPos, float rotation) { RectTransform rect = targetCard.GetComponent <RectTransform>(); PathCurve path = PathCurve.CreateWithRandomMiddle(rect.position, worldToUISpace(worldPos, rect)); yield return(targetCard.Animate(path, curve, rotation, animationLength)); Vector3 outsidePos = new Vector3(1500, path.startPos.y, 0); rect.position = outsidePos; targetCard.ShowSelected(false); bool drawCard = true; if (deckOffset < shapes.Count) { ReplaceCard(targetCard, shapes[deckOffset]); deckOffset++; } else { targetCard.gameObject.SetActive(false); visibleCards--; drawCard = false; } int index = cards.IndexOf(targetCard); if (index > 0) { ShapeCard first = cards[0]; first.GetComponent <RectTransform>().position = outsidePos; cards.RemoveAt(index); cards.RemoveAt(0); cards.Add(targetCard); cards.Add(first); if (index == 1) { StartCoroutine(cards[0].Animate(PathCurve.CreateStraight(cardPositions[2], cardPositions[0]), curve, 0, animationLength)); } else { StartCoroutine(cards[0].Animate(PathCurve.CreateStraight(cardPositions[1], cardPositions[0]), curve, 0, animationLength)); } if (drawCard) { StartCoroutine(WithDelay(targetCard.Animate(PathCurve.CreateStraight(outsidePos, cardPositions[1]), curve, 0, animationLength), 0.2f)); } if (deckOffset < shapes.Count) { StartCoroutine(WithDelay(first.Animate(PathCurve.CreateWithRandomMiddle(outsidePos, cardPositions[2]), curve, 0, animationLength), 0.6f)); ReplaceCard(first, shapes[deckOffset]); deckOffset++; } else { first.gameObject.SetActive(false); visibleCards--; } } else { cards.RemoveAt(index); for (int i = index; i < 2; i++) { StartCoroutine(cards[i].Animate(PathCurve.CreateStraight(cardPositions[i + 1], cardPositions[i]), curve, 0, animationLength)); } cards.Add(targetCard); if (drawCard) { StartCoroutine(WithDelay(targetCard.Animate(PathCurve.CreateWithRandomMiddle(outsidePos, cardPositions[2]), curve, 0, animationLength), 0.2f)); } } if (!drawCard && visibleCards > 0) { audioSource.PlayOneShot(slideCardSound); } }