Beispiel #1
0
        /// <summary>
        /// 显示面板
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="panelName"></param>
        /// <param name="prefabName"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public T ShowPanel <T>(string panelName, string prefabName, Layer layer = Layer.Mid)
            where T : UIBase
        {
            UIBase panel;

            if (!IsHavePanel(panelName))
            {
                GameObject obj = ResLoad.LoadPrefab(uiPrefabPath + prefabName);
                obj.name = panelName;
                //设置层级
                RectTransform tr = obj.transform as RectTransform;
                switch (layer)
                {
                case Layer.Top: tr.SetParent(UITop); break;

                case Layer.Mid: tr.SetParent(UIMid); break;

                case Layer.Bot: tr.SetParent(UIBot); break;
                }
                tr.localPosition = Vector3.zero;
                tr.localScale    = Vector3.one;
                tr.offsetMax     = Vector2.zero;
                tr.offsetMin     = Vector2.zero;
                panel            = obj.AddComponent <T>();
                uiPanelList.Add(panelName, panel);
                panel.Init();
            }
            else
            {
                panel = uiPanelList[panelName];
                panel.transform.SetAsLastSibling();
            }
            panel.Show();
            return(panel as T);
        }
Beispiel #2
0
        private void SetPos(DirType dir = DirType.Null)
        {
            float x     = LeftPoint.x + CurData.Pos.x * 88;
            float y     = LeftPoint.y - CurData.Pos.y * 88;
            int   index = CurData.Pos.x + CurData.Pos.y * MapData.MapW;
            int   item  = MapData.Map[MapData.CurLevel][index];

            if (item > 5)
            {
                RotateItem(transform.GetChild(0) as RectTransform, item);
                CurData.Dir = (DirType)item;
            }
            else if (dir != DirType.Null)
            {
                RotateItem(transform.GetChild(0) as RectTransform, (int)dir);
                CurData.Dir = dir;
            }

            if (item == (int)CurData.Type && item < 6 && item > 0)
            {
                IsWin = true;
                GetComponent <Image>().sprite =
                    ResLoad.LoadAsset <Sprite>("UI/Map/Target", item.ToString());
            }
            else
            {
                IsWin = false;
                GetComponent <Image>().sprite =
                    ResLoad.LoadAsset <Sprite>("UI/Map/Squares", ((int)CurData.Type).ToString());
            }
            (transform.parent as RectTransform).DOLocalMove(new Vector2(x, y), 0.4f);
        }
Beispiel #3
0
        private GameObject AddItem(string pName, string sName, int ix, int iy)
        {
            GameObject go = UIManager.Instance.LoadUIPrefab(pName, mapTr, pName);

            go.transform.GetChild(0).GetComponent <Image>().sprite =
                ResLoad.LoadAsset <Sprite>($"UI/Map/{pName}", sName);
            float x = leftPoint.localPosition.x + ix * 88;
            float y = leftPoint.localPosition.y - iy * 88;

            (go.transform as RectTransform).localPosition = new Vector2(x, y);
            return(go);
        }
Beispiel #4
0
        /// <summary>
        /// 动态加载UI预设体
        /// </summary>
        /// <param name="prefabName"></param>
        /// <param name="parent"></param>
        /// <param name="name"></param>
        public GameObject LoadUIPrefab(string prefabName, Transform parent, string name = null)
        {
            GameObject obj = ResLoad.LoadPrefab(uiPrefabPath + prefabName);

            obj.name = name != String.Empty ? name : prefabName;
            RectTransform tr = obj.transform as RectTransform;

            tr.SetParent(parent);
            tr.localPosition = Vector3.zero;
            tr.localScale    = Vector3.one;
            tr.offsetMax     = Vector2.zero;
            tr.offsetMin     = Vector2.zero;
            return(obj);
        }
Beispiel #5
0
 private UIManager()
 {
     uiPanelList       = new Dictionary <string, UIBase>();
     UI                = ResLoad.LoadPrefab(uiPrefabPath + "UI").transform;
     UIRoot            = UI.Find("Canvas");
     UITop             = UIRoot.Find("Top");
     UIMid             = UIRoot.Find("Mid");
     UIBot             = UIRoot.Find("Bot");
     RootCanvas        = UIRoot.GetComponent <Canvas>();
     RootRectTransform = UIRoot.GetComponent <RectTransform>();
     RootScaler        = UIRoot.GetComponent <CanvasScaler>();
     Object.DontDestroyOnLoad(UI.gameObject);
     ScreenToUI(new Vector3(Screen.width, Screen.height), out screenUI);
 }