Beispiel #1
0
        /// hook into emitters for displaying text and recording completion then prepare the visual
        protected void Awake()
        {
            void show(Emitter emitter)
            {
                var text = showing.Value;

                if (string.IsNullOrEmpty(text))
                {
                    return;
                }
                textToDisplay = text;
                repeat        = 0;
                display.Go();
            }

            float pixelsPerSecond = 0;

            void prepare(Fiber fiber)
            {
                if (string.IsNullOrEmpty(textToDisplay))
                {
                    fiber.Break();
                    return;
                }
                repeat       = repeats + 1;
                content.text = textToDisplay;
                content.resizeTextMaxSize = content.cachedTextGenerator.fontSizeUsedForBestFit;
                var rect = content.rectTransform;

                rect.SetSizeWithCurrentAnchors(axis: RectTransform.Axis.Horizontal, size: content.preferredWidth);
                scroller.Reset();
                Vector3[] corners = new Vector3[4];
                rect.GetWorldCorners(corners);
                float pixelsWide         = corners[2].x - corners[0].x;
                float pixelsPerCharacter = (pixelsWide / textToDisplay.Length);

                pixelsPerSecond = charactersPerSecond * pixelsPerCharacter;
            }

            void step(Fiber fiber)
            {
                if (!scroller.Step(pixelsPerSecond * Time.fixedUnscaledDeltaTime) || (repeat == 0))
                {
                    fiber.Break();
                }
            }

            display = Fiber.Instance.Do(prepare).Begin.Begin.Do(step).Again.Until(_ => -- repeat <= 0);
            display.OnComplete.Listen(_ => showingComplete.Fire());
            showing.Emitter.Listen(show);
            if (showing.Emitter.Firings > 0)
            {
                show(showing.Emitter);
            }
        }
Beispiel #2
0
 private static void FirstUpdate(Fiber fiber) => fiber.Go();
Beispiel #3
0
 /// <a href="http://bit.ly/2CV0RNn">Wait for another fiber to complete, starting it if needed</a>
 public Fiber WaitFor(Fiber anotherFiber)
 {
     WaitFor(PrepareAnotherFiber(anotherFiber).OnComplete, "WaitFor(Fiber)");
     Do(_ => anotherFiber.Go());
     return(this);
 }