Esempio 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }