Beispiel #1
0
        public void AddCustomDebugToolItem(string text, GameHandler callbackHandler)
        {
            GameObject    newGo         = GameCloneUtils.CreateEmptyUIObjectWithParent(DebugToolsItemHost.transform, "DebugToolItem");
            RectTransform rectTransform = newGo.GetComponent <RectTransform>();

            rectTransform.pivot = new Vector2(0, 1);
            UIAnchorPosUtils.SetUIAnchor(rectTransform, UIAnchor.Stretch, UIAnchor.Top);

            CustomData customData = newGo.AddComponent <CustomData> ();

            customData.customData = callbackHandler;
            Text newText = newGo.AddComponent <Text>();

            newText.font      = Resources.GetBuiltinResource <Font>("Arial.ttf");
            newText.text      = text;
            newText.color     = Color.white;
            newText.fontSize  = 11;
            newText.alignment = TextAnchor.MiddleCenter;
            ContentSizeFitter contentSizeFitter = newGo.AddComponent <ContentSizeFitter>();

            contentSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;

            EventTriggerListener.Get(newGo).onClick = OnCustomDebugToolItemClick;
            rectTransform.anchoredPosition          = new Vector2(rectTransform.anchoredPosition.x, -customDebugToolItemY);
            customDebugToolItemY        += 20;
            DebugToolsItemHost.sizeDelta = new Vector2(DebugToolsItemHost.sizeDelta.x, customDebugToolItemY);
        }
