Ejemplo n.º 1
0
        /// <summary>
        /// 由数据获取对应元素的实例化预设
        /// </summary>
        /// <param name="data"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static UIElement GetInstanceElementByData(UIElementData data, Transform parent = null)
        {
            if (data == null)
            {
                Debug.LogError("Data为null");
                return(null);
            }

            if (bindingDict.ContainsKey(data.GetType()))
            {
                var bindingInfo = bindingDict[data.GetType()];
                if (!string.IsNullOrEmpty(bindingInfo.prefabPath))
                {
                    var source = data.GetUIPrefabSource();
                    var clone  = GameObject.Instantiate <UIElement>(source);
                    if (parent != null)
                    {
                        clone.transform.SetParent(parent);
                    }
                    clone.Data = data;
                    clone.transform.localPosition = Vector3.zero;
                    clone.transform.localRotation = Quaternion.identity;
                    clone.transform.localScale    = Vector3.one;

                    return(clone);
                }
            }

            return(null);
        }
        protected UIElement Get(UIElementData data)
        {
            UIElement ui          = null;
            var       bindingInfo = UIElement.GetBindingInfo(data);

            if (bindingInfo != null)
            {
                foreach (var item in poolList)
                {
                    if (item.GetType() == bindingInfo.uiType)
                    {
                        ui = item;
                        break;
                    }
                }
            }

            //从池中移除
            if (ui != null)
            {
                poolList.Remove(ui);
            }

            //实例化新的
            if (ui == null)
            {
                ui = UIElement.GetInstanceElementByData(data);
                if (ui == null)
                {
                    Debug.LogErrorFormat("{0}数据未绑定到元素!", data);
                }
            }

            return(ui);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取Data上绑定数据
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static UIBindingAttribute GetBindingInfo(UIElementData data)
        {
            if (bindingDict.ContainsKey(data.GetType()))
            {
                return(bindingDict[data.GetType()]);
            }

            return(null);
        }
Ejemplo n.º 4
0
        protected override bool SetData(UIElementData value)
        {
            if (!base.SetData(value))
            {
                return(false);
            }
            if (!typeof(UIPanelData).IsAssignableFrom(value.GetType()))
            {
                Debug.LogErrorFormat("Data类型必须继承自UIPanelData {0}", value);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        protected virtual bool SetData(UIElementData value)
        {
            if (value == null)
            {
                Debug.LogErrorFormat("不支持Data为空!");
                return(false);
            }
            if (GetBindingInfo(value).uiType != this.GetType())
            {
                Debug.LogErrorFormat("赋值的数据类型应为ui元素绑定的数据类型! UI:{0}  Data:{1}", this, value);
                return(false);
            }

            m_Data = value;
            SetDirty();

            return(true);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 打开
 /// </summary>
 /// <param name="state"></param>
 public virtual void Open(UIElementData state)
 {
     Data = state;
     Open();
 }
Ejemplo n.º 7
0
 public void LoadAsync(UIElementData data, Action <UIElement> element)
 {
 }
Ejemplo n.º 8
0
 public UIElement Load(UIElementData data)
 {
     return(UIElement.GetInstanceElementByData(data));
 }