Exemple #1
0
    private GameObject buttonShop;    //关卡界面的按钮对象
    public override void OnInit()     //用于初始化UI控件
    {
        //给定ID
        this.id          = EUiId.ID_MainPanel; //对UI的ID赋值(重点,一定要赋值)
        this.IsKeepAbove = true;               //保持在最前面

        //用于查找游戏对象
        buttonRoleBag = UtilUI.findChild(this.gameObject, "BtnRoleBag").gameObject;
        butotnSet     = UtilUI.findChild(this.gameObject, "BtnSet").gameObject;
        buttonStage   = UtilUI.findChild(this.gameObject, "BtnStages").gameObject;
        buttonShop    = UtilUI.findChild(this.gameObject, "BtnShop").gameObject;

        UGUIEventListener.Get(buttonRoleBag).onClick += OnBtnRoleBag;//事件和方法的关联
        UGUIEventListener.Get(butotnSet).onClick      = OnBtnSet;
        UGUIEventListener.Get(buttonStage).onClick    = OnBtnStage;
        UGUIEventListener.Get(buttonShop).onClick     = OnBtnShop;


        //3:如果有动画添加动画
        //显示动画
        animShow = this.transform.DOLocalMoveY(805, 1.0f).From();
        animShow.Pause();
        animShow.SetAutoKill(false);

        //隐藏动画
        animHide = this.transform.DOLocalMoveY(805, 1.0f);
        animHide.Pause();
        animHide.SetAutoKill(false);
        animHide.OnComplete(delegate() { this.gameObject.SetActive(false); });
    }
Exemple #2
0
    public override void OnInit()
    {
        //指定id
        this.id = EUiId.ID_SaveGamePanel;

        buttonClose  = UtilUI.findChild(this.gameObject, "Cross").gameObject;
        buttonLoad_1 = UtilUI.findChild(this.gameObject, "Load_1").gameObject;
        buttonLoad_2 = UtilUI.findChild(this.gameObject, "Load_2").gameObject;
        buttonLoad_3 = UtilUI.findChild(this.gameObject, "Load_3").gameObject;
        buttonLoad_4 = UtilUI.findChild(this.gameObject, "Load_4").gameObject;
        buttonLoad_5 = UtilUI.findChild(this.gameObject, "Load_5").gameObject;
        buttonLoad_6 = UtilUI.findChild(this.gameObject, "Load_6").gameObject;

        UGUIEventListener.Get(buttonClose).onClick  = OnClose;
        UGUIEventListener.Get(buttonLoad_1).onClick = OnSave_1;
        UGUIEventListener.Get(buttonLoad_2).onClick = OnSave_2;
        UGUIEventListener.Get(buttonLoad_3).onClick = OnSave_3;
        UGUIEventListener.Get(buttonLoad_4).onClick = OnSave_4;
        UGUIEventListener.Get(buttonLoad_5).onClick = OnSave_5;
        UGUIEventListener.Get(buttonLoad_6).onClick = OnSave_6;

        textLog       = transform.Find("SaveGame").Find("LogInfo").GetComponent <Text>();
        textLog.color = new Color(textLog.color.r, textLog.color.g, textLog.color.b, 0.0f);


        buttonLoad_1.GetComponentInChildren <Text>().text = GameState.Instance.mapIDSaved(01);
        buttonLoad_2.GetComponentInChildren <Text>().text = GameState.Instance.mapIDSaved(02);
        buttonLoad_3.GetComponentInChildren <Text>().text = GameState.Instance.mapIDSaved(03);
        buttonLoad_4.GetComponentInChildren <Text>().text = GameState.Instance.mapIDSaved(04);
        buttonLoad_5.GetComponentInChildren <Text>().text = GameState.Instance.mapIDSaved(05);
        buttonLoad_6.GetComponentInChildren <Text>().text = GameState.Instance.mapIDSaved(06);
    }
Exemple #3
0
    public void init()
    {
        transUIRoot = transform;        //画布
        DontDestroyOnLoad(transUIRoot); //不销毁脚本所在的对象
        if (dicAllUI != null)
        {
            dicAllUI.Clear();
        }
        if (dicShowUI != null)
        {
            dicShowUI.Clear();
        }

        if (transUIRootKeepAbove == null)                                       //主界面根节点
        {
            transUIRootKeepAbove = new GameObject("UIRootKeepAbove").transform; //创建根节点(主界面)对象
            UtilUI.addChildToParent(transUIRoot, transUIRootKeepAbove);         //把此对象放在父对象下面
        }
        if (transUIRootNormal == null)                                          //普通UI根节点
        {
            transUIRootNormal = new GameObject("UIRootNormal").transform;
            UtilUI.addChildToParent(transUIRoot, transUIRootNormal);
        }

        //第一个UI
        showUI(EUiId.ID_MainPanel);//显示主界面UI
    }
