Exemplo n.º 1
0
 public void InitUIManager()
 {
     //清空缓存的窗体
     if (dicAllUI != null)
     {
         dicAllUI.Clear();
     }
     if (dicShownUI != null)
     {
         dicShownUI.Clear();
     }
     DontDestroyOnLoad(uiRootTrans);
     //初始化显示窗体的父节点
     if (normalUIRoot == null)
     {
         normalUIRoot = new GameObject("NormalUIRoot").transform;
         GameTool.AddChildToParent(uiRootTrans, normalUIRoot);
         GameTool.SetLayer(uiRootTrans.gameObject.layer, normalUIRoot);
     }
     if (KeepAboveUIRoot == null)
     {
         KeepAboveUIRoot = new GameObject("KeepAboveUIRoot").transform;
         GameTool.AddChildToParent(uiRootTrans, KeepAboveUIRoot);
         GameTool.SetLayer(uiRootTrans.gameObject.layer, KeepAboveUIRoot);
     }
     if (topUIRoot == null)
     {
         topUIRoot = new GameObject("TopUIRoot").transform;
         GameTool.AddChildToParent(uiRootTrans, topUIRoot);
         GameTool.SetLayer(uiRootTrans.gameObject.layer, topUIRoot);
     }
 }
Exemplo n.º 2
0
        private BaseUi JudgeShowUI(E_UIID uiid) //判断要显示的是哪个UI,返回现在显示的UI
        {
            //判断要显示的窗体是否正在显示,如果正在显示则不用处理
            if (dicShowUi.ContainsKey(uiid))
            {
                return(null);
            }
            BaseUi baseUi = GetGaseUI(uiid);

            if (baseUi == null)//判断需要显示的窗体是否加载过
            {
                //拿到UIID然后向UI路径字典取值
                string     path   = GameDefine.dicPath[uiid];
                GameObject loadUi = Resources.Load <GameObject>(path);
                if (loadUi != null)
                {
                    //路径正确,实例化窗体
                    GameObject willShowUI = Instantiate(loadUi);
                    baseUi = willShowUI.GetComponent <BaseUi>();
                    Type type = GameDefine.GetUiScriptType(uiid);
                    if (baseUi == null)
                    {
                        //说明窗体是没有挂载脚本,自动添加对应的UI脚本
                        baseUi = willShowUI.AddComponent(type) as BaseUi;
                    }
                    else
                    {
                        baseUi = willShowUI.GetComponent(type) as BaseUi;
                    }
                    Transform uiRoot = GetTheRoot(baseUi);
                    GameTool.AddChildToParent(uiRoot, willShowUI.transform);
                    //位置不正确,重设UI位置
                    willShowUI.GetComponent <RectTransform>().sizeDelta          = Vector2.zero;
                    willShowUI.GetComponent <RectTransform>().anchoredPosition3D = Vector3.zero;

                    //窗体第一次加载,把该窗体缓存到aicAllUi字典。
                    dicAllUi.Add(uiid, baseUi);
                }
                else
                {
                    Debug.Log("没有加载到" + uiid + "预制体");
                }
            }
            else
            {
                baseUi.ShowUI();
            }
            UpdateShowUiHedeUi(baseUi);
            return(baseUi);
        }
Exemplo n.º 3
0
        //判断窗体是否有显示过隐藏起来了,如果没有,就要去加载了
        private BaseUI JudgeShowUI(UIid uiId)
        {
            //判断要显示的窗体是不是正在显示
            if (dicShowUI.ContainsKey(uiId))
            {
                return(null);
            }
            //判断窗体是不是显示过了,然后被隐藏起来了
            BaseUI baseUI = GetBaseUI(uiId);

            if (baseUI == null)                           //说明将要显示的窗体还未被加载过
            {
                if (GameDefine.dicPath.ContainsKey(uiId)) //有该窗体的加载路径
                {
                    string     path  = GameDefine.dicPath[uiId];
                    GameObject theUI = Resources.Load <GameObject>(path);
                    if (theUI != null)
                    {
                        //把窗体生成出来
                        GameObject willShowUI = Instantiate(theUI);
                        //判断显示的窗体上面是否有挂载UI脚本
                        baseUI = willShowUI.GetComponent <BaseUI>();
                        if (baseUI == null)
                        {
                            //自动挂载对应的UI脚本
                            Type type = GameDefine.GetUIScriptType(uiId);
                            baseUI = willShowUI.AddComponent(type) as BaseUI;
                        }
                        GameTool.AddChildToParent(uiRoot, willShowUI.transform);
                        willShowUI.GetComponent <RectTransform>().sizeDelta          = Vector2.zero;
                        willShowUI.GetComponent <RectTransform>().anchoredPosition3D = Vector3.zero;
                        dicAllUI.Add(uiId, baseUI);
                    }
                    else
                    {
                        Debug.LogError("在路径" + path + "下面加载不到窗体,请查看该路径下面是否有窗体的预制体");
                    }
                }
                else//没有该窗体的加载路径
                {
                    Debug.LogError("没有该窗体的路径,请到GameDefine里面去添加");
                }
            }
            //更新字典并且隐藏需要隐藏的UI
            UpdateDicAndHideUI(baseUI);
            return(baseUI);
        }
