Esempio n. 1
0
        private CBLuaPanel GetLuaPanel(string key, UIControlData uiControlData)
        {
            string   luaPath   = UIPathHelper.GetLuaPath(key);
            LuaTable scriptEnv = NgameLua.Load(luaPath);

            if (scriptEnv == null)
            {
                return(null);
            }
            CBLuaPanel pnl = new CBLuaPanel(luaPath, scriptEnv, uiControlData);

            return(pnl);
        }
Esempio n. 2
0
        /// <summary>
        /// 加载指定名称的“UI窗体”
        /// 功能:
        ///    1:根据“UI窗体名称”,加载预设克隆体。
        ///    2:根据不同预设克隆体中带的脚本中不同的“位置信息”,加载到“根窗体”下不同的节点。
        ///    3:隐藏刚创建的UI克隆体。
        ///    4:把克隆体,加入到“所有UI窗体”(缓存)集合中。
        ///
        /// </summary>
        /// <param name="uiFormName">UI窗体名称</param>
        private BaseUIForm LoadUIForm(string uiFormName)
        {
            string     strUIFormPaths   = uiFormName;       //UI窗体路径
            GameObject goCloneUIPrefabs = null;             //创建的UI克隆体预设
            BaseUIForm baseUiForm       = null;             //窗体基类


            //根据UI窗体名称,得到对应的加载路径
            //_DicFormsPaths.TryGetValue(uiFormName, out strUIFormPaths);
            //根据“UI窗体名称”,加载“预设克隆体”
            if (!string.IsNullOrEmpty(strUIFormPaths))
            {
                goCloneUIPrefabs = OpenUIPanel(strUIFormPaths);
            }

            UIControlData ctrlData = goCloneUIPrefabs.GetComponent <UIControlData>();
            CBLuaPanel    luaPanel = GetLuaPanel(uiFormName, ctrlData);

            if (luaPanel == null)
            {
                //C# 脚本逻辑
                IBindableUI uiA = Activator.CreateInstance(Type.GetType(uiFormName)) as IBindableUI;
                baseUiForm = uiA as BaseUIForm;
            }
            else
            {
                //Lua 逻辑
                baseUiForm = luaPanel as BaseUIForm;
            }
            baseUiForm.Source = goCloneUIPrefabs;
            if (ctrlData != null)
            {
                ctrlData.BindDataTo(baseUiForm);
            }
            //设置“UI克隆体”的父节点(根据克隆体中带的脚本中不同的“位置信息”)
            if (_TraCanvasTransfrom != null && goCloneUIPrefabs != null)
            {
                //baseUiForm = goCloneUIPrefabs.GetComponent<BaseUIForm>();
                if (baseUiForm == null)
                {
                    Debug.Log("baseUiForm==null! ,请先确认窗体预设对象上是否加载了baseUIForm的子类脚本! 参数 uiFormName=" + uiFormName);
                    return(null);
                }
                baseUiForm.OnReady();

                switch (baseUiForm.CurrentUIType.UIForms_Type)
                {
                case UIFormType.Normal:                     //普通窗体节点
                    goCloneUIPrefabs.transform.SetParent(_TraNormal, false);
                    break;

                case UIFormType.Fixed:                      //固定窗体节点
                    goCloneUIPrefabs.transform.SetParent(_TraFixed, false);
                    break;

                case UIFormType.PopUp:                      //弹出窗体节点
                    goCloneUIPrefabs.transform.SetParent(_TraPopUp, false);
                    break;

                default:
                    break;
                }

                //设置隐藏
                goCloneUIPrefabs.SetActive(false);
                //把克隆体,加入到“所有UI窗体”(缓存)集合中。
                _DicALLUIForms.Add(uiFormName, baseUiForm);
                return(baseUiForm);
            }
            else
            {
                Debug.Log("_TraCanvasTransfrom==null Or goCloneUIPrefabs==null!! ,Plese Check!, 参数uiFormName=" + uiFormName);
            }

            Debug.Log("出现不可以预估的错误,请检查,参数 uiFormName=" + uiFormName);
            return(null);
        }//Mehtod_end