Beispiel #1
0
 public override void SetChildPath(string path)
 {
     if (path != "" && childInterFace == null)
     {
         childInterFace = CreateUIPrefab(Parent.transform, path).GetComponent <IWindowInterface>();
     }
 }
Beispiel #2
0
        /// <summary>
        /// 创建UI视图实例
        /// </summary>
        /// <param name="path">Path.</param>
        /// <param name="id">Identifier.</param>
        /// <param name="offsetWidth">Offset width.</param>
        /// <param name="offsetHeight">Offset height.</param>
        /// <param name="index">Index.</param>
        protected static void InstantiateView(string path, string id = "", float offsetWidth = 0, float offsetHeight = 0, Transform parent = null)
        {
            if (UIModel.Windows == null)
            {
                UIModel.Windows = new Dictionary <string, GameObject>();
                UIModel.AllWindowTypeMapping = new Dictionary <string, string>();
            }

            if (_ctrls == null)
            {
                _ctrls = new Dictionary <string, T>();
            }
            string typeStr = typeof(T).ToString();

            if (id == "")
            {
                id = typeStr;
            }
            if (!UIModel.Windows.ContainsKey(id))
            {
                GameObject winObj = CreateUIPrefab(parent == null ? UIModel.UICanvas.transform : parent, path, offsetWidth, offsetHeight);
                if (winObj != null)
                {
                    winObj.name = id;
                    UIModel.Windows.Add(id, winObj);
                    _ctrl = winObj.GetComponent <T>();
                    if (_ctrl != null)
                    {
                        _ctrls.Add(id, _ctrl);
                        IWindowInterface iWindowInterface = (IWindowInterface)_ctrl;
                        iWindowInterface.SetId(id);
                        UIModel.AllWindowTypeMapping.Add(id, typeStr);
                    }
                    else
                    {
                        Debug.LogWarning("没绑定控制器脚本!");
                    }
                }
                Debug.LogWarning("InstantiateView - " + UIModel.Windows.Count + "," + _ctrls.Count + "," + (_ctrl));
            }
        }
 public MainViewModel(IWindowInterface windowfactory)
 {
     this._windowfactory = windowfactory;
 }