Exemple #4
0
    public override void OnInit()
    {
        //指定id
        this.id = EUiId.ID_InfoPanel;

        buttonClose = UtilUI.findChild(this.gameObject, "Cross").gameObject;
        UGUIEventListener.Get(buttonClose).onClick = OnClose;
    }
Exemple #5
0
    public override void OnInit()
    {
        //指定id
        this.id = EUiId.ID_ExitPanel;

        buttonQuit  = UtilUI.findChild(this.gameObject, "Yes").gameObject;
        buttonClose = UtilUI.findChild(this.gameObject, "Maybe").gameObject;
        UGUIEventListener.Get(buttonQuit).onClick  = OnQuit;
        UGUIEventListener.Get(buttonClose).onClick = OnClose;
    }
Exemple #6
0
    public override void OnInit()
    {
        //指定id
        this.id = EUiId.ID_SettingPanel;

        buttonClose = UtilUI.findChild(this.gameObject, "Cross").gameObject;
        UGUIEventListener.Get(buttonClose).onClick = OnClose;

        bgmvolume       = transform.Find("Set").Find("VolumeSlider").GetComponent <Slider>();
        bgmvolume.value = PlayerPrefs.GetFloat("volume"); //初始化为之前的音量
    }
Exemple #7
0
 private void OnStage(GameObject obj)
 {
     print("Onstage");
     UtilUI.OpenLoadSceneHelper();
     UIPanelManager.Instance.showUI(EUiId.ID_LoadingPanel);
     LoadSceneHelper.Instance.loadScene("battle", delegate
     {
         UIPanelManager.Instance.hideUI(EUiId.ID_LoadingPanel); //隐藏loading界面
         UIPanelManager.Instance.showUI(EUiId.ID_MainPanel);    //显示主UI
     });
 }
Exemple #8
0
    public void showUI(EUiId id)
    {
        //1:加载当前UI
        if (dicShowUI.ContainsKey(id))//当前UI已经在显示列表中了,就直接返回
        {
            return;
        }
        UIBasePanel ui = getUI(id);               //通过ID获取需要显示的UI,从dicAllUI容器中获取,得到的是隐藏的UIPanel

        if (ui == null)                           //如果在dicAllUI容器中没有此UI,就从资源中读取ui预制体
        {
            string path = UIPath.getUiIdPath(id); //通过ID,获取对应的路径
            if (!string.IsNullOrEmpty(path))
            {
                GameObject prefab = Resources.Load <GameObject>(path);//加载资源
                //获取UI原始数据
                Vector2 offMin    = prefab.GetComponent <RectTransform>().offsetMin;
                Vector2 offMax    = prefab.GetComponent <RectTransform>().offsetMax;
                Vector2 anchorMin = prefab.GetComponent <RectTransform>().anchorMin;
                Vector2 anchorMax = prefab.GetComponent <RectTransform>().anchorMax;
                if (prefab != null)                                           //资源加载成功
                {
                    GameObject goWillShowUI = GameObject.Instantiate(prefab); //克隆游戏对象到层次面板上
                    //goWillShowUI.SetActive(true);
                    ui = goWillShowUI.GetComponent <UIBasePanel>();           //获取此对象上的UI
                    if (ui != null)
                    {
                        //Transform root = getUIRoot(ui);//获取UI所对应的根节点
                        //放入根节点下面
                        UtilUI.addChildToParent(transUIRoot, goWillShowUI.transform);//放入根节点下面
                        //数据的恢复
                        goWillShowUI.GetComponent <RectTransform>().offsetMin = offMin;
                        goWillShowUI.GetComponent <RectTransform>().offsetMax = offMax;
                        goWillShowUI.GetComponent <RectTransform>().anchorMin = anchorMin;
                        goWillShowUI.GetComponent <RectTransform>().anchorMax = anchorMax;
                        prefab = null;//清空预制体对象
                    }
                }
                else
                {
                    Debug.LogError("资源" + path + "不存在");
                }
            }
        }
        //2:更新显示其它的UI
        UpdateOtherUIState(ui);

        //3:显示当前UI
        dicAllUI[id]  = ui;
        dicShowUI[id] = ui;
        ui.show();
    }
Exemple #9
0
    private void OnBtnMenu(GameObject obj)
    {
        //UIPanelManager.Instance.showUI(EUiId.ID_LoadingPanel1);
        //LoadSceneHelper.Instance.loadScene("MyBoxStart", delegate
        //{
        //    UIPanelManager.Instance.hideUI(EUiId.ID_LoadingPanel1);
        //    UIPanelManager.Instance.showUI(EUiId.ID_MenuPanel);
        //});
        UIPanelManager.Instance.hideUI(this.id);
        UtilUI.clearMemory();
        GameObject uiRoot = GameObject.FindGameObjectWithTag("UIRoot");

        Destroy(uiRoot);
        SceneManager.LoadScene("MyBoxStart");
    }
