Ejemplo n.º 1
0
        // async series.


        public static IEnumerator LayoutAsync <T>(Transform parent, Vector2 baseSize, LTAsyncRootElement rootElement, IAsyncLayouter layouter) where T : IMissingSpriteCache, new()
        {
            Debug.Assert(parent.GetComponent <Canvas>() != null, "should set parent transform which contains Canvas. this limitation is caused by spec of TextMesh Pro.");
            var originX = 0f;
            var originY = 0f;

            var rootObject = rootElement.gameObject;
            var elements   = rootElement.GetLTElements();

            var rootRect = rootObject.GetComponent <RectTransform>();

            // 親の基礎サイズをセット
            rootRect.sizeDelta = baseSize;

            // set parent.
            foreach (var element in elements)
            {
                element.gameObject.transform.SetParent(rootObject.transform);
            }

            // ここでCanvas要素にセットしちゃう(でないとTMProのinfoが取れない。)
            rootObject.transform.SetParent(parent);

            var lineContents         = new List <RectTransform>();// 同じ行に入っている要素を整列させるために使用するリスト
            var currentLineMaxHeight = 0f;

            var opId = Guid.NewGuid().ToString();

            var currentSize = baseSize;

            // この下のレイヤーで全ての非同期layout処理を集める。
            var layoutOps = layouter.LayoutAsync <T>(ref currentSize, out originX, out originY, rootObject, rootElement, elements, ref currentLineMaxHeight, ref lineContents);

            var layouted = false;
            ParameterReference resultRefObject = null;

            AsyncLayoutExecutor.LaunchLayoutOps(
                opId,
                currentSize.x,
                layoutOps,
                refs =>
            {
                layouted        = true;
                resultRefObject = refs;
            }
                );

            while (!layouted)
            {
                yield return(null);
            }

            layouter.AfterLayout(baseSize, resultRefObject.originX, resultRefObject.originY, rootObject, rootElement, elements, ref resultRefObject.currentLineMaxHeight, ref resultRefObject.lineContents, resultRefObject.wrappedSize);

            lineContents.Clear();
            yield break;
        }
Ejemplo n.º 2
0
        public static void RelayoutWithUpdateAsync <T>(Vector2 baseSize, LTAsyncRootElement rootElement, Dictionary <LTElementType, object> updateValues, IAsyncLayouter layouter, Action onRelayouted) where T : IMissingSpriteCache, new()
        {
            var originX = 0f;
            var originY = 0f;

            var rootObject = rootElement.gameObject;
            var elements   = rootElement.GetLTElements();

            foreach (var element in elements)
            {
                if (element is ILayoutableText)
                {
                    if (0 < element.transform.childCount)
                    {
                        var count = element.transform.childCount;
                        for (var i = 0; i < count; i++)
                        {
                            // get first child.
                            var child = element.transform.GetChild(0);
                            child.gameObject.SetActive(false);
                            child.transform.SetParent(null);
                            GameObject.Destroy(child.gameObject);
                        }
                    }
                }

                var rectTrans = element.GetComponent <RectTransform>();
                rectTrans.anchoredPosition = Vector2.zero;
            }

            layouter.UpdateValuesAsync(elements, updateValues);

            var lineContents         = new List <RectTransform>();// 同じ行に入っている要素を整列させるために使用するリスト
            var currentLineMaxHeight = 0f;

            var opId = Guid.NewGuid().ToString();

            var currentSize = baseSize;

            // この下のレイヤーで全ての非同期layout処理を集める。
            var layoutOps = layouter.LayoutAsync <T>(ref currentSize, out originX, out originY, rootObject, rootElement, elements, ref currentLineMaxHeight, ref lineContents);

            AsyncLayoutExecutor.LaunchLayoutOps(
                opId,
                currentSize.x,
                layoutOps,
                refs =>
            {
                layouter.AfterLayout(baseSize, refs.originX, refs.originY, rootObject, rootElement, elements, ref refs.currentLineMaxHeight, ref refs.lineContents, refs.wrappedSize);
                lineContents.Clear();

                onRelayouted();
            }
                );
        }