Exemplo n.º 4
0
        private BaseUI JudgeShowUI(E_UiId uiId)
        {
            //判断将要显示的窗体是否已经正在显示了
            if (dicShowUI.ContainsKey(uiId))
            {
                //如果已经正在显示了,就不需要处理其他逻辑了
                return(null);
            }
            //判断窗体是否有加载过
            BaseUI baseUI = GetBaseUI(uiId);

            if (baseUI == null)
            {
                //说明这个窗体没显示过(没有加载过),要去动态加载
                string     path  = GameDefine.dicPath[uiId];
                GameObject theUI = Resources.Load <GameObject>(path);
                if (theUI != null)
                {
                    //把该窗体生成出来
                    GameObject willShowUI = Instantiate(theUI);
                    //窗体生成出来后,要确保有挂对应的UI脚本
                    baseUI = willShowUI.GetComponent <BaseUI>();
                    if (baseUI == null)
                    {
                        //说明生成出来的这个窗体上面没有挂载对应的UI脚本
                        //那么就需要给这个窗体自动添加对应的脚本
                        Type type = GameDefine.GetUIScriptType(uiId);
                        baseUI = willShowUI.AddComponent(type) as BaseUI;
                    }
                    //判断这个窗体是属于哪个父节点的
                    Transform uiRoot = GetTheUIRoot(baseUI);
                    GameTool.AddChildToParent(uiRoot, willShowUI.transform);
                    willShowUI.GetComponent <RectTransform>().sizeDelta = Vector2.zero;
                    //这个窗体是第一次加载显示出来的,那么就需要缓存起来
                    dicAllUI.Add(uiId, baseUI);
                }
                else
                {
                    Debug.LogError("指定路径下面找不到对应的预制体");
                }
            }
            UpdateDicShowUIAndHideUI(baseUI);
            return(baseUI);
        }
Exemplo n.º 5
0
    private void InitLevel()
    {
        int levelCount = DataController.Instance.GetCfgCount(DataController.Instance.dicLevel);

        PerfitWidth(levelCount);
        //获取当前可进入的最高级关卡
        int        currentLevel = LevelManager.Instance.GetCurrentMaxLevel();
        GameObject levelItem    = null;

        for (int i = 1; i < 16; i++)
        {
            if (i % 2 == 0)
            {
                //下
                levelItem = Instantiate(levelItemDown);
            }
            else
            {
                //上
                levelItem = Instantiate(levelItemUp);
            }
            //打卡对应的关卡
            if (i <= currentLevel)
            {
                //可进入的关卡
                GameTool.GetTheChildComponent <Image>(levelItem, "Btn_Level").color = Color.white;
            }
            else
            {
                //不可进入的关卡
                GameTool.GetTheChildComponent <Button>(levelItem, "Btn_Level").enabled = false;
            }
            levelItem.AddComponent <LevelEntity>().levelId = i;
            //通过配置表获取关卡名称
            string levelName = DataController.Instance.ReadCfg("LevelName", i, DataController.Instance.dicLevel);
            GameTool.GetTheChildComponent <Text>(levelItem, "Txt_LevelName").text = levelName;
            GameTool.GetTheChildComponent <Text>(levelItem, "Txt_LevelId").text   = i.ToString();
            GameTool.AddChildToParent(content, levelItem.transform);
        }
        levelItem = null;
        scrollView.AddComponent <ChangePage>();
    }
Exemplo n.º 6
0
    public BaseView JudgeShowUI(EUiId uiID)
    {
        //先判断窗体是不是正在显示(已经显出)
        if (dicShownUI.ContainsKey(uiID))//已经显示出来了
        {
            GetViewByUiID(uiID).Render();
            return(null);
        }
        BaseView baseUI = GetBaseUI(uiID);

        //如果baseui在字典里面没有查找到,说明该窗体还没有加载过
        if (baseUI == null)
        {
            //开始加载
            if (GameDefine.dicUIPath.ContainsKey(uiID))
            {
                GameObject theUI = null;

                string path = GameDefine.dicUIPath[uiID];
                theUI = ResourceManager.GetInstance.LoadPrefab(path, null);

                if (theUI != null)
                {
                    theUI.SetActive(true);
                    //把窗体放到对应的节点下面
                    baseUI = theUI.GetComponent <BaseView>();
                    Transform theRoot = GetUIRoot(baseUI);
                    GameTool.AddChildToParent(theRoot, theUI.transform);
                    theUI          = null;
                    dicAllUI[uiID] = baseUI;
                }
                else
                {
                    Debug.LogError("Load UI Null");
                }
            }
        }
        UpDateStack(baseUI);
        return(baseUI);
    }
Exemplo n.º 7
0
    private void ShowItem()
    {
        //获取物品的数量
        int itemCount = DataController.Instance.GetCfgCount(DataController.Instance.dicItem);

        //Debug.Log(itemCount);
        for (int i = 0; i < itemCount; i++)
        {
            GameObject item       = Instantiate(itemPrefab);
            ItemEntity itemEntity = item.AddComponent <ItemEntity>();
            itemEntity.itemId = i + 1;
            //先获取物品对应的图片名称
            string iconName = DataController.Instance.ReadCfg("IconName", i + 1, DataController.Instance.dicItem);
            item.GetComponent <Image>().sprite = Resources.Load <Sprite>("PackSprite/" + iconName);
            //把物品的图片缓存在物品实体类里面
            itemEntity.itemSprite = item.GetComponent <Image>().sprite;
            //存储物品的类型
            int typeIndex = int.Parse(DataController.Instance.ReadCfg("Type", i + 1, DataController.Instance.dicItem));
            itemEntity.goodsType = (E_GoodsType)typeIndex;
            //给物品的数量赋值
            GameTool.GetTheChildComponent <Text>(item, "Txt_Count").text = PackData.Instance.ReadCountById(i + 1).ToString();
            GameTool.AddChildToParent(content, item.transform);
        }
    }