Example #1
0
    /// <summary>
    /// 初始化视图配置信息
    /// </summary>
    private void InitConfig()
    {
        string fullPath = FileUtils.GetStreamingCFilePath(string.Format(StrDef.PATH_VIEWCONFIG));

        if (!File.Exists(fullPath))
        {
            Debug.LogError(string.Format("The file [{0}] is not exist!!", fullPath));
            throw new Exception(string.Format("The file [{0}] is not exist!!", fullPath));
        }
        try
        {
            TextReader txtreader = new StreamReader(fullPath);

            string strLine = txtreader.ReadLine();
            for (; strLine != null; strLine = txtreader.ReadLine())
            {
                strLine = strLine.Trim();

                if (strLine != "")
                {
                    if (strLine[0] == '#')
                    {
                        continue;
                    }

                    string[] keyPair = strLine.Split(new char[] { '=' }, 2);
                    if (keyPair.Length < 2)
                    {
                        continue;
                    }

                    string strKey = keyPair[0];

                    int iKey = 0;
                    if (!int.TryParse(strKey, out iKey))
                    {
                        continue;
                    }
                    EViewID dlgid = (EViewID)Enum.ToObject(typeof(EViewID), iKey);

                    if (!viewInfoDic.ContainsKey(dlgid))
                    {
                        string[] valPair = keyPair[1].Split(new char[] { '|' });
                        ViewInfo info    = new ViewInfo();
                        info.instType   = (EViewInstType)Enum.Parse(typeof(EViewInstType), valPair[0]);
                        info.prefabPath = valPair[1];
                        viewInfoDic.Add(dlgid, info);
                    }
                    else
                    {
                        Debug.LogWarning(string.Format("The key [{0}],value:[{1}] has already been existed", iKey, keyPair[1]));
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
Example #2
0
    public GameObject GetViewPrefab(EViewID viewID)
    {
        if (viewPrefabDic.ContainsKey(viewID))
        {
            return(viewPrefabDic[viewID]);
        }

        string   strUIPrefab = "";
        ViewInfo viewInfo    = null;

        if (!viewInfoDic.TryGetValue(viewID, out viewInfo))
        {
            Debug.LogWarning(string.Format("The EDialogID [{0}] is not configed", viewID.ToString()));
            return(null);
        }

        string     viewPrefabPath = string.Format("{0}/{1}", StrDef.VIEWDIR, viewInfo.prefabPath);
        GameObject viewPrefab     = AssetLoadMgr.Instance.LoadNativePrefab <GameObject>(viewPrefabPath);

        if (viewPrefab == null)
        {
            Debug.LogError(string.Format("The view [{0}] is not exists", viewPrefab.name));
            return(null);
        }
        viewPrefabDic.Add(viewID, viewPrefab);
        return(viewPrefab);
    }
Example #3
0
 /// <summary>
 /// 初始化
 /// </summary>
 private void InitPre(EViewID viewID, int viewInstID, GameObject view)
 {
     this.Model = CreateModel();
     this.View  = CreateView(view);
     this.createViewFinishListener += this.InitPost;
     this.dlgOpenListener          += this.AddListener;
     this.dlgCloseListener         += this.RemoveListener;
     this.SetViewID(viewID);
     this.SetViewInstID(viewInstID);
 }
Example #4
0
    /// <summary>
    /// 获取窗口实例化类型
    /// </summary>
    public EViewInstType GetViewInstType(EViewID viewID)
    {
        ViewInfo viewInfo = null;

        if (!viewInfoDic.TryGetValue(viewID, out viewInfo))
        {
            Debug.LogWarning(string.Format("The EDialogID [{0}] is not configed", viewID.ToString()));
            return(EViewInstType.None);
        }
        return(viewInfo.instType);
    }
Example #5
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="active">生成view时是否是激活的</param>
    /// <param name="native">true:the asset is in Resource folder,false:the asset is in other folder </param>
    protected Controller(EViewID viewID, int viewInstID, GameObject view, bool active = true, bool native = false)
    {
        try
        {
            if (null != view)
            {
                this.InitPre(viewID, viewInstID, view);
                this.IsLoaded = true;
            }
            else
            {
                Debug.LogError(string.Format("Create the View viewID:[{0}] fail.", viewID));
            }
        }
        catch (Exception ex)
        {
            Debug.Log(ex);
        }

        /*
         * string viewPath = string.Format("{0}/{1}", StrDef.VIEWDIR, viewName);
         * if (native)
         * {
         *      GameObject view = AssetLoadMgr.Instance.LoadnNativeAsset<GameObject>(viewPath);
         *      if (null != view)
         *      {
         *              Init(view);
         *      }
         *      else
         *      {
         *              Debug.LogError(string.Format("The view [{0}] is not exists", view.name));
         *      }
         * }
         * else
         * {
         *      ModelMgr.Instance.LoadModel(viewPath, new ModelMgr.ModelCallback((string name, GameObject view, object callbackData)=>
         *      {
         *              if(null != view)
         *              {
         *                      Init(view);
         *              }
         *              else
         *              {
         *                      Debug.LogError(string.Format("The view [{0}] is not exists", name));
         *              }
         *      }));
         * }
         */
    }
Example #6
0
    /// <summary>
    /// 创建窗口操作
    /// </summary>
    private Controller CreateView(EViewID viewID)
    {
        Controller controller = null;

        try
        {
            EViewInstType viewInstType = ViewConfig.Instance.GetViewInstType(viewID);
            foreach (KeyValuePair <int, Controller> keyval in listAllViews)
            {
                if (keyval.Value.GetViewID() == viewID)                  //已经打开的窗口 并且不允许多开的窗口  直接用这个实例返回
                {
                    if (viewInstType == EViewInstType.Single)
                    {
                        Debug.LogWarning(string.Format("The View viewID:[{0}] only allowed to be created one and it already exists ", viewID));
                        return(controller);
                    }
                    else
                    {
                        //TODO
                        break;
                    }
                }
            }

            GameObject viewPrefab = ViewConfig.Instance.GetViewPrefab(viewID);            //待修改
            if (viewPrefab != null)
            {
                GameObject viewObj    = GameObject.Instantiate <GameObject>(viewPrefab);
                int        viewInstID = seqView.nextval;
                controller = ViewConfig.Instance.CreateViewInstance(viewID, viewInstID, viewObj);                 //创建窗口控制层

                if (null != controller)
                {
                    listAllViews.Add(new KeyValuePair <int, Controller>(viewInstID, controller));
                }
                controller.OpenView();
                controller.createViewFinishListener();
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(string.Format("Create the View viewID:[{0}] fail,Msg:{1} exception:{2}", viewID, ex.Message, ex.StackTrace));
        }
        return(controller);
    }
Example #7
0
    public Controller CreateViewInstance(EViewID viewID, int viewInstID, GameObject viewObj)
    {
        Controller controller = null;

        switch (viewID)
        {
        case EViewID.MainMenu: controller = new MainMenuController(viewID, viewInstID, viewObj); break;

        case EViewID.PayLine: controller = new PayLineController(viewID, viewInstID, viewObj); break;

        case EViewID.Symbol: controller = new SymbolController(viewID, viewInstID, viewObj); break;
        }

        if (!controller.IsLoaded)
        {
            Debug.LogError(string.Format("The View viewID:[{0}] viewInstID:[{1}] Init fail", viewID, viewInstID));
            GameObject.Destroy(viewObj);
            controller = null;
            return(null);
        }

        return(controller);
    }
Example #8
0
    /// <summary>
    /// 获取窗口操作,所有窗口都通过这里打开
    /// </summary>
    public Controller GetView(EViewID viewID)
    {
        Controller    controller   = null;
        EViewInstType viewInstType = ViewConfig.Instance.GetViewInstType(viewID);

        foreach (KeyValuePair <int, Controller> keyval in listAllViews)
        {
            if (keyval.Value.GetViewID() == viewID)              //已经打开的窗口 并且不允许多开的窗口  直接用这个实例返回
            {
                if (viewInstType == EViewInstType.Single)
                {
                    controller = keyval.Value;
                    return(controller);
                }
                else
                {
                    //TODO
                    break;
                }
            }
        }
        controller = this.CreateView(viewID);
        return(controller);
    }
 public MainMenuController(EViewID viewID, int viewInstID, GameObject view, bool active = true, bool native = false)
     : base(viewID, viewInstID, view, active, native)
 {
 }
Example #10
0
 /// <summary>
 /// 设置窗口ID
 /// </summary>
 public void SetViewID(EViewID viewID)
 {
     this.Model.ViewID = viewID;
 }