Exemple #10
0
    public override void OnInit()
    {
        //指定id
        this.id = EUiId.ID_PausePanel;

        buttonContinue = UtilUI.findChild(this.gameObject, "ContinueButton").gameObject;
        buttonSave     = UtilUI.findChild(this.gameObject, "SaveButton").gameObject;
        buttonLoad     = UtilUI.findChild(this.gameObject, "LoadButton").gameObject;
        buttonExit     = UtilUI.findChild(this.gameObject, "ExitButton").gameObject;
        buttonMenu     = UtilUI.findChild(this.gameObject, "MenuButton").gameObject;
        UGUIEventListener.Get(buttonContinue).onClick = OnClose;
        UGUIEventListener.Get(buttonSave).onClick     = OnSave;
        UGUIEventListener.Get(buttonLoad).onClick     = OnLoad;
        UGUIEventListener.Get(buttonExit).onClick     = OnBtnExit;
        UGUIEventListener.Get(buttonMenu).onClick     = OnBtnMenu;

        sceneName = SceneManager.GetActiveScene().name;
    }
Exemple #11
0
    public override void OnInit()
    {
        //1:必须给定ID
        this.id = EUiId.ID_RoleBagPanel;
        //2:获取组件,如果有事件添加事件
        goBtnClose = UtilUI.findChild(this.gameObject, "BtnClose").gameObject;
        UGUIEventListener.Get(goBtnClose).onClick = OnBtnClose;
        //3:如果有动画添加动画
        //显示动画
        animShow = this.transform.DOLocalMoveY(805, 1.0f).From();
        animShow.Pause();
        animShow.SetAutoKill(false);

        //隐藏动画
        animHide = this.transform.DOLocalMoveY(805, 1.0f);
        animHide.Pause();
        animHide.SetAutoKill(false);
        animHide.OnComplete(delegate() { this.gameObject.SetActive(false); });
    }
Exemple #12
0
    public override void OnInit()
    {
        base.OnInit();
        this.id     = EUiId.ID_StagesPanel;
        buttonClose = UtilUI.findChild(this.gameObject, "BtnClose").gameObject;
        UGUIEventListener.Get(buttonClose).onClick = OnClose;

        //3:如果有动画添加动画
        //显示动画
        animShow = this.transform.DOLocalMoveY(805, 1.0f).From();
        animShow.Pause();
        animShow.SetAutoKill(false);

        //隐藏动画
        animHide = this.transform.DOLocalMoveY(805, 1.0f);
        animHide.Pause();
        animHide.SetAutoKill(false);
        animHide.OnComplete(() => { this.gameObject.SetActive(false); });
    }
Exemple #13
0
    public override void OnInit()//初始化UI控件
    {
        //给定ID
        this.id          = EUiId.ID_MenuPanel; //对UI的ID赋值(重点,一定要赋值)
        this.IsKeepAbove = true;               //保持始终不消失

        //用于查找游戏对象
        buttonSet      = UtilUI.findChild(this.gameObject, "SettingButton").gameObject;
        buttonExit     = UtilUI.findChild(this.gameObject, "ExitButton").gameObject;
        buttonInfo     = UtilUI.findChild(this.gameObject, "InfoButton").gameObject;
        buttonNewGame  = UtilUI.findChild(this.gameObject, "NewGameButton").gameObject;
        buttonLoadGame = UtilUI.findChild(this.gameObject, "LoadGameButton").gameObject;
        buttonInfinity = UtilUI.findChild(this.gameObject, "InfinityModButton").gameObject;
        UGUIEventListener.Get(buttonSet).onClick      = OnBtnSet;//事件和方法的关联
        UGUIEventListener.Get(buttonExit).onClick     = OnBtnExit;
        UGUIEventListener.Get(buttonInfo).onClick     = OnBtnInfo;
        UGUIEventListener.Get(buttonNewGame).onClick  = OnBtnNew;
        UGUIEventListener.Get(buttonLoadGame).onClick = OnBtnLoad;
        UGUIEventListener.Get(buttonInfinity).onClick = OnBtnInfinity;
    }
Exemple #14
0
    void Update()
    {
        if (asyn == null)
        {
            return;
        }
        int trueProgress = 0;

        if (asyn.progress < 0.9f)//异步加载场景的进度值
        {
            trueProgress = (int)asyn.progress * 100;
        }
        else
        {
            trueProgress = 100;
        }

        if (curLoadedValue < trueProgress)
        {
            curLoadedValue++;
        }
        imgLoading.fillAmount = curLoadedValue / 100f; //把百分比赋值给图片
        txtValue.text         = curLoadedValue + "%";  //赋值给文字
        if (curLoadedValue >= 100)
        {
            txtValue.text             = "生成世界中,请稍候";
            asyn.allowSceneActivation = true;
        }
        if (asyn.isDone)
        {
            if (actionAfterLoadScene != null)
            {
                actionAfterLoadScene();
            }
            imgLoading.fillAmount = 0.0f;
            asyn = null;
            UtilUI.clearMemory();
            this.gameObject.SetActive(false);
        }
    }