public void SetUIParams(UINode node)
        {
            var pic = node.GetComponent <UnityEngine.UI.Image>();

            mechine.ChargeInfo(pic, node.layerInfo.resourceDic);

            var newRect = LayerImportUtil.AddSubRectFromResourceDic(node.layerInfo.rect, node.layerInfo.resourceDic);

            LayerImportUtil.LoadCommonResources(mechine, node, newRect);
        }
        public void SetUIParams(UINode node)
        {
            var toggle = node.GetComponent <Toggle>();

            if (node.layerInfo.resourceDic != null)
            {
                mechine.ChargeInfo(toggle, node.layerInfo.resourceDic);
            }

            var update_targetGraphicRect = false;
            var update_graphicRect       = false;

            ///加载子项资源
            if (node.layerInfo.subResourceDic != null)
            {
                using (var enumerator = node.layerInfo.subResourceDic.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        var current = enumerator.Current;
                        if (current.Key == titleKey)
                        {
                            var title = LayerImportUtil.MakeTitleComponenet("Title", toggle.transform);
                            title.rectTransform.SetRectFromResource(node.layerInfo.rect, current.Value);
                            mechine.ChargeInfo(title, current.Value);
                        }
                        else if (current.Key == targetGraphicKey)
                        {
                            toggle.targetGraphic.rectTransform.SetRectFromResource(node.layerInfo.rect, current.Value);
                            update_targetGraphicRect = true;
                            mechine.ChargeInfo(toggle.targetGraphic, current.Value);
                        }
                        else if (current.Key == graphicKey)
                        {
                            toggle.graphic.rectTransform.SetRectFromResource(node.layerInfo.rect, current.Value);
                            update_graphicRect = true;
                            mechine.ChargeInfo(toggle.graphic, current.Value);
                        }
                    }
                }
            }

            if (!update_targetGraphicRect)
            {
                toggle.targetGraphic.rectTransform.SetRectFromResource(node.layerInfo.rect);
            }

            if (!update_graphicRect)
            {
                toggle.graphic.rectTransform.SetRectFromResource(node.layerInfo.rect);
            }
        }
示例#3
0
        /// <summary>
        /// 设置目标Anchor
        /// </summary>
        /// <param name="image"></param>
        /// <param name="rectTransform"></param>
        public static void SetAnchorByNode(UINode node)
        {
            RectTransform p_rt = node.parentNode.GetComponent <RectTransform>();
            RectTransform c_rt = node.GetComponent <RectTransform>();

            switch (node.anchoType)
            {
            case AnchoType.Custom:
                SetCustomAnchor(p_rt.sizeDelta, c_rt);
                break;

            default:
                SetNormalAnchor(node.anchoType, p_rt.sizeDelta, c_rt);
                break;
            }
        }
示例#4
0
        public void SetUIParams(UINode node)
        {
            var component = node.GetComponent <UnityEngine.UI.Text>();

            component.resizeTextForBestFit = true;//缩放时会看不到?
            if (PreferHelper.defultFont)
            {
                component.font = PreferHelper.defultFont;
            }

            mechine.ChargeInfo(component, node.layerInfo.resourceDic);

            var newRect = LayerImportUtil.AddSubRectFromResourceDic(node.layerInfo.rect, node.layerInfo.resourceDic);

            LayerImportUtil.LoadCommonResources(mechine, node, newRect);
        }