Beispiel #2
0
        /// <summary>
        /// 强制重新适应 MinSize MaxSize
        /// </summary>
        public void DoResize()
        {
            UIAnchor[] thisAnchor = UIAnchorPosUtils.GetUIAnchor(RectTransform);

            if (RectTransform.rect.width < MinSize.x && thisAnchor[0] != UIAnchor.Stretch)
            {
                RectTransform.sizeDelta = new Vector2(MinSize.x, RectTransform.sizeDelta.y);
            }
            if (RectTransform.rect.height < MinSize.y && thisAnchor[1] != UIAnchor.Stretch)
            {
                RectTransform.sizeDelta = new Vector2(RectTransform.sizeDelta.x, MinSize.y);
            }

            if (MaxSize.x > 0 && RectTransform.rect.width > MaxSize.x && thisAnchor[0] != UIAnchor.Stretch)
            {
                RectTransform.sizeDelta = new Vector2(MaxSize.x, RectTransform.sizeDelta.y);
            }
            if (MaxSize.y > 0 && RectTransform.rect.height > MaxSize.y && thisAnchor[1] != UIAnchor.Stretch)
            {
                RectTransform.sizeDelta = new Vector2(RectTransform.sizeDelta.x, MaxSize.y);
            }

            if (thisAnchor[0] == UIAnchor.Stretch)
            {
                UIAnchorPosUtils.SetUILeftBottom(RectTransform, layout_marginLeft, UIAnchorPosUtils.GetUIBottom(RectTransform));
                UIAnchorPosUtils.SetUIRightTop(RectTransform, layout_marginRight, UIAnchorPosUtils.GetUITop(RectTransform));
            }
            if (thisAnchor[1] == UIAnchor.Stretch)
            {
                UIAnchorPosUtils.SetUILeftBottom(RectTransform, UIAnchorPosUtils.GetUILeft(RectTransform), layout_marginBottom);
                UIAnchorPosUtils.SetUIRightTop(RectTransform, UIAnchorPosUtils.GetUIRight(RectTransform), layout_marginTop);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 设置窗口的自定义区域视图
        /// </summary>
        /// <param name="view">要绑定的子视图</param>
        /// <returns></returns>
        public RectTransform SetView(RectTransform view)
        {
            RectTransform oldView = GetView();

            view.SetParent(UIWindowClientArea.transform);
            UIAnchorPosUtils.SetUIPos(view, 0, 0, 0, 0);

            if (oldView != null)
            {
                oldView.gameObject.SetActive(false);
                UIManager.SetViewToTemporarily(oldView);
            }
            return(oldView);
        }
Beispiel #4
0
        protected override void OnLayout()
        {
            UIElement     e             = null;
            RectTransform rectTransform = null;
            float         startVal      = 0;

            UIAnchor[] thisAnchor = UIAnchorPosUtils.GetUIAnchor(RectTransform);

            //需要布局子布局,
            for (int i = 0; i < Elements.Count; i++)
            {
                e = Elements[i];
                if (e.Visibility != UIVisibility.Gone)
                {
                    if (e.IsLayout)
                    {
                        (e as UILayout).DoLayout();
                    }
                }
            }

            //计算所有元素布局占用高度
            float allLayoutHeight = (Elements.Count - 1) * layoutChildSpacing;
            //另外一个轴最高的元素高度
            float maxLayoutOtherHeight = 0;

            for (int i = 0; i < Elements.Count; i++)
            {
                e = Elements[i];
                if (e.Visibility != UIVisibility.Gone)
                {
                    rectTransform    = e.RectTransform;
                    allLayoutHeight += (layoutDirection == LayoutAxis.Vertical ? rectTransform.rect.height : rectTransform.rect.width);
                    //计算控件边距
                    allLayoutHeight += (layoutDirection == LayoutAxis.Vertical ?
                                        (e.Layout_marginTop + e.Layout_marginBottom) : (e.Layout_marginLeft + e.Layout_marginRight));

                    if (layoutDirection == LayoutAxis.Vertical)
                    {
                        if (e.AnchorX == UIAnchor.Stretch)
                        {
                            UIAnchorPosUtils.SetUIAnchor(e.RectTransform, UIAnchor.Stretch,
                                                         layoutReverse ? UIAnchor.Bottom : UIAnchor.Top);
                            UIAnchorPosUtils.SetUILeftBottom(e.RectTransform, e.Layout_marginLeft,
                                                             UIAnchorPosUtils.GetUIBottom(e.RectTransform));
                            UIAnchorPosUtils.SetUIRightTop(e.RectTransform, e.Layout_marginRight,
                                                           UIAnchorPosUtils.GetUITop(e.RectTransform));
                        }
                        else
                        {
                            UIAnchorPosUtils.SetUIAnchor(e.RectTransform,
                                                         UILayoutUtils.GravityToAnchor(Gravity, RectTransform.Axis.Horizontal),
                                                         layoutReverse ? UIAnchor.Bottom : UIAnchor.Top);

                            e.RectTransform.anchoredPosition = Vector2.zero;
                        }

                        UIAnchorPosUtils.SetUIPivot(e.RectTransform,
                                                    UILayoutUtils.AnchorToPivot(
                                                        layoutReverse ? UIAnchor.Bottom : UIAnchor.Top, RectTransform.Axis.Vertical),
                                                    RectTransform.Axis.Vertical);

                        e.DoResize();

                        if (e.RectTransform.rect.width > maxLayoutOtherHeight)
                        {
                            maxLayoutOtherHeight = e.RectTransform.rect.width;
                        }
                    }
                    else
                    {
                        if (e.AnchorY == UIAnchor.Stretch)
                        {
                            UIAnchorPosUtils.SetUIAnchor(e.RectTransform,
                                                         layoutReverse ? UIAnchor.Right : UIAnchor.Left,
                                                         UIAnchor.Stretch);
                            UIAnchorPosUtils.SetUILeftBottom(e.RectTransform,
                                                             UIAnchorPosUtils.GetUILeft(e.RectTransform), e.Layout_marginBottom);
                            UIAnchorPosUtils.SetUIRightTop(e.RectTransform,
                                                           UIAnchorPosUtils.GetUIRight(e.RectTransform), e.Layout_marginTop);
                        }
                        else
                        {
                            UIAnchorPosUtils.SetUIAnchor(e.RectTransform,
                                                         layoutReverse ? UIAnchor.Right : UIAnchor.Left,
                                                         UILayoutUtils.GravityToAnchor(Gravity, RectTransform.Axis.Vertical));

                            e.RectTransform.anchoredPosition = Vector2.zero;
                        }

                        UIAnchorPosUtils.SetUIPivot(e.RectTransform,
                                                    UILayoutUtils.AnchorToPivot(
                                                        layoutReverse ? UIAnchor.Right : UIAnchor.Left, RectTransform.Axis.Horizontal),
                                                    RectTransform.Axis.Horizontal);

                        e.DoResize();

                        if (e.RectTransform.rect.height > maxLayoutOtherHeight)
                        {
                            maxLayoutOtherHeight = e.RectTransform.rect.height;
                        }
                    }
                }
            }

            if (maxLayoutOtherHeight <= 0)
            {
                maxLayoutOtherHeight = layoutDirection == LayoutAxis.Vertical ? RectTransform.rect.width : RectTransform.rect.height;
            }

            //自动将本容器撑大
            if (layoutDirection == LayoutAxis.Vertical)
            {
                if (MaxSize.y > 0 && allLayoutHeight > MaxSize.y)
                {
                    allLayoutHeight = MaxSize.y;
                }
                if (allLayoutHeight > MinSize.y)
                {
                    RectTransform.sizeDelta = new Vector2(widthAutoWarp ? maxLayoutOtherHeight : RectTransform.sizeDelta.x, allLayoutHeight);
                }
                else if (thisAnchor[1] != UIAnchor.Stretch)
                {
                    RectTransform.sizeDelta = new Vector2(widthAutoWarp ? maxLayoutOtherHeight : RectTransform.sizeDelta.x, MinSize.y);
                }
            }
            else if (layoutDirection == LayoutAxis.Horizontal)
            {
                if (MaxSize.x > 0 && allLayoutHeight > MaxSize.x)
                {
                    allLayoutHeight = MaxSize.x;
                }
                if (allLayoutHeight > MinSize.x)
                {
                    RectTransform.sizeDelta = new Vector2(allLayoutHeight, heightAutoWarp ? maxLayoutOtherHeight : RectTransform.sizeDelta.y);
                }
                else if (thisAnchor[0] != UIAnchor.Stretch)
                {
                    RectTransform.sizeDelta = new Vector2(MinSize.x, heightAutoWarp ? maxLayoutOtherHeight : RectTransform.sizeDelta.y);
                }
            }

            DoResize();

            //如果内容空间小于容器大小,那么居中内容
            if (allLayoutHeight < (layoutDirection == LayoutAxis.Vertical ? RectTransform.rect.height : RectTransform.rect.width))
            {
                if (layoutDirection == LayoutAxis.Vertical)
                {
                    if ((Gravity & LayoutGravity.CenterVertical) == LayoutGravity.CenterVertical)
                    {
                        startVal -= (RectTransform.rect.height / 2 - allLayoutHeight / 2);
                    }
                    if ((Gravity & LayoutGravity.Bottom) == LayoutGravity.Bottom)
                    {
                        startVal -= (RectTransform.rect.height - allLayoutHeight);
                    }
                }
                else
                {
                    if ((Gravity & LayoutGravity.CenterHorizontal) == LayoutGravity.CenterHorizontal)
                    {
                        startVal += (RectTransform.rect.width / 2 - allLayoutHeight / 2);
                    }
                    if ((Gravity & LayoutGravity.End) == LayoutGravity.End)
                    {
                        startVal += (RectTransform.rect.width - allLayoutHeight);
                    }
                }
            }

            //布局
            if (!layoutReverse)
            {
                for (int i = 0; i < Elements.Count; i++)
                {
                    e = Elements[i];
                    if (e.Visibility != UIVisibility.Gone) //跳过隐藏元素
                    {
                        rectTransform = e.RectTransform;

                        if (layoutDirection == LayoutAxis.Vertical)
                        {
                            startVal -= e.Layout_marginTop;
                            rectTransform.anchoredPosition = new Vector2(rectTransform.anchoredPosition.x, startVal);
                            startVal -= e.Layout_marginBottom;
                            startVal -= (rectTransform.rect.height + layoutChildSpacing);
                        }
                        else
                        {
                            startVal += e.Layout_marginLeft;
                            rectTransform.anchoredPosition = new Vector2(startVal, rectTransform.anchoredPosition.y);
                            startVal += e.Layout_marginRight;
                            startVal += (rectTransform.rect.width + layoutChildSpacing);
                        }
                    }
                }
            }
            else
            {
                //反向布局
                for (int i = Elements.Count; i >= 0; i--)
                {
                    e = Elements[i];
                    if (e.Visibility != UIVisibility.Gone)//跳过隐藏元素
                    {
                        rectTransform = e.RectTransform;

                        if (layoutDirection == LayoutAxis.Vertical)
                        {
                            startVal -= e.Layout_marginTop;
                            rectTransform.anchoredPosition = new Vector2(rectTransform.anchoredPosition.x, startVal);
                            startVal -= e.Layout_marginBottom;
                            startVal  = startVal - rectTransform.rect.height - layoutChildSpacing;
                        }
                        else
                        {
                            startVal += e.Layout_marginLeft;
                            rectTransform.anchoredPosition = new Vector2(startVal, rectTransform.anchoredPosition.y);
                            startVal += e.Layout_marginRight;
                            startVal  = startVal + rectTransform.rect.width + layoutChildSpacing;
                        }
                    }
                }
            }

            if (Parent != null)
            {
                Parent.DoLayout();
            }

            base.OnLayout();
        }
Beispiel #5
0
        private void InitDebugWindow()
        {
            RectTransform debugRectTransform = GameCloneUtils.CloneNewObjectWithParent(GameManager.FindStaticPrefabs("UIDebugWindow"), GameManager.UIManager.UIRoot.transform).GetComponent <RectTransform>();

            debugWindow             = GameManager.UIManager.CreateWindow("Debug console window", debugRectTransform);
            UIDebugToolBar          = GameCloneUtils.CloneNewObjectWithParent(GameManager.FindStaticPrefabs("UIDebugToolBar"), GameManager.UIManager.UIRoot.transform, "GameUIDebugToolBar");
            debugWindow.CloseAsHide = true;
            debugWindow.SetSize(450, 330);
            debugWindow.SetMinSize(420, 270);
            debugWindow.MoveToCenter();
            debugWindow.Hide();

            ico_warning2_big       = GameManager.FindStaticAssets <Sprite>("ico_warning2_big");
            ico_warning_big        = GameManager.FindStaticAssets <Sprite>("ico_warning_big");
            ico_info_big           = GameManager.FindStaticAssets <Sprite>("ico_info_big");
            ico_error_big          = GameManager.FindStaticAssets <Sprite>("ico_error_big");
            ico_success_big        = GameManager.FindStaticAssets <Sprite>("ico_success_big");
            ico_warning            = GameManager.FindStaticAssets <Sprite>("ico_warning");
            ico_info               = GameManager.FindStaticAssets <Sprite>("ico_info");
            ico_error              = GameManager.FindStaticAssets <Sprite>("ico_error");
            ico_success            = GameManager.FindStaticAssets <Sprite>("ico_success");
            box_round_light        = GameManager.FindStaticAssets <Sprite>("box_round_grey");
            background_transparent = GameManager.FindStaticAssets <Sprite>("background_transparent");

            GameManager.UIManager.RegisterWindow(debugWindow);

            UIDebugToolBar.SetActive(true);
            DebugTextFPS       = UIDebugToolBar.transform.Find("DebugTextFPS").GetComponent <Text>();
            DebugTextErrors    = debugRectTransform.transform.Find("DebugToolErrors/Text").GetComponent <Text>();
            DebugTextWarnings  = debugRectTransform.transform.Find("DebugToolWarnings/Text").GetComponent <Text>();
            DebugTextInfos     = debugRectTransform.transform.Find("DebugToolInfos/Text").GetComponent <Text>();
            DebugCmdContent    = debugRectTransform.transform.Find("DebugCmdScrollView/Viewport/DebugCmdContent").GetComponent <RectTransform>();
            DebugInputCommand  = debugRectTransform.transform.Find("DebugInputCommand").GetComponent <InputField>();
            DebugToggleInfo    = debugRectTransform.transform.Find("DebugToggleInfo").GetComponent <Toggle>();
            DebugToggleWarning = debugRectTransform.transform.Find("DebugToggleWarning").GetComponent <Toggle>();
            DebugToggleError   = debugRectTransform.transform.Find("DebugToggleError").GetComponent <Toggle>();
            DebugItemContent   = debugRectTransform.transform.Find("DebugDetailsScrollView/Viewport/DebugItemContent").GetComponent <Text>();
            Toggle DebugToggleStackTrace = debugRectTransform.transform.Find("DebugToggleStackTrace").GetComponent <Toggle>();

            DebugCmdScrollView           = debugRectTransform.transform.Find("DebugCmdScrollView").GetComponent <RectTransform>();
            DebugCmdScrollViewScrollRect = DebugCmdScrollView.GetComponent <ScrollRect>();
            DebugDetailsScrollView       = debugRectTransform.transform.Find("DebugDetailsScrollView").GetComponent <RectTransform>();
            DebugToolsItem     = UIDebugToolBar.transform.Find("DebugToolsItem").gameObject;
            DebugToolsItemHost = UIDebugToolBar.transform.Find("DebugToolsItem/Viewport/DebugToolsItemHost").GetComponent <RectTransform>();

            UIDebugTextItem = GameManager.FindStaticPrefabs("UIDebugTextItem");

            fPSManager         = GameCloneUtils.CreateEmptyObjectWithParent(GameManager.GameRoot.transform, "FPSManager").AddComponent <FPSManager>();
            fPSManager.FpsText = DebugTextFPS;

            EventTriggerListener.Get(UIDebugToolBar.transform.Find("DebugToolCmd").gameObject).onClick = (g) => {
                if (debugWindow.GetVisible())
                {
                    debugWindow.Hide();
                }
                else
                {
                    debugWindow.Show();
                    ForceReloadLogList();
                }
            };
            EventTriggerListener.Get(UIDebugToolBar.transform.Find("DebugTools").gameObject).onClick = (g) => { DebugToolsItem.SetActive(!DebugToolsItem.activeSelf); };

            EventTriggerListener.Get(debugRectTransform.transform.Find("DebugButtonRun").gameObject).onClick = (g) =>
            {
                if (RunCommand(DebugInputCommand.text))
                {
                    DebugInputCommand.text = "";
                }
            };
            EventTriggerListener.Get(debugRectTransform.transform.Find("DebugButtonClear").gameObject).onClick = (g) => { ClearLogs(); };

            DebugInputCommand.onEndEdit.AddListener((s) =>
            {
                ClearCurrentActiveLogItem();
                if (RunCommand(s))
                {
                    DebugInputCommand.text = "";
                }
            });
            DebugToggleError.onValueChanged.AddListener((b) =>
            {
                SetShowLogTypes(GameLogger.LogType.Error, b);
                SetShowLogTypes(GameLogger.LogType.Assert, b);
                ForceReloadLogList();
            });
            DebugToggleWarning.onValueChanged.AddListener((b) =>
            {
                SetShowLogTypes(GameLogger.LogType.Warning, b);
                ForceReloadLogList();
            });
            DebugToggleInfo.onValueChanged.AddListener((b) =>
            {
                SetShowLogTypes(GameLogger.LogType.Text, b);
                SetShowLogTypes(GameLogger.LogType.Info, b);
                ForceReloadLogList();
            });
            DebugToggleStackTrace.onValueChanged.AddListener((b) =>
            {
                DebugDetailsScrollView.gameObject.SetActive(b);
                if (!b)
                {
                    UIAnchorPosUtils.SetUILeftBottom(DebugCmdScrollView, UIAnchorPosUtils.GetUILeft(DebugCmdScrollView), 30);
                }
                else
                {
                    UIAnchorPosUtils.SetUILeftBottom(DebugCmdScrollView, UIAnchorPosUtils.GetUILeft(DebugCmdScrollView), 100);
                }
            });

            GameLogger.RegisterLogCallback(HandleLog);
            ForceReloadLogList();
        }
Beispiel #6
0
        private UILayout BuildLayoutByTemplateInternal(string name, XmlNode templateXml,
                                                       Dictionary <string, GameHandler> handlers,
                                                       UILayout parent, UILayout root, string[] initialProps)
        {
            //实例化UI预制体
            string     prefabName = templateXml.Name;
            GameObject prefab     = UIManager.FindRegisterElementPrefab(prefabName);

            if (prefab == null)
            {
                GameLogger.Log(TAG, "BuildLayoutByTemplate failed, not found prefab {0}", prefabName);
                GameErrorManager.LastError = GameError.PrefabNotFound;
                return(null);
            }

            //获取预制体上的脚本
            UILayout ilayout = prefab.GetComponent <UILayout>();

            if (ilayout == null) //该方法必须实例化UI容器
            {
                GameLogger.Error(TAG, "BuildLayoutByTemplate with prefab {0} failed, root must be a container", prefabName);
                GameErrorManager.LastError = GameError.MustBeContainer;
                return(null);
            }

            GameObject newCon = GameCloneUtils.CloneNewObjectWithParent(prefab,
                                                                        parent == null ? UIManager.UIRoot.transform : parent.RectTransform);

            ilayout = newCon.GetComponent <UILayout>();
            ilayout.DoCallStart();
            ilayout.LayoutLock();
            ilayout.RectTransform = newCon.GetComponent <RectTransform>();
            UIAnchorPosUtils.SetUIPivot(ilayout.RectTransform, UIPivot.TopCenter);
            ilayout.RectTransform.anchoredPosition = Vector2.zero;

            if (root == null)
            {
                root = ilayout;
                root.IsRootLayout = true;
            }

            GameObject newEle    = null;
            UIElement  uIElement = null;

            //子元素
            for (int i = 0, c = templateXml.ChildNodes.Count; i < c; i++)
            {
                string eleName = "";
                //xml 属性读取
                XmlNode eleNode = templateXml.ChildNodes[i];
                foreach (XmlAttribute a in eleNode.Attributes)
                {
                    if (a.Name.ToLower() == "name")
                    {
                        eleName = a.Value;
                    }
                }

                //预制体
                prefab = UIManager.FindRegisterElementPrefab(eleNode.Name);
                if (prefab == null)
                {
                    GameLogger.Error(TAG, "BuildLayoutByTemplate failed, not found prefab {0}", prefabName);
                    continue;
                }
                if (prefab.GetComponent <UILayout>() != null)                                                                    //这是UI容器
                {
                    UILayout newLayout = BuildLayoutByTemplateInternal(eleName, eleNode, handlers, ilayout, root, initialProps); //递归构建

                    uIElement = newLayout;
                    uIElement.rootContainer = root;
                    uIElement.Name          = eleName;
                }
                else
                {
                    //构建子元素
                    newEle = GameCloneUtils.CloneNewObjectWithParent(prefab, ilayout.RectTransform, eleName);

                    uIElement = newEle.GetComponent <UIElement>();
                    uIElement.RectTransform = newEle.GetComponent <RectTransform>();
                    uIElement.DoCallStart();
                    uIElement.Init(eleNode);
                    uIElement.rootContainer = root;
                    uIElement.Name          = eleName;
                }

                //初始化
                InitiazeChildElement(uIElement, handlers, initialProps);

                //添加元素
                ilayout.AddElement(uIElement, false);
            }

            ilayout.Init(templateXml); //容器的XML读取
            InitiazeChildElement(ilayout, handlers, initialProps);
            ilayout.LayoutUnLock();
            ilayout.PostDoLayout();

            if (root == ilayout)
            {
                ilayout.DoLayout();
            }

            return(ilayout);
        }
Beispiel #7
0
        protected virtual void SetProp(string name, string val)
        {
            switch (name)
            {
            case "name":
            {
                Name = val;
                break;
            }

            case "minSize":
            {
                string[] av = val.Split(',');
                float    x, y;
                if (av.Length >= 2 && float.TryParse(av[0], out x) && float.TryParse(av[1], out y))
                {
                    minSize = new Vector2(x, y);
                    DoPostLayout();
                }
                break;
            }

            case "width":
            {
                if (val.ToLower() == "match_parent")
                {
                    anchorX = UIAnchor.Stretch;
                    UIAnchorPosUtils.SetUIAnchor(RectTransform, anchorX, anchorY);
                    DoPostLayout();
                }
                else
                {
                    float x;
                    if (float.TryParse(val, out x))
                    {
                        RectTransform.sizeDelta = new Vector2(x, RectTransform.sizeDelta.y);
                        DoPostLayout();
                    }
                }
                break;
            }

            case "height":
            {
                if (val.ToLower() == "match_parent")
                {
                    anchorY = UIAnchor.Stretch;
                    UIAnchorPosUtils.SetUIAnchor(RectTransform, anchorX, anchorY);
                    DoPostLayout();
                }
                else
                {
                    float y;
                    if (float.TryParse(val, out y))
                    {
                        RectTransform.sizeDelta = new Vector2(RectTransform.sizeDelta.x, y);
                        DoPostLayout();
                    }
                }
                break;
            }

            case "x":
            {
                float v;
                if (float.TryParse(val, out v))
                {
                    RectTransform.anchoredPosition = new Vector2(v, RectTransform.anchoredPosition.y);
                    DoPostLayout();
                }
                break;
            }

            case "y":
            {
                float v;
                if (float.TryParse(val, out v))
                {
                    RectTransform.anchoredPosition = new Vector2(RectTransform.anchoredPosition.x, v);
                    DoPostLayout();
                }
                break;
            }

            case "position":
            {
                string[] av = val.Split(',');
                float    x, y;
                if (av.Length >= 2 && float.TryParse(av[0], out x) && float.TryParse(av[1], out y))
                {
                    RectTransform.anchoredPosition = new Vector2(x, y);
                    DoPostLayout();
                }
                break;
            }

            case "left":
            {
                float v;
                if (float.TryParse(val, out v))
                {
                    UIAnchorPosUtils.SetUILeftBottom(RectTransform, v, UIAnchorPosUtils.GetUIBottom(RectTransform));
                }
                break;
            }

            case "bottom":
            {
                float v;
                if (float.TryParse(val, out v))
                {
                    UIAnchorPosUtils.SetUILeftBottom(RectTransform, UIAnchorPosUtils.GetUILeft(RectTransform), v);
                }
                break;
            }

            case "leftBottom":
            {
                string[] av = val.Split(',');
                float    x, y;
                if (av.Length >= 2 && float.TryParse(av[0], out x) && float.TryParse(av[1], out y))
                {
                    UIAnchorPosUtils.SetUILeftBottom(RectTransform, x, y);
                }
                break;
            }

            case "right":
            {
                float v;
                if (float.TryParse(val, out v))
                {
                    UIAnchorPosUtils.SetUIRightTop(RectTransform, v, UIAnchorPosUtils.GetUITop(RectTransform));
                }
                break;
            }

            case "top":
            {
                float v;
                if (float.TryParse(val, out v))
                {
                    UIAnchorPosUtils.SetUIRightTop(RectTransform, UIAnchorPosUtils.GetUIRight(RectTransform), v);
                }
                break;
            }

            case "rightTop":
            {
                string[] av = val.Split(',');
                float    x, y;
                if (av.Length >= 2 && float.TryParse(av[0], out x) && float.TryParse(av[1], out y))
                {
                    UIAnchorPosUtils.SetUIRightTop(RectTransform, x, y);
                }
                break;
            }

            case "anchor":
            {
                string[] av = val.Split(',');
                if (av.Length >= 2)
                {
                    System.Enum.TryParse(av[0], out anchorX);
                    System.Enum.TryParse(av[1], out anchorY);
                    DoPostLayout();
                }
                break;
            }

            case "anchorX":
            {
                System.Enum.TryParse(val, out anchorX);
                DoPostLayout();
                break;
            }

            case "visibility":
            {
                UIVisibility v;
                System.Enum.TryParse(val, out v);
                Visibility = v;
                break;
            }

            case "anchorY":
            {
                System.Enum.TryParse(val, out anchorY);
                DoPostLayout();
                break;
            }

            case "layout_margin":
            {
                string[] av = val.Split(',');
                float    x, y, z, w;
                if (av.Length >= 4 &&
                    float.TryParse(av[0], out x) && float.TryParse(av[1], out y) &&
                    float.TryParse(av[1], out z) && float.TryParse(av[2], out w))
                {
                    Layout_marginLeft   = x;
                    Layout_marginTop    = y;
                    Layout_marginRight  = z;
                    Layout_marginBottom = w;
                }

                if (av.Length >= 2 &&
                    float.TryParse(av[0], out x) && float.TryParse(av[1], out y))
                {
                    Layout_marginLeft   = x;
                    Layout_marginTop    = y;
                    Layout_marginRight  = x;
                    Layout_marginBottom = y;
                }
                if (av.Length >= 1 &&
                    float.TryParse(av[0], out x))
                {
                    Layout_marginLeft   = x;
                    Layout_marginTop    = x;
                    Layout_marginRight  = x;
                    Layout_marginBottom = x;
                }
                DoPostLayout();
                break;
            }

            case "layout_marginLeft":
            {
                float v;
                if (float.TryParse(val, out v))
                {
                    Layout_marginLeft = v;
                    DoPostLayout();
                }
                break;
            }

            case "layout_marginTop":
            {
                float v;
                if (float.TryParse(val, out v))
                {
                    Layout_marginTop = v;
                    DoPostLayout();
                }
                break;
            }

            case "layout_marginRight":
            {
                float v;
                if (float.TryParse(val, out v))
                {
                    Layout_marginRight = v;
                    DoPostLayout();
                }
                break;
            }

            case "layout_marginBottom":
            {
                float v;
                if (float.TryParse(val, out v))
                {
                    Layout_marginBottom = v;
                    DoPostLayout();
                }
                break;
            }

            case "layout_centerHorizontal":
            {
                if (bool.TryParse(val, out layout_centerHorizontal))
                {
                    DoPostLayout();
                }
                break;
            }

            case "layout_centerVertical":
            {
                if (bool.TryParse(val, out layout_centerVertical))
                {
                    DoPostLayout();
                }
                break;
            }

            case "layout_centerInParent":
            {
                if (bool.TryParse(val, out layout_centerInParent))
                {
                    DoPostLayout();
                }
                break;
            }

            case "layout_alignParentTop":
            {
                if (bool.TryParse(val, out layout_alignParentTop))
                {
                    DoPostLayout();
                }
                break;
            }

            case "layout_alignParentBottom":
            {
                if (bool.TryParse(val, out layout_alignParentBottom))
                {
                    DoPostLayout();
                }
                break;
            }

            case "layout_alignParentLeft":
            {
                if (bool.TryParse(val, out layout_alignParentLeft))
                {
                    DoPostLayout();
                }
                break;
            }

            case "layout_alignParentRight":
            {
                if (bool.TryParse(val, out layout_alignParentRight))
                {
                    DoPostLayout();
                }
                break;
            }

            case "layout_above":
            {
                layout_toLeftOf = val;
                DoPostLayout();
                break;
            }

            case "layout_below":
            {
                layout_toLeftOf = val;
                DoPostLayout();
                break;
            }

            case "layout_toRightOf":
            {
                layout_toLeftOf = val;
                DoPostLayout();
                break;
            }

            case "layout_toLeftOf":
            {
                layout_toLeftOf = val;
                DoPostLayout();
                break;
            }

            case "layout_alignTop":
            {
                layout_alignTop = val;
                DoPostLayout();
                break;
            }

            case "layout_alignBottom":
            {
                layout_alignBottom = val;
                DoPostLayout();
                break;
            }

            case "layout_alignLeft":
            {
                layout_alignLeft = val;
                DoPostLayout();
                break;
            }

            case "layout_alignRight":
            {
                layout_alignRight = val;
                DoPostLayout();
                break;
            }
            }
        }
Beispiel #8
0
        private void DoLayoutElementVerticalInternal(UIElement e)
        {
            UIAnchor a = UIAnchor.None;

            if (e.AnchorY != UIAnchor.Stretch)
            {
                if (!string.IsNullOrEmpty(e.Layout_alignTop) || !string.IsNullOrEmpty(e.Layout_below) ||
                    e.Layout_alignParentTop)
                {
                    a = UIAnchor.Top;
                }
                else if (!string.IsNullOrEmpty(e.Layout_alignBottom) || !string.IsNullOrEmpty(e.Layout_above) ||
                         e.Layout_alignParentBottom)
                {
                    a = UIAnchor.Bottom;
                }
                else if (e.Layout_centerVertical || e.Layout_centerInParent)
                {
                    a = UIAnchor.Center;
                }
                else
                {
                    a = UILayoutUtils.GravityToAnchor(Gravity, RectTransform.Axis.Vertical);
                }

                UIAnchorPosUtils.SetUIAnchor(e.RectTransform,
                                             UIAnchorPosUtils.GetUIAnchor(e.RectTransform, RectTransform.Axis.Horizontal), a);
                UIAnchorPosUtils.SetUIPivot(e.RectTransform,
                                            UILayoutUtils.AnchorToPivot(a, RectTransform.Axis.Vertical), RectTransform.Axis.Vertical);

                float     finalValue = 0;
                UIElement eRef       = null;
                if (!string.IsNullOrEmpty(e.Layout_below))
                {
                    eRef = FindElementInLayoutByName(e.Layout_below);
                    if (eRef != null)
                    {
                        finalValue = eRef.RectTransform.anchoredPosition.y - eRef.RectTransform.rect.height
                                     - e.Layout_marginTop;
                    }
                }
                else if (!string.IsNullOrEmpty(e.Layout_above))
                {
                    eRef = FindElementInLayoutByName(e.Layout_above);
                    if (eRef != null)
                    {
                        finalValue = eRef.RectTransform.anchoredPosition.x + e.RectTransform.rect.height
                                     + e.Layout_marginBottom;
                    }
                }
                else if (!string.IsNullOrEmpty(e.Layout_alignTop))
                {
                    eRef = FindElementInLayoutByName(e.Layout_alignTop);
                    if (eRef != null)
                    {
                        finalValue = eRef.RectTransform.anchoredPosition.y - e.Layout_marginTop;
                    }
                }
                else if (!string.IsNullOrEmpty(e.Layout_alignBottom))
                {
                    eRef = FindElementInLayoutByName(e.Layout_alignBottom);
                    if (eRef != null)
                    {
                        finalValue = eRef.RectTransform.anchoredPosition.y - eRef.RectTransform.rect.height
                                     + e.RectTransform.rect.height + e.Layout_marginBottom;
                    }
                }
                else if (a == UIAnchor.Center)
                {
                    finalValue = 0;
                }
                else if (a == UIAnchor.Top)
                {
                    finalValue = -e.Layout_marginTop;
                }
                else if (a == UIAnchor.Bottom)
                {
                    finalValue = e.Layout_marginBottom;
                }


                e.RectTransform.anchoredPosition = new Vector2(
                    e.RectTransform.anchoredPosition.x,
                    finalValue
                    );
            }
        }
Beispiel #9
0
        private void DoLayoutElementHorizontalInternal(UIElement e)
        {
            UIAnchor a = UIAnchor.None;

            if (e.AnchorX != UIAnchor.Stretch)
            {
                if (!string.IsNullOrEmpty(e.Layout_alignLeft) || !string.IsNullOrEmpty(e.Layout_toLeftOf) ||
                    e.Layout_alignParentLeft)
                {
                    a = UIAnchor.Left;
                }
                else if (!string.IsNullOrEmpty(e.Layout_alignRight) || !string.IsNullOrEmpty(e.Layout_toRightOf) ||
                         e.Layout_alignParentRight)
                {
                    a = UIAnchor.Right;
                }
                else if (e.Layout_centerHorizontal || e.Layout_centerInParent)
                {
                    a = UIAnchor.Center;
                }
                else
                {
                    a = UILayoutUtils.GravityToAnchor(Gravity, RectTransform.Axis.Horizontal);
                }

                UIAnchorPosUtils.SetUIAnchor(e.RectTransform, a,
                                             UIAnchorPosUtils.GetUIAnchor(e.RectTransform, RectTransform.Axis.Vertical));
                UIAnchorPosUtils.SetUIPivot(e.RectTransform,
                                            UILayoutUtils.AnchorToPivot(a, RectTransform.Axis.Horizontal), RectTransform.Axis.Horizontal);

                float     finalValue = 0;
                UIElement eRef       = null;
                if (!string.IsNullOrEmpty(e.Layout_toLeftOf))
                {
                    eRef = FindElementInLayoutByName(e.Layout_toLeftOf);
                    if (eRef != null)
                    {
                        finalValue = eRef.RectTransform.anchoredPosition.x + eRef.RectTransform.rect.width
                                     + e.Layout_marginLeft;
                    }
                }
                else if (!string.IsNullOrEmpty(e.Layout_toRightOf))
                {
                    eRef = FindElementInLayoutByName(e.Layout_toRightOf);
                    if (eRef != null)
                    {
                        finalValue = eRef.RectTransform.anchoredPosition.x - eRef.RectTransform.rect.width
                                     - e.RectTransform.rect.width
                                     - e.Layout_marginRight;
                    }
                }
                else if (!string.IsNullOrEmpty(e.Layout_alignLeft))
                {
                    eRef = FindElementInLayoutByName(e.Layout_alignLeft);
                    if (eRef != null)
                    {
                        finalValue = eRef.RectTransform.anchoredPosition.x + e.Layout_marginLeft;
                    }
                }
                else if (!string.IsNullOrEmpty(e.Layout_alignRight))
                {
                    eRef = FindElementInLayoutByName(e.Layout_alignRight);
                    if (eRef != null)
                    {
                        finalValue = eRef.RectTransform.anchoredPosition.x + eRef.RectTransform.rect.width
                                     - e.RectTransform.rect.width - e.Layout_marginRight;
                    }
                }
                else if (a == UIAnchor.Center)
                {
                    finalValue = 0;
                }
                else if (a == UIAnchor.Right)
                {
                    finalValue = -e.Layout_marginRight;
                }
                else if (a == UIAnchor.Left)
                {
                    finalValue = e.Layout_marginLeft;
                }

                e.RectTransform.anchoredPosition = new Vector2(
                    finalValue,
                    e.RectTransform.anchoredPosition.y);
            }
        }