示例#5
0
        public void SetUIParams(UINode node)
        {
            var inputField = node.GetComponent <InputField>();

            ResourceDic textComponentResourceDic = null;
            ResourceDic placeHolderResourceDic   = null;

            ///加载子项资源
            if (node.layerInfo.subResourceDic != null)
            {
                using (var enumerator = node.layerInfo.subResourceDic.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        var current = enumerator.Current;
                        if (current.Key == key_placeholder)
                        {
                            mechine.ChargeInfo(inputField.placeholder, current.Value);
                            placeHolderResourceDic = current.Value;
                        }
                        else if (current.Key == key_textComponent)
                        {
                            mechine.ChargeInfo(inputField.textComponent, current.Value);
                            textComponentResourceDic = current.Value;
                        }
                        else
                        {
                            mechine.ChargeSubInfo(inputField, current.Key, current.Value);
                        }
                    }
                }
            }

            //加载属性信息
            if (node.layerInfo.resourceDic != null)
            {
                mechine.ChargeInfo(inputField, node.layerInfo.resourceDic);
            }

            inputField.placeholder.rectTransform.SetRectFromResource(node.layerInfo.rect, placeHolderResourceDic);
            inputField.textComponent.rectTransform.SetRectFromResource(node.layerInfo.rect, textComponentResourceDic);
        }
        public void SetUIParams(UINode node)
        {
            var slider          = node.GetComponent <Slider>();
            var backgroundImage = node.GetSubComponent <Image>(runtime_key_background);

            ///加载Slider属性
            if (node.layerInfo.resourceDic != null)
            {
                mechine.ChargeInfo(slider, node.layerInfo.resourceDic);
            }

            var         fillRect        = node.GetSubComponent <RectTransform>(runtime_key_fill);
            ResourceDic fillResourceDic = null;

            ///加载子项资源
            if (node.layerInfo.subResourceDic != null)
            {
                using (var enumerator = node.layerInfo.subResourceDic.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        var current = enumerator.Current;
                        if (current.Key == runtime_key_background)//动态背景
                        {
                            backgroundImage.rectTransform.SetRectFromResource(node.layerInfo.rect, current.Value);
                            mechine.ChargeInfo(backgroundImage, current.Value);
                        }
                        else if (current.Key == runtime_key_fill)
                        {
                            var key = current.Key;
                            mechine.ChargeInfo(slider.fillRect.GetComponent <Image>(), current.Value);

                            fillResourceDic = current.Value;
                        }
                        else if (current.Key == runtime_key_handle)
                        {
                            var handleArea = new GameObject("Handle Slide Area", typeof(RectTransform)).GetComponent <RectTransform>();
                            handleArea.transform.SetParent(slider.transform, false);

                            var handle = new GameObject("Handle", typeof(Image)).GetComponent <RectTransform>();
                            handle.transform.SetParent(handleArea.transform, false);

                            slider.handleRect = handle.GetComponent <RectTransform>();
                            mechine.ChargeInfo(slider.handleRect.GetComponent <Image>(), current.Value);

                            Vector2 handleSize = new Vector2(node.layerInfo.rect.height, node.layerInfo.rect.height);
                            LayerImportUtil.UpdateSizeFromResourceDic(current.Value, ref handleSize);

                            if (slider.direction == Slider.Direction.BottomToTop || slider.direction == Slider.Direction.TopToBottom)
                            {
                                var handleRectX    = (node.layerInfo.rect.width - handleSize.x) * 0.5f;
                                var handleAreaRect = new Rect(handleRectX, handleSize.y * 0.5f, handleSize.x, node.layerInfo.rect.height - handleSize.y);
                                handleAreaRect = ParamAnalysisTool.PsRectToUnityRect(node.layerInfo.rect.size, handleAreaRect);
                                LayerImportUtil.SetRectTransform(handleAreaRect, handleArea);
                                LayerImportUtil.SetCustomAnchor(node.layerInfo.rect.size, handleArea);

                                handle.anchorMin = Vector2.zero;
                                handle.anchorMax = new Vector2(1, 0);
                                handle.sizeDelta = new Vector2(0, handleSize.y);
                            }
                            else
                            {
                                var handleRectY    = (node.layerInfo.rect.height - handleSize.y) * 0.5f;
                                var handleAreaRect = new Rect(handleSize.x * 0.5f, handleRectY, node.layerInfo.rect.width - handleSize.x, handleSize.y);
                                handleAreaRect = ParamAnalysisTool.PsRectToUnityRect(node.layerInfo.rect.size, handleAreaRect);
                                LayerImportUtil.SetRectTransform(handleAreaRect, handleArea);
                                LayerImportUtil.SetCustomAnchor(node.layerInfo.rect.size, handleArea);

                                handle.anchorMin = Vector2.zero;
                                handle.anchorMax = new Vector2(0, 1);
                                handle.sizeDelta = new Vector2(handleSize.x, 0);
                            }
                        }
                        else
                        {
                            mechine.ChargeSubInfo(slider, current.Key, current.Value);
                        }
                    }
                }
            }

            fillRect.SetRectFromResource(node.layerInfo.rect, fillResourceDic);
            slider.fillRect.anchorMin = Vector2.zero;
            slider.fillRect.anchorMax = Vector2.one;
            slider.fillRect.sizeDelta = Vector2.zero;

            LayerImportUtil.LoadCommonResources(mechine, node);
            slider.value = slider.minValue